1
>
/*---------------------------------------------------------------------------------------------
mcpManagement.ts
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 { CancellationToken } from '../../../base/common/cancellation.js';
7
>
import { Event } from '../../../base/common/event.js';
8
>
import { IMarkdownString } from '../../../base/common/htmlContent.js';
9
>
import { IIterativePager } from '../../../base/common/paging.js';
10
>
import { URI } from '../../../base/common/uri.js';
11
>
import { SortBy, SortOrder } from '../../extensionManagement/common/extensionManagement.js';
12
>
import { createDecorator } from '../../instantiation/common/instantiation.js';
13
>
import { IMcpServerIdentity } from './allowedMcpServers.js';
14
>
import { IMcpSandboxConfiguration, IMcpServerConfiguration, IMcpServerVariable } from './mcpPlatformTypes.js';
15
>
16
>
export type InstallSource = 'gallery' | 'local';
17
>
18
>
export interface ILocalMcpServer {
19
>
readonly name: string;
20
>
readonly config: IMcpServerConfiguration;
21
>
readonly rootSandbox?: IMcpSandboxConfiguration;
22
>
readonly version?: string;
23
>
readonly mcpResource: URI;
24
>
readonly location?: URI;
25
>
readonly displayName?: string;
26
>
readonly description?: string;
27
>
readonly galleryUrl?: string;
28
>
readonly galleryId?: string;
29
>
readonly repositoryUrl?: string;
30
>
readonly readmeUrl?: URI;
31
>
readonly publisher?: string;
32
>
readonly publisherDisplayName?: string;
33
>
readonly icon?: {
34
>
readonly dark: string;
35
>
readonly light: string;
36
>
};
37
>
readonly codicon?: string;
38
>
readonly manifest?: IGalleryMcpServerConfiguration;
39
>
readonly source: InstallSource;
40
>
}
41
>
42
>
export interface IMcpServerInput {
43
>
readonly description?: string;
44
>
readonly isRequired?: boolean;
45
>
readonly format?: 'string' | 'number' | 'boolean' | 'filepath';
46
>
readonly value?: string;
47
>
readonly isSecret?: boolean;
48
>
readonly default?: string;
49
>
readonly choices?: readonly string[];
50
>
}
51
>
52
>
export interface IMcpServerVariableInput extends IMcpServerInput {
53
>
readonly variables?: Record<string, IMcpServerInput>;
54
>
}
55
>
56
>
export interface IMcpServerPositionalArgument extends IMcpServerVariableInput {
57
>
readonly type: 'positional';
58
>
readonly valueHint?: string;
59
>
readonly isRepeated?: boolean;
60
>
}
61
>
62
>
export interface IMcpServerNamedArgument extends IMcpServerVariableInput {
63
>
readonly type: 'named';
64
>
readonly name: string;
65
>
readonly isRepeated?: boolean;
66
>
}
67
>
68
>
export interface IMcpServerKeyValueInput extends IMcpServerVariableInput {
69
>
readonly name: string;
70
>
readonly value?: string;
71
>
}
72
>
73
>
export type IMcpServerArgument = IMcpServerPositionalArgument | IMcpServerNamedArgument;
74
>
75
>
export const enum RegistryType {
76
>
NODE = 'npm',
77
>
PYTHON = 'pypi',
78
>
DOCKER = 'oci',
79
>
NUGET = 'nuget',
80
>
MCPB = 'mcpb',
81
>
REMOTE = 'remote'
82
>
}
83
>
84
>
export const enum TransportType {
85
>
STDIO = 'stdio',
86
>
STREAMABLE_HTTP = 'streamable-http',
87
>
SSE = 'sse'
88
>
}
89
>
90
>
export interface StdioTransport {
91
>
readonly type: TransportType.STDIO;
92
>
}
93
>
94
>
export interface StreamableHttpTransport {
95
>
readonly type: TransportType.STREAMABLE_HTTP;
96
>
readonly url: string;
97
>
readonly headers?: ReadonlyArray<IMcpServerKeyValueInput>;
98
>
}
99
>
100
>
export interface SseTransport {
101
>
readonly type: TransportType.SSE;
102
>
readonly url: string;
103
>
readonly headers?: ReadonlyArray<IMcpServerKeyValueInput>;
104
>
}
105
>
106
>
export type Transport = StdioTransport | StreamableHttpTransport | SseTransport;
107
>
108
>
export interface IMcpServerPackage {
109
>
readonly registryType: RegistryType;
110
>
readonly identifier: string;
111
>
readonly transport: Transport;
112
>
readonly version?: string;
113
>
readonly registryBaseUrl?: string;
114
>
readonly fileSha256?: string;
115
>
readonly packageArguments?: readonly IMcpServerArgument[];
116
>
readonly runtimeHint?: string;
117
>
readonly runtimeArguments?: readonly IMcpServerArgument[];
118
>
readonly environmentVariables?: ReadonlyArray<IMcpServerKeyValueInput>;
119
>
}
120
>
121
>
export interface IGalleryMcpServerConfiguration {
122
>
readonly packages?: readonly IMcpServerPackage[];
123
>
readonly remotes?: ReadonlyArray<SseTransport | StreamableHttpTransport>;
124
>
}
125
>
126
>
export const enum GalleryMcpServerStatus {
127
>
Active = 'active',
128
>
Deprecated = 'deprecated'
129
>
}
130
>
131
>
export interface IGalleryMcpServer {
132
>
readonly name: string;
133
>
readonly displayName: string;
134
>
readonly description: string;
135
>
readonly version: string;
136
>
readonly isLatest: boolean;
137
>
readonly status: GalleryMcpServerStatus;
138
>
readonly id?: string;
139
>
readonly galleryUrl?: string;
140
>
readonly webUrl?: string;
141
>
readonly codicon?: string;
142
>
readonly icon?: {
143
>
readonly dark: string;
144
>
readonly light: string;
145
>
};
146
>
readonly lastUpdated?: number;
147
>
readonly publishDate?: number;
148
>
readonly repositoryUrl?: string;
149
>
readonly configuration: IGalleryMcpServerConfiguration;
150
>
readonly readmeUrl?: string;
151
>
readonly readme?: string;
152
>
readonly publisher: string;
153
>
readonly publisherDisplayName?: string;
154
>
readonly publisherUrl?: string;
155
>
readonly publisherDomain?: { link: string; verified: boolean };
156
>
readonly ratingCount?: number;
157
>
readonly topics?: readonly string[];
158
>
readonly license?: string;
159
>
readonly starsCount?: number;
160
>
}
161
>
162
>
export interface IQueryOptions {
163
>
text?: string;
164
>
sortBy?: SortBy;
165
>
sortOrder?: SortOrder;
166
>
}
167
>
168
>
export const IMcpGalleryService = createDecorator<IMcpGalleryService>('IMcpGalleryService');
169
>
export interface IMcpGalleryService {
170
>
readonly _serviceBrand: undefined;
171
>
isEnabled(): boolean;
172
>
query(options?: IQueryOptions, token?: CancellationToken): Promise<IIterativePager<IGalleryMcpServer>>;
173
>
getMcpServersFromGallery(infos: { name: string; id?: string }[]): Promise<IGalleryMcpServer[]>;
174
>
getMcpServer(url: string): Promise<IGalleryMcpServer | undefined>;
175
>
getReadme(extension: IGalleryMcpServer, token: CancellationToken): Promise<string>;
176
>
}
177
>
178
>
export interface InstallMcpServerEvent {
179
>
readonly name: string;
180
>
readonly mcpResource: URI;
181
>
readonly source?: IGalleryMcpServer;
182
>
}
183
>
184
>
export interface InstallMcpServerResult {
185
>
readonly name: string;
186
>
readonly mcpResource: URI;
187
>
readonly source?: IGalleryMcpServer;
188
>
readonly local?: ILocalMcpServer;
189
>
readonly error?: Error;
190
>
}
191
>
192
>
export interface UninstallMcpServerEvent {
193
>
readonly name: string;
194
>
readonly mcpResource: URI;
195
>
}
196
>
197
>
export interface DidUninstallMcpServerEvent {
198
>
readonly name: string;
199
>
readonly mcpResource: URI;
200
>
readonly error?: string;
201
>
}
202
>
203
>
export type InstallOptions = {
204
>
packageType?: RegistryType;
205
>
mcpResource?: URI;
206
>
};
207
>
208
>
export type UninstallOptions = {
209
>
mcpResource?: URI;
210
>
};
211
>
212
>
export interface IInstallableMcpServer {
213
>
readonly name: string;
214
>
readonly config: IMcpServerConfiguration;
215
>
readonly inputs?: IMcpServerVariable[];
216
>
}
217
>
218
>
export type McpServerConfiguration = Omit<IInstallableMcpServer, 'name'>;
219
>
export interface McpServerConfigurationParseResult {
220
>
readonly mcpServerConfiguration: McpServerConfiguration;
221
>
readonly notices: string[];
222
>
}
223
>
224
>
export const IMcpManagementService = createDecorator<IMcpManagementService>('IMcpManagementService');
225
>
export interface IMcpManagementService {
226
>
readonly _serviceBrand: undefined;
227
>
readonly onInstallMcpServer: Event<InstallMcpServerEvent>;
228
>
readonly onDidInstallMcpServers: Event<readonly InstallMcpServerResult[]>;
229
>
readonly onDidUpdateMcpServers: Event<readonly InstallMcpServerResult[]>;
230
>
readonly onUninstallMcpServer: Event<UninstallMcpServerEvent>;
231
>
readonly onDidUninstallMcpServer: Event<DidUninstallMcpServerEvent>;
232
>
getInstalled(mcpResource?: URI): Promise<ILocalMcpServer[]>;
233
>
canInstall(server: IGalleryMcpServer | IInstallableMcpServer): true | IMarkdownString;
234
>
install(server: IInstallableMcpServer, options?: InstallOptions): Promise<ILocalMcpServer>;
235
>
installFromGallery(server: IGalleryMcpServer, options?: InstallOptions): Promise<ILocalMcpServer>;
236
>
updateMetadata(local: ILocalMcpServer, server: IGalleryMcpServer, profileLocation?: URI): Promise<ILocalMcpServer>;
237
>
uninstall(server: ILocalMcpServer, options?: UninstallOptions): Promise<void>;
238
>
239
>
getMcpServerConfigurationFromManifest(manifest: IGalleryMcpServerConfiguration, packageType: RegistryType): McpServerConfigurationParseResult;
240
>
}
241
>
242
>
export const IAllowedMcpServersService = createDecorator<IAllowedMcpServersService>('IAllowedMcpServersService');
243
>
export interface IAllowedMcpServersService {
244
>
readonly _serviceBrand: undefined;
245
>
246
>
readonly onDidChangeAllowedMcpServers: Event<void>;
247
>
isAllowed(mcpServer: IGalleryMcpServer | ILocalMcpServer | IInstallableMcpServer): true | IMarkdownString;
248
>
249
>
/**
250
>
* Checks whether an MCP server identified by name / remote URL / local command is permitted by
251
>
* the `chat.mcp.allowedServers` allowlist (in addition to the `chat.mcp.access` gate). Used by
252
>
* the runtime enforcement path, which does not have a gallery/local/installable representation.
253
>
*/
254
>
isServerAllowed(identity: IMcpServerIdentity): true | IMarkdownString;
255
>
}
256
>
257
>
export const mcpAccessConfig = 'chat.mcp.access';
258
>
export const mcpAllowedServersConfig = 'chat.mcp.allowedServers';
259
>
export const mcpDeniedServersConfig = 'chat.mcp.deniedServers';
260
>
export const mcpGalleryServiceUrlConfig = 'chat.mcp.gallery.serviceUrl';
261
>
export const mcpGalleryServiceEnablementConfig = 'chat.mcp.gallery.enabled';
262
>
export const mcpAutoStartConfig = 'chat.mcp.autostart';
263
>
export const mcpAppsEnabledConfig = 'chat.mcp.apps.enabled';
264
>
265
>
export interface IMcpGalleryConfig {
266
>
readonly serviceUrl?: string;
267
>
readonly enabled?: boolean;
268
>
readonly version?: string;
269
>
}
270
>
271
>
export const enum McpAutoStartValue {
272
>
Never = 'never',
273
>
OnlyNew = 'onlyNew',
274
>
NewAndOutdated = 'newAndOutdated',
275
>
}
276
>
277
>
export const enum McpAccessValue {
278
>
None = 'none',
279
>
Registry = 'registry',
280
>
All = 'all',
281
>
}