Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/mcp/node/mcpManagementService.ts
5237 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.name, server.galleryUrl);
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 ?? (
36
manifest.remotes?.length
37
? RegistryType.REMOTE
38
: (manifest.packages?.[0]?.registryType ?? RegistryType.REMOTE)
39
);
40
41
const { mcpServerConfiguration, notices } = this.getMcpServerConfigurationFromManifest(manifest, packageType);
42
43
if (notices.length > 0) {
44
this.logService.warn(`MCP Management Service: Warnings while installing ${server.name}`, notices);
45
}
46
47
const installable: IInstallableMcpServer = {
48
name: server.name,
49
config: {
50
...mcpServerConfiguration.config,
51
gallery: server.galleryUrl ?? true,
52
version: server.version
53
},
54
inputs: mcpServerConfiguration.inputs
55
};
56
57
await this.mcpResourceScannerService.addMcpServers([installable], this.mcpResource, this.target);
58
59
await this.updateLocal();
60
const local = (await this.getInstalled()).find(s => s.name === server.name);
61
if (!local) {
62
throw new Error(`Failed to install MCP server: ${server.name}`);
63
}
64
return local;
65
} catch (e) {
66
this._onDidInstallMcpServers.fire([{ name: server.name, source: server, error: e, mcpResource: this.mcpResource }]);
67
throw e;
68
}
69
}
70
71
}
72
73
export class McpManagementService extends CommonMcpManagementService implements IMcpManagementService {
74
protected override createMcpResourceManagementService(mcpResource: URI): McpUserResourceManagementService {
75
return this.instantiationService.createInstance(McpUserResourceManagementService, mcpResource);
76
}
77
}
78
79