@codingame/monaco-vscode-mcp-service-override 26.2.2 → 27.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/index.js +8 -2
  2. package/package.json +2 -2
  3. package/vscode/src/vs/base/common/jsonRpcProtocol.d.ts +66 -0
  4. package/vscode/src/vs/base/common/jsonRpcProtocol.js +216 -0
  5. package/vscode/src/vs/platform/mcp/common/allowedMcpServersService.js +1 -1
  6. package/vscode/src/vs/platform/mcp/common/mcpGalleryService.js +2 -2
  7. package/vscode/src/vs/platform/mcp/common/mcpGateway.d.ts +39 -0
  8. package/vscode/src/vs/platform/mcp/common/mcpGateway.js +6 -0
  9. package/vscode/src/vs/platform/mcp/common/mcpResourceScannerService.d.ts +2 -1
  10. package/vscode/src/vs/platform/mcp/common/mcpResourceScannerService.js +12 -6
  11. package/vscode/src/vs/workbench/contrib/mcp/browser/mcp.contribution.js +15 -5
  12. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpAddContextContribution.js +2 -2
  13. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpCommands.js +58 -58
  14. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpElicitationService.js +27 -28
  15. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpGatewayService.d.ts +18 -0
  16. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpGatewayService.js +34 -0
  17. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpGatewayToolBrokerContribution.d.ts +6 -0
  18. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpGatewayToolBrokerContribution.js +15 -0
  19. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpLanguageFeatures.js +18 -18
  20. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpMigration.js +4 -4
  21. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpResourceQuickAccess.js +8 -8
  22. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServersView.d.ts +4 -1
  23. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServersView.js +42 -24
  24. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpWorkbenchService.d.ts +1 -1
  25. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpWorkbenchService.js +13 -12
  26. package/vscode/src/vs/workbench/contrib/mcp/common/discovery/extensionMcpDiscovery.js +4 -4
  27. package/vscode/src/vs/workbench/contrib/mcp/common/discovery/installedMcpServersDiscovery.js +2 -0
  28. package/vscode/src/vs/workbench/contrib/mcp/common/discovery/nativeMcpDiscoveryAbstract.js +1 -1
  29. package/vscode/src/vs/workbench/contrib/mcp/common/discovery/pluginMcpDiscovery.d.ts +15 -0
  30. package/vscode/src/vs/workbench/contrib/mcp/common/discovery/pluginMcpDiscovery.js +106 -0
  31. package/vscode/src/vs/workbench/contrib/mcp/common/mcpContextKeys.js +4 -4
  32. package/vscode/src/vs/workbench/contrib/mcp/common/mcpGatewayToolBrokerChannel.d.ts +23 -0
  33. package/vscode/src/vs/workbench/contrib/mcp/common/mcpGatewayToolBrokerChannel.js +202 -0
  34. package/vscode/src/vs/workbench/contrib/mcp/common/mcpLanguageModelToolContribution.js +25 -17
  35. package/vscode/src/vs/workbench/contrib/mcp/common/mcpRegistry.d.ts +3 -5
  36. package/vscode/src/vs/workbench/contrib/mcp/common/mcpRegistry.js +27 -32
  37. package/vscode/src/vs/workbench/contrib/mcp/common/mcpSamplingLog.js +1 -1
  38. package/vscode/src/vs/workbench/contrib/mcp/common/mcpSamplingService.js +11 -11
  39. package/vscode/src/vs/workbench/contrib/mcp/common/mcpSandboxService.d.ts +34 -0
  40. package/vscode/src/vs/workbench/contrib/mcp/common/mcpSandboxService.js +233 -0
  41. package/vscode/src/vs/workbench/contrib/mcp/common/mcpServerConnection.js +3 -3
  42. package/vscode/src/vs/workbench/contrib/mcp/common/mcpServerRequestHandler.d.ts +1 -18
  43. package/vscode/src/vs/workbench/contrib/mcp/common/mcpServerRequestHandler.js +88 -142
  44. package/vscode/src/vs/workbench/services/authentication/browser/authenticationMcpService.js +9 -9
  45. package/vscode/src/vs/workbench/services/mcp/browser/mcpWorkbenchManagementService.d.ts +1 -1
  46. package/vscode/src/vs/workbench/services/mcp/browser/mcpWorkbenchManagementService.js +2 -2
  47. package/vscode/src/vs/platform/mcp/common/mcpManagementIpc.d.ts +0 -42
  48. package/vscode/src/vs/platform/mcp/common/mcpManagementIpc.js +0 -105
  49. package/vscode/src/vs/platform/mcp/common/mcpManagementService.d.ts +0 -130
  50. package/vscode/src/vs/platform/mcp/common/mcpManagementService.js +0 -665
  51. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServerActions.d.ts +0 -259
  52. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServerActions.js +0 -1225
  53. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServerEditor.d.ts +0 -72
  54. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServerEditor.js +0 -996
  55. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServerEditorInput.d.ts +0 -17
  56. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServerEditorInput.js +0 -49
  57. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServerIcons.d.ts +0 -5
  58. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServerIcons.js +0 -12
  59. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServerWidgets.d.ts +0 -88
  60. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServerWidgets.js +0 -464
  61. package/vscode/src/vs/workbench/contrib/mcp/browser/media/mcpServerEditor.css +0 -94
  62. package/vscode/src/vs/workbench/services/mcp/common/mcpWorkbenchManagementService.d.ts +0 -87
  63. package/vscode/src/vs/workbench/services/mcp/common/mcpWorkbenchManagementService.js +0 -702
