Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/mcp/node/mcpManagementService.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 { URI } from '../../../base/common/uri.js';
7
import { IEnvironmentService } from '../../environment/common/environment.js';
8
import { IFileService } from '../../files/common/files.js';
9
import { ILogService } from '../../log/common/log.js';
10
import { IUriIdentityService } from '../../uriIdentity/common/uriIdentity.js';
11
import { IGalleryMcpServer, IMcpGalleryService, IMcpManagementService, InstallOptions, ILocalMcpServer, RegistryType, IInstallableMcpServer } from '../common/mcpManagement.js';
12
import { McpUserResourceManagementService as CommonMcpUserResourceManagementService, McpManagementService as CommonMcpManagementService } from '../common/mcpManagementService.js';
13
import { IMcpResourceScannerService } from '../common/mcpResourceScannerService.js';
14
15
export class McpUserResourceManagementService extends CommonMcpUserResourceManagementService {
16
constructor(
17
mcpResource: URI,
18
@IMcpGalleryService mcpGalleryService: IMcpGalleryService,
19
@IFileService fileService: IFileService,
20
@IUriIdentityService uriIdentityService: IUriIdentityService,
21
@ILogService logService: ILogService,
22
@IMcpResourceScannerService mcpResourceScannerService: IMcpResourceScannerService,
23
@IEnvironmentService environmentService: IEnvironmentService,
24
) {
25
super(mcpResource, mcpGalleryService, fileService, uriIdentityService, logService, mcpResourceScannerService, environmentService);
26
}
27
28
override async installFromGallery(server: IGalleryMcpServer, options?: InstallOptions): Promise<ILocalMcpServer> {
29
this.logService.trace('MCP Management Service: installGallery', server.url);
30
31
this._onInstallMcpServer.fire({ name: server.name, mcpResource: this.mcpResource });
32
33
try {
34
const manifest = await this.updateMetadataFromGallery(server);
35
const packageType = options?.packageType ?? manifest.packages?.[0]?.registry_type ?? RegistryType.REMOTE;
36
37
const { config, inputs } = this.getMcpServerConfigurationFromManifest(manifest, packageType);
38
39
const installable: IInstallableMcpServer = {
40
name: server.name,
41
config: {
42
...config,
43
gallery: server.url ?? true,
44
version: server.version
45
},
46
inputs
47
};
48
49
await this.mcpResourceScannerService.addMcpServers([installable], this.mcpResource, this.target);
50
51
await this.updateLocal();
52
const local = (await this.getInstalled()).find(s => s.name === server.name);
53
if (!local) {
54
throw new Error(`Failed to install MCP server: ${server.name}`);
55
}
56
return local;
57
} catch (e) {
58
this._onDidInstallMcpServers.fire([{ name: server.name, source: server, error: e, mcpResource: this.mcpResource }]);
59
throw e;
60
}
61
}
62
63
}
64
65
export class McpManagementService extends CommonMcpManagementService implements IMcpManagementService {
66
protected override createMcpResourceManagementService(mcpResource: URI): McpUserResourceManagementService {
67
return this.instantiationService.createInstance(McpUserResourceManagementService, mcpResource);
68
}
69
}
70
71