Path: blob/main/src/vs/workbench/contrib/mcp/common/modelContextProtocolApps.ts
5258 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { MCP } from './modelContextProtocol.js';67type CallToolResult = MCP.CallToolResult;8type ContentBlock = MCP.ContentBlock;9type Implementation = MCP.Implementation;10type RequestId = MCP.RequestId;11type Tool = MCP.Tool;1213export namespace McpApps {14export type AppRequest =15| MCP.CallToolRequest16| MCP.ReadResourceRequest17| MCP.PingRequest18| (McpUiOpenLinkRequest & MCP.JSONRPCRequest)19| (McpUiUpdateModelContextRequest & MCP.JSONRPCRequest)20| (McpUiMessageRequest & MCP.JSONRPCRequest)21| (McpUiRequestDisplayModeRequest & MCP.JSONRPCRequest)22| (McpApps.McpUiInitializeRequest & MCP.JSONRPCRequest);2324export type AppNotification =25| McpUiInitializedNotification26| McpUiSizeChangedNotification27| MCP.LoggingMessageNotification28| CustomSandboxWheelNotification;2930export type AppMessage = AppRequest | AppNotification;3132export type HostResult =33| MCP.CallToolResult34| MCP.ReadResourceResult35| MCP.EmptyResult36| McpApps.McpUiInitializeResult37| McpUiMessageResult38| McpUiOpenLinkResult39| McpUiRequestDisplayModeResult;4041export type HostNotification =42| McpUiHostContextChangedNotification43| McpUiResourceTeardownRequest44| McpUiToolInputNotification45| McpUiToolInputPartialNotification46| McpUiToolResultNotification47| McpUiToolCancelledNotification48| McpUiSizeChangedNotification;4950export type HostMessage = HostResult | HostNotification;515253/** Custom notification used for bubbling up sandbox wheel events. */54export interface CustomSandboxWheelNotification {55method: 'ui/notifications/sandbox-wheel';56params: {57deltaMode: number;58deltaX: number;59deltaY: number;60deltaZ: number;61};62}63}6465/* eslint-disable local/code-no-unexternalized-strings */666768/**69* Schema updated from the Model Context Protocol Apps repository at70* https://github.com/modelcontextprotocol/ext-apps/blob/main/src/spec.types.ts71*72* ⚠️ Do not edit within `namespace` manually except to update schema versions ⚠️73*/74export namespace McpApps {75/**76* Current protocol version supported by this SDK.77*78* The SDK automatically handles version negotiation during initialization.79* Apps and hosts don't need to manage protocol versions manually.80*/81export const LATEST_PROTOCOL_VERSION = "2026-01-26";8283/**84* @description Color theme preference for the host environment.85*/86export type McpUiTheme = "light" | "dark";8788/**89* @description Display mode for UI presentation.90*/91export type McpUiDisplayMode = "inline" | "fullscreen" | "pip";9293/**94* @description CSS variable keys available to MCP apps for theming.95*/96export type McpUiStyleVariableKey =97// Background colors98| "--color-background-primary"99| "--color-background-secondary"100| "--color-background-tertiary"101| "--color-background-inverse"102| "--color-background-ghost"103| "--color-background-info"104| "--color-background-danger"105| "--color-background-success"106| "--color-background-warning"107| "--color-background-disabled"108// Text colors109| "--color-text-primary"110| "--color-text-secondary"111| "--color-text-tertiary"112| "--color-text-inverse"113| "--color-text-ghost"114| "--color-text-info"115| "--color-text-danger"116| "--color-text-success"117| "--color-text-warning"118| "--color-text-disabled"119| "--color-text-ghost"120// Border colors121| "--color-border-primary"122| "--color-border-secondary"123| "--color-border-tertiary"124| "--color-border-inverse"125| "--color-border-ghost"126| "--color-border-info"127| "--color-border-danger"128| "--color-border-success"129| "--color-border-warning"130| "--color-border-disabled"131// Ring colors132| "--color-ring-primary"133| "--color-ring-secondary"134| "--color-ring-inverse"135| "--color-ring-info"136| "--color-ring-danger"137| "--color-ring-success"138| "--color-ring-warning"139// Typography - Family140| "--font-sans"141| "--font-mono"142// Typography - Weight143| "--font-weight-normal"144| "--font-weight-medium"145| "--font-weight-semibold"146| "--font-weight-bold"147// Typography - Text Size148| "--font-text-xs-size"149| "--font-text-sm-size"150| "--font-text-md-size"151| "--font-text-lg-size"152// Typography - Heading Size153| "--font-heading-xs-size"154| "--font-heading-sm-size"155| "--font-heading-md-size"156| "--font-heading-lg-size"157| "--font-heading-xl-size"158| "--font-heading-2xl-size"159| "--font-heading-3xl-size"160// Typography - Text Line Height161| "--font-text-xs-line-height"162| "--font-text-sm-line-height"163| "--font-text-md-line-height"164| "--font-text-lg-line-height"165// Typography - Heading Line Height166| "--font-heading-xs-line-height"167| "--font-heading-sm-line-height"168| "--font-heading-md-line-height"169| "--font-heading-lg-line-height"170| "--font-heading-xl-line-height"171| "--font-heading-2xl-line-height"172| "--font-heading-3xl-line-height"173// Border radius174| "--border-radius-xs"175| "--border-radius-sm"176| "--border-radius-md"177| "--border-radius-lg"178| "--border-radius-xl"179| "--border-radius-full"180// Border width181| "--border-width-regular"182// Shadows183| "--shadow-hairline"184| "--shadow-sm"185| "--shadow-md"186| "--shadow-lg";187188/**189* @description Style variables for theming MCP apps.190*191* Individual style keys are optional - hosts may provide any subset of these values.192* Values are strings containing CSS values (colors, sizes, font stacks, etc.).193*194* Note: This type uses `Record<K, string | undefined>` rather than `Partial<Record<K, string>>`195* for compatibility with Zod schema generation. Both are functionally equivalent for validation.196*/197export type McpUiStyles = Record<McpUiStyleVariableKey, string | undefined>;198199/**200* @description Request to open an external URL in the host's default browser.201* @see {@link app.App.sendOpenLink} for the method that sends this request202*/203export interface McpUiOpenLinkRequest {204method: "ui/open-link";205params: {206/** @description URL to open in the host's browser */207url: string;208};209}210211/**212* @description Result from opening a URL.213* @see {@link McpUiOpenLinkRequest}214*/215export interface McpUiOpenLinkResult {216/** @description True if the host failed to open the URL (e.g., due to security policy). */217isError?: boolean;218/**219* Index signature required for MCP SDK `Protocol` class compatibility.220* Note: The schema intentionally omits this to enforce strict validation.221*/222[key: string]: unknown;223}224225/**226* @description Request to send a message to the host's chat interface.227* @see {@link app.App.sendMessage} for the method that sends this request228*/229export interface McpUiMessageRequest {230method: "ui/message";231params: {232/** @description Message role, currently only "user" is supported. */233role: "user";234/** @description Message content blocks (text, image, etc.). */235content: ContentBlock[];236};237}238239/**240* @description Result from sending a message.241* @see {@link McpUiMessageRequest}242*/243export interface McpUiMessageResult {244/** @description True if the host rejected or failed to deliver the message. */245isError?: boolean;246/**247* Index signature required for MCP SDK `Protocol` class compatibility.248* Note: The schema intentionally omits this to enforce strict validation.249*/250[key: string]: unknown;251}252253/**254* @description Notification that the sandbox proxy iframe is ready to receive content.255* @internal256* @see https://github.com/modelcontextprotocol/ext-apps/blob/main/specification/draft/apps.mdx#sandbox-proxy257*/258export interface McpUiSandboxProxyReadyNotification {259method: "ui/notifications/sandbox-proxy-ready";260params: {};261}262263/**264* @description Notification containing HTML resource for the sandbox proxy to load.265* @internal266* @see https://github.com/modelcontextprotocol/ext-apps/blob/main/specification/draft/apps.mdx#sandbox-proxy267*/268export interface McpUiSandboxResourceReadyNotification {269method: "ui/notifications/sandbox-resource-ready";270params: {271/** @description HTML content to load into the inner iframe. */272html: string;273/** @description Optional override for the inner iframe's sandbox attribute. */274sandbox?: string;275/** @description CSP configuration from resource metadata. */276csp?: McpUiResourceCsp;277/** @description Sandbox permissions from resource metadata. */278permissions?: McpUiResourcePermissions;279};280}281282/**283* @description Notification of UI size changes (bidirectional: Guest <-> Host).284* @see {@link app.App.sendSizeChanged} for the method to send this from Guest UI285*/286export interface McpUiSizeChangedNotification {287method: "ui/notifications/size-changed";288params: {289/** @description New width in pixels. */290width?: number;291/** @description New height in pixels. */292height?: number;293};294}295296/**297* @description Notification containing complete tool arguments (Host -> Guest UI).298*/299export interface McpUiToolInputNotification {300method: "ui/notifications/tool-input";301params: {302/** @description Complete tool call arguments as key-value pairs. */303arguments?: Record<string, unknown>;304};305}306307/**308* @description Notification containing partial/streaming tool arguments (Host -> Guest UI).309*/310export interface McpUiToolInputPartialNotification {311method: "ui/notifications/tool-input-partial";312params: {313/** @description Partial tool call arguments (incomplete, may change). */314arguments?: Record<string, unknown>;315};316}317318/**319* @description Notification containing tool execution result (Host -> Guest UI).320*/321export interface McpUiToolResultNotification {322method: "ui/notifications/tool-result";323/** @description Standard MCP tool execution result. */324params: CallToolResult;325}326327/**328* @description Notification that tool execution was cancelled (Host -> Guest UI).329* Host MUST send this if tool execution was cancelled for any reason (user action,330* sampling error, classifier intervention, etc.).331*/332export interface McpUiToolCancelledNotification {333method: "ui/notifications/tool-cancelled";334params: {335/** @description Optional reason for the cancellation (e.g., "user action", "timeout"). */336reason?: string;337};338}339340/**341* @description CSS blocks that can be injected by apps.342*/343export interface McpUiHostCss {344/** @description CSS for font loading (@font-face rules or @import statements). Apps must apply using applyHostFonts(). */345fonts?: string;346}347348/**349* @description Style configuration for theming MCP apps.350*/351export interface McpUiHostStyles {352/** @description CSS variables for theming the app. */353variables?: McpUiStyles;354/** @description CSS blocks that apps can inject. */355css?: McpUiHostCss;356}357358/**359* @description Rich context about the host environment provided to Guest UIs.360*/361export interface McpUiHostContext {362/** @description Allow additional properties for forward compatibility. */363[key: string]: unknown;364/** @description Metadata of the tool call that instantiated this App. */365toolInfo?: {366/** @description JSON-RPC id of the tools/call request. */367id?: RequestId;368/** @description Tool definition including name, inputSchema, etc. */369tool: Tool;370};371/** @description Current color theme preference. */372theme?: McpUiTheme;373/** @description Style configuration for theming the app. */374styles?: McpUiHostStyles;375/** @description How the UI is currently displayed. */376displayMode?: McpUiDisplayMode;377/** @description Display modes the host supports. */378availableDisplayModes?: string[];379/**380* @description Container dimensions. Represents the dimensions of the iframe or other381* container holding the app. Specify either width or maxWidth, and either height or maxHeight.382*/383containerDimensions?: (384| {385/** @description Fixed container height in pixels. */386height: number;387}388| {389/** @description Maximum container height in pixels. */390maxHeight?: number | undefined;391}392) &393(394| {395/** @description Fixed container width in pixels. */396width: number;397}398| {399/** @description Maximum container width in pixels. */400maxWidth?: number | undefined;401}402);403/** @description User's language and region preference in BCP 47 format. */404locale?: string;405/** @description User's timezone in IANA format. */406timeZone?: string;407/** @description Host application identifier. */408userAgent?: string;409/** @description Platform type for responsive design decisions. */410platform?: "web" | "desktop" | "mobile";411/** @description Device input capabilities. */412deviceCapabilities?: {413/** @description Whether the device supports touch input. */414touch?: boolean;415/** @description Whether the device supports hover interactions. */416hover?: boolean;417};418/** @description Mobile safe area boundaries in pixels. */419safeAreaInsets?: {420/** @description Top safe area inset in pixels. */421top: number;422/** @description Right safe area inset in pixels. */423right: number;424/** @description Bottom safe area inset in pixels. */425bottom: number;426/** @description Left safe area inset in pixels. */427left: number;428};429}430431/**432* @description Notification that host context has changed (Host -> Guest UI).433* @see {@link McpUiHostContext} for the full context structure434*/435export interface McpUiHostContextChangedNotification {436method: "ui/notifications/host-context-changed";437/** @description Partial context update containing only changed fields. */438params: McpUiHostContext;439}440441/**442* @description Request to update the agent's context without requiring a follow-up action (Guest UI -> Host).443*444* Unlike `notifications/message` which is for debugging/logging, this request is intended445* to update the Host's model context. Each request overwrites the previous context sent by the Guest UI.446* Unlike messages, context updates do not trigger follow-ups.447*448* The host will typically defer sending the context to the model until the next user message449* (including `ui/message`), and will only send the last update received.450*451* @see {@link app.App.updateModelContext} for the method that sends this request452*/453export interface McpUiUpdateModelContextRequest {454method: "ui/update-model-context";455params: {456/** @description Context content blocks (text, image, etc.). */457content?: ContentBlock[];458/** @description Structured content for machine-readable context data. */459structuredContent?: Record<string, unknown>;460};461}462463/**464* @description Request for graceful shutdown of the Guest UI (Host -> Guest UI).465* @see {@link app-bridge.AppBridge.teardownResource} for the host method that sends this466*/467export interface McpUiResourceTeardownRequest {468method: "ui/resource-teardown";469params: {};470}471472/**473* @description Result from graceful shutdown request.474* @see {@link McpUiResourceTeardownRequest}475*/476export interface McpUiResourceTeardownResult {477/**478* Index signature required for MCP SDK `Protocol` class compatibility.479*/480[key: string]: unknown;481}482483export interface McpUiSupportedContentBlockModalities {484/** @description Host supports text content blocks. */485text?: {};486/** @description Host supports image content blocks. */487image?: {};488/** @description Host supports audio content blocks. */489audio?: {};490/** @description Host supports resource content blocks. */491resource?: {};492/** @description Host supports resource link content blocks. */493resourceLink?: {};494/** @description Host supports structured content. */495structuredContent?: {};496}497498/**499* @description Capabilities supported by the host application.500* @see {@link McpUiInitializeResult} for the initialization result that includes these capabilities501*/502export interface McpUiHostCapabilities {503/** @description Experimental features (structure TBD). */504experimental?: {};505/** @description Host supports opening external URLs. */506openLinks?: {};507/** @description Host can proxy tool calls to the MCP server. */508serverTools?: {509/** @description Host supports tools/list_changed notifications. */510listChanged?: boolean;511};512/** @description Host can proxy resource reads to the MCP server. */513serverResources?: {514/** @description Host supports resources/list_changed notifications. */515listChanged?: boolean;516};517/** @description Host accepts log messages. */518logging?: {};519/** @description Sandbox configuration applied by the host. */520sandbox?: {521/** @description Permissions granted by the host (camera, microphone, geolocation). */522permissions?: McpUiResourcePermissions;523/** @description CSP domains approved by the host. */524csp?: McpUiResourceCsp;525};526/** @description Host accepts context updates (ui/update-model-context) to be included in the model's context for future turns. */527updateModelContext?: McpUiSupportedContentBlockModalities;528/** @description Host supports receiving content messages (ui/message) from the View. */529message?: McpUiSupportedContentBlockModalities;530}531532/**533* @description Capabilities provided by the View (App).534* @see {@link McpUiInitializeRequest} for the initialization request that includes these capabilities535*/536export interface McpUiAppCapabilities {537/** @description Experimental features (structure TBD). */538experimental?: {};539/** @description App exposes MCP-style tools that the host can call. */540tools?: {541/** @description App supports tools/list_changed notifications. */542listChanged?: boolean;543};544/**545* @description Display modes the app supports. See Display Modes section of the spec for details.546* @example ["inline", "fullscreen"]547*/548availableDisplayModes?: McpUiDisplayMode[];549}550551/**552* @description Initialization request sent from Guest UI to Host.553* @see {@link app.App.connect} for the method that sends this request554*/555export interface McpUiInitializeRequest {556method: "ui/initialize";557params: {558/** @description App identification (name and version). */559appInfo: Implementation;560/** @description Features and capabilities this app provides. */561appCapabilities: McpUiAppCapabilities;562/** @description Protocol version this app supports. */563protocolVersion: string;564};565}566567/**568* @description Initialization result returned from Host to Guest UI.569* @see {@link McpUiInitializeRequest}570*/571export interface McpUiInitializeResult {572/** @description Negotiated protocol version string (e.g., "2025-11-21"). */573protocolVersion: string;574/** @description Host application identification and version. */575hostInfo: Implementation;576/** @description Features and capabilities provided by the host. */577hostCapabilities: McpUiHostCapabilities;578/** @description Rich context about the host environment. */579hostContext: McpUiHostContext;580/**581* Index signature required for MCP SDK `Protocol` class compatibility.582* Note: The schema intentionally omits this to enforce strict validation.583*/584[key: string]: unknown;585}586587/**588* @description Notification that Guest UI has completed initialization (Guest UI -> Host).589* @see {@link app.App.connect} for the method that sends this notification590*/591export interface McpUiInitializedNotification {592method: "ui/notifications/initialized";593params?: {};594}595596/**597* @description Content Security Policy configuration for UI resources.598*/599export interface McpUiResourceCsp {600/** @description Origins for network requests (fetch/XHR/WebSocket). */601connectDomains?: string[];602/** @description Origins for static resources (scripts, images, styles, fonts). */603resourceDomains?: string[];604/** @description Origins for nested iframes (frame-src directive). */605frameDomains?: string[];606/** @description Allowed base URIs for the document (base-uri directive). */607baseUriDomains?: string[];608}609610/**611* @description Sandbox permissions requested by the UI resource.612* Hosts MAY honor these by setting appropriate iframe `allow` attributes.613* Apps SHOULD NOT assume permissions are granted; use JS feature detection as fallback.614*/615export interface McpUiResourcePermissions {616/** @description Request camera access (Permission Policy `camera` feature). */617camera?: {};618/** @description Request microphone access (Permission Policy `microphone` feature). */619microphone?: {};620/** @description Request geolocation access (Permission Policy `geolocation` feature). */621geolocation?: {};622/** @description Request clipboard write access (Permission Policy `clipboard-write` feature). */623clipboardWrite?: {};624}625626/**627* @description UI Resource metadata for security and rendering configuration.628*/629export interface McpUiResourceMeta {630/** @description Content Security Policy configuration. */631csp?: McpUiResourceCsp;632/** @description Sandbox permissions requested by the UI. */633permissions?: McpUiResourcePermissions;634/** @description Dedicated origin for widget sandbox. */635domain?: string;636/** @description Visual boundary preference - true if UI prefers a visible border. */637prefersBorder?: boolean;638}639640/**641* @description Request to change the display mode of the UI.642* The host will respond with the actual display mode that was set,643* which may differ from the requested mode if not supported.644* @see {@link app.App.requestDisplayMode} for the method that sends this request645*/646export interface McpUiRequestDisplayModeRequest {647method: "ui/request-display-mode";648params: {649/** @description The display mode being requested. */650mode: McpUiDisplayMode;651};652}653654/**655* @description Result from requesting a display mode change.656* @see {@link McpUiRequestDisplayModeRequest}657*/658export interface McpUiRequestDisplayModeResult {659/** @description The display mode that was actually set. May differ from requested if not supported. */660mode: McpUiDisplayMode;661/**662* Index signature required for MCP SDK `Protocol` class compatibility.663* Note: The schema intentionally omits this to enforce strict validation.664*/665[key: string]: unknown;666}667668/**669* @description Tool visibility scope - who can access the tool.670*/671export type McpUiToolVisibility = "model" | "app";672673/**674* @description UI-related metadata for tools.675*/676export interface McpUiToolMeta {677/**678* URI of the UI resource to display for this tool, if any.679* This is converted to `_meta["ui/resourceUri"]`.680*681* @example "ui://weather/widget.html"682*/683resourceUri?: string;684/**685* @description Who can access this tool. Default: ["model", "app"]686* - "model": Tool visible to and callable by the agent687* - "app": Tool callable by the app from this server only688*/689visibility?: McpUiToolVisibility[];690}691692/**693* Method string constants for MCP Apps protocol messages.694*695* These constants provide a type-safe way to check message methods without696* accessing internal Zod schema properties. External libraries should use697* these constants instead of accessing `schema.shape.method._def.values[0]`.698*699* @example700* ```typescript701* import { SANDBOX_PROXY_READY_METHOD } from '@modelcontextprotocol/ext-apps';702*703* if (event.data.method === SANDBOX_PROXY_READY_METHOD) {704* // Handle sandbox proxy ready notification705* }706* ```707*/708export const OPEN_LINK_METHOD: McpUiOpenLinkRequest["method"] = "ui/open-link";709export const MESSAGE_METHOD: McpUiMessageRequest["method"] = "ui/message";710export const SANDBOX_PROXY_READY_METHOD: McpUiSandboxProxyReadyNotification["method"] =711"ui/notifications/sandbox-proxy-ready";712export const SANDBOX_RESOURCE_READY_METHOD: McpUiSandboxResourceReadyNotification["method"] =713"ui/notifications/sandbox-resource-ready";714export const SIZE_CHANGED_METHOD: McpUiSizeChangedNotification["method"] =715"ui/notifications/size-changed";716export const TOOL_INPUT_METHOD: McpUiToolInputNotification["method"] =717"ui/notifications/tool-input";718export const TOOL_INPUT_PARTIAL_METHOD: McpUiToolInputPartialNotification["method"] =719"ui/notifications/tool-input-partial";720export const TOOL_RESULT_METHOD: McpUiToolResultNotification["method"] =721"ui/notifications/tool-result";722export const TOOL_CANCELLED_METHOD: McpUiToolCancelledNotification["method"] =723"ui/notifications/tool-cancelled";724export const HOST_CONTEXT_CHANGED_METHOD: McpUiHostContextChangedNotification["method"] =725"ui/notifications/host-context-changed";726export const RESOURCE_TEARDOWN_METHOD: McpUiResourceTeardownRequest["method"] =727"ui/resource-teardown";728export const INITIALIZE_METHOD: McpUiInitializeRequest["method"] =729"ui/initialize";730export const INITIALIZED_METHOD: McpUiInitializedNotification["method"] =731"ui/notifications/initialized";732export const REQUEST_DISPLAY_MODE_METHOD: McpUiRequestDisplayModeRequest["method"] =733"ui/request-display-mode";734export const UPDATE_MODEL_CONTEXT_METHOD: McpUiUpdateModelContextRequest["method"] =735"ui/update-model-context";736}737738739