Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/mcp/common/modelContextProtocolApps.ts
4780 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { MCP } from './modelContextProtocol.js';
7
8
type CallToolResult = MCP.CallToolResult;
9
type ContentBlock = MCP.ContentBlock;
10
type Implementation = MCP.Implementation;
11
type RequestId = MCP.RequestId;
12
type Tool = MCP.Tool;
13
14
//#region utilities
15
16
export namespace McpApps {
17
export type AppRequest =
18
| MCP.CallToolRequest
19
| MCP.ReadResourceRequest
20
| MCP.PingRequest
21
| (McpUiOpenLinkRequest & MCP.JSONRPCRequest)
22
| (McpUiMessageRequest & MCP.JSONRPCRequest)
23
| (McpUiRequestDisplayModeRequest & MCP.JSONRPCRequest)
24
| (McpApps.McpUiInitializeRequest & MCP.JSONRPCRequest);
25
26
export type AppNotification =
27
| McpUiInitializedNotification
28
| McpUiSizeChangedNotification
29
| MCP.LoggingMessageNotification;
30
31
export type AppMessage = AppRequest | AppNotification;
32
33
export type HostResult =
34
| MCP.CallToolResult
35
| MCP.ReadResourceResult
36
| MCP.EmptyResult
37
| McpApps.McpUiInitializeResult
38
| McpUiMessageResult
39
| McpUiOpenLinkResult
40
| McpUiRequestDisplayModeResult;
41
42
export type HostNotification =
43
| McpUiHostContextChangedNotification
44
| McpUiResourceTeardownRequest
45
| McpUiToolInputNotification
46
| McpUiToolInputPartialNotification
47
| McpUiToolResultNotification
48
| McpUiToolCancelledNotification
49
| McpUiSizeChangedNotification;
50
51
export type HostMessage = HostResult | HostNotification;
52
}
53
54
/* eslint-disable local/code-no-unexternalized-strings */
55
56
57
/**
58
* Schema updated from the Model Context Protocol Apps repository at
59
* https://github.com/modelcontextprotocol/ext-apps/blob/main/src/spec.types.ts
60
*
61
* ⚠️ Do not edit within `namespace` manually except to update schema versions ⚠️
62
*/
63
export namespace McpApps {
64
/*
65
* Current protocol version supported by this SDK.
66
*
67
* The SDK automatically handles version negotiation during initialization.
68
* Apps and hosts don't need to manage protocol versions manually.
69
*/
70
export const LATEST_PROTOCOL_VERSION = "2025-11-21";
71
72
/**
73
* @description Color theme preference for the host environment.
74
*/
75
export type McpUiTheme = "light" | "dark";
76
77
/**
78
* @description Display mode for UI presentation.
79
*/
80
export type McpUiDisplayMode = "inline" | "fullscreen" | "pip";
81
82
/**
83
* @description CSS variable keys available to MCP apps for theming.
84
*/
85
export type McpUiStyleVariableKey =
86
// Background colors
87
| "--color-background-primary"
88
| "--color-background-secondary"
89
| "--color-background-tertiary"
90
| "--color-background-inverse"
91
| "--color-background-ghost"
92
| "--color-background-info"
93
| "--color-background-danger"
94
| "--color-background-success"
95
| "--color-background-warning"
96
| "--color-background-disabled"
97
// Text colors
98
| "--color-text-primary"
99
| "--color-text-secondary"
100
| "--color-text-tertiary"
101
| "--color-text-inverse"
102
| "--color-text-ghost"
103
| "--color-text-info"
104
| "--color-text-danger"
105
| "--color-text-success"
106
| "--color-text-warning"
107
| "--color-text-disabled"
108
| "--color-text-ghost"
109
// Border colors
110
| "--color-border-primary"
111
| "--color-border-secondary"
112
| "--color-border-tertiary"
113
| "--color-border-inverse"
114
| "--color-border-ghost"
115
| "--color-border-info"
116
| "--color-border-danger"
117
| "--color-border-success"
118
| "--color-border-warning"
119
| "--color-border-disabled"
120
// Ring colors
121
| "--color-ring-primary"
122
| "--color-ring-secondary"
123
| "--color-ring-inverse"
124
| "--color-ring-info"
125
| "--color-ring-danger"
126
| "--color-ring-success"
127
| "--color-ring-warning"
128
// Typography - Family
129
| "--font-sans"
130
| "--font-mono"
131
// Typography - Weight
132
| "--font-weight-normal"
133
| "--font-weight-medium"
134
| "--font-weight-semibold"
135
| "--font-weight-bold"
136
// Typography - Text Size
137
| "--font-text-xs-size"
138
| "--font-text-sm-size"
139
| "--font-text-md-size"
140
| "--font-text-lg-size"
141
// Typography - Heading Size
142
| "--font-heading-xs-size"
143
| "--font-heading-sm-size"
144
| "--font-heading-md-size"
145
| "--font-heading-lg-size"
146
| "--font-heading-xl-size"
147
| "--font-heading-2xl-size"
148
| "--font-heading-3xl-size"
149
// Typography - Text Line Height
150
| "--font-text-xs-line-height"
151
| "--font-text-sm-line-height"
152
| "--font-text-md-line-height"
153
| "--font-text-lg-line-height"
154
// Typography - Heading Line Height
155
| "--font-heading-xs-line-height"
156
| "--font-heading-sm-line-height"
157
| "--font-heading-md-line-height"
158
| "--font-heading-lg-line-height"
159
| "--font-heading-xl-line-height"
160
| "--font-heading-2xl-line-height"
161
| "--font-heading-3xl-line-height"
162
// Border radius
163
| "--border-radius-xs"
164
| "--border-radius-sm"
165
| "--border-radius-md"
166
| "--border-radius-lg"
167
| "--border-radius-xl"
168
| "--border-radius-full"
169
// Border width
170
| "--border-width-regular"
171
// Shadows
172
| "--shadow-hairline"
173
| "--shadow-sm"
174
| "--shadow-md"
175
| "--shadow-lg";
176
177
/**
178
* @description Style variables for theming MCP apps.
179
*
180
* Individual style keys are optional - hosts may provide any subset of these values.
181
* Values are strings containing CSS values (colors, sizes, font stacks, etc.).
182
*
183
* Note: This type uses `Record<K, string | undefined>` rather than `Partial<Record<K, string>>`
184
* for compatibility with Zod schema generation. Both are functionally equivalent for validation.
185
*/
186
export type McpUiStyles = Record<McpUiStyleVariableKey, string | undefined>;
187
188
/**
189
* @description Request to open an external URL in the host's default browser.
190
* @see {@link app.App.sendOpenLink} for the method that sends this request
191
*/
192
export interface McpUiOpenLinkRequest {
193
method: "ui/open-link";
194
params: {
195
/** @description URL to open in the host's browser */
196
url: string;
197
};
198
}
199
200
/**
201
* @description Result from opening a URL.
202
* @see {@link McpUiOpenLinkRequest}
203
*/
204
export interface McpUiOpenLinkResult {
205
/** @description True if the host failed to open the URL (e.g., due to security policy). */
206
isError?: boolean;
207
/**
208
* Index signature required for MCP SDK `Protocol` class compatibility.
209
* Note: The schema intentionally omits this to enforce strict validation.
210
*/
211
[key: string]: unknown;
212
}
213
214
/**
215
* @description Request to send a message to the host's chat interface.
216
* @see {@link app.App.sendMessage} for the method that sends this request
217
*/
218
export interface McpUiMessageRequest {
219
method: "ui/message";
220
params: {
221
/** @description Message role, currently only "user" is supported. */
222
role: "user";
223
/** @description Message content blocks (text, image, etc.). */
224
content: ContentBlock[];
225
};
226
}
227
228
/**
229
* @description Result from sending a message.
230
* @see {@link McpUiMessageRequest}
231
*/
232
export interface McpUiMessageResult {
233
/** @description True if the host rejected or failed to deliver the message. */
234
isError?: boolean;
235
/**
236
* Index signature required for MCP SDK `Protocol` class compatibility.
237
* Note: The schema intentionally omits this to enforce strict validation.
238
*/
239
[key: string]: unknown;
240
}
241
242
/**
243
* @description Notification that the sandbox proxy iframe is ready to receive content.
244
* @internal
245
* @see https://github.com/modelcontextprotocol/ext-apps/blob/main/specification/draft/apps.mdx#sandbox-proxy
246
*/
247
export interface McpUiSandboxProxyReadyNotification {
248
method: "ui/notifications/sandbox-proxy-ready";
249
params: {};
250
}
251
252
/**
253
* @description Notification containing HTML resource for the sandbox proxy to load.
254
* @internal
255
* @see https://github.com/modelcontextprotocol/ext-apps/blob/main/specification/draft/apps.mdx#sandbox-proxy
256
*/
257
export interface McpUiSandboxResourceReadyNotification {
258
method: "ui/notifications/sandbox-resource-ready";
259
params: {
260
/** @description HTML content to load into the inner iframe. */
261
html: string;
262
/** @description Optional override for the inner iframe's sandbox attribute. */
263
sandbox?: string;
264
/** @description CSP configuration from resource metadata. */
265
csp?: {
266
/** @description Origins for network requests (fetch/XHR/WebSocket). */
267
connectDomains?: string[];
268
/** @description Origins for static resources (scripts, images, styles, fonts). */
269
resourceDomains?: string[];
270
};
271
};
272
}
273
274
/**
275
* @description Notification of UI size changes (bidirectional: Guest <-> Host).
276
* @see {@link app.App.sendSizeChanged} for the method to send this from Guest UI
277
*/
278
export interface McpUiSizeChangedNotification {
279
method: "ui/notifications/size-changed";
280
params: {
281
/** @description New width in pixels. */
282
width?: number;
283
/** @description New height in pixels. */
284
height?: number;
285
};
286
}
287
288
/**
289
* @description Notification containing complete tool arguments (Host -> Guest UI).
290
*/
291
export interface McpUiToolInputNotification {
292
method: "ui/notifications/tool-input";
293
params: {
294
/** @description Complete tool call arguments as key-value pairs. */
295
arguments?: Record<string, unknown>;
296
};
297
}
298
299
/**
300
* @description Notification containing partial/streaming tool arguments (Host -> Guest UI).
301
*/
302
export interface McpUiToolInputPartialNotification {
303
method: "ui/notifications/tool-input-partial";
304
params: {
305
/** @description Partial tool call arguments (incomplete, may change). */
306
arguments?: Record<string, unknown>;
307
};
308
}
309
310
/**
311
* @description Notification containing tool execution result (Host -> Guest UI).
312
*/
313
export interface McpUiToolResultNotification {
314
method: "ui/notifications/tool-result";
315
/** @description Standard MCP tool execution result. */
316
params: CallToolResult;
317
}
318
319
/**
320
* @description Notification that tool execution was cancelled (Host -> Guest UI).
321
* Host MUST send this if tool execution was cancelled for any reason (user action,
322
* sampling error, classifier intervention, etc.).
323
*/
324
export interface McpUiToolCancelledNotification {
325
method: "ui/notifications/tool-cancelled";
326
params: {
327
/** @description Optional reason for the cancellation (e.g., "user action", "timeout"). */
328
reason?: string;
329
};
330
}
331
332
/**
333
* @description CSS blocks that can be injected by apps.
334
*/
335
export interface McpUiHostCss {
336
/** @description CSS for font loading (@font-face rules or @import statements). Apps must apply using applyHostFonts(). */
337
fonts?: string;
338
}
339
340
/**
341
* @description Style configuration for theming MCP apps.
342
*/
343
export interface McpUiHostStyles {
344
/** @description CSS variables for theming the app. */
345
variables?: McpUiStyles;
346
/** @description CSS blocks that apps can inject. */
347
css?: McpUiHostCss;
348
}
349
350
/**
351
* @description Rich context about the host environment provided to Guest UIs.
352
*/
353
export interface McpUiHostContext {
354
/** @description Allow additional properties for forward compatibility. */
355
[key: string]: unknown;
356
/** @description Metadata of the tool call that instantiated this App. */
357
toolInfo?: {
358
/** @description JSON-RPC id of the tools/call request. */
359
id: RequestId;
360
/** @description Tool definition including name, inputSchema, etc. */
361
tool: Tool;
362
};
363
/** @description Current color theme preference. */
364
theme?: McpUiTheme;
365
/** @description Style configuration for theming the app. */
366
styles?: McpUiHostStyles;
367
/** @description How the UI is currently displayed. */
368
displayMode?: McpUiDisplayMode;
369
/** @description Display modes the host supports. */
370
availableDisplayModes?: string[];
371
/**
372
* @description Container dimensions. Represents the dimensions of the iframe or other
373
* container holding the app. Specify either width or maxWidth, and either height or maxHeight.
374
*/
375
containerDimensions?: (
376
| {
377
/** @description Fixed container height in pixels. */
378
height: number;
379
}
380
| {
381
/** @description Maximum container height in pixels. */
382
maxHeight?: number | undefined;
383
}
384
) &
385
(
386
| {
387
/** @description Fixed container width in pixels. */
388
width: number;
389
}
390
| {
391
/** @description Maximum container width in pixels. */
392
maxWidth?: number | undefined;
393
}
394
);
395
/** @description User's language and region preference in BCP 47 format. */
396
locale?: string;
397
/** @description User's timezone in IANA format. */
398
timeZone?: string;
399
/** @description Host application identifier. */
400
userAgent?: string;
401
/** @description Platform type for responsive design decisions. */
402
platform?: "web" | "desktop" | "mobile";
403
/** @description Device input capabilities. */
404
deviceCapabilities?: {
405
/** @description Whether the device supports touch input. */
406
touch?: boolean;
407
/** @description Whether the device supports hover interactions. */
408
hover?: boolean;
409
};
410
/** @description Mobile safe area boundaries in pixels. */
411
safeAreaInsets?: {
412
/** @description Top safe area inset in pixels. */
413
top: number;
414
/** @description Right safe area inset in pixels. */
415
right: number;
416
/** @description Bottom safe area inset in pixels. */
417
bottom: number;
418
/** @description Left safe area inset in pixels. */
419
left: number;
420
};
421
}
422
423
/**
424
* @description Notification that host context has changed (Host -> Guest UI).
425
* @see {@link McpUiHostContext} for the full context structure
426
*/
427
export interface McpUiHostContextChangedNotification {
428
method: "ui/notifications/host-context-changed";
429
/** @description Partial context update containing only changed fields. */
430
params: McpUiHostContext;
431
}
432
433
/**
434
* @description Request for graceful shutdown of the Guest UI (Host -> Guest UI).
435
* @see {@link app-bridge.AppBridge.teardownResource} for the host method that sends this
436
*/
437
export interface McpUiResourceTeardownRequest {
438
method: "ui/resource-teardown";
439
params: {};
440
}
441
442
/**
443
* @description Result from graceful shutdown request.
444
* @see {@link McpUiResourceTeardownRequest}
445
*/
446
export interface McpUiResourceTeardownResult {
447
/**
448
* Index signature required for MCP SDK `Protocol` class compatibility.
449
*/
450
[key: string]: unknown;
451
}
452
453
/**
454
* @description Capabilities supported by the host application.
455
* @see {@link McpUiInitializeResult} for the initialization result that includes these capabilities
456
*/
457
export interface McpUiHostCapabilities {
458
/** @description Experimental features (structure TBD). */
459
experimental?: {};
460
/** @description Host supports opening external URLs. */
461
openLinks?: {};
462
/** @description Host can proxy tool calls to the MCP server. */
463
serverTools?: {
464
/** @description Host supports tools/list_changed notifications. */
465
listChanged?: boolean;
466
};
467
/** @description Host can proxy resource reads to the MCP server. */
468
serverResources?: {
469
/** @description Host supports resources/list_changed notifications. */
470
listChanged?: boolean;
471
};
472
/** @description Host accepts log messages. */
473
logging?: {};
474
}
475
476
/**
477
* @description Capabilities provided by the Guest UI (App).
478
* @see {@link McpUiInitializeRequest} for the initialization request that includes these capabilities
479
*/
480
export interface McpUiAppCapabilities {
481
/** @description Experimental features (structure TBD). */
482
experimental?: {};
483
/** @description App exposes MCP-style tools that the host can call. */
484
tools?: {
485
/** @description App supports tools/list_changed notifications. */
486
listChanged?: boolean;
487
};
488
}
489
490
/**
491
* @description Initialization request sent from Guest UI to Host.
492
* @see {@link app.App.connect} for the method that sends this request
493
*/
494
export interface McpUiInitializeRequest {
495
method: "ui/initialize";
496
params: {
497
/** @description App identification (name and version). */
498
appInfo: Implementation;
499
/** @description Features and capabilities this app provides. */
500
appCapabilities: McpUiAppCapabilities;
501
/** @description Protocol version this app supports. */
502
protocolVersion: string;
503
};
504
}
505
506
/**
507
* @description Initialization result returned from Host to Guest UI.
508
* @see {@link McpUiInitializeRequest}
509
*/
510
export interface McpUiInitializeResult {
511
/** @description Negotiated protocol version string (e.g., "2025-11-21"). */
512
protocolVersion: string;
513
/** @description Host application identification and version. */
514
hostInfo: Implementation;
515
/** @description Features and capabilities provided by the host. */
516
hostCapabilities: McpUiHostCapabilities;
517
/** @description Rich context about the host environment. */
518
hostContext: McpUiHostContext;
519
/**
520
* Index signature required for MCP SDK `Protocol` class compatibility.
521
* Note: The schema intentionally omits this to enforce strict validation.
522
*/
523
[key: string]: unknown;
524
}
525
526
/**
527
* @description Notification that Guest UI has completed initialization (Guest UI -> Host).
528
* @see {@link app.App.connect} for the method that sends this notification
529
*/
530
export interface McpUiInitializedNotification {
531
method: "ui/notifications/initialized";
532
params?: {};
533
}
534
535
/**
536
* @description Content Security Policy configuration for UI resources.
537
*/
538
export interface McpUiResourceCsp {
539
/** @description Origins for network requests (fetch/XHR/WebSocket). */
540
connectDomains?: string[];
541
/** @description Origins for static resources (scripts, images, styles, fonts). */
542
resourceDomains?: string[];
543
}
544
545
/**
546
* @description UI Resource metadata for security and rendering configuration.
547
*/
548
export interface McpUiResourceMeta {
549
/** @description Content Security Policy configuration. */
550
csp?: McpUiResourceCsp;
551
/** @description Dedicated origin for widget sandbox. */
552
domain?: string;
553
/** @description Visual boundary preference - true if UI prefers a visible border. */
554
prefersBorder?: boolean;
555
}
556
557
/**
558
* @description Request to change the display mode of the UI.
559
* The host will respond with the actual display mode that was set,
560
* which may differ from the requested mode if not supported.
561
* @see {@link app.App.requestDisplayMode} for the method that sends this request
562
*/
563
export interface McpUiRequestDisplayModeRequest {
564
method: "ui/request-display-mode";
565
params: {
566
/** @description The display mode being requested. */
567
mode: McpUiDisplayMode;
568
};
569
}
570
571
/**
572
* @description Result from requesting a display mode change.
573
* @see {@link McpUiRequestDisplayModeRequest}
574
*/
575
export interface McpUiRequestDisplayModeResult {
576
/** @description The display mode that was actually set. May differ from requested if not supported. */
577
mode: McpUiDisplayMode;
578
/**
579
* Index signature required for MCP SDK `Protocol` class compatibility.
580
* Note: The schema intentionally omits this to enforce strict validation.
581
*/
582
[key: string]: unknown;
583
}
584
585
/**
586
* @description Tool visibility scope - who can access the tool.
587
*/
588
export type McpUiToolVisibility = "model" | "app";
589
590
/**
591
* @description UI-related metadata for tools.
592
*/
593
export interface McpUiToolMeta {
594
/**
595
* URI of the UI resource to display for this tool.
596
* This is converted to `_meta["ui/resourceUri"]`.
597
*
598
* @example "ui://weather/widget.html"
599
*/
600
resourceUri: string;
601
/**
602
* @description Who can access this tool. Default: ["model", "app"]
603
* - "model": Tool visible to and callable by the agent
604
* - "app": Tool callable by the app from this server only
605
*/
606
visibility?: McpUiToolVisibility[];
607
}
608
}
609
610