Skip to main content
import { getUiCapability, EXTENSION_ID, RESOURCE_MIME_TYPE } from "sunpeak/mcp";

Overview

Not all MCP hosts support Apps yet. Servers should check whether the connecting host supports MCP Apps before registering UI-enabled tools — if it doesn’t, register text-only fallback tools instead. This keeps your server compatible with every host while delivering rich UIs where available.

getUiCapability

Extracts the MCP Apps capability from the client’s extensions field.

Signature

function getUiCapability(
  clientCapabilities: ClientCapabilities | null | undefined,
): McpUiClientCapabilities | undefined

Returns

return
McpUiClientCapabilities | undefined
The capability object if the host supports MCP Apps, or undefined if not.
mimeTypes
string[]
Supported MIME types. Must include "text/html;profile=mcp-app" for MCP Apps support.

Usage

Use server.server.oninitialized to check capabilities after the MCP handshake:
import {
  getUiCapability,
  registerAppTool,
  RESOURCE_MIME_TYPE,
} from "sunpeak/mcp";

server.server.oninitialized = () => {
  const clientCapabilities = server.server.getClientCapabilities();
  const uiCap = getUiCapability(clientCapabilities);

  if (uiCap?.mimeTypes?.includes(RESOURCE_MIME_TYPE)) {
    // Host supports MCP Apps — register tool with UI
    registerAppTool(
      server,
      "weather",
      {
        description: "Get weather with interactive dashboard",
        _meta: { ui: { resourceUri: "ui://weather/dashboard" } },
      },
      weatherHandler,
    );
  } else {
    // Host does not support MCP Apps — register text-only fallback
    server.registerTool(
      "weather",
      { description: "Get weather information" },
      textWeatherHandler,
    );
  }
};

EXTENSION_ID

The extension identifier used in the MCP extensions field for capability negotiation.
const EXTENSION_ID = "io.modelcontextprotocol/ui";
Hosts advertise MCP Apps support by including this key in their extensions capabilities during the MCP initialization handshake. getUiCapability reads from this key internally.