@codingame/monaco-vscode-mcp-service-override 26.2.2 → 27.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +8 -2
- package/package.json +2 -2
- package/vscode/src/vs/base/common/jsonRpcProtocol.d.ts +66 -0
- package/vscode/src/vs/base/common/jsonRpcProtocol.js +216 -0
- package/vscode/src/vs/platform/mcp/common/allowedMcpServersService.js +1 -1
- package/vscode/src/vs/platform/mcp/common/mcpGalleryService.js +2 -2
- package/vscode/src/vs/platform/mcp/common/mcpGateway.d.ts +39 -0
- package/vscode/src/vs/platform/mcp/common/mcpGateway.js +6 -0
- package/vscode/src/vs/platform/mcp/common/mcpResourceScannerService.d.ts +2 -1
- package/vscode/src/vs/platform/mcp/common/mcpResourceScannerService.js +12 -6
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcp.contribution.js +15 -5
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcpAddContextContribution.js +2 -2
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcpCommands.js +58 -58
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcpElicitationService.js +27 -28
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcpGatewayService.d.ts +18 -0
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcpGatewayService.js +34 -0
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcpGatewayToolBrokerContribution.d.ts +6 -0
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcpGatewayToolBrokerContribution.js +15 -0
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcpLanguageFeatures.js +18 -18
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcpMigration.js +4 -4
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcpResourceQuickAccess.js +8 -8
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServersView.d.ts +4 -1
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServersView.js +42 -24
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcpWorkbenchService.d.ts +1 -1
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcpWorkbenchService.js +13 -12
- package/vscode/src/vs/workbench/contrib/mcp/common/discovery/extensionMcpDiscovery.js +4 -4
- package/vscode/src/vs/workbench/contrib/mcp/common/discovery/installedMcpServersDiscovery.js +2 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/discovery/nativeMcpDiscoveryAbstract.js +1 -1
- package/vscode/src/vs/workbench/contrib/mcp/common/discovery/pluginMcpDiscovery.d.ts +15 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/discovery/pluginMcpDiscovery.js +106 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpContextKeys.js +4 -4
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpGatewayToolBrokerChannel.d.ts +23 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpGatewayToolBrokerChannel.js +202 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpLanguageModelToolContribution.js +25 -17
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpRegistry.d.ts +3 -5
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpRegistry.js +27 -32
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpSamplingLog.js +1 -1
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpSamplingService.js +11 -11
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpSandboxService.d.ts +34 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpSandboxService.js +233 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpServerConnection.js +3 -3
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpServerRequestHandler.d.ts +1 -18
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpServerRequestHandler.js +88 -142
- package/vscode/src/vs/workbench/services/authentication/browser/authenticationMcpService.js +9 -9
- package/vscode/src/vs/workbench/services/mcp/browser/mcpWorkbenchManagementService.d.ts +1 -1
- package/vscode/src/vs/workbench/services/mcp/browser/mcpWorkbenchManagementService.js +2 -2
- package/vscode/src/vs/platform/mcp/common/mcpManagementIpc.d.ts +0 -42
- package/vscode/src/vs/platform/mcp/common/mcpManagementIpc.js +0 -105
- package/vscode/src/vs/platform/mcp/common/mcpManagementService.d.ts +0 -130
- package/vscode/src/vs/platform/mcp/common/mcpManagementService.js +0 -665
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServerActions.d.ts +0 -259
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServerActions.js +0 -1225
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServerEditor.d.ts +0 -72
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServerEditor.js +0 -996
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServerEditorInput.d.ts +0 -17
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServerEditorInput.js +0 -49
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServerIcons.d.ts +0 -5
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServerIcons.js +0 -12
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServerWidgets.d.ts +0 -88
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServerWidgets.js +0 -464
- package/vscode/src/vs/workbench/contrib/mcp/browser/media/mcpServerEditor.css +0 -94
- package/vscode/src/vs/workbench/services/mcp/common/mcpWorkbenchManagementService.d.ts +0 -87
- package/vscode/src/vs/workbench/services/mcp/common/mcpWorkbenchManagementService.js +0 -702
|
@@ -141,20 +141,20 @@ let ExtensionMcpDiscovery = ExtensionMcpDiscovery_1 = class ExtensionMcpDiscover
|
|
|
141
141
|
}
|
|
142
142
|
static _validate(user) {
|
|
143
143
|
if (!Array.isArray(user.value)) {
|
|
144
|
-
user.collector.error(( localize(
|
|
144
|
+
user.collector.error(( localize(10188, "Expected an array of MCP collections")));
|
|
145
145
|
return false;
|
|
146
146
|
}
|
|
147
147
|
for (const contribution of user.value) {
|
|
148
148
|
if (typeof contribution.id !== "string" || isFalsyOrWhitespace(contribution.id)) {
|
|
149
|
-
user.collector.error(( localize(
|
|
149
|
+
user.collector.error(( localize(10189, "Expected 'id' to be a non-empty string.")));
|
|
150
150
|
return false;
|
|
151
151
|
}
|
|
152
152
|
if (typeof contribution.label !== "string" || isFalsyOrWhitespace(contribution.label)) {
|
|
153
|
-
user.collector.error(( localize(
|
|
153
|
+
user.collector.error(( localize(10190, "Expected 'label' to be a non-empty string.")));
|
|
154
154
|
return false;
|
|
155
155
|
}
|
|
156
156
|
if (contribution.when !== undefined && (typeof contribution.when !== "string" || isFalsyOrWhitespace(contribution.when))) {
|
|
157
|
-
user.collector.error(( localize(
|
|
157
|
+
user.collector.error(( localize(10191, "Expected 'when' to be a non-empty string.")));
|
|
158
158
|
return false;
|
|
159
159
|
}
|
|
160
160
|
}
|
package/vscode/src/vs/workbench/contrib/mcp/common/discovery/installedMcpServersDiscovery.js
CHANGED
|
@@ -94,6 +94,8 @@ let InstalledMcpServersDiscovery = class InstalledMcpServersDiscovery extends Di
|
|
|
94
94
|
id: `${collectionId}.${server.name}`,
|
|
95
95
|
label: server.name,
|
|
96
96
|
launch,
|
|
97
|
+
sandboxEnabled: config.type === "http" ? undefined : config.sandboxEnabled,
|
|
98
|
+
sandbox: config.type === "http" || !config.sandboxEnabled ? undefined : config.sandbox,
|
|
97
99
|
cacheNonce: await McpServerLaunch.hash(launch),
|
|
98
100
|
roots: mcpConfigPath?.workspaceFolder ? [mcpConfigPath.workspaceFolder.uri] : undefined,
|
|
99
101
|
variableReplacement: {
|
|
@@ -86,7 +86,7 @@ let NativeFilesystemMcpDiscovery = class NativeFilesystemMcpDiscovery extends Fi
|
|
|
86
86
|
this.suffix = "";
|
|
87
87
|
if (remoteAuthority) {
|
|
88
88
|
this.suffix = " " + ( localize(
|
|
89
|
-
|
|
89
|
+
10192,
|
|
90
90
|
" on {0}",
|
|
91
91
|
labelService.getHostLabel(Schemas.vscodeRemote, remoteAuthority)
|
|
92
92
|
));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Disposable } from "@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle";
|
|
2
|
+
import { IAgentPluginService } from "@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/common/plugins/agentPluginService.service";
|
|
3
|
+
import { IMcpRegistry } from "@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/mcp/common/mcpRegistryTypes.service";
|
|
4
|
+
import { IMcpDiscovery } from "./mcpDiscovery.js";
|
|
5
|
+
export declare class PluginMcpDiscovery extends Disposable implements IMcpDiscovery {
|
|
6
|
+
private readonly _agentPluginService;
|
|
7
|
+
private readonly _mcpRegistry;
|
|
8
|
+
readonly fromGallery = false;
|
|
9
|
+
private readonly _collections;
|
|
10
|
+
constructor(_agentPluginService: IAgentPluginService, _mcpRegistry: IMcpRegistry);
|
|
11
|
+
start(): void;
|
|
12
|
+
private createCollectionState;
|
|
13
|
+
private _toServerDefinition;
|
|
14
|
+
private _toLaunch;
|
|
15
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
|
|
2
|
+
import { __decorate, __param } from '@codingame/monaco-vscode-api/external/tslib/tslib.es6';
|
|
3
|
+
import { hash } from '@codingame/monaco-vscode-api/vscode/vs/base/common/hash';
|
|
4
|
+
import { Disposable, DisposableResourceMap } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
|
|
5
|
+
import { ResourceSet } from '@codingame/monaco-vscode-api/vscode/vs/base/common/map';
|
|
6
|
+
import { Schemas } from '@codingame/monaco-vscode-api/vscode/vs/base/common/network';
|
|
7
|
+
import '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/index';
|
|
8
|
+
import { basename } from '@codingame/monaco-vscode-api/vscode/vs/base/common/resources';
|
|
9
|
+
import { isDefined } from '@codingame/monaco-vscode-api/vscode/vs/base/common/types';
|
|
10
|
+
import { URI } from '@codingame/monaco-vscode-api/vscode/vs/base/common/uri';
|
|
11
|
+
import { ConfigurationTarget } from '@codingame/monaco-vscode-api/vscode/vs/platform/configuration/common/configuration';
|
|
12
|
+
import { McpServerType } from '@codingame/monaco-vscode-api/vscode/vs/platform/mcp/common/mcpPlatformTypes';
|
|
13
|
+
import { StorageScope } from '@codingame/monaco-vscode-api/vscode/vs/platform/storage/common/storage';
|
|
14
|
+
import { IAgentPluginService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/common/plugins/agentPluginService.service';
|
|
15
|
+
import { IMcpRegistry } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/mcp/common/mcpRegistryTypes.service';
|
|
16
|
+
import { McpCollectionSortOrder, McpServerTrust, McpServerTransportType } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/mcp/common/mcpTypes';
|
|
17
|
+
import { autorun } from '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/reactions/autorun';
|
|
18
|
+
|
|
19
|
+
let PluginMcpDiscovery = class PluginMcpDiscovery extends Disposable {
|
|
20
|
+
constructor(_agentPluginService, _mcpRegistry) {
|
|
21
|
+
super();
|
|
22
|
+
this._agentPluginService = _agentPluginService;
|
|
23
|
+
this._mcpRegistry = _mcpRegistry;
|
|
24
|
+
this.fromGallery = false;
|
|
25
|
+
this._collections = this._register(( new DisposableResourceMap()));
|
|
26
|
+
}
|
|
27
|
+
start() {
|
|
28
|
+
this._register(autorun(reader => {
|
|
29
|
+
const plugins = this._agentPluginService.plugins.read(reader);
|
|
30
|
+
const seen = ( new ResourceSet());
|
|
31
|
+
for (const plugin of plugins) {
|
|
32
|
+
seen.add(plugin.uri);
|
|
33
|
+
let collectionState = this._collections.get(plugin.uri);
|
|
34
|
+
if (!collectionState) {
|
|
35
|
+
collectionState = this.createCollectionState(plugin);
|
|
36
|
+
this._collections.set(plugin.uri, collectionState);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
for (const [pluginUri] of this._collections) {
|
|
40
|
+
if (!( seen.has(pluginUri))) {
|
|
41
|
+
this._collections.deleteAndDispose(pluginUri);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
createCollectionState(plugin) {
|
|
47
|
+
const collectionId = `plugin.${plugin.uri}`;
|
|
48
|
+
return this._mcpRegistry.registerCollection({
|
|
49
|
+
id: collectionId,
|
|
50
|
+
label: `${basename(plugin.uri)} (Agent Plugin)`,
|
|
51
|
+
remoteAuthority: plugin.uri.scheme === Schemas.vscodeRemote ? plugin.uri.authority : null,
|
|
52
|
+
configTarget: ConfigurationTarget.USER,
|
|
53
|
+
scope: StorageScope.PROFILE,
|
|
54
|
+
trustBehavior: McpServerTrust.Kind.Trusted,
|
|
55
|
+
serverDefinitions: ( plugin.mcpServerDefinitions.map(defs => ( defs.map(d => this._toServerDefinition(collectionId, d))).filter(isDefined))),
|
|
56
|
+
presentation: {
|
|
57
|
+
origin: plugin.uri,
|
|
58
|
+
order: McpCollectionSortOrder.Plugin
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
_toServerDefinition(
|
|
63
|
+
collectionId,
|
|
64
|
+
{
|
|
65
|
+
name,
|
|
66
|
+
configuration
|
|
67
|
+
}
|
|
68
|
+
) {
|
|
69
|
+
const launch = this._toLaunch(configuration);
|
|
70
|
+
if (!launch) {
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
id: `${collectionId}.${name}`,
|
|
75
|
+
label: name,
|
|
76
|
+
launch,
|
|
77
|
+
cacheNonce: String(hash(launch))
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
_toLaunch(config) {
|
|
81
|
+
if (config.type === McpServerType.LOCAL) {
|
|
82
|
+
return {
|
|
83
|
+
type: McpServerTransportType.Stdio,
|
|
84
|
+
command: config.command,
|
|
85
|
+
args: config.args ? [...config.args] : [],
|
|
86
|
+
env: config.env ? {
|
|
87
|
+
...config.env
|
|
88
|
+
} : {},
|
|
89
|
+
envFile: config.envFile,
|
|
90
|
+
cwd: config.cwd
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
return {
|
|
95
|
+
type: McpServerTransportType.HTTP,
|
|
96
|
+
uri: ( URI.parse(config.url)),
|
|
97
|
+
headers: Object.entries(config.headers ?? {})
|
|
98
|
+
};
|
|
99
|
+
} catch {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
PluginMcpDiscovery = ( __decorate([( __param(0, IAgentPluginService)), ( __param(1, IMcpRegistry))], PluginMcpDiscovery));
|
|
105
|
+
|
|
106
|
+
export { PluginMcpDiscovery };
|
|
@@ -14,19 +14,19 @@ var McpContextKeys;
|
|
|
14
14
|
(function(McpContextKeys) {
|
|
15
15
|
McpContextKeys.serverCount = ( new RawContextKey("mcp.serverCount", undefined, {
|
|
16
16
|
type: "number",
|
|
17
|
-
description: ( localize(
|
|
17
|
+
description: ( localize(10233, "Context key that has the number of registered MCP servers"))
|
|
18
18
|
}));
|
|
19
19
|
McpContextKeys.hasUnknownTools = ( new RawContextKey("mcp.hasUnknownTools", undefined, {
|
|
20
20
|
type: "boolean",
|
|
21
|
-
description: ( localize(
|
|
21
|
+
description: ( localize(10234, "Indicates whether there are MCP servers with unknown tools."))
|
|
22
22
|
}));
|
|
23
23
|
McpContextKeys.hasServersWithErrors = ( new RawContextKey("mcp.hasServersWithErrors", undefined, {
|
|
24
24
|
type: "boolean",
|
|
25
|
-
description: ( localize(
|
|
25
|
+
description: ( localize(10235, "Indicates whether there are any MCP servers with errors."))
|
|
26
26
|
}));
|
|
27
27
|
McpContextKeys.toolsCount = ( new RawContextKey("mcp.toolsCount", undefined, {
|
|
28
28
|
type: "number",
|
|
29
|
-
description: ( localize(
|
|
29
|
+
description: ( localize(10236, "Context key that has the number of registered MCP tools"))
|
|
30
30
|
}));
|
|
31
31
|
})(McpContextKeys || (McpContextKeys = {}));
|
|
32
32
|
let McpContextKeysController = class McpContextKeysController extends Disposable {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CancellationToken } from "@codingame/monaco-vscode-api/vscode/vs/base/common/cancellation";
|
|
2
|
+
import { Event } from "@codingame/monaco-vscode-api/vscode/vs/base/common/event";
|
|
3
|
+
import { Disposable } from "@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle";
|
|
4
|
+
import { IServerChannel } from "@codingame/monaco-vscode-api/vscode/vs/base/parts/ipc/common/ipc";
|
|
5
|
+
import { IMcpService } from "@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/mcp/common/mcpTypes.service";
|
|
6
|
+
export declare class McpGatewayToolBrokerChannel extends Disposable implements IServerChannel<unknown> {
|
|
7
|
+
private readonly _mcpService;
|
|
8
|
+
private readonly _onDidChangeTools;
|
|
9
|
+
private readonly _onDidChangeResources;
|
|
10
|
+
private readonly _serverIdMap;
|
|
11
|
+
private _nextServerIndex;
|
|
12
|
+
constructor(_mcpService: IMcpService);
|
|
13
|
+
private _getServerIndex;
|
|
14
|
+
private _getServerByIndex;
|
|
15
|
+
listen<T>(_ctx: unknown, event: string): Event<T>;
|
|
16
|
+
call<T>(_ctx: unknown, command: string, arg?: unknown, cancellationToken?: CancellationToken): Promise<T>;
|
|
17
|
+
private _listTools;
|
|
18
|
+
private _callTool;
|
|
19
|
+
private _listResources;
|
|
20
|
+
private _readResource;
|
|
21
|
+
private _listResourceTemplates;
|
|
22
|
+
private _ensureServerReady;
|
|
23
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
import { CancellationToken } from '@codingame/monaco-vscode-api/vscode/vs/base/common/cancellation';
|
|
3
|
+
import { Emitter } from '@codingame/monaco-vscode-api/vscode/vs/base/common/event';
|
|
4
|
+
import { Disposable } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
|
|
5
|
+
import '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/index';
|
|
6
|
+
import { McpServer } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/mcp/common/mcpServer';
|
|
7
|
+
import { McpServerCacheState, McpToolVisibility, McpCapability } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/mcp/common/mcpTypes';
|
|
8
|
+
import { startServerAndWaitForLiveTools } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/mcp/common/mcpTypesUtils';
|
|
9
|
+
import { autorun } from '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/reactions/autorun';
|
|
10
|
+
|
|
11
|
+
class McpGatewayToolBrokerChannel extends Disposable {
|
|
12
|
+
constructor(_mcpService) {
|
|
13
|
+
super();
|
|
14
|
+
this._mcpService = _mcpService;
|
|
15
|
+
this._onDidChangeTools = this._register(( new Emitter()));
|
|
16
|
+
this._onDidChangeResources = this._register(( new Emitter()));
|
|
17
|
+
this._serverIdMap = ( new Map());
|
|
18
|
+
this._nextServerIndex = 0;
|
|
19
|
+
let toolsInitialized = false;
|
|
20
|
+
this._register(autorun(reader => {
|
|
21
|
+
for (const server of this._mcpService.servers.read(reader)) {
|
|
22
|
+
server.tools.read(reader);
|
|
23
|
+
}
|
|
24
|
+
if (toolsInitialized) {
|
|
25
|
+
this._onDidChangeTools.fire();
|
|
26
|
+
} else {
|
|
27
|
+
toolsInitialized = true;
|
|
28
|
+
}
|
|
29
|
+
}));
|
|
30
|
+
let resourcesInitialized = false;
|
|
31
|
+
this._register(autorun(reader => {
|
|
32
|
+
for (const server of this._mcpService.servers.read(reader)) {
|
|
33
|
+
server.capabilities.read(reader);
|
|
34
|
+
}
|
|
35
|
+
if (resourcesInitialized) {
|
|
36
|
+
this._onDidChangeResources.fire();
|
|
37
|
+
} else {
|
|
38
|
+
resourcesInitialized = true;
|
|
39
|
+
}
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
_getServerIndex(server) {
|
|
43
|
+
const defId = server.definition.id;
|
|
44
|
+
let index = this._serverIdMap.get(defId);
|
|
45
|
+
if (index === undefined) {
|
|
46
|
+
index = this._nextServerIndex++;
|
|
47
|
+
this._serverIdMap.set(defId, index);
|
|
48
|
+
}
|
|
49
|
+
return index;
|
|
50
|
+
}
|
|
51
|
+
_getServerByIndex(serverIndex) {
|
|
52
|
+
for (const server of this._mcpService.servers.get()) {
|
|
53
|
+
if (this._getServerIndex(server) === serverIndex) {
|
|
54
|
+
return server;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
listen(_ctx, event) {
|
|
60
|
+
switch (event) {
|
|
61
|
+
case "onDidChangeTools":
|
|
62
|
+
return this._onDidChangeTools.event;
|
|
63
|
+
case "onDidChangeResources":
|
|
64
|
+
return this._onDidChangeResources.event;
|
|
65
|
+
}
|
|
66
|
+
throw ( new Error(`Invalid listen: ${event}`));
|
|
67
|
+
}
|
|
68
|
+
async call(_ctx, command, arg, cancellationToken) {
|
|
69
|
+
switch (command) {
|
|
70
|
+
case "listTools":
|
|
71
|
+
{
|
|
72
|
+
const tools = await this._listTools();
|
|
73
|
+
return tools;
|
|
74
|
+
}
|
|
75
|
+
case "callTool":
|
|
76
|
+
{
|
|
77
|
+
const {
|
|
78
|
+
name,
|
|
79
|
+
args
|
|
80
|
+
} = arg;
|
|
81
|
+
const result = await this._callTool(name, args || {}, cancellationToken);
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
case "listResources":
|
|
85
|
+
{
|
|
86
|
+
const resources = await this._listResources();
|
|
87
|
+
return resources;
|
|
88
|
+
}
|
|
89
|
+
case "readResource":
|
|
90
|
+
{
|
|
91
|
+
const {
|
|
92
|
+
serverIndex,
|
|
93
|
+
uri
|
|
94
|
+
} = arg;
|
|
95
|
+
const result = await this._readResource(serverIndex, uri, cancellationToken);
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
case "listResourceTemplates":
|
|
99
|
+
{
|
|
100
|
+
const templates = await this._listResourceTemplates();
|
|
101
|
+
return templates;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
throw ( new Error(`Invalid call: ${command}`));
|
|
105
|
+
}
|
|
106
|
+
async _listTools() {
|
|
107
|
+
const mcpTools = [];
|
|
108
|
+
const servers = this._mcpService.servers.get();
|
|
109
|
+
await Promise.all(( servers.map(server => this._ensureServerReady(server))));
|
|
110
|
+
for (const server of servers) {
|
|
111
|
+
const cacheState = server.cacheState.get();
|
|
112
|
+
if (cacheState !== McpServerCacheState.Live && cacheState !== McpServerCacheState.Cached && cacheState !== McpServerCacheState.RefreshingFromCached) {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
for (const tool of server.tools.get()) {
|
|
116
|
+
if (!(tool.visibility & McpToolVisibility.Model)) {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
mcpTools.push(tool.definition);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return mcpTools;
|
|
123
|
+
}
|
|
124
|
+
async _callTool(name, args, token = CancellationToken.None) {
|
|
125
|
+
for (const server of this._mcpService.servers.get()) {
|
|
126
|
+
const tool = server.tools.get().find(
|
|
127
|
+
t => t.definition.name === name && (t.visibility & McpToolVisibility.Model)
|
|
128
|
+
);
|
|
129
|
+
if (tool) {
|
|
130
|
+
const result = await tool.call(args, undefined, token);
|
|
131
|
+
return {
|
|
132
|
+
result,
|
|
133
|
+
serverIndex: this._getServerIndex(server)
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
throw ( new Error(`Unknown tool: ${name}`));
|
|
138
|
+
}
|
|
139
|
+
async _listResources() {
|
|
140
|
+
const results = [];
|
|
141
|
+
const servers = this._mcpService.servers.get();
|
|
142
|
+
await Promise.all(( servers.map(async server => {
|
|
143
|
+
await this._ensureServerReady(server);
|
|
144
|
+
const capabilities = server.capabilities.get();
|
|
145
|
+
if (!capabilities || !(capabilities & McpCapability.Resources)) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
try {
|
|
149
|
+
const resources = await McpServer.callOn(server, h => h.listResources());
|
|
150
|
+
results.push({
|
|
151
|
+
serverIndex: this._getServerIndex(server),
|
|
152
|
+
resources
|
|
153
|
+
});
|
|
154
|
+
} catch {}
|
|
155
|
+
})));
|
|
156
|
+
return results;
|
|
157
|
+
}
|
|
158
|
+
async _readResource(serverIndex, uri, token = CancellationToken.None) {
|
|
159
|
+
const server = this._getServerByIndex(serverIndex);
|
|
160
|
+
if (!server) {
|
|
161
|
+
throw ( new Error(`Unknown server index: ${serverIndex}`));
|
|
162
|
+
}
|
|
163
|
+
return McpServer.callOn(server, h => h.readResource({
|
|
164
|
+
uri
|
|
165
|
+
}, token), token);
|
|
166
|
+
}
|
|
167
|
+
async _listResourceTemplates() {
|
|
168
|
+
const results = [];
|
|
169
|
+
const servers = this._mcpService.servers.get();
|
|
170
|
+
await Promise.all(( servers.map(async server => {
|
|
171
|
+
await this._ensureServerReady(server);
|
|
172
|
+
const capabilities = server.capabilities.get();
|
|
173
|
+
if (!capabilities || !(capabilities & McpCapability.Resources)) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
try {
|
|
177
|
+
const resourceTemplates = await McpServer.callOn(server, h => h.listResourceTemplates());
|
|
178
|
+
results.push({
|
|
179
|
+
serverIndex: this._getServerIndex(server),
|
|
180
|
+
resourceTemplates
|
|
181
|
+
});
|
|
182
|
+
} catch {}
|
|
183
|
+
})));
|
|
184
|
+
return results;
|
|
185
|
+
}
|
|
186
|
+
async _ensureServerReady(server) {
|
|
187
|
+
const cacheState = server.cacheState.get();
|
|
188
|
+
if (cacheState !== McpServerCacheState.Unknown && cacheState !== McpServerCacheState.Outdated) {
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
try {
|
|
192
|
+
return await startServerAndWaitForLiveTools(server, {
|
|
193
|
+
promptType: "all-untrusted",
|
|
194
|
+
errorOnUserInteraction: true
|
|
195
|
+
});
|
|
196
|
+
} catch {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export { McpGatewayToolBrokerChannel };
|
|
@@ -25,6 +25,7 @@ import { McpToolVisibility, McpToolResourceLinkMimeType, McpResourceURI } from '
|
|
|
25
25
|
import { IMcpService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/mcp/common/mcpTypes.service';
|
|
26
26
|
import { mcpServerToSourceData } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/mcp/common/mcpTypesUtils';
|
|
27
27
|
import { ILifecycleService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/lifecycle/common/lifecycle.service';
|
|
28
|
+
import { McpServer } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/mcp/common/mcpServer';
|
|
28
29
|
import { autorun } from '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/reactions/autorun';
|
|
29
30
|
|
|
30
31
|
let McpLanguageModelToolContribution = class McpLanguageModelToolContribution extends Disposable {
|
|
@@ -66,7 +67,7 @@ let McpLanguageModelToolContribution = class McpLanguageModelToolContribution ex
|
|
|
66
67
|
const toolSet = store.add(
|
|
67
68
|
this._toolsService.createToolSet(source, server.definition.id, referenceName, {
|
|
68
69
|
icon: Codicon.mcp,
|
|
69
|
-
description: ( localize(
|
|
70
|
+
description: ( localize(10237, "{0}: All Tools", server.definition.label))
|
|
70
71
|
})
|
|
71
72
|
);
|
|
72
73
|
return {
|
|
@@ -181,30 +182,37 @@ let McpToolImplementation = class McpToolImplementation {
|
|
|
181
182
|
async prepareToolInvocation(context) {
|
|
182
183
|
const tool = this._tool;
|
|
183
184
|
const server = this._server;
|
|
185
|
+
const sandboxEnabled = await McpServer.callOn(server, async (_handler, connection) => {
|
|
186
|
+
return connection.definition.sandboxEnabled;
|
|
187
|
+
});
|
|
188
|
+
const isSandboxedServer = sandboxEnabled === true;
|
|
184
189
|
const mcpToolWarning = ( localize(
|
|
185
|
-
|
|
190
|
+
10238,
|
|
186
191
|
"Note that MCP servers or malicious conversation content may attempt to misuse '{0}' through tools.",
|
|
187
192
|
this._productService.nameShort
|
|
188
193
|
));
|
|
189
194
|
const title = tool.definition.annotations?.title || tool.definition.title || ("`" + tool.definition.name + "`");
|
|
190
|
-
|
|
191
|
-
if (!
|
|
192
|
-
confirm
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
195
|
+
let confirm;
|
|
196
|
+
if (!isSandboxedServer) {
|
|
197
|
+
confirm = {};
|
|
198
|
+
if (!tool.definition.annotations?.readOnlyHint) {
|
|
199
|
+
confirm.title = ( new MarkdownString(( localize(10239, "Run {0}", title))));
|
|
200
|
+
confirm.message = ( new MarkdownString(tool.definition.description, {
|
|
201
|
+
supportThemeIcons: true
|
|
202
|
+
}));
|
|
203
|
+
confirm.disclaimer = mcpToolWarning;
|
|
204
|
+
confirm.allowAutoConfirm = true;
|
|
205
|
+
}
|
|
206
|
+
if (tool.definition.annotations?.openWorldHint) {
|
|
207
|
+
confirm.confirmResults = true;
|
|
208
|
+
}
|
|
201
209
|
}
|
|
202
210
|
const mcpUiEnabled = this._configurationService.getValue(mcpAppsEnabledConfig);
|
|
203
211
|
return {
|
|
204
212
|
confirmationMessages: confirm,
|
|
205
|
-
invocationMessage: ( new MarkdownString(( localize(
|
|
206
|
-
pastTenseMessage: ( new MarkdownString(( localize(
|
|
207
|
-
originMessage: ( localize(
|
|
213
|
+
invocationMessage: ( new MarkdownString(( localize(10240, "Running {0}", title)))),
|
|
214
|
+
pastTenseMessage: ( new MarkdownString(( localize(10241, "Ran {0} ", title)))),
|
|
215
|
+
originMessage: ( localize(10242, "{0} (MCP Server)", server.definition.label)),
|
|
208
216
|
toolSpecificData: {
|
|
209
217
|
kind: "input",
|
|
210
218
|
rawInput: context.parameters,
|
|
@@ -222,7 +230,7 @@ let McpToolImplementation = class McpToolImplementation {
|
|
|
222
230
|
};
|
|
223
231
|
const callResult = await this._tool.callWithProgress(invocation.parameters, progress, {
|
|
224
232
|
chatRequestId: invocation.chatRequestId,
|
|
225
|
-
|
|
233
|
+
chatSessionResource: invocation.context?.sessionResource
|
|
226
234
|
}, token);
|
|
227
235
|
const details = {
|
|
228
236
|
input: JSON.stringify(invocation.parameters, undefined, 2),
|
|
@@ -10,13 +10,12 @@ import { INotificationService } from "@codingame/monaco-vscode-api/vscode/vs/pla
|
|
|
10
10
|
import { IQuickInputService } from "@codingame/monaco-vscode-api/vscode/vs/platform/quickinput/common/quickInput.service";
|
|
11
11
|
import { StorageScope } from "@codingame/monaco-vscode-api/vscode/vs/platform/storage/common/storage";
|
|
12
12
|
import { IWorkspaceFolderData } from "@codingame/monaco-vscode-api/vscode/vs/platform/workspace/common/workspace";
|
|
13
|
-
import { IWorkspaceTrustRequestService } from "@codingame/monaco-vscode-api/vscode/vs/platform/workspace/common/workspaceTrust.service";
|
|
14
|
-
import { IWorkspaceTrustManagementService } from "@codingame/monaco-vscode-api/vscode/vs/platform/workspace/common/workspaceTrust.service";
|
|
15
13
|
import { IConfigurationResolverService } from "@codingame/monaco-vscode-api/vscode/vs/workbench/services/configurationResolver/common/configurationResolver.service";
|
|
16
14
|
import { IResolvedValue } from "@codingame/monaco-vscode-api/vscode/vs/workbench/services/configurationResolver/common/configurationResolverExpression";
|
|
17
15
|
import { IEditorService } from "@codingame/monaco-vscode-api/vscode/vs/workbench/services/editor/common/editorService.service";
|
|
18
16
|
import { IMcpHostDelegate, IMcpResolveConnectionOptions } from "@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/mcp/common/mcpRegistryTypes";
|
|
19
17
|
import { IMcpRegistry } from "@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/mcp/common/mcpRegistryTypes.service";
|
|
18
|
+
import { IMcpSandboxService } from "@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/mcp/common/mcpSandboxService.service";
|
|
20
19
|
import { IMcpServerConnection, LazyCollectionState, McpCollectionDefinition, McpDefinitionReference, McpServerDefinition } from "@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/mcp/common/mcpTypes";
|
|
21
20
|
export declare class McpRegistry extends Disposable implements IMcpRegistry {
|
|
22
21
|
private readonly _instantiationService;
|
|
@@ -27,8 +26,7 @@ export declare class McpRegistry extends Disposable implements IMcpRegistry {
|
|
|
27
26
|
private readonly _quickInputService;
|
|
28
27
|
private readonly _labelService;
|
|
29
28
|
private readonly _logService;
|
|
30
|
-
private readonly
|
|
31
|
-
private readonly _workspaceTrustRequestService;
|
|
29
|
+
private readonly _mcpSandboxService;
|
|
32
30
|
readonly _serviceBrand: undefined;
|
|
33
31
|
private readonly _collections;
|
|
34
32
|
private readonly _delegates;
|
|
@@ -44,7 +42,7 @@ export declare class McpRegistry extends Disposable implements IMcpRegistry {
|
|
|
44
42
|
get delegates(): IObservable<readonly IMcpHostDelegate[]>;
|
|
45
43
|
private readonly _onDidChangeInputs;
|
|
46
44
|
readonly onDidChangeInputs: import("@codingame/monaco-vscode-api/vscode/vs/base/common/event").Event<void>;
|
|
47
|
-
constructor(_instantiationService: IInstantiationService, _configurationResolverService: IConfigurationResolverService, _dialogService: IDialogService, _notificationService: INotificationService, _editorService: IEditorService, configurationService: IConfigurationService, _quickInputService: IQuickInputService, _labelService: ILabelService, _logService: ILogService,
|
|
45
|
+
constructor(_instantiationService: IInstantiationService, _configurationResolverService: IConfigurationResolverService, _dialogService: IDialogService, _notificationService: INotificationService, _editorService: IEditorService, configurationService: IConfigurationService, _quickInputService: IQuickInputService, _labelService: ILabelService, _logService: ILogService, _mcpSandboxService: IMcpSandboxService);
|
|
48
46
|
registerDelegate(delegate: IMcpHostDelegate): IDisposable;
|
|
49
47
|
registerCollection(collection: McpCollectionDefinition): IDisposable;
|
|
50
48
|
getServerDefinition(collectionRef: McpDefinitionReference, definitionRef: McpDefinitionReference): IObservable<{
|