Path: blob/main/src/vs/workbench/contrib/mcp/common/modelContextProtocolApps.ts
4780 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;1213//#region utilities1415export namespace McpApps {16export type AppRequest =17| MCP.CallToolRequest18| MCP.ReadResourceRequest19| MCP.PingRequest20| (McpUiOpenLinkRequest & MCP.JSONRPCRequest)21| (McpUiMessageRequest & MCP.JSONRPCRequest)22| (McpUiRequestDisplayModeRequest & MCP.JSONRPCRequest)23| (McpApps.McpUiInitializeRequest & MCP.JSONRPCRequest);2425export type AppNotification =26| McpUiInitializedNotification27| McpUiSizeChangedNotification28| MCP.LoggingMessageNotification;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;51}5253/* eslint-disable local/code-no-unexternalized-strings */545556/**57* Schema updated from the Model Context Protocol Apps repository at58* https://github.com/modelcontextprotocol/ext-apps/blob/main/src/spec.types.ts59*60* ⚠️ Do not edit within `namespace` manually except to update schema versions ⚠️61*/62export namespace McpApps {63/*64* Current protocol version supported by this SDK.65*66* The SDK automatically handles version negotiation during initialization.67* Apps and hosts don't need to manage protocol versions manually.68*/69export const LATEST_PROTOCOL_VERSION = "2025-11-21";7071/**72* @description Color theme preference for the host environment.73*/74export type McpUiTheme = "light" | "dark";7576/**77* @description Display mode for UI presentation.78*/79export type McpUiDisplayMode = "inline" | "fullscreen" | "pip";8081/**82* @description CSS variable keys available to MCP apps for theming.83*/84export type McpUiStyleVariableKey =85// Background colors86| "--color-background-primary"87| "--color-background-secondary"88| "--color-background-tertiary"89| "--color-background-inverse"90| "--color-background-ghost"91| "--color-background-info"92| "--color-background-danger"93| "--color-background-success"94| "--color-background-warning"95| "--color-background-disabled"96// Text colors97| "--color-text-primary"98| "--color-text-secondary"99| "--color-text-tertiary"100| "--color-text-inverse"101| "--color-text-ghost"102| "--color-text-info"103| "--color-text-danger"104| "--color-text-success"105| "--color-text-warning"106| "--color-text-disabled"107| "--color-text-ghost"108// Border colors109| "--color-border-primary"110| "--color-border-secondary"111| "--color-border-tertiary"112| "--color-border-inverse"113| "--color-border-ghost"114| "--color-border-info"115| "--color-border-danger"116| "--color-border-success"117| "--color-border-warning"118| "--color-border-disabled"119// Ring colors120| "--color-ring-primary"121| "--color-ring-secondary"122| "--color-ring-inverse"123| "--color-ring-info"124| "--color-ring-danger"125| "--color-ring-success"126| "--color-ring-warning"127// Typography - Family128| "--font-sans"129| "--font-mono"130// Typography - Weight131| "--font-weight-normal"132| "--font-weight-medium"133| "--font-weight-semibold"134| "--font-weight-bold"135// Typography - Text Size136| "--font-text-xs-size"137| "--font-text-sm-size"138| "--font-text-md-size"139| "--font-text-lg-size"140// Typography - Heading Size141| "--font-heading-xs-size"142| "--font-heading-sm-size"143| "--font-heading-md-size"144| "--font-heading-lg-size"145| "--font-heading-xl-size"146| "--font-heading-2xl-size"147| "--font-heading-3xl-size"148// Typography - Text Line Height149| "--font-text-xs-line-height"150| "--font-text-sm-line-height"151| "--font-text-md-line-height"152| "--font-text-lg-line-height"153// Typography - Heading Line Height154| "--font-heading-xs-line-height"155| "--font-heading-sm-line-height"156| "--font-heading-md-line-height"157| "--font-heading-lg-line-height"158| "--font-heading-xl-line-height"159| "--font-heading-2xl-line-height"160| "--font-heading-3xl-line-height"161// Border radius162| "--border-radius-xs"163| "--border-radius-sm"164| "--border-radius-md"165| "--border-radius-lg"166| "--border-radius-xl"167| "--border-radius-full"168// Border width169| "--border-width-regular"170// Shadows171| "--shadow-hairline"172| "--shadow-sm"173| "--shadow-md"174| "--shadow-lg";175176/**177* @description Style variables for theming MCP apps.178*179* Individual style keys are optional - hosts may provide any subset of these values.180* Values are strings containing CSS values (colors, sizes, font stacks, etc.).181*182* Note: This type uses `Record<K, string | undefined>` rather than `Partial<Record<K, string>>`183* for compatibility with Zod schema generation. Both are functionally equivalent for validation.184*/185export type McpUiStyles = Record<McpUiStyleVariableKey, string | undefined>;186187/**188* @description Request to open an external URL in the host's default browser.189* @see {@link app.App.sendOpenLink} for the method that sends this request190*/191export interface McpUiOpenLinkRequest {192method: "ui/open-link";193params: {194/** @description URL to open in the host's browser */195url: string;196};197}198199/**200* @description Result from opening a URL.201* @see {@link McpUiOpenLinkRequest}202*/203export interface McpUiOpenLinkResult {204/** @description True if the host failed to open the URL (e.g., due to security policy). */205isError?: boolean;206/**207* Index signature required for MCP SDK `Protocol` class compatibility.208* Note: The schema intentionally omits this to enforce strict validation.209*/210[key: string]: unknown;211}212213/**214* @description Request to send a message to the host's chat interface.215* @see {@link app.App.sendMessage} for the method that sends this request216*/217export interface McpUiMessageRequest {218method: "ui/message";219params: {220/** @description Message role, currently only "user" is supported. */221role: "user";222/** @description Message content blocks (text, image, etc.). */223content: ContentBlock[];224};225}226227/**228* @description Result from sending a message.229* @see {@link McpUiMessageRequest}230*/231export interface McpUiMessageResult {232/** @description True if the host rejected or failed to deliver the message. */233isError?: boolean;234/**235* Index signature required for MCP SDK `Protocol` class compatibility.236* Note: The schema intentionally omits this to enforce strict validation.237*/238[key: string]: unknown;239}240241/**242* @description Notification that the sandbox proxy iframe is ready to receive content.243* @internal244* @see https://github.com/modelcontextprotocol/ext-apps/blob/main/specification/draft/apps.mdx#sandbox-proxy245*/246export interface McpUiSandboxProxyReadyNotification {247method: "ui/notifications/sandbox-proxy-ready";248params: {};249}250251/**252* @description Notification containing HTML resource for the sandbox proxy to load.253* @internal254* @see https://github.com/modelcontextprotocol/ext-apps/blob/main/specification/draft/apps.mdx#sandbox-proxy255*/256export interface McpUiSandboxResourceReadyNotification {257method: "ui/notifications/sandbox-resource-ready";258params: {259/** @description HTML content to load into the inner iframe. */260html: string;261/** @description Optional override for the inner iframe's sandbox attribute. */262sandbox?: string;263/** @description CSP configuration from resource metadata. */264csp?: {265/** @description Origins for network requests (fetch/XHR/WebSocket). */266connectDomains?: string[];267/** @description Origins for static resources (scripts, images, styles, fonts). */268resourceDomains?: string[];269};270};271}272273/**274* @description Notification of UI size changes (bidirectional: Guest <-> Host).275* @see {@link app.App.sendSizeChanged} for the method to send this from Guest UI276*/277export interface McpUiSizeChangedNotification {278method: "ui/notifications/size-changed";279params: {280/** @description New width in pixels. */281width?: number;282/** @description New height in pixels. */283height?: number;284};285}286287/**288* @description Notification containing complete tool arguments (Host -> Guest UI).289*/290export interface McpUiToolInputNotification {291method: "ui/notifications/tool-input";292params: {293/** @description Complete tool call arguments as key-value pairs. */294arguments?: Record<string, unknown>;295};296}297298/**299* @description Notification containing partial/streaming tool arguments (Host -> Guest UI).300*/301export interface McpUiToolInputPartialNotification {302method: "ui/notifications/tool-input-partial";303params: {304/** @description Partial tool call arguments (incomplete, may change). */305arguments?: Record<string, unknown>;306};307}308309/**310* @description Notification containing tool execution result (Host -> Guest UI).311*/312export interface McpUiToolResultNotification {313method: "ui/notifications/tool-result";314/** @description Standard MCP tool execution result. */315params: CallToolResult;316}317318/**319* @description Notification that tool execution was cancelled (Host -> Guest UI).320* Host MUST send this if tool execution was cancelled for any reason (user action,321* sampling error, classifier intervention, etc.).322*/323export interface McpUiToolCancelledNotification {324method: "ui/notifications/tool-cancelled";325params: {326/** @description Optional reason for the cancellation (e.g., "user action", "timeout"). */327reason?: string;328};329}330331/**332* @description CSS blocks that can be injected by apps.333*/334export interface McpUiHostCss {335/** @description CSS for font loading (@font-face rules or @import statements). Apps must apply using applyHostFonts(). */336fonts?: string;337}338339/**340* @description Style configuration for theming MCP apps.341*/342export interface McpUiHostStyles {343/** @description CSS variables for theming the app. */344variables?: McpUiStyles;345/** @description CSS blocks that apps can inject. */346css?: McpUiHostCss;347}348349/**350* @description Rich context about the host environment provided to Guest UIs.351*/352export interface McpUiHostContext {353/** @description Allow additional properties for forward compatibility. */354[key: string]: unknown;355/** @description Metadata of the tool call that instantiated this App. */356toolInfo?: {357/** @description JSON-RPC id of the tools/call request. */358id: RequestId;359/** @description Tool definition including name, inputSchema, etc. */360tool: Tool;361};362/** @description Current color theme preference. */363theme?: McpUiTheme;364/** @description Style configuration for theming the app. */365styles?: McpUiHostStyles;366/** @description How the UI is currently displayed. */367displayMode?: McpUiDisplayMode;368/** @description Display modes the host supports. */369availableDisplayModes?: string[];370/**371* @description Container dimensions. Represents the dimensions of the iframe or other372* container holding the app. Specify either width or maxWidth, and either height or maxHeight.373*/374containerDimensions?: (375| {376/** @description Fixed container height in pixels. */377height: number;378}379| {380/** @description Maximum container height in pixels. */381maxHeight?: number | undefined;382}383) &384(385| {386/** @description Fixed container width in pixels. */387width: number;388}389| {390/** @description Maximum container width in pixels. */391maxWidth?: number | undefined;392}393);394/** @description User's language and region preference in BCP 47 format. */395locale?: string;396/** @description User's timezone in IANA format. */397timeZone?: string;398/** @description Host application identifier. */399userAgent?: string;400/** @description Platform type for responsive design decisions. */401platform?: "web" | "desktop" | "mobile";402/** @description Device input capabilities. */403deviceCapabilities?: {404/** @description Whether the device supports touch input. */405touch?: boolean;406/** @description Whether the device supports hover interactions. */407hover?: boolean;408};409/** @description Mobile safe area boundaries in pixels. */410safeAreaInsets?: {411/** @description Top safe area inset in pixels. */412top: number;413/** @description Right safe area inset in pixels. */414right: number;415/** @description Bottom safe area inset in pixels. */416bottom: number;417/** @description Left safe area inset in pixels. */418left: number;419};420}421422/**423* @description Notification that host context has changed (Host -> Guest UI).424* @see {@link McpUiHostContext} for the full context structure425*/426export interface McpUiHostContextChangedNotification {427method: "ui/notifications/host-context-changed";428/** @description Partial context update containing only changed fields. */429params: McpUiHostContext;430}431432/**433* @description Request for graceful shutdown of the Guest UI (Host -> Guest UI).434* @see {@link app-bridge.AppBridge.teardownResource} for the host method that sends this435*/436export interface McpUiResourceTeardownRequest {437method: "ui/resource-teardown";438params: {};439}440441/**442* @description Result from graceful shutdown request.443* @see {@link McpUiResourceTeardownRequest}444*/445export interface McpUiResourceTeardownResult {446/**447* Index signature required for MCP SDK `Protocol` class compatibility.448*/449[key: string]: unknown;450}451452/**453* @description Capabilities supported by the host application.454* @see {@link McpUiInitializeResult} for the initialization result that includes these capabilities455*/456export interface McpUiHostCapabilities {457/** @description Experimental features (structure TBD). */458experimental?: {};459/** @description Host supports opening external URLs. */460openLinks?: {};461/** @description Host can proxy tool calls to the MCP server. */462serverTools?: {463/** @description Host supports tools/list_changed notifications. */464listChanged?: boolean;465};466/** @description Host can proxy resource reads to the MCP server. */467serverResources?: {468/** @description Host supports resources/list_changed notifications. */469listChanged?: boolean;470};471/** @description Host accepts log messages. */472logging?: {};473}474475/**476* @description Capabilities provided by the Guest UI (App).477* @see {@link McpUiInitializeRequest} for the initialization request that includes these capabilities478*/479export interface McpUiAppCapabilities {480/** @description Experimental features (structure TBD). */481experimental?: {};482/** @description App exposes MCP-style tools that the host can call. */483tools?: {484/** @description App supports tools/list_changed notifications. */485listChanged?: boolean;486};487}488489/**490* @description Initialization request sent from Guest UI to Host.491* @see {@link app.App.connect} for the method that sends this request492*/493export interface McpUiInitializeRequest {494method: "ui/initialize";495params: {496/** @description App identification (name and version). */497appInfo: Implementation;498/** @description Features and capabilities this app provides. */499appCapabilities: McpUiAppCapabilities;500/** @description Protocol version this app supports. */501protocolVersion: string;502};503}504505/**506* @description Initialization result returned from Host to Guest UI.507* @see {@link McpUiInitializeRequest}508*/509export interface McpUiInitializeResult {510/** @description Negotiated protocol version string (e.g., "2025-11-21"). */511protocolVersion: string;512/** @description Host application identification and version. */513hostInfo: Implementation;514/** @description Features and capabilities provided by the host. */515hostCapabilities: McpUiHostCapabilities;516/** @description Rich context about the host environment. */517hostContext: McpUiHostContext;518/**519* Index signature required for MCP SDK `Protocol` class compatibility.520* Note: The schema intentionally omits this to enforce strict validation.521*/522[key: string]: unknown;523}524525/**526* @description Notification that Guest UI has completed initialization (Guest UI -> Host).527* @see {@link app.App.connect} for the method that sends this notification528*/529export interface McpUiInitializedNotification {530method: "ui/notifications/initialized";531params?: {};532}533534/**535* @description Content Security Policy configuration for UI resources.536*/537export interface McpUiResourceCsp {538/** @description Origins for network requests (fetch/XHR/WebSocket). */539connectDomains?: string[];540/** @description Origins for static resources (scripts, images, styles, fonts). */541resourceDomains?: string[];542}543544/**545* @description UI Resource metadata for security and rendering configuration.546*/547export interface McpUiResourceMeta {548/** @description Content Security Policy configuration. */549csp?: McpUiResourceCsp;550/** @description Dedicated origin for widget sandbox. */551domain?: string;552/** @description Visual boundary preference - true if UI prefers a visible border. */553prefersBorder?: boolean;554}555556/**557* @description Request to change the display mode of the UI.558* The host will respond with the actual display mode that was set,559* which may differ from the requested mode if not supported.560* @see {@link app.App.requestDisplayMode} for the method that sends this request561*/562export interface McpUiRequestDisplayModeRequest {563method: "ui/request-display-mode";564params: {565/** @description The display mode being requested. */566mode: McpUiDisplayMode;567};568}569570/**571* @description Result from requesting a display mode change.572* @see {@link McpUiRequestDisplayModeRequest}573*/574export interface McpUiRequestDisplayModeResult {575/** @description The display mode that was actually set. May differ from requested if not supported. */576mode: McpUiDisplayMode;577/**578* Index signature required for MCP SDK `Protocol` class compatibility.579* Note: The schema intentionally omits this to enforce strict validation.580*/581[key: string]: unknown;582}583584/**585* @description Tool visibility scope - who can access the tool.586*/587export type McpUiToolVisibility = "model" | "app";588589/**590* @description UI-related metadata for tools.591*/592export interface McpUiToolMeta {593/**594* URI of the UI resource to display for this tool.595* This is converted to `_meta["ui/resourceUri"]`.596*597* @example "ui://weather/widget.html"598*/599resourceUri: string;600/**601* @description Who can access this tool. Default: ["model", "app"]602* - "model": Tool visible to and callable by the agent603* - "app": Tool callable by the app from this server only604*/605visibility?: McpUiToolVisibility[];606}607}608609610