Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/mcp/node/mcpGatewayChannel.ts
5240 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 { Event } from '../../../base/common/event.js';
7
import { Disposable } from '../../../base/common/lifecycle.js';
8
import { IPCServer, IServerChannel } from '../../../base/parts/ipc/common/ipc.js';
9
import { IMcpGatewayService } from '../common/mcpGateway.js';
10
11
/**
12
* IPC channel for the MCP Gateway service, used by the remote server.
13
*
14
* This channel tracks which client (identified by reconnectionToken) creates gateways,
15
* enabling cleanup when a client disconnects.
16
*/
17
export class McpGatewayChannel<TContext> extends Disposable implements IServerChannel<TContext> {
18
19
constructor(
20
ipcServer: IPCServer<TContext>,
21
@IMcpGatewayService private readonly mcpGatewayService: IMcpGatewayService
22
) {
23
super();
24
this._register(ipcServer.onDidRemoveConnection(c => mcpGatewayService.disposeGatewaysForClient(c.ctx)));
25
}
26
27
listen<T>(_ctx: TContext, _event: string): Event<T> {
28
throw new Error('Invalid listen');
29
}
30
31
async call<T>(ctx: TContext, command: string, args?: unknown): Promise<T> {
32
switch (command) {
33
case 'createGateway': {
34
const result = await this.mcpGatewayService.createGateway(ctx);
35
return result as T;
36
}
37
case 'disposeGateway': {
38
await this.mcpGatewayService.disposeGateway(args as string);
39
return undefined as T;
40
}
41
}
42
43
throw new Error(`Invalid call: ${command}`);
44
}
45
}
46
47