Path: blob/main/src/vs/platform/mcp/node/mcpGatewayChannel.ts
5240 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { Event } from '../../../base/common/event.js';6import { Disposable } from '../../../base/common/lifecycle.js';7import { IPCServer, IServerChannel } from '../../../base/parts/ipc/common/ipc.js';8import { IMcpGatewayService } from '../common/mcpGateway.js';910/**11* IPC channel for the MCP Gateway service, used by the remote server.12*13* This channel tracks which client (identified by reconnectionToken) creates gateways,14* enabling cleanup when a client disconnects.15*/16export class McpGatewayChannel<TContext> extends Disposable implements IServerChannel<TContext> {1718constructor(19ipcServer: IPCServer<TContext>,20@IMcpGatewayService private readonly mcpGatewayService: IMcpGatewayService21) {22super();23this._register(ipcServer.onDidRemoveConnection(c => mcpGatewayService.disposeGatewaysForClient(c.ctx)));24}2526listen<T>(_ctx: TContext, _event: string): Event<T> {27throw new Error('Invalid listen');28}2930async call<T>(ctx: TContext, command: string, args?: unknown): Promise<T> {31switch (command) {32case 'createGateway': {33const result = await this.mcpGatewayService.createGateway(ctx);34return result as T;35}36case 'disposeGateway': {37await this.mcpGatewayService.disposeGateway(args as string);38return undefined as T;39}40}4142throw new Error(`Invalid call: ${command}`);43}44}454647