Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/mcp/browser/mcpGatewayService.ts
5251 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 { IMcpGatewayService, McpGatewayChannelName } from '../../../../platform/mcp/common/mcpGateway.js';
9
import { IRemoteAgentService } from '../../../services/remote/common/remoteAgentService.js';
10
import { IMcpGatewayResult, IWorkbenchMcpGatewayService } from '../common/mcpGatewayService.js';
11
12
/**
13
* Browser implementation of the MCP Gateway Service.
14
*
15
* In browser/serverless web environments without a remote connection,
16
* there is no Node.js process available to create an HTTP server.
17
*
18
* When running with a remote connection, the gateway is created on the
19
* remote server via IPC.
20
*/
21
export class BrowserMcpGatewayService implements IWorkbenchMcpGatewayService {
22
declare readonly _serviceBrand: undefined;
23
24
constructor(
25
@IRemoteAgentService private readonly _remoteAgentService: IRemoteAgentService,
26
) { }
27
28
async createGateway(inRemote: boolean): Promise<IMcpGatewayResult | undefined> {
29
// Browser can only create gateways in remote environment
30
if (!inRemote) {
31
return undefined;
32
}
33
34
const connection = this._remoteAgentService.getConnection();
35
if (!connection) {
36
// Serverless web environment - no gateway available
37
return undefined;
38
}
39
40
// Use the remote server's gateway service
41
return connection.withChannel(McpGatewayChannelName, async channel => {
42
const service = ProxyChannel.toService<IMcpGatewayService>(channel);
43
const info = await service.createGateway(undefined);
44
45
return {
46
address: URI.revive(info.address),
47
dispose: () => {
48
service.disposeGateway(info.gatewayId);
49
}
50
};
51
});
52
}
53
}
54
55