Path: blob/main/src/vs/platform/mcp/node/mcpManagementService.ts
5237 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.name, server.galleryUrl);2930this._onInstallMcpServer.fire({ name: server.name, mcpResource: this.mcpResource });3132try {33const manifest = await this.updateMetadataFromGallery(server);34const packageType = options?.packageType ?? (35manifest.remotes?.length36? RegistryType.REMOTE37: (manifest.packages?.[0]?.registryType ?? RegistryType.REMOTE)38);3940const { mcpServerConfiguration, notices } = this.getMcpServerConfigurationFromManifest(manifest, packageType);4142if (notices.length > 0) {43this.logService.warn(`MCP Management Service: Warnings while installing ${server.name}`, notices);44}4546const installable: IInstallableMcpServer = {47name: server.name,48config: {49...mcpServerConfiguration.config,50gallery: server.galleryUrl ?? true,51version: server.version52},53inputs: mcpServerConfiguration.inputs54};5556await this.mcpResourceScannerService.addMcpServers([installable], this.mcpResource, this.target);5758await this.updateLocal();59const local = (await this.getInstalled()).find(s => s.name === server.name);60if (!local) {61throw new Error(`Failed to install MCP server: ${server.name}`);62}63return local;64} catch (e) {65this._onDidInstallMcpServers.fire([{ name: server.name, source: server, error: e, mcpResource: this.mcpResource }]);66throw e;67}68}6970}7172export class McpManagementService extends CommonMcpManagementService implements IMcpManagementService {73protected override createMcpResourceManagementService(mcpResource: URI): McpUserResourceManagementService {74return this.instantiationService.createInstance(McpUserResourceManagementService, mcpResource);75}76}777879