@@ -1,665 +0,0 @@
1
-
2
- import { __decorate, __param } from '@codingame/monaco-vscode-api/external/tslib/tslib.es6';
3
- import { RunOnceScheduler } from '@codingame/monaco-vscode-api/vscode/vs/base/common/async';
4
- import { VSBuffer } from '@codingame/monaco-vscode-api/vscode/vs/base/common/buffer';
5
- import { CancellationToken } from '@codingame/monaco-vscode-api/vscode/vs/base/common/cancellation';
6
- import { Emitter } from '@codingame/monaco-vscode-api/vscode/vs/base/common/event';
7
- import { MarkdownString } from '@codingame/monaco-vscode-api/vscode/vs/base/common/htmlContent';
8
- import { Disposable, DisposableStore } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
9
- import { ResourceMap } from '@codingame/monaco-vscode-api/vscode/vs/base/common/map';
10
- import { equals } from '@codingame/monaco-vscode-api/vscode/vs/base/common/objects';
11
- import { isString } from '@codingame/monaco-vscode-api/vscode/vs/base/common/types';
12
- import { URI } from '@codingame/monaco-vscode-api/vscode/vs/base/common/uri';
13
- import { localize } from '@codingame/monaco-vscode-api/vscode/vs/nls';
14
- import { ConfigurationTarget } from '@codingame/monaco-vscode-api/vscode/vs/platform/configuration/common/configuration';
15
- import { IEnvironmentService } from '@codingame/monaco-vscode-api/vscode/vs/platform/environment/common/environment.service';
16
- import { IFileService } from '@codingame/monaco-vscode-api/vscode/vs/platform/files/common/files.service';
17
- import { IInstantiationService } from '@codingame/monaco-vscode-api/vscode/vs/platform/instantiation/common/instantiation';
18
- import { ILogService } from '@codingame/monaco-vscode-api/vscode/vs/platform/log/common/log.service';
19
- import { IUriIdentityService } from '@codingame/monaco-vscode-api/vscode/vs/platform/uriIdentity/common/uriIdentity.service';
20
- import { IUserDataProfilesService } from '@codingame/monaco-vscode-api/vscode/vs/platform/userDataProfile/common/userDataProfile.service';
21
- import { RegistryType } from '@codingame/monaco-vscode-api/vscode/vs/platform/mcp/common/mcpManagement';
22
- import { IMcpGalleryService, IAllowedMcpServersService } from '@codingame/monaco-vscode-api/vscode/vs/platform/mcp/common/mcpManagement.service';
23
- import { McpServerType, McpServerVariableType } from '@codingame/monaco-vscode-api/vscode/vs/platform/mcp/common/mcpPlatformTypes';
24
- import { IMcpResourceScannerService } from '@codingame/monaco-vscode-api/vscode/vs/platform/mcp/common/mcpResourceScannerService.service';
25
-
26
- let AbstractCommonMcpManagementService = class AbstractCommonMcpManagementService extends Disposable {
27
- constructor(logService) {
28
- super();
29
- this.logService = logService;
30
- }
31
- getMcpServerConfigurationFromManifest(manifest, packageType) {
32
- if (packageType === RegistryType.REMOTE && manifest.remotes?.length) {
33
- const url = manifest.remotes[0].url;
34
- const headers = manifest.remotes[0].headers ?? [];
35
- const {
36
- inputs,
37
- variables
38
- } = this.processKeyValueInputs(
39
- url.startsWith("https://api.githubcopilot.com/mcp") ? headers.filter(h => h.name.toLowerCase() !== "authorization") : headers
40
- );
41
- return {
42
- mcpServerConfiguration: {
43
- config: {
44
- type: McpServerType.REMOTE,
45
- url: manifest.remotes[0].url,
46
- headers: ( Object.keys(inputs)).length ? inputs : undefined
47
- },
48
- inputs: variables.length ? variables : undefined
49
- },
50
- notices: []
51
- };
52
- }
53
- const serverPackage = manifest.packages?.find(p => p.registryType === packageType) ?? manifest.packages?.[0];
54
- if (!serverPackage) {
55
- throw ( new Error(`No server package found`));
56
- }
57
- const args = [];
58
- const inputs = [];
59
- const env = {};
60
- const notices = [];
61
- if (serverPackage.registryType === RegistryType.DOCKER) {
62
- args.push("run");
63
- args.push("-i");
64
- args.push("--rm");
65
- }
66
- if (serverPackage.runtimeArguments?.length) {
67
- const result = this.processArguments(serverPackage.runtimeArguments ?? []);
68
- args.push(...result.args);
69
- inputs.push(...result.variables);
70
- notices.push(...result.notices);
71
- }
72
- if (serverPackage.environmentVariables?.length) {
73
- const {
74
- inputs: envInputs,
75
- variables: envVariables,
76
- notices: envNotices
77
- } = this.processKeyValueInputs(serverPackage.environmentVariables ?? []);
78
- inputs.push(...envVariables);
79
- notices.push(...envNotices);
80
- for (const [name, value] of Object.entries(envInputs)) {
81
- env[name] = value;
82
- if (serverPackage.registryType === RegistryType.DOCKER) {
83
- args.push("-e");
84
- args.push(name);
85
- }
86
- }
87
- }
88
- switch (serverPackage.registryType) {
89
- case RegistryType.NODE:
90
- if (serverPackage.registryBaseUrl) {
91
- args.push("--registry", serverPackage.registryBaseUrl);
92
- }
93
- args.push(
94
- serverPackage.version ? `${serverPackage.identifier}@${serverPackage.version}` : serverPackage.identifier
95
- );
96
- break;
97
- case RegistryType.PYTHON:
98
- if (serverPackage.registryBaseUrl) {
99
- args.push("--index-url", serverPackage.registryBaseUrl);
100
- }
101
- args.push(
102
- serverPackage.version ? `${serverPackage.identifier}@${serverPackage.version}` : serverPackage.identifier
103
- );
104
- break;
105
- case RegistryType.DOCKER:
106
- {
107
- const dockerIdentifier = serverPackage.registryBaseUrl ? `${serverPackage.registryBaseUrl}/${serverPackage.identifier}` : serverPackage.identifier;
108
- args.push(
109
- serverPackage.version ? `${dockerIdentifier}:${serverPackage.version}` : dockerIdentifier
110
- );
111
- break;
112
- }
113
- case RegistryType.NUGET:
114
- args.push(
115
- serverPackage.version ? `${serverPackage.identifier}@${serverPackage.version}` : serverPackage.identifier
116
- );
117
- args.push("--yes");
118
- if (serverPackage.registryBaseUrl) {
119
- args.push("--source", serverPackage.registryBaseUrl);
120
- }
121
- if (serverPackage.packageArguments?.length) {
122
- args.push("--");
123
- }
124
- break;
125
- }
126
- if (serverPackage.packageArguments?.length) {
127
- const result = this.processArguments(serverPackage.packageArguments);
128
- args.push(...result.args);
129
- inputs.push(...result.variables);
130
- notices.push(...result.notices);
131
- }
132
- return {
133
- notices,
134
- mcpServerConfiguration: {
135
- config: {
136
- type: McpServerType.LOCAL,
137
- command: this.getCommandName(serverPackage.registryType),
138
- args: args.length ? args : undefined,
139
- env: ( Object.keys(env)).length ? env : undefined
140
- },
141
- inputs: inputs.length ? inputs : undefined
142
- }
143
- };
144
- }
145
- getCommandName(packageType) {
146
- switch (packageType) {
147
- case RegistryType.NODE:
148
- return "npx";
149
- case RegistryType.DOCKER:
150
- return "docker";
151
- case RegistryType.PYTHON:
152
- return "uvx";
153
- case RegistryType.NUGET:
154
- return "dnx";
155
- }
156
- return packageType;
157
- }
158
- getVariables(variableInputs) {
159
- const variables = [];
160
- for (const [key, value] of Object.entries(variableInputs)) {
161
- variables.push({
162
- id: key,
163
- type: value.choices ? McpServerVariableType.PICK : McpServerVariableType.PROMPT,
164
- description: value.description ?? "",
165
- password: !!value.isSecret,
166
- default: value.default,
167
- options: value.choices
168
- });
169
- }
170
- return variables;
171
- }
172
- processKeyValueInputs(keyValueInputs) {
173
- const notices = [];
174
- const inputs = {};
175
- const variables = [];
176
- for (const input of keyValueInputs) {
177
- const inputVariables = input.variables ? this.getVariables(input.variables) : [];
178
- let value = input.value || "";
179
- if (inputVariables.length) {
180
- for (const variable of inputVariables) {
181
- value = value.replace(`{${variable.id}}`, `\${input:${variable.id}}`);
182
- }
183
- variables.push(...inputVariables);
184
- } else if (!value && (input.description || input.choices || input.default !== undefined)) {
185
- variables.push({
186
- id: input.name,
187
- type: input.choices ? McpServerVariableType.PICK : McpServerVariableType.PROMPT,
188
- description: input.description ?? "",
189
- password: !!input.isSecret,
190
- default: input.default,
191
- options: input.choices
192
- });
193
- value = `\${input:${input.name}}`;
194
- }
195
- inputs[input.name] = value;
196
- }
197
- return {
198
- inputs,
199
- variables,
200
- notices
201
- };
202
- }
203
- processArguments(argumentsList) {
204
- const args = [];
205
- const variables = [];
206
- const notices = [];
207
- for (const arg of argumentsList) {
208
- const argVariables = arg.variables ? this.getVariables(arg.variables) : [];
209
- if (arg.type === "positional") {
210
- let value = arg.value;
211
- if (value) {
212
- for (const variable of argVariables) {
213
- value = value.replace(`{${variable.id}}`, `\${input:${variable.id}}`);
214
- }
215
- args.push(value);
216
- if (argVariables.length) {
217
- variables.push(...argVariables);
218
- }
219
- } else if (arg.valueHint && (arg.description || arg.default !== undefined)) {
220
- variables.push({
221
- id: arg.valueHint,
222
- type: McpServerVariableType.PROMPT,
223
- description: arg.description ?? "",
224
- password: false,
225
- default: arg.default
226
- });
227
- args.push(`\${input:${arg.valueHint}}`);
228
- } else {
229
- args.push(arg.valueHint ?? "");
230
- }
231
- } else if (arg.type === "named") {
232
- if (!arg.name) {
233
- notices.push(`Named argument is missing a name. ${JSON.stringify(arg)}`);
234
- continue;
235
- }
236
- args.push(arg.name);
237
- if (arg.value) {
238
- let value = arg.value;
239
- for (const variable of argVariables) {
240
- value = value.replace(`{${variable.id}}`, `\${input:${variable.id}}`);
241
- }
242
- args.push(value);
243
- if (argVariables.length) {
244
- variables.push(...argVariables);
245
- }
246
- } else if (arg.description || arg.default !== undefined) {
247
- const variableId = arg.name.replace(/^--?/, "");
248
- variables.push({
249
- id: variableId,
250
- type: McpServerVariableType.PROMPT,
251
- description: arg.description ?? "",
252
- password: false,
253
- default: arg.default
254
- });
255
- args.push(`\${input:${variableId}}`);
256
- }
257
- }
258
- }
259
- return {
260
- args,
261
- variables,
262
- notices
263
- };
264
- }
265
- };
266
- AbstractCommonMcpManagementService = ( __decorate([( __param(0, ILogService))], AbstractCommonMcpManagementService));
267
- let AbstractMcpResourceManagementService = class AbstractMcpResourceManagementService extends AbstractCommonMcpManagementService {
268
- get onDidInstallMcpServers() {
269
- return this._onDidInstallMcpServers.event;
270
- }
271
- get onDidUpdateMcpServers() {
272
- return this._onDidUpdateMcpServers.event;
273
- }
274
- get onUninstallMcpServer() {
275
- return this._onUninstallMcpServer.event;
276
- }
277
- get onDidUninstallMcpServer() {
278
- return this._onDidUninstallMcpServer.event;
279
- }
280
- constructor(
281
- mcpResource,
282
- target,
283
- mcpGalleryService,
284
- fileService,
285
- uriIdentityService,
286
- logService,
287
- mcpResourceScannerService
288
- ) {
289
- super(logService);
290
- this.mcpResource = mcpResource;
291
- this.target = target;
292
- this.mcpGalleryService = mcpGalleryService;
293
- this.fileService = fileService;
294
- this.uriIdentityService = uriIdentityService;
295
- this.mcpResourceScannerService = mcpResourceScannerService;
296
- this.local = ( new Map());
297
- this._onInstallMcpServer = this._register(( new Emitter()));
298
- this.onInstallMcpServer = this._onInstallMcpServer.event;
299
- this._onDidInstallMcpServers = this._register(( new Emitter()));
300
- this._onDidUpdateMcpServers = this._register(( new Emitter()));
301
- this._onUninstallMcpServer = this._register(( new Emitter()));
302
- this._onDidUninstallMcpServer = this._register(( new Emitter()));
303
- this.reloadConfigurationScheduler = this._register(( new RunOnceScheduler(() => this.updateLocal(), 50)));
304
- }
305
- initialize() {
306
- if (!this.initializePromise) {
307
- this.initializePromise = (async () => {
308
- try {
309
- this.local = await this.populateLocalServers();
310
- } finally {
311
- this.startWatching();
312
- }
313
- })();
314
- }
315
- return this.initializePromise;
316
- }
317
- async populateLocalServers() {
318
- this.logService.trace(
319
- "AbstractMcpResourceManagementService#populateLocalServers",
320
- ( this.mcpResource.toString())
321
- );
322
- const local = ( new Map());
323
- try {
324
- const scannedMcpServers = await this.mcpResourceScannerService.scanMcpServers(this.mcpResource, this.target);
325
- if (scannedMcpServers.servers) {
326
- await Promise.allSettled(( Object.entries(scannedMcpServers.servers).map(async ([name, scannedServer]) => {
327
- const server = await this.scanLocalServer(name, scannedServer);
328
- local.set(name, server);
329
- })));
330
- }
331
- } catch (error) {
332
- this.logService.debug("Could not read user MCP servers:", error);
333
- throw error;
334
- }
335
- return local;
336
- }
337
- startWatching() {
338
- this._register(this.fileService.watch(this.mcpResource));
339
- this._register(this.fileService.onDidFilesChange(e => {
340
- if (e.affects(this.mcpResource)) {
341
- this.reloadConfigurationScheduler.schedule();
342
- }
343
- }));
344
- }
345
- async updateLocal() {
346
- try {
347
- const current = await this.populateLocalServers();
348
- const added = [];
349
- const updated = [];
350
- const removed = [...( this.local.keys())].filter(name => !( current.has(name)));
351
- for (const server of removed) {
352
- this.local.delete(server);
353
- }
354
- for (const [name, server] of current) {
355
- const previous = this.local.get(name);
356
- if (previous) {
357
- if (!equals(previous, server)) {
358
- updated.push(server);
359
- this.local.set(name, server);
360
- }
361
- } else {
362
- added.push(server);
363
- this.local.set(name, server);
364
- }
365
- }
366
- for (const server of removed) {
367
- this.local.delete(server);
368
- this._onDidUninstallMcpServer.fire({
369
- name: server,
370
- mcpResource: this.mcpResource
371
- });
372
- }
373
- if (updated.length) {
374
- this._onDidUpdateMcpServers.fire(( updated.map(server => ({
375
- name: server.name,
376
- local: server,
377
- mcpResource: this.mcpResource
378
- }))));
379
- }
380
- if (added.length) {
381
- this._onDidInstallMcpServers.fire(( added.map(server => ({
382
- name: server.name,
383
- local: server,
384
- mcpResource: this.mcpResource
385
- }))));
386
- }
387
- } catch (error) {
388
- this.logService.error("Failed to load installed MCP servers:", error);
389
- }
390
- }
391
- async getInstalled() {
392
- await this.initialize();
393
- return Array.from(( this.local.values()));
394
- }
395
- async scanLocalServer(name, config) {
396
- let mcpServerInfo = await this.getLocalServerInfo(name, config);
397
- if (!mcpServerInfo) {
398
- mcpServerInfo = {
399
- name,
400
- version: config.version,
401
- galleryUrl: isString(config.gallery) ? config.gallery : undefined
402
- };
403
- }
404
- return {
405
- name,
406
- config,
407
- mcpResource: this.mcpResource,
408
- version: mcpServerInfo.version,
409
- location: mcpServerInfo.location,
410
- displayName: mcpServerInfo.displayName,
411
- description: mcpServerInfo.description,
412
- publisher: mcpServerInfo.publisher,
413
- publisherDisplayName: mcpServerInfo.publisherDisplayName,
414
- galleryUrl: mcpServerInfo.galleryUrl,
415
- galleryId: mcpServerInfo.galleryId,
416
- repositoryUrl: mcpServerInfo.repositoryUrl,
417
- readmeUrl: mcpServerInfo.readmeUrl,
418
- icon: mcpServerInfo.icon,
419
- codicon: mcpServerInfo.codicon,
420
- manifest: mcpServerInfo.manifest,
421
- source: config.gallery ? "gallery" : "local"
422
- };
423
- }
424
- async install(server, options) {
425
- this.logService.trace("MCP Management Service: install", server.name);
426
- this._onInstallMcpServer.fire({
427
- name: server.name,
428
- mcpResource: this.mcpResource
429
- });
430
- try {
431
- await this.mcpResourceScannerService.addMcpServers([server], this.mcpResource, this.target);
432
- await this.updateLocal();
433
- const local = this.local.get(server.name);
434
- if (!local) {
435
- throw ( new Error(`Failed to install MCP server: ${server.name}`));
436
- }
437
- return local;
438
- } catch (e) {
439
- this._onDidInstallMcpServers.fire([{
440
- name: server.name,
441
- error: e,
442
- mcpResource: this.mcpResource
443
- }]);
444
- throw e;
445
- }
446
- }
447
- async uninstall(server, options) {
448
- this.logService.trace("MCP Management Service: uninstall", server.name);
449
- this._onUninstallMcpServer.fire({
450
- name: server.name,
451
- mcpResource: this.mcpResource
452
- });
453
- try {
454
- const currentServers = await this.mcpResourceScannerService.scanMcpServers(this.mcpResource, this.target);
455
- if (!currentServers.servers) {
456
- return;
457
- }
458
- await this.mcpResourceScannerService.removeMcpServers([server.name], this.mcpResource, this.target);
459
- if (server.location) {
460
- await this.fileService.del(URI.revive(server.location), {
461
- recursive: true
462
- });
463
- }
464
- await this.updateLocal();
465
- } catch (e) {
466
- this._onDidUninstallMcpServer.fire({
467
- name: server.name,
468
- error: e,
469
- mcpResource: this.mcpResource
470
- });
471
- throw e;
472
- }
473
- }
474
- };
475
- AbstractMcpResourceManagementService = ( __decorate([( __param(2, IMcpGalleryService)), ( __param(3, IFileService)), ( __param(4, IUriIdentityService)), ( __param(5, ILogService)), ( __param(6, IMcpResourceScannerService))], AbstractMcpResourceManagementService));
476
- let McpUserResourceManagementService = class McpUserResourceManagementService extends AbstractMcpResourceManagementService {
477
- constructor(
478
- mcpResource,
479
- mcpGalleryService,
480
- fileService,
481
- uriIdentityService,
482
- logService,
483
- mcpResourceScannerService,
484
- environmentService
485
- ) {
486
- super(
487
- mcpResource,
488
- ConfigurationTarget.USER,
489
- mcpGalleryService,
490
- fileService,
491
- uriIdentityService,
492
- logService,
493
- mcpResourceScannerService
494
- );
495
- this.mcpLocation = uriIdentityService.extUri.joinPath(environmentService.userRoamingDataHome, "mcp");
496
- }
497
- async installFromGallery(server, options) {
498
- throw ( new Error("Not supported"));
499
- }
500
- async updateMetadata(local, gallery) {
501
- await this.updateMetadataFromGallery(gallery);
502
- await this.updateLocal();
503
- const updatedLocal = (await this.getInstalled()).find(s => s.name === local.name);
504
- if (!updatedLocal) {
505
- throw ( new Error(`Failed to find MCP server: ${local.name}`));
506
- }
507
- return updatedLocal;
508
- }
509
- async updateMetadataFromGallery(gallery) {
510
- const manifest = gallery.configuration;
511
- const location = this.getLocation(gallery.name, gallery.version);
512
- const manifestPath = this.uriIdentityService.extUri.joinPath(location, "manifest.json");
513
- const local = {
514
- galleryUrl: gallery.galleryUrl,
515
- galleryId: gallery.id,
516
- name: gallery.name,
517
- displayName: gallery.displayName,
518
- description: gallery.description,
519
- version: gallery.version,
520
- publisher: gallery.publisher,
521
- publisherDisplayName: gallery.publisherDisplayName,
522
- repositoryUrl: gallery.repositoryUrl,
523
- licenseUrl: gallery.license,
524
- icon: gallery.icon,
525
- codicon: gallery.codicon,
526
- manifest
527
- };
528
- await this.fileService.writeFile(manifestPath, VSBuffer.fromString(JSON.stringify(local)));
529
- if (gallery.readmeUrl || gallery.readme) {
530
- const readme = gallery.readme ? gallery.readme : await this.mcpGalleryService.getReadme(gallery, CancellationToken.None);
531
- await this.fileService.writeFile(
532
- this.uriIdentityService.extUri.joinPath(location, "README.md"),
533
- VSBuffer.fromString(readme)
534
- );
535
- }
536
- return manifest;
537
- }
538
- async getLocalServerInfo(name, mcpServerConfig) {
539
- let storedMcpServerInfo;
540
- let location;
541
- let readmeUrl;
542
- if (mcpServerConfig.gallery) {
543
- location = this.getLocation(name, mcpServerConfig.version);
544
- const manifestLocation = this.uriIdentityService.extUri.joinPath(location, "manifest.json");
545
- try {
546
- const content = await this.fileService.readFile(manifestLocation);
547
- storedMcpServerInfo = JSON.parse(( content.value.toString()));
548
- if (storedMcpServerInfo.galleryUrl?.includes("/v0/")) {
549
- storedMcpServerInfo.galleryUrl = storedMcpServerInfo.galleryUrl.substring(0, storedMcpServerInfo.galleryUrl.indexOf("/v0/"));
550
- await this.fileService.writeFile(manifestLocation, VSBuffer.fromString(JSON.stringify(storedMcpServerInfo)));
551
- }
552
- storedMcpServerInfo.location = location;
553
- readmeUrl = this.uriIdentityService.extUri.joinPath(location, "README.md");
554
- if (!(await this.fileService.exists(readmeUrl))) {
555
- readmeUrl = undefined;
556
- }
557
- storedMcpServerInfo.readmeUrl = readmeUrl;
558
- } catch (e) {
559
- this.logService.error("MCP Management Service: failed to read manifest", ( location.toString()), e);
560
- }
561
- }
562
- return storedMcpServerInfo;
563
- }
564
- getLocation(name, version) {
565
- name = name.replace("/", ".");
566
- return this.uriIdentityService.extUri.joinPath(this.mcpLocation, version ? `${name}-${version}` : name);
567
- }
568
- installFromUri(uri, options) {
569
- throw ( new Error("Method not supported."));
570
- }
571
- canInstall() {
572
- throw ( new Error("Not supported"));
573
- }
574
- };
575
- McpUserResourceManagementService = ( __decorate([( __param(1, IMcpGalleryService)), ( __param(2, IFileService)), ( __param(3, IUriIdentityService)), ( __param(4, ILogService)), ( __param(5, IMcpResourceScannerService)), ( __param(6, IEnvironmentService))], McpUserResourceManagementService));
576
- let AbstractMcpManagementService = class AbstractMcpManagementService extends AbstractCommonMcpManagementService {
577
- constructor(allowedMcpServersService, logService) {
578
- super(logService);
579
- this.allowedMcpServersService = allowedMcpServersService;
580
- }
581
- canInstall(server) {
582
- const allowedToInstall = this.allowedMcpServersService.isAllowed(server);
583
- if (allowedToInstall !== true) {
584
- return (new MarkdownString(localize(
585
- 2005,
586
- "This mcp server cannot be installed because {0}",
587
- allowedToInstall.value
588
- )));
589
- }
590
- return true;
591
- }
592
- };
593
- AbstractMcpManagementService = ( __decorate([( __param(0, IAllowedMcpServersService)), ( __param(1, ILogService))], AbstractMcpManagementService));
594
- let McpManagementService = class McpManagementService extends AbstractMcpManagementService {
595
- constructor(
596
- allowedMcpServersService,
597
- logService,
598
- userDataProfilesService,
599
- instantiationService
600
- ) {
601
- super(allowedMcpServersService, logService);
602
- this.userDataProfilesService = userDataProfilesService;
603
- this.instantiationService = instantiationService;
604
- this._onInstallMcpServer = this._register(( new Emitter()));
605
- this.onInstallMcpServer = this._onInstallMcpServer.event;
606
- this._onDidInstallMcpServers = this._register(( new Emitter()));
607
- this.onDidInstallMcpServers = this._onDidInstallMcpServers.event;
608
- this._onDidUpdateMcpServers = this._register(( new Emitter()));
609
- this.onDidUpdateMcpServers = this._onDidUpdateMcpServers.event;
610
- this._onUninstallMcpServer = this._register(( new Emitter()));
611
- this.onUninstallMcpServer = this._onUninstallMcpServer.event;
612
- this._onDidUninstallMcpServer = this._register(( new Emitter()));
613
- this.onDidUninstallMcpServer = this._onDidUninstallMcpServer.event;
614
- this.mcpResourceManagementServices = ( new ResourceMap());
615
- }
616
- getMcpResourceManagementService(mcpResource) {
617
- let mcpResourceManagementService = this.mcpResourceManagementServices.get(mcpResource);
618
- if (!mcpResourceManagementService) {
619
- const disposables = ( new DisposableStore());
620
- const service = disposables.add(this.createMcpResourceManagementService(mcpResource));
621
- disposables.add(service.onInstallMcpServer(e => this._onInstallMcpServer.fire(e)));
622
- disposables.add(service.onDidInstallMcpServers(e => this._onDidInstallMcpServers.fire(e)));
623
- disposables.add(service.onDidUpdateMcpServers(e => this._onDidUpdateMcpServers.fire(e)));
624
- disposables.add(service.onUninstallMcpServer(e => this._onUninstallMcpServer.fire(e)));
625
- disposables.add(
626
- service.onDidUninstallMcpServer(e => this._onDidUninstallMcpServer.fire(e))
627
- );
628
- this.mcpResourceManagementServices.set(mcpResource, mcpResourceManagementService = {
629
- service,
630
- dispose: () => disposables.dispose()
631
- });
632
- }
633
- return mcpResourceManagementService.service;
634
- }
635
- async getInstalled(mcpResource) {
636
- const mcpResourceUri = mcpResource || this.userDataProfilesService.defaultProfile.mcpResource;
637
- return this.getMcpResourceManagementService(mcpResourceUri).getInstalled();
638
- }
639
- async install(server, options) {
640
- const mcpResourceUri = options?.mcpResource || this.userDataProfilesService.defaultProfile.mcpResource;
641
- return this.getMcpResourceManagementService(mcpResourceUri).install(server, options);
642
- }
643
- async uninstall(server, options) {
644
- const mcpResourceUri = options?.mcpResource || this.userDataProfilesService.defaultProfile.mcpResource;
645
- return this.getMcpResourceManagementService(mcpResourceUri).uninstall(server, options);
646
- }
647
- async installFromGallery(server, options) {
648
- const mcpResourceUri = options?.mcpResource || this.userDataProfilesService.defaultProfile.mcpResource;
649
- return this.getMcpResourceManagementService(mcpResourceUri).installFromGallery(server, options);
650
- }
651
- async updateMetadata(local, gallery, mcpResource) {
652
- return this.getMcpResourceManagementService(mcpResource || this.userDataProfilesService.defaultProfile.mcpResource).updateMetadata(local, gallery);
653
- }
654
- dispose() {
655
- this.mcpResourceManagementServices.forEach(service => service.dispose());
656
- this.mcpResourceManagementServices.clear();
657
- super.dispose();
658
- }
659
- createMcpResourceManagementService(mcpResource) {
660
- return this.instantiationService.createInstance(McpUserResourceManagementService, mcpResource);
661
- }
662
- };
663
- McpManagementService = ( __decorate([( __param(0, IAllowedMcpServersService)), ( __param(1, ILogService)), ( __param(2, IUserDataProfilesService)), ( __param(3, IInstantiationService))], McpManagementService));
664
-
665
- export { AbstractCommonMcpManagementService, AbstractMcpManagementService, AbstractMcpResourceManagementService, McpManagementService, McpUserResourceManagementService };