Path: blob/main/src/vs/workbench/services/mcp/electron-browser/mcpGalleryManifestService.ts
3296 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 { Emitter } from '../../../../base/common/event.js';6import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';7import { IMcpGalleryManifestService, IMcpGalleryManifest, McpGalleryManifestStatus } from '../../../../platform/mcp/common/mcpGalleryManifest.js';8import { McpGalleryManifestService as McpGalleryManifestService } from '../../../../platform/mcp/common/mcpGalleryManifestService.js';9import { InstantiationType, registerSingleton } from '../../../../platform/instantiation/common/extensions.js';10import { ISharedProcessService } from '../../../../platform/ipc/electron-browser/services.js';11import { IProductService } from '../../../../platform/product/common/productService.js';12import { IRemoteAgentService } from '../../remote/common/remoteAgentService.js';13import { mcpGalleryServiceUrlConfig } from '../../../../platform/mcp/common/mcpManagement.js';14import { ILogService } from '../../../../platform/log/common/log.js';1516export class WorkbenchMcpGalleryManifestService extends McpGalleryManifestService implements IMcpGalleryManifestService {1718private mcpGalleryManifest: IMcpGalleryManifest | null = null;1920private _onDidChangeMcpGalleryManifest = this._register(new Emitter<IMcpGalleryManifest | null>());21override readonly onDidChangeMcpGalleryManifest = this._onDidChangeMcpGalleryManifest.event;2223private currentStatus: McpGalleryManifestStatus = McpGalleryManifestStatus.Unavailable;24override get mcpGalleryManifestStatus(): McpGalleryManifestStatus { return this.currentStatus; }25private _onDidChangeMcpGalleryManifestStatus = this._register(new Emitter<McpGalleryManifestStatus>());26override readonly onDidChangeMcpGalleryManifestStatus = this._onDidChangeMcpGalleryManifestStatus.event;2728constructor(29@IProductService productService: IProductService,30@IRemoteAgentService remoteAgentService: IRemoteAgentService,31@ISharedProcessService sharedProcessService: ISharedProcessService,32@IConfigurationService private readonly configurationService: IConfigurationService,33@ILogService private readonly logService: ILogService,34) {35super(productService);3637const channels = [sharedProcessService.getChannel('mcpGalleryManifest')];38const remoteConnection = remoteAgentService.getConnection();39if (remoteConnection) {40channels.push(remoteConnection.getChannel('mcpGalleryManifest'));41}42this.getMcpGalleryManifest().then(manifest => {43channels.forEach(channel => channel.call('setMcpGalleryManifest', [manifest]));44});45}4647private initPromise: Promise<void> | undefined;48override async getMcpGalleryManifest(): Promise<IMcpGalleryManifest | null> {49if (!this.initPromise) {50this.initPromise = this.doGetMcpGalleryManifest();51}52await this.initPromise;53return this.mcpGalleryManifest;54}5556private async doGetMcpGalleryManifest(): Promise<void> {57if (this.productService.quality === 'stable') {58return;59}6061await this.getAndUpdateMcpGalleryManifest();6263this._register(this.configurationService.onDidChangeConfiguration(e => {64if (e.affectsConfiguration(mcpGalleryServiceUrlConfig)) {65this.getAndUpdateMcpGalleryManifest();66}67}));68}6970private async getAndUpdateMcpGalleryManifest(): Promise<void> {71const value = this.configurationService.getValue<string>(mcpGalleryServiceUrlConfig);72if (value) {73this.update(this.createMcpGalleryManifest(value));74} else {75this.update(await super.getMcpGalleryManifest());76}77}7879private update(manifest: IMcpGalleryManifest | null): void {80if (this.mcpGalleryManifest?.url === manifest?.url) {81return;82}8384this.mcpGalleryManifest = manifest;85if (this.mcpGalleryManifest) {86this.logService.info('MCP Registry configured:', this.mcpGalleryManifest.url);87} else {88this.logService.info('No MCP Registry configured');89}90this.currentStatus = this.mcpGalleryManifest ? McpGalleryManifestStatus.Available : McpGalleryManifestStatus.Unavailable;91this._onDidChangeMcpGalleryManifest.fire(this.mcpGalleryManifest);92this._onDidChangeMcpGalleryManifestStatus.fire(this.currentStatus);93}9495}9697registerSingleton(IMcpGalleryManifestService, WorkbenchMcpGalleryManifestService, InstantiationType.Eager);9899100