Path: blob/main/src/vs/platform/mcp/node/mcpManagementService.ts
3294 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { URI } from '../../../base/common/uri.js';6import { IEnvironmentService } from '../../environment/common/environment.js';7import { IFileService } from '../../files/common/files.js';8import { ILogService } from '../../log/common/log.js';9import { IUriIdentityService } from '../../uriIdentity/common/uriIdentity.js';10import { IGalleryMcpServer, IMcpGalleryService, IMcpManagementService, InstallOptions, ILocalMcpServer, RegistryType, IInstallableMcpServer } from '../common/mcpManagement.js';11import { McpUserResourceManagementService as CommonMcpUserResourceManagementService, McpManagementService as CommonMcpManagementService } from '../common/mcpManagementService.js';12import { IMcpResourceScannerService } from '../common/mcpResourceScannerService.js';1314export class McpUserResourceManagementService extends CommonMcpUserResourceManagementService {15constructor(16mcpResource: URI,17@IMcpGalleryService mcpGalleryService: IMcpGalleryService,18@IFileService fileService: IFileService,19@IUriIdentityService uriIdentityService: IUriIdentityService,20@ILogService logService: ILogService,21@IMcpResourceScannerService mcpResourceScannerService: IMcpResourceScannerService,22@IEnvironmentService environmentService: IEnvironmentService,23) {24super(mcpResource, mcpGalleryService, fileService, uriIdentityService, logService, mcpResourceScannerService, environmentService);25}2627override async installFromGallery(server: IGalleryMcpServer, options?: InstallOptions): Promise<ILocalMcpServer> {28this.logService.trace('MCP Management Service: installGallery', server.url);2930this._onInstallMcpServer.fire({ name: server.name, mcpResource: this.mcpResource });3132try {33const manifest = await this.updateMetadataFromGallery(server);34const packageType = options?.packageType ?? manifest.packages?.[0]?.registry_type ?? RegistryType.REMOTE;3536const { config, inputs } = this.getMcpServerConfigurationFromManifest(manifest, packageType);3738const installable: IInstallableMcpServer = {39name: server.name,40config: {41...config,42gallery: server.url ?? true,43version: server.version44},45inputs46};4748await this.mcpResourceScannerService.addMcpServers([installable], this.mcpResource, this.target);4950await this.updateLocal();51const local = (await this.getInstalled()).find(s => s.name === server.name);52if (!local) {53throw new Error(`Failed to install MCP server: ${server.name}`);54}55return local;56} catch (e) {57this._onDidInstallMcpServers.fire([{ name: server.name, source: server, error: e, mcpResource: this.mcpResource }]);58throw e;59}60}6162}6364export class McpManagementService extends CommonMcpManagementService implements IMcpManagementService {65protected override createMcpResourceManagementService(mcpResource: URI): McpUserResourceManagementService {66return this.instantiationService.createInstance(McpUserResourceManagementService, mcpResource);67}68}697071