Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/mcp/common/mcpManagement.ts
3294 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 { IPager } 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 repositoryUrl?: string;
27
readonly readmeUrl?: URI;
28
readonly publisher?: string;
29
readonly publisherDisplayName?: string;
30
readonly icon?: {
31
readonly dark: string;
32
readonly light: string;
33
};
34
readonly codicon?: string;
35
readonly manifest?: IGalleryMcpServerConfiguration;
36
readonly source: InstallSource;
37
}
38
39
export interface IMcpServerInput {
40
readonly description?: string;
41
readonly is_required?: boolean;
42
readonly format?: 'string' | 'number' | 'boolean' | 'filepath';
43
readonly value?: string;
44
readonly is_secret?: boolean;
45
readonly default?: string;
46
readonly choices?: readonly string[];
47
}
48
49
export interface IMcpServerVariableInput extends IMcpServerInput {
50
readonly variables?: Record<string, IMcpServerInput>;
51
}
52
53
export interface IMcpServerPositionalArgument extends IMcpServerVariableInput {
54
readonly type: 'positional';
55
readonly value_hint: string;
56
readonly is_repeatable: boolean;
57
}
58
59
export interface IMcpServerNamedArgument extends IMcpServerVariableInput {
60
readonly type: 'named';
61
readonly name: string;
62
readonly is_repeatable: boolean;
63
}
64
65
export interface IMcpServerKeyValueInput extends IMcpServerVariableInput {
66
readonly name: string;
67
readonly value: string;
68
}
69
70
export type IMcpServerArgument = IMcpServerPositionalArgument | IMcpServerNamedArgument;
71
72
export const enum RegistryType {
73
NODE = 'npm',
74
PYTHON = 'pypi',
75
DOCKER = 'docker-hub',
76
NUGET = 'nuget',
77
REMOTE = 'remote',
78
MCPB = 'mcpb',
79
}
80
81
export interface IMcpServerPackage {
82
readonly registry_type: RegistryType;
83
readonly registry_base_url?: string;
84
readonly identifier: string;
85
readonly version: string;
86
readonly file_sha256?: string;
87
readonly runtime_hint?: string;
88
readonly package_arguments?: readonly IMcpServerArgument[];
89
readonly runtime_arguments?: readonly IMcpServerArgument[];
90
readonly environment_variables?: ReadonlyArray<IMcpServerKeyValueInput>;
91
}
92
93
export interface IMcpServerRemote {
94
readonly url: string;
95
readonly transport_type?: 'streamable' | 'sse';
96
readonly headers?: ReadonlyArray<IMcpServerKeyValueInput>;
97
}
98
99
export interface IGalleryMcpServerConfiguration {
100
readonly packages?: readonly IMcpServerPackage[];
101
readonly remotes?: readonly IMcpServerRemote[];
102
}
103
104
export const enum GalleryMcpServerStatus {
105
Active = 'active',
106
Deprecated = 'deprecated'
107
}
108
109
export interface IGalleryMcpServer {
110
readonly id: string;
111
readonly name: string;
112
readonly displayName: string;
113
readonly description: string;
114
readonly version: string;
115
readonly isLatest: boolean;
116
readonly status: GalleryMcpServerStatus;
117
readonly url?: string;
118
readonly codicon?: string;
119
readonly icon?: {
120
readonly dark: string;
121
readonly light: string;
122
};
123
readonly lastUpdated?: number;
124
readonly publishDate?: number;
125
readonly releaseDate?: number;
126
readonly repositoryUrl?: string;
127
readonly configuration?: IGalleryMcpServerConfiguration;
128
readonly readmeUrl?: string;
129
readonly readme?: string;
130
readonly publisher: string;
131
readonly publisherDisplayName?: string;
132
readonly publisherDomain?: { link: string; verified: boolean };
133
readonly ratingCount?: number;
134
readonly topics?: readonly string[];
135
readonly license?: string;
136
readonly starsCount?: number;
137
}
138
139
export interface IQueryOptions {
140
text?: string;
141
sortBy?: SortBy;
142
sortOrder?: SortOrder;
143
}
144
145
export const IMcpGalleryService = createDecorator<IMcpGalleryService>('IMcpGalleryService');
146
export interface IMcpGalleryService {
147
readonly _serviceBrand: undefined;
148
isEnabled(): boolean;
149
query(options?: IQueryOptions, token?: CancellationToken): Promise<IPager<IGalleryMcpServer>>;
150
getMcpServersFromVSCodeGallery(servers: string[]): Promise<IGalleryMcpServer[]>;
151
getMcpServersFromGallery(urls: string[]): Promise<IGalleryMcpServer[]>;
152
getMcpServer(url: string): Promise<IGalleryMcpServer | undefined>;
153
getMcpServerConfiguration(extension: IGalleryMcpServer, token: CancellationToken): Promise<IGalleryMcpServerConfiguration>;
154
getReadme(extension: IGalleryMcpServer, token: CancellationToken): Promise<string>;
155
}
156
157
export interface InstallMcpServerEvent {
158
readonly name: string;
159
readonly mcpResource: URI;
160
readonly source?: IGalleryMcpServer;
161
}
162
163
export interface InstallMcpServerResult {
164
readonly name: string;
165
readonly mcpResource: URI;
166
readonly source?: IGalleryMcpServer;
167
readonly local?: ILocalMcpServer;
168
readonly error?: Error;
169
}
170
171
export interface UninstallMcpServerEvent {
172
readonly name: string;
173
readonly mcpResource: URI;
174
}
175
176
export interface DidUninstallMcpServerEvent {
177
readonly name: string;
178
readonly mcpResource: URI;
179
readonly error?: string;
180
}
181
182
export type InstallOptions = {
183
packageType?: RegistryType;
184
mcpResource?: URI;
185
};
186
187
export type UninstallOptions = {
188
mcpResource?: URI;
189
};
190
191
export interface IInstallableMcpServer {
192
readonly name: string;
193
readonly config: IMcpServerConfiguration;
194
readonly inputs?: IMcpServerVariable[];
195
}
196
197
export const IMcpManagementService = createDecorator<IMcpManagementService>('IMcpManagementService');
198
export interface IMcpManagementService {
199
readonly _serviceBrand: undefined;
200
readonly onInstallMcpServer: Event<InstallMcpServerEvent>;
201
readonly onDidInstallMcpServers: Event<readonly InstallMcpServerResult[]>;
202
readonly onDidUpdateMcpServers: Event<readonly InstallMcpServerResult[]>;
203
readonly onUninstallMcpServer: Event<UninstallMcpServerEvent>;
204
readonly onDidUninstallMcpServer: Event<DidUninstallMcpServerEvent>;
205
getInstalled(mcpResource?: URI): Promise<ILocalMcpServer[]>;
206
canInstall(server: IGalleryMcpServer | IInstallableMcpServer): true | IMarkdownString;
207
install(server: IInstallableMcpServer, options?: InstallOptions): Promise<ILocalMcpServer>;
208
installFromGallery(server: IGalleryMcpServer, options?: InstallOptions): Promise<ILocalMcpServer>;
209
updateMetadata(local: ILocalMcpServer, server: IGalleryMcpServer, profileLocation?: URI): Promise<ILocalMcpServer>;
210
uninstall(server: ILocalMcpServer, options?: UninstallOptions): Promise<void>;
211
212
getMcpServerConfigurationFromManifest(manifest: IGalleryMcpServerConfiguration, packageType: RegistryType): Omit<IInstallableMcpServer, 'name'>;
213
}
214
215
export const IAllowedMcpServersService = createDecorator<IAllowedMcpServersService>('IAllowedMcpServersService');
216
export interface IAllowedMcpServersService {
217
readonly _serviceBrand: undefined;
218
219
readonly onDidChangeAllowedMcpServers: Event<void>;
220
isAllowed(mcpServer: IGalleryMcpServer | ILocalMcpServer | IInstallableMcpServer): true | IMarkdownString;
221
}
222
223
export const mcpAccessConfig = 'chat.mcp.access';
224
export const mcpGalleryServiceUrlConfig = 'chat.mcp.gallery.serviceUrl';
225
export const mcpAutoStartConfig = 'chat.mcp.autostart';
226
227
export const enum McpAutoStartValue {
228
Never = 'never',
229
OnlyNew = 'onlyNew',
230
NewAndOutdated = 'newAndOutdated',
231
}
232
233
export const enum McpAccessValue {
234
None = 'none',
235
Registry = 'registry',
236
All = 'all',
237
}
238
239