Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/mcp/node/nativeMcpDiscoveryHelperChannel.ts
5241 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 { IURITransformer, transformOutgoingURIs } from '../../../base/common/uriIpc.js';
8
import { IServerChannel } from '../../../base/parts/ipc/common/ipc.js';
9
import { RemoteAgentConnectionContext } from '../../remote/common/remoteAgentEnvironment.js';
10
import { INativeMcpDiscoveryHelperService } from '../common/nativeMcpDiscoveryHelper.js';
11
12
export class NativeMcpDiscoveryHelperChannel implements IServerChannel<RemoteAgentConnectionContext> {
13
14
constructor(
15
private readonly getUriTransformer: undefined | ((requestContext: RemoteAgentConnectionContext) => IURITransformer),
16
@INativeMcpDiscoveryHelperService private nativeMcpDiscoveryHelperService: INativeMcpDiscoveryHelperService
17
) { }
18
19
listen<T>(context: RemoteAgentConnectionContext, event: string): Event<T> {
20
throw new Error('Invalid listen');
21
}
22
23
async call<T>(context: RemoteAgentConnectionContext, command: string, args?: unknown): Promise<T> {
24
const uriTransformer = this.getUriTransformer?.(context);
25
switch (command) {
26
case 'load': {
27
const result = await this.nativeMcpDiscoveryHelperService.load();
28
return (uriTransformer ? transformOutgoingURIs(result, uriTransformer) : result) as T;
29
}
30
}
31
throw new Error('Invalid call');
32
}
33
}
34
35
36