Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/mcp/electron-main/mcpGatewayMainChannel.ts
5252 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 in the electron-main process.
13
*
14
* This channel tracks which client (identified by ctx) creates gateways,
15
* enabling cleanup when a client disconnects (e.g., window crash).
16
*/
17
export class McpGatewayMainChannel extends Disposable implements IServerChannel<string> {
18
19
constructor(
20
ipcServer: IPCServer,
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: string, _event: string): Event<T> {
28
throw new Error('Invalid listen');
29
}
30
31
async call<T>(ctx: string, command: string, args?: unknown): Promise<T> {
32
switch (command) {
33
case 'createGateway': {
34
// Use the context (client ID) to track gateway ownership
35
const result = await this.mcpGatewayService.createGateway(ctx);
36
return result as T;
37
}
38
case 'disposeGateway': {
39
await this.mcpGatewayService.disposeGateway(args as string);
40
return undefined as T;
41
}
42
}
43
throw new Error(`Invalid call: ${command}`);
44
}
45
}
46
47