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