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