Path: blob/main/src/vs/workbench/services/mcp/browser/mcpGalleryManifestService.ts
5310 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 { IMcpGalleryManifest, IMcpGalleryManifestService, McpGalleryManifestStatus } from '../../../../platform/mcp/common/mcpGalleryManifest.js';6import { McpGalleryManifestService } from '../../../../platform/mcp/common/mcpGalleryManifestService.js';7import { IProductService } from '../../../../platform/product/common/productService.js';8import { IRemoteAgentService } from '../../remote/common/remoteAgentService.js';9import { IRequestService } from '../../../../platform/request/common/request.js';10import { ILogService } from '../../../../platform/log/common/log.js';11import { Emitter } from '../../../../base/common/event.js';12import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';13import { IMcpGalleryConfig, mcpGalleryServiceUrlConfig } from '../../../../platform/mcp/common/mcpManagement.js';1415export class WorkbenchMcpGalleryManifestService extends McpGalleryManifestService implements IMcpGalleryManifestService {1617private mcpGalleryManifest: IMcpGalleryManifest | null = null;1819private _onDidChangeMcpGalleryManifest = this._register(new Emitter<IMcpGalleryManifest | null>());20override readonly onDidChangeMcpGalleryManifest = this._onDidChangeMcpGalleryManifest.event;2122private currentStatus: McpGalleryManifestStatus = McpGalleryManifestStatus.Unavailable;23override get mcpGalleryManifestStatus(): McpGalleryManifestStatus { return this.currentStatus; }24private _onDidChangeMcpGalleryManifestStatus = this._register(new Emitter<McpGalleryManifestStatus>());25override readonly onDidChangeMcpGalleryManifestStatus = this._onDidChangeMcpGalleryManifestStatus.event;2627constructor(28@IProductService productService: IProductService,29@IRemoteAgentService remoteAgentService: IRemoteAgentService,30@IRequestService requestService: IRequestService,31@ILogService logService: ILogService,32@IConfigurationService private readonly configurationService: IConfigurationService,33) {34super(productService, requestService, logService);35const remoteConnection = remoteAgentService.getConnection();36if (remoteConnection) {37const channel = remoteConnection.getChannel('mcpGalleryManifest');38this.getMcpGalleryManifest().then(manifest => {39channel.call('setMcpGalleryManifest', [manifest]);40this._register(this.onDidChangeMcpGalleryManifest(manifest => channel.call('setMcpGalleryManifest', [manifest])));41});42}43}4445private initPromise: Promise<void> | undefined;46override async getMcpGalleryManifest(): Promise<IMcpGalleryManifest | null> {47if (!this.initPromise) {48this.initPromise = this.doGetMcpGalleryManifest();49}50await this.initPromise;51return this.mcpGalleryManifest;52}5354private async doGetMcpGalleryManifest(): Promise<void> {55await this.getAndUpdateMcpGalleryManifest();5657this._register(this.configurationService.onDidChangeConfiguration(e => {58if (e.affectsConfiguration(mcpGalleryServiceUrlConfig) || e.affectsConfiguration('chat.mcp.gallery.version')) {59this.getAndUpdateMcpGalleryManifest();60}61}));62}6364private async getAndUpdateMcpGalleryManifest(): Promise<void> {65const mcpGalleryConfig = this.configurationService.getValue<IMcpGalleryConfig | undefined>('chat.mcp.gallery');66if (mcpGalleryConfig?.serviceUrl) {67this.update(await this.createMcpGalleryManifest(mcpGalleryConfig.serviceUrl, mcpGalleryConfig.version));68} else {69this.update(await super.getMcpGalleryManifest());70}71}7273private update(manifest: IMcpGalleryManifest | null): void {74if (this.mcpGalleryManifest?.url === manifest?.url && this.mcpGalleryManifest?.version === manifest?.version) {75return;76}7778this.mcpGalleryManifest = manifest;79if (this.mcpGalleryManifest) {80this.logService.info('MCP Registry configured:', this.mcpGalleryManifest.url);81} else {82this.logService.info('No MCP Registry configured');83}84this.currentStatus = this.mcpGalleryManifest ? McpGalleryManifestStatus.Available : McpGalleryManifestStatus.Unavailable;85this._onDidChangeMcpGalleryManifest.fire(this.mcpGalleryManifest);86this._onDidChangeMcpGalleryManifestStatus.fire(this.currentStatus);87}8889}909192