Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/mcp/electron-browser/mcpGatewayService.ts
5263 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 { URI } from '../../../../base/common/uri.js';
7
import { ProxyChannel } from '../../../../base/parts/ipc/common/ipc.js';
8
import { IMainProcessService } from '../../../../platform/ipc/common/mainProcessService.js';
9
import { IMcpGatewayService, McpGatewayChannelName } from '../../../../platform/mcp/common/mcpGateway.js';
10
import { IRemoteAgentService } from '../../../services/remote/common/remoteAgentService.js';
11
import { IMcpGatewayResult, IWorkbenchMcpGatewayService } from '../common/mcpGatewayService.js';
12
13
/**
14
* Electron workbench implementation of the MCP Gateway Service.
15
*
16
* This implementation can create gateways either in the main process (local)
17
* or on a remote server (if connected).
18
*/
19
export class WorkbenchMcpGatewayService implements IWorkbenchMcpGatewayService {
20
declare readonly _serviceBrand: undefined;
21
22
private readonly _localPlatformService: IMcpGatewayService;
23
24
constructor(
25
@IMainProcessService mainProcessService: IMainProcessService,
26
@IRemoteAgentService private readonly _remoteAgentService: IRemoteAgentService,
27
) {
28
this._localPlatformService = ProxyChannel.toService<IMcpGatewayService>(
29
mainProcessService.getChannel(McpGatewayChannelName)
30
);
31
}
32
33
async createGateway(inRemote: boolean): Promise<IMcpGatewayResult | undefined> {
34
if (inRemote) {
35
return this._createRemoteGateway();
36
} else {
37
return this._createLocalGateway();
38
}
39
}
40
41
private async _createLocalGateway(): Promise<IMcpGatewayResult> {
42
const info = await this._localPlatformService.createGateway(undefined);
43
44
return {
45
address: URI.revive(info.address),
46
dispose: () => {
47
this._localPlatformService.disposeGateway(info.gatewayId);
48
}
49
};
50
}
51
52
private async _createRemoteGateway(): Promise<IMcpGatewayResult | undefined> {
53
const connection = this._remoteAgentService.getConnection();
54
if (!connection) {
55
// No remote connection - cannot create remote gateway
56
return undefined;
57
}
58
59
return connection.withChannel(McpGatewayChannelName, async channel => {
60
const service = ProxyChannel.toService<IMcpGatewayService>(channel);
61
const info = await service.createGateway(undefined);
62
63
return {
64
address: URI.revive(info.address),
65
dispose: () => {
66
service.disposeGateway(info.gatewayId);
67
}
68
};
69
});
70
}
71
}
72
73