Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/mcp/common/mcpGateway.ts
5243 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 { createDecorator } from '../../instantiation/common/instantiation.js';
8
9
export const IMcpGatewayService = createDecorator<IMcpGatewayService>('IMcpGatewayService');
10
11
export const McpGatewayChannelName = 'mcpGateway';
12
13
/**
14
* Result of creating an MCP gateway.
15
*/
16
export interface IMcpGatewayInfo {
17
/**
18
* The address of the HTTP endpoint for this gateway.
19
*/
20
readonly address: URI;
21
22
/**
23
* The unique identifier for this gateway, used for disposal.
24
*/
25
readonly gatewayId: string;
26
}
27
28
/**
29
* Service that manages MCP gateway HTTP endpoints in the main process (or remote server).
30
*
31
* The gateway provides an HTTP server that external processes can connect
32
* to in order to interact with MCP servers known to the editor. The server
33
* is shared among all gateways and is automatically torn down when the
34
* last gateway is disposed.
35
*/
36
export interface IMcpGatewayService {
37
readonly _serviceBrand: undefined;
38
39
/**
40
* Disposes all gateways associated with a given client context (e.g., client ID or connection).
41
* @param context The client context whose gateways should be disposed.
42
* @return A disposable that can be used to unregister the client context from future cleanup (e.g., if the context is reused).
43
*/
44
disposeGatewaysForClient<TContext>(context: TContext): void;
45
46
/**
47
* Creates a new MCP gateway endpoint.
48
*
49
* The gateway is assigned a secure random route ID to make the endpoint
50
* URL unguessable without authentication.
51
*
52
* @param context Optional context (e.g., client ID) to associate with the gateway for cleanup purposes.
53
* @returns A promise that resolves to the gateway info if successful.
54
*/
55
createGateway<TContext>(context: TContext): Promise<IMcpGatewayInfo>;
56
57
/**
58
* Disposes a previously created gateway.
59
*
60
* When the last gateway is disposed, the underlying HTTP server is shut down.
61
*
62
* @param gatewayId The unique identifier of the gateway to dispose.
63
*/
64
disposeGateway(gatewayId: string): Promise<void>;
65
}
66
67