Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/services/mcp/browser/mcpGalleryManifestService.ts
5310 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 { IMcpGalleryManifest, IMcpGalleryManifestService, McpGalleryManifestStatus } from '../../../../platform/mcp/common/mcpGalleryManifest.js';
7
import { McpGalleryManifestService } from '../../../../platform/mcp/common/mcpGalleryManifestService.js';
8
import { IProductService } from '../../../../platform/product/common/productService.js';
9
import { IRemoteAgentService } from '../../remote/common/remoteAgentService.js';
10
import { IRequestService } from '../../../../platform/request/common/request.js';
11
import { ILogService } from '../../../../platform/log/common/log.js';
12
import { Emitter } from '../../../../base/common/event.js';
13
import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';
14
import { IMcpGalleryConfig, mcpGalleryServiceUrlConfig } from '../../../../platform/mcp/common/mcpManagement.js';
15
16
export class WorkbenchMcpGalleryManifestService extends McpGalleryManifestService implements IMcpGalleryManifestService {
17
18
private mcpGalleryManifest: IMcpGalleryManifest | null = null;
19
20
private _onDidChangeMcpGalleryManifest = this._register(new Emitter<IMcpGalleryManifest | null>());
21
override readonly onDidChangeMcpGalleryManifest = this._onDidChangeMcpGalleryManifest.event;
22
23
private currentStatus: McpGalleryManifestStatus = McpGalleryManifestStatus.Unavailable;
24
override get mcpGalleryManifestStatus(): McpGalleryManifestStatus { return this.currentStatus; }
25
private _onDidChangeMcpGalleryManifestStatus = this._register(new Emitter<McpGalleryManifestStatus>());
26
override readonly onDidChangeMcpGalleryManifestStatus = this._onDidChangeMcpGalleryManifestStatus.event;
27
28
constructor(
29
@IProductService productService: IProductService,
30
@IRemoteAgentService remoteAgentService: IRemoteAgentService,
31
@IRequestService requestService: IRequestService,
32
@ILogService logService: ILogService,
33
@IConfigurationService private readonly configurationService: IConfigurationService,
34
) {
35
super(productService, requestService, logService);
36
const remoteConnection = remoteAgentService.getConnection();
37
if (remoteConnection) {
38
const channel = remoteConnection.getChannel('mcpGalleryManifest');
39
this.getMcpGalleryManifest().then(manifest => {
40
channel.call('setMcpGalleryManifest', [manifest]);
41
this._register(this.onDidChangeMcpGalleryManifest(manifest => channel.call('setMcpGalleryManifest', [manifest])));
42
});
43
}
44
}
45
46
private initPromise: Promise<void> | undefined;
47
override async getMcpGalleryManifest(): Promise<IMcpGalleryManifest | null> {
48
if (!this.initPromise) {
49
this.initPromise = this.doGetMcpGalleryManifest();
50
}
51
await this.initPromise;
52
return this.mcpGalleryManifest;
53
}
54
55
private async doGetMcpGalleryManifest(): Promise<void> {
56
await this.getAndUpdateMcpGalleryManifest();
57
58
this._register(this.configurationService.onDidChangeConfiguration(e => {
59
if (e.affectsConfiguration(mcpGalleryServiceUrlConfig) || e.affectsConfiguration('chat.mcp.gallery.version')) {
60
this.getAndUpdateMcpGalleryManifest();
61
}
62
}));
63
}
64
65
private async getAndUpdateMcpGalleryManifest(): Promise<void> {
66
const mcpGalleryConfig = this.configurationService.getValue<IMcpGalleryConfig | undefined>('chat.mcp.gallery');
67
if (mcpGalleryConfig?.serviceUrl) {
68
this.update(await this.createMcpGalleryManifest(mcpGalleryConfig.serviceUrl, mcpGalleryConfig.version));
69
} else {
70
this.update(await super.getMcpGalleryManifest());
71
}
72
}
73
74
private update(manifest: IMcpGalleryManifest | null): void {
75
if (this.mcpGalleryManifest?.url === manifest?.url && this.mcpGalleryManifest?.version === manifest?.version) {
76
return;
77
}
78
79
this.mcpGalleryManifest = manifest;
80
if (this.mcpGalleryManifest) {
81
this.logService.info('MCP Registry configured:', this.mcpGalleryManifest.url);
82
} else {
83
this.logService.info('No MCP Registry configured');
84
}
85
this.currentStatus = this.mcpGalleryManifest ? McpGalleryManifestStatus.Available : McpGalleryManifestStatus.Unavailable;
86
this._onDidChangeMcpGalleryManifest.fire(this.mcpGalleryManifest);
87
this._onDidChangeMcpGalleryManifestStatus.fire(this.currentStatus);
88
}
89
90
}
91
92