Path: blob/main/src/vs/workbench/contrib/mcp/browser/mcpGatewayService.ts
5251 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 { URI } from '../../../../base/common/uri.js';6import { ProxyChannel } from '../../../../base/parts/ipc/common/ipc.js';7import { IMcpGatewayService, McpGatewayChannelName } from '../../../../platform/mcp/common/mcpGateway.js';8import { IRemoteAgentService } from '../../../services/remote/common/remoteAgentService.js';9import { IMcpGatewayResult, IWorkbenchMcpGatewayService } from '../common/mcpGatewayService.js';1011/**12* Browser implementation of the MCP Gateway Service.13*14* In browser/serverless web environments without a remote connection,15* there is no Node.js process available to create an HTTP server.16*17* When running with a remote connection, the gateway is created on the18* remote server via IPC.19*/20export class BrowserMcpGatewayService implements IWorkbenchMcpGatewayService {21declare readonly _serviceBrand: undefined;2223constructor(24@IRemoteAgentService private readonly _remoteAgentService: IRemoteAgentService,25) { }2627async createGateway(inRemote: boolean): Promise<IMcpGatewayResult | undefined> {28// Browser can only create gateways in remote environment29if (!inRemote) {30return undefined;31}3233const connection = this._remoteAgentService.getConnection();34if (!connection) {35// Serverless web environment - no gateway available36return undefined;37}3839// Use the remote server's gateway service40return connection.withChannel(McpGatewayChannelName, async channel => {41const service = ProxyChannel.toService<IMcpGatewayService>(channel);42const info = await service.createGateway(undefined);4344return {45address: URI.revive(info.address),46dispose: () => {47service.disposeGateway(info.gatewayId);48}49};50});51}52}535455