useMcp(options)
React hook for managing MCP connections.
url- SSE endpoint URL (required)identity- User/Client identifier (required)authToken- Authentication token (optional)autoConnect- Auto-connect SSE on mount (default: true)autoInitialize- Auto-load sessions on mount (default: true)onConnectionEvent- Connection event handler (optional)onLog- Debug log handler (optional)
useMcpApps(mcpClient) (Deprecated)
[!WARNING]React hook for rendering MCP Apps (interactive tool UIs in a sandboxed iframe via AppBridge).
useMcpAppsis officially deprecated. You should now import<McpAppRenderer>andgetMcpAppMetadatadirectly from@mcp-ts/sdk/client/reactand use them without wrapping them in this hook.
mcpClient— Object shaped likeuseMcp()’s return (at minimumconnectionswith tools and optionalsseClientfor forwarding). May benullwhen disconnected.
getAppMetadata(toolName: string)— Resolves UI metadata for a tool (stripstool_<id>_prefixes).McpAppRenderer— Stable, memoized component; pass per-tool-call props.
getMcpAppMetadata(mcpClient, toolName, input?)
Returns: McpAppMetadata | undefined
tool.mcpApp.resourceUri, then tool._meta?.ui?.resourceUri, then tool._meta?.['ui/resourceUri'].
When input is provided, it automatically unwraps AI agent proxy calls (like mcp_execute_tool), resolves the true tool target, and returns the underlying UI metadata.
McpAppRenderer Component
The standalone <McpAppRenderer> element is the primary engine for rendering inline MCP interactive apps inside a secure iframe Sandbox using AppBridge.
For ui:// / mcp-app:// HTML (and any injected HTML path), you must pass sandbox with your hosted proxy page (see MCP Apps).
Props (McpAppRendererProps):
useAppHost(client, iframeRef, options?)
Lower-level React helper that constructs an AppHost for a given HTMLIFrameElement ref. Accepts the same options as AppHostOptions (sandbox, callbacks, hostContext, etc.). The hook currently initializes only when client is non-null; prefer McpAppRenderer for the usual useMcp integration.
AppHost class
Core MCP App host: AppBridge setup, sandbox proxy launch, resource fetch/cache, and tool I/O. Import from @mcp-ts/sdk/client.
Constructor
client— UsuallySSEClient. Ifnull, you must implementonCallTool/onReadResource(and any other paths your app uses) yourself.options— See below.
AppHostOptions (selected fields)
debug?: booleansandbox?: SandboxConfig— Required when launching with HTML to inject (fetchedui://HTML orhtmlstring).hostContext?: Record<string, unknown>— Theme, locale, dimensions, etc.; synced to the guest via AppBridge.onCallTool,onReadResource,onFallbackRequest,onMessage,onOpenLink,onLoggingMessage,onSizeChanged,onError,onRequestDisplayMode— Optional; override defaults (forwarding toclientwhen provided and connected).
Methods
| Method | Description |
|---|---|
start(): Promise<void> | Prepares handlers; bridge connects during launch(). |
preload(tools: Array<{ _meta?: unknown }>): void | Warms resource cache for tools with UI metadata. |
launch(source: { uri?: string; html?: string }, sessionId?: string): Promise<void> | Loads UI (fetch uri or use html), runs sandbox proxy when needed, connects AppBridge. |
sendToolInput(args: Record<string, unknown>): void | Sends tool arguments to the guest. |
sendToolResult(result: unknown): void | Sends final tool result. |
sendToolCancelled(reason: string): void | Notifies cancellation. |
sendToolInputPartial(params: unknown): void | Streaming partial input. |
setHostContext(context: Record<string, unknown>): void | Updates host context on the bridge. |
Constants
DEFAULT_MCP_APP_CSP— Sensible baseline CSP object forsandbox.csp(extend or narrow per app).APP_HOST_DEFAULTS— Default timeout, host info label, URI schemes, theme/platform hints.SANDBOX_PROXY_READY_METHOD/SANDBOX_RESOURCE_READY_METHOD— Re-exported from@modelcontextprotocol/ext-appsfor custom sandbox pages (same as importing from that package directly).
SSEClient
Lower-level SSE client for custom implementations.
Methods
connect(): void
Connect to the SSE endpoint.
disconnect(): void
Disconnect from the SSE endpoint.
getSessions(): Promise<Session[]>
Get all user sessions.
connectToServer(config): Promise<{ sessionId: string }>
Connect to an MCP server.
disconnectFromServer(sessionId: string): Promise<void>
Disconnect from an MCP server.
callTool(sessionId, name, args): Promise<any>
Call a tool on a connected server.
listTools(sessionId): Promise<Tool[]>
List tools for a session.