@codingame/monaco-vscode-mcp-service-override 16.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.d.ts +2 -0
- package/index.js +20 -0
- package/package.json +50 -0
- package/vscode/src/vs/platform/mcp/common/nativeMcpDiscoveryHelper.d.ts +9 -0
- package/vscode/src/vs/platform/mcp/common/nativeMcpDiscoveryHelper.js +5 -0
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcp.contribution.d.ts +1 -0
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcp.contribution.js +47 -0
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcpDiscovery.d.ts +8 -0
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcpDiscovery.js +36 -0
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcpLanguageFeatures.d.ts +21 -0
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcpLanguageFeatures.js +340 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/discovery/configMcpDiscovery.d.ts +17 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/discovery/configMcpDiscovery.js +146 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/discovery/extensionMcpDiscovery.d.ts +15 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/discovery/extensionMcpDiscovery.js +108 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/discovery/mcpDiscovery.d.ts +12 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/discovery/mcpDiscovery.js +16 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/discovery/nativeMcpDiscoveryAbstract.d.ts +34 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/discovery/nativeMcpDiscoveryAbstract.js +134 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/discovery/nativeMcpDiscoveryAdapters.d.ts +34 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/discovery/nativeMcpDiscoveryAdapters.js +79 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/discovery/nativeMcpRemoteDiscovery.d.ts +14 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/discovery/nativeMcpRemoteDiscovery.js +44 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/discovery/workspaceMcpDiscoveryAdapter.d.ts +15 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/discovery/workspaceMcpDiscoveryAdapter.js +68 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpConfigFileUtils.d.ts +6 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpConfigFileUtils.js +30 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpConfigPathsService.d.ts +33 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpConfigPathsService.js +112 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpRegistry.d.ts +59 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpRegistry.js +322 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpRegistryInputStorage.d.ts +27 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpRegistryInputStorage.js +134 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpServer.d.ts +77 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpServer.js +383 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpServerConnection.d.ts +26 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpServerConnection.js +114 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpServerRequestHandler.d.ts +63 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpServerRequestHandler.js +318 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpService.d.ts +27 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpService.js +220 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/modelContextProtocol.d.ts +374 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/modelContextProtocol.js +14 -0
package/vscode/src/vs/workbench/contrib/mcp/common/discovery/workspaceMcpDiscoveryAdapter.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IConfigurationService } from "@codingame/monaco-vscode-api/vscode/vs/platform/configuration/common/configuration.service";
|
|
2
|
+
import { IFileService } from "@codingame/monaco-vscode-api/vscode/vs/platform/files/common/files.service";
|
|
3
|
+
import { IWorkspaceContextService } from "@codingame/monaco-vscode-api/vscode/vs/platform/workspace/common/workspace.service";
|
|
4
|
+
import { IRemoteAgentService } from "@codingame/monaco-vscode-api/vscode/vs/workbench/services/remote/common/remoteAgentService.service";
|
|
5
|
+
import { IMcpRegistry } from "@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/mcp/common/mcpRegistryTypes.service";
|
|
6
|
+
import { IMcpDiscovery } from "./mcpDiscovery.js";
|
|
7
|
+
import { FilesystemMcpDiscovery } from "./nativeMcpDiscoveryAbstract.js";
|
|
8
|
+
export declare class CursorWorkspaceMcpDiscoveryAdapter extends FilesystemMcpDiscovery implements IMcpDiscovery {
|
|
9
|
+
private readonly _workspaceContextService;
|
|
10
|
+
private readonly _remoteAgentService;
|
|
11
|
+
private readonly _collections;
|
|
12
|
+
constructor(fileService: IFileService, _workspaceContextService: IWorkspaceContextService, mcpRegistry: IMcpRegistry, configurationService: IConfigurationService, _remoteAgentService: IRemoteAgentService);
|
|
13
|
+
start(): void;
|
|
14
|
+
private watchFolder;
|
|
15
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
|
|
2
|
+
import { __decorate, __param } from '@codingame/monaco-vscode-api/external/tslib/tslib.es6';
|
|
3
|
+
import { DisposableMap } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
|
|
4
|
+
import '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/index';
|
|
5
|
+
import { joinPath } from '@codingame/monaco-vscode-api/vscode/vs/base/common/resources';
|
|
6
|
+
import { URI } from '@codingame/monaco-vscode-api/vscode/vs/base/common/uri';
|
|
7
|
+
import { IConfigurationService } from '@codingame/monaco-vscode-api/vscode/vs/platform/configuration/common/configuration.service';
|
|
8
|
+
import { IFileService } from '@codingame/monaco-vscode-api/vscode/vs/platform/files/common/files.service';
|
|
9
|
+
import { StorageScope } from '@codingame/monaco-vscode-api/vscode/vs/platform/storage/common/storage';
|
|
10
|
+
import { IWorkspaceContextService } from '@codingame/monaco-vscode-api/vscode/vs/platform/workspace/common/workspace.service';
|
|
11
|
+
import { IRemoteAgentService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/remote/common/remoteAgentService.service';
|
|
12
|
+
import { DiscoverySource } from '@codingame/monaco-vscode-ec21d4de-4d65-574c-8715-bb1a6bbad376-common/vscode/vs/workbench/contrib/mcp/common/mcpConfiguration';
|
|
13
|
+
import { IMcpRegistry } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/mcp/common/mcpRegistryTypes.service';
|
|
14
|
+
import { McpCollectionSortOrder } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/mcp/common/mcpTypes';
|
|
15
|
+
import { FilesystemMcpDiscovery } from './nativeMcpDiscoveryAbstract.js';
|
|
16
|
+
import { claudeConfigToServerDefinition } from './nativeMcpDiscoveryAdapters.js';
|
|
17
|
+
import { observableValue } from '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/base';
|
|
18
|
+
|
|
19
|
+
let CursorWorkspaceMcpDiscoveryAdapter = class CursorWorkspaceMcpDiscoveryAdapter extends FilesystemMcpDiscovery {
|
|
20
|
+
constructor(fileService, _workspaceContextService, mcpRegistry, configurationService, _remoteAgentService) {
|
|
21
|
+
super(configurationService, fileService, mcpRegistry);
|
|
22
|
+
this._workspaceContextService = _workspaceContextService;
|
|
23
|
+
this._remoteAgentService = _remoteAgentService;
|
|
24
|
+
this._collections = this._register(( new DisposableMap()));
|
|
25
|
+
}
|
|
26
|
+
start() {
|
|
27
|
+
this._register(this._workspaceContextService.onDidChangeWorkspaceFolders(e => {
|
|
28
|
+
for (const removed of e.removed) {
|
|
29
|
+
this._collections.deleteAndDispose(( removed.uri.toString()));
|
|
30
|
+
}
|
|
31
|
+
for (const added of e.added) {
|
|
32
|
+
this.watchFolder(added);
|
|
33
|
+
}
|
|
34
|
+
}));
|
|
35
|
+
for (const folder of this._workspaceContextService.getWorkspace().folders) {
|
|
36
|
+
this.watchFolder(folder);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
watchFolder(folder) {
|
|
40
|
+
const configFile = joinPath(folder.uri, '.cursor', 'mcp.json');
|
|
41
|
+
const collection = {
|
|
42
|
+
id: `cursor-workspace.${folder.index}`,
|
|
43
|
+
label: `${folder.name}/.cursor/mcp.json`,
|
|
44
|
+
remoteAuthority: this._remoteAgentService.getConnection()?.remoteAuthority || null,
|
|
45
|
+
scope: StorageScope.WORKSPACE,
|
|
46
|
+
isTrustedByDefault: false,
|
|
47
|
+
serverDefinitions: observableValue(this, []),
|
|
48
|
+
presentation: {
|
|
49
|
+
origin: configFile,
|
|
50
|
+
order: McpCollectionSortOrder.WorkspaceFolder + 1,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
this._collections.set(( folder.uri.toString()), this.watchFile(URI.joinPath(folder.uri, '.cursor', 'mcp.json'), collection, DiscoverySource.CursorWorkspace, contents => {
|
|
54
|
+
const defs = claudeConfigToServerDefinition(collection.id, contents, folder.uri);
|
|
55
|
+
defs?.forEach(d => d.roots = [folder.uri]);
|
|
56
|
+
return defs;
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
CursorWorkspaceMcpDiscoveryAdapter = ( __decorate([
|
|
61
|
+
( __param(0, IFileService)),
|
|
62
|
+
( __param(1, IWorkspaceContextService)),
|
|
63
|
+
( __param(2, IMcpRegistry)),
|
|
64
|
+
( __param(3, IConfigurationService)),
|
|
65
|
+
( __param(4, IRemoteAgentService))
|
|
66
|
+
], CursorWorkspaceMcpDiscoveryAdapter));
|
|
67
|
+
|
|
68
|
+
export { CursorWorkspaceMcpDiscoveryAdapter };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Location } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/languages";
|
|
2
|
+
import { ITextModel } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/model";
|
|
3
|
+
export declare const getMcpServerMapping: (opts: {
|
|
4
|
+
model: ITextModel;
|
|
5
|
+
pathToServers: string[];
|
|
6
|
+
}) => Map<string, Location>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
|
|
2
|
+
import { parseTree, findNodeAtLocation } from '@codingame/monaco-vscode-api/vscode/vs/base/common/json';
|
|
3
|
+
|
|
4
|
+
const getMcpServerMapping = (opts) => {
|
|
5
|
+
const tree = parseTree(opts.model.getValue());
|
|
6
|
+
const servers = findNodeAtLocation(tree, opts.pathToServers);
|
|
7
|
+
if (!servers || servers.type !== 'object') {
|
|
8
|
+
return ( new Map());
|
|
9
|
+
}
|
|
10
|
+
const result = ( new Map());
|
|
11
|
+
for (const node of servers.children || []) {
|
|
12
|
+
if (node.type !== 'property' || node.children?.[0]?.type !== 'string') {
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
const start = opts.model.getPositionAt(node.offset);
|
|
16
|
+
const end = opts.model.getPositionAt(node.offset + node.length);
|
|
17
|
+
result.set(node.children[0].value, {
|
|
18
|
+
uri: opts.model.uri,
|
|
19
|
+
range: {
|
|
20
|
+
startLineNumber: start.lineNumber,
|
|
21
|
+
startColumn: start.column,
|
|
22
|
+
endLineNumber: end.lineNumber,
|
|
23
|
+
endColumn: end.column,
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export { getMcpServerMapping };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Disposable } from "@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle";
|
|
2
|
+
import { IObservable } from "@codingame/monaco-vscode-api/vscode/vs/base/common/observable";
|
|
3
|
+
import { URI } from "@codingame/monaco-vscode-api/vscode/vs/base/common/uri";
|
|
4
|
+
import { ConfigurationTarget } from "@codingame/monaco-vscode-api/vscode/vs/platform/configuration/common/configuration";
|
|
5
|
+
import { ILabelService } from "@codingame/monaco-vscode-api/vscode/vs/platform/label/common/label.service";
|
|
6
|
+
import { IProductService } from "@codingame/monaco-vscode-api/vscode/vs/platform/product/common/productService.service";
|
|
7
|
+
import { StorageScope } from "@codingame/monaco-vscode-api/vscode/vs/platform/storage/common/storage";
|
|
8
|
+
import { IWorkspaceFolder } from "@codingame/monaco-vscode-api/vscode/vs/platform/workspace/common/workspace";
|
|
9
|
+
import { IWorkspaceContextService } from "@codingame/monaco-vscode-api/vscode/vs/platform/workspace/common/workspace.service";
|
|
10
|
+
import { IWorkbenchEnvironmentService } from "@codingame/monaco-vscode-api/vscode/vs/workbench/services/environment/common/environmentService.service";
|
|
11
|
+
import { IPreferencesService } from "@codingame/monaco-vscode-api/vscode/vs/workbench/services/preferences/common/preferences.service";
|
|
12
|
+
import { IRemoteAgentService } from "@codingame/monaco-vscode-api/vscode/vs/workbench/services/remote/common/remoteAgentService.service";
|
|
13
|
+
import { IMcpConfigPathsService } from "@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/mcp/common/mcpConfigPathsService.service";
|
|
14
|
+
export interface IMcpConfigPath {
|
|
15
|
+
id: string;
|
|
16
|
+
key: "userLocalValue" | "userRemoteValue" | "workspaceValue" | "workspaceFolderValue";
|
|
17
|
+
label: string;
|
|
18
|
+
scope: StorageScope;
|
|
19
|
+
target: ConfigurationTarget;
|
|
20
|
+
order: number;
|
|
21
|
+
remoteAuthority?: string;
|
|
22
|
+
uri: URI | undefined;
|
|
23
|
+
section?: string[];
|
|
24
|
+
workspaceFolder?: IWorkspaceFolder;
|
|
25
|
+
}
|
|
26
|
+
export declare class McpConfigPathsService extends Disposable implements IMcpConfigPathsService {
|
|
27
|
+
private readonly _environmentService;
|
|
28
|
+
_serviceBrand: undefined;
|
|
29
|
+
private readonly _paths;
|
|
30
|
+
get paths(): IObservable<readonly IMcpConfigPath[]>;
|
|
31
|
+
constructor(workspaceContextService: IWorkspaceContextService, productService: IProductService, labelService: ILabelService, _environmentService: IWorkbenchEnvironmentService, remoteAgentService: IRemoteAgentService, preferencesService: IPreferencesService);
|
|
32
|
+
private _fromWorkspaceFolder;
|
|
33
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
|
|
2
|
+
import { __decorate, __param } from '@codingame/monaco-vscode-api/external/tslib/tslib.es6';
|
|
3
|
+
import { Disposable } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
|
|
4
|
+
import { Schemas } from '@codingame/monaco-vscode-api/vscode/vs/base/common/network';
|
|
5
|
+
import '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/index';
|
|
6
|
+
import { basename } from '@codingame/monaco-vscode-api/vscode/vs/base/common/resources';
|
|
7
|
+
import { isDefined } from '@codingame/monaco-vscode-api/vscode/vs/base/common/types';
|
|
8
|
+
import { URI } from '@codingame/monaco-vscode-api/vscode/vs/base/common/uri';
|
|
9
|
+
import { localize } from '@codingame/monaco-vscode-api/vscode/vs/nls';
|
|
10
|
+
import { ConfigurationTarget } from '@codingame/monaco-vscode-api/vscode/vs/platform/configuration/common/configuration';
|
|
11
|
+
import { ILabelService } from '@codingame/monaco-vscode-api/vscode/vs/platform/label/common/label.service';
|
|
12
|
+
import { IProductService } from '@codingame/monaco-vscode-api/vscode/vs/platform/product/common/productService.service';
|
|
13
|
+
import { StorageScope } from '@codingame/monaco-vscode-api/vscode/vs/platform/storage/common/storage';
|
|
14
|
+
import { IWorkspaceContextService } from '@codingame/monaco-vscode-api/vscode/vs/platform/workspace/common/workspace.service';
|
|
15
|
+
import { IWorkbenchEnvironmentService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/environment/common/environmentService.service';
|
|
16
|
+
import { FOLDER_SETTINGS_PATH } from '@codingame/monaco-vscode-2b1a9082-790f-527f-b013-d1b29d6265a3-common/vscode/vs/workbench/services/preferences/common/preferences';
|
|
17
|
+
import { IPreferencesService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/preferences/common/preferences.service';
|
|
18
|
+
import { IRemoteAgentService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/remote/common/remoteAgentService.service';
|
|
19
|
+
import { mcpConfigurationSection } from '@codingame/monaco-vscode-ec21d4de-4d65-574c-8715-bb1a6bbad376-common/vscode/vs/workbench/contrib/mcp/common/mcpConfiguration';
|
|
20
|
+
import { McpCollectionSortOrder } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/mcp/common/mcpTypes';
|
|
21
|
+
import { observableValue } from '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/base';
|
|
22
|
+
|
|
23
|
+
let McpConfigPathsService = class McpConfigPathsService extends Disposable {
|
|
24
|
+
get paths() {
|
|
25
|
+
return this._paths;
|
|
26
|
+
}
|
|
27
|
+
constructor(workspaceContextService, productService, labelService, _environmentService, remoteAgentService, preferencesService) {
|
|
28
|
+
super();
|
|
29
|
+
this._environmentService = _environmentService;
|
|
30
|
+
const workspaceConfig = workspaceContextService.getWorkspace().configuration;
|
|
31
|
+
const initialPaths = [
|
|
32
|
+
{
|
|
33
|
+
id: 'usrlocal',
|
|
34
|
+
key: 'userLocalValue',
|
|
35
|
+
target: ConfigurationTarget.USER_LOCAL,
|
|
36
|
+
label: ( localize(7635, 'Global in {0}', productService.nameShort)),
|
|
37
|
+
scope: StorageScope.PROFILE,
|
|
38
|
+
order: McpCollectionSortOrder.User,
|
|
39
|
+
uri: preferencesService.userSettingsResource,
|
|
40
|
+
section: [mcpConfigurationSection],
|
|
41
|
+
},
|
|
42
|
+
workspaceConfig && {
|
|
43
|
+
id: 'workspace',
|
|
44
|
+
key: 'workspaceValue',
|
|
45
|
+
target: ConfigurationTarget.WORKSPACE,
|
|
46
|
+
label: basename(workspaceConfig),
|
|
47
|
+
scope: StorageScope.WORKSPACE,
|
|
48
|
+
order: McpCollectionSortOrder.Workspace,
|
|
49
|
+
remoteAuthority: _environmentService.remoteAuthority,
|
|
50
|
+
uri: workspaceConfig,
|
|
51
|
+
section: ['settings', mcpConfigurationSection],
|
|
52
|
+
},
|
|
53
|
+
...( workspaceContextService.getWorkspace()
|
|
54
|
+
.folders
|
|
55
|
+
.map(wf => this._fromWorkspaceFolder(wf)))
|
|
56
|
+
];
|
|
57
|
+
this._paths = observableValue('mcpConfigPaths', initialPaths.filter(isDefined));
|
|
58
|
+
remoteAgentService.getEnvironment().then((env) => {
|
|
59
|
+
const label = _environmentService.remoteAuthority ? labelService.getHostLabel(Schemas.vscodeRemote, _environmentService.remoteAuthority) : 'Remote';
|
|
60
|
+
this._paths.set([
|
|
61
|
+
...this.paths.get(),
|
|
62
|
+
{
|
|
63
|
+
id: 'usrremote',
|
|
64
|
+
key: 'userRemoteValue',
|
|
65
|
+
target: ConfigurationTarget.USER_REMOTE,
|
|
66
|
+
label,
|
|
67
|
+
scope: StorageScope.PROFILE,
|
|
68
|
+
order: McpCollectionSortOrder.User + McpCollectionSortOrder.RemoteBoost,
|
|
69
|
+
uri: env?.settingsPath,
|
|
70
|
+
remoteAuthority: _environmentService.remoteAuthority,
|
|
71
|
+
section: [mcpConfigurationSection],
|
|
72
|
+
}
|
|
73
|
+
], undefined);
|
|
74
|
+
});
|
|
75
|
+
this._register(workspaceContextService.onDidChangeWorkspaceFolders(e => {
|
|
76
|
+
const next = this._paths.get().slice();
|
|
77
|
+
for (const folder of e.added) {
|
|
78
|
+
next.push(this._fromWorkspaceFolder(folder));
|
|
79
|
+
}
|
|
80
|
+
for (const folder of e.removed) {
|
|
81
|
+
const idx = next.findIndex(c => c.workspaceFolder === folder);
|
|
82
|
+
if (idx !== -1) {
|
|
83
|
+
next.splice(idx, 1);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
this._paths.set(next, undefined);
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
_fromWorkspaceFolder(workspaceFolder) {
|
|
90
|
+
return {
|
|
91
|
+
id: `wf${workspaceFolder.index}`,
|
|
92
|
+
key: 'workspaceFolderValue',
|
|
93
|
+
target: ConfigurationTarget.WORKSPACE_FOLDER,
|
|
94
|
+
label: `${workspaceFolder.name}/.vscode/mcp.json`,
|
|
95
|
+
scope: StorageScope.WORKSPACE,
|
|
96
|
+
remoteAuthority: this._environmentService.remoteAuthority,
|
|
97
|
+
order: McpCollectionSortOrder.WorkspaceFolder,
|
|
98
|
+
uri: URI.joinPath(workspaceFolder.uri, FOLDER_SETTINGS_PATH, '../mcp.json'),
|
|
99
|
+
workspaceFolder,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
McpConfigPathsService = ( __decorate([
|
|
104
|
+
( __param(0, IWorkspaceContextService)),
|
|
105
|
+
( __param(1, IProductService)),
|
|
106
|
+
( __param(2, ILabelService)),
|
|
107
|
+
( __param(3, IWorkbenchEnvironmentService)),
|
|
108
|
+
( __param(4, IRemoteAgentService)),
|
|
109
|
+
( __param(5, IPreferencesService))
|
|
110
|
+
], McpConfigPathsService));
|
|
111
|
+
|
|
112
|
+
export { McpConfigPathsService };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Disposable, IDisposable } from "@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle";
|
|
2
|
+
import { IObservable } from "@codingame/monaco-vscode-api/vscode/vs/base/common/observable";
|
|
3
|
+
import { ConfigurationTarget } from "@codingame/monaco-vscode-api/vscode/vs/platform/configuration/common/configuration";
|
|
4
|
+
import { IDialogService } from "@codingame/monaco-vscode-api/vscode/vs/platform/dialogs/common/dialogs.service";
|
|
5
|
+
import { IInstantiationService } from "@codingame/monaco-vscode-api/vscode/vs/platform/instantiation/common/instantiation";
|
|
6
|
+
import { INotificationService } from "@codingame/monaco-vscode-api/vscode/vs/platform/notification/common/notification.service";
|
|
7
|
+
import { IProductService } from "@codingame/monaco-vscode-api/vscode/vs/platform/product/common/productService.service";
|
|
8
|
+
import { StorageScope } from "@codingame/monaco-vscode-api/vscode/vs/platform/storage/common/storage";
|
|
9
|
+
import { IStorageService } from "@codingame/monaco-vscode-api/vscode/vs/platform/storage/common/storage.service";
|
|
10
|
+
import { IWorkspaceFolderData } from "@codingame/monaco-vscode-api/vscode/vs/platform/workspace/common/workspace";
|
|
11
|
+
import { IConfigurationResolverService } from "@codingame/monaco-vscode-api/vscode/vs/workbench/services/configurationResolver/common/configurationResolver.service";
|
|
12
|
+
import { IResolvedValue } from "@codingame/monaco-vscode-api/vscode/vs/workbench/services/configurationResolver/common/configurationResolverExpression";
|
|
13
|
+
import { IEditorService } from "@codingame/monaco-vscode-api/vscode/vs/workbench/services/editor/common/editorService.service";
|
|
14
|
+
import { IMcpHostDelegate, IMcpResolveConnectionOptions } from "@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/mcp/common/mcpRegistryTypes";
|
|
15
|
+
import { IMcpRegistry } from "@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/mcp/common/mcpRegistryTypes.service";
|
|
16
|
+
import { IMcpServerConnection, LazyCollectionState, McpCollectionDefinition, McpCollectionReference } from "@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/mcp/common/mcpTypes";
|
|
17
|
+
export declare class McpRegistry extends Disposable implements IMcpRegistry {
|
|
18
|
+
private readonly _instantiationService;
|
|
19
|
+
private readonly _configurationResolverService;
|
|
20
|
+
private readonly _dialogService;
|
|
21
|
+
private readonly _storageService;
|
|
22
|
+
private readonly _productService;
|
|
23
|
+
private readonly _notificationService;
|
|
24
|
+
private readonly _editorService;
|
|
25
|
+
readonly _serviceBrand: undefined;
|
|
26
|
+
private readonly _trustPrompts;
|
|
27
|
+
private readonly _collections;
|
|
28
|
+
private readonly _delegates;
|
|
29
|
+
readonly collections: IObservable<readonly McpCollectionDefinition[]>;
|
|
30
|
+
private readonly _collectionToPrefixes;
|
|
31
|
+
private readonly _workspaceStorage;
|
|
32
|
+
private readonly _profileStorage;
|
|
33
|
+
private readonly _trustMemento;
|
|
34
|
+
private readonly _lazyCollectionsToUpdate;
|
|
35
|
+
private readonly _ongoingLazyActivations;
|
|
36
|
+
readonly lazyCollectionState: IObservable<LazyCollectionState>;
|
|
37
|
+
get delegates(): readonly IMcpHostDelegate[];
|
|
38
|
+
private readonly _onDidChangeInputs;
|
|
39
|
+
readonly onDidChangeInputs: import("@codingame/monaco-vscode-api/vscode/vs/base/common/event").Event<void>;
|
|
40
|
+
constructor(_instantiationService: IInstantiationService, _configurationResolverService: IConfigurationResolverService, _dialogService: IDialogService, _storageService: IStorageService, _productService: IProductService, _notificationService: INotificationService, _editorService: IEditorService);
|
|
41
|
+
registerDelegate(delegate: IMcpHostDelegate): IDisposable;
|
|
42
|
+
registerCollection(collection: McpCollectionDefinition): IDisposable;
|
|
43
|
+
collectionToolPrefix(collection: McpCollectionReference): IObservable<string>;
|
|
44
|
+
discoverCollections(): Promise<McpCollectionDefinition[]>;
|
|
45
|
+
private _getInputStorage;
|
|
46
|
+
private _getInputStorageInConfigTarget;
|
|
47
|
+
clearSavedInputs(scope: StorageScope, inputId?: string): Promise<void>;
|
|
48
|
+
editSavedInput(inputId: string, folderData: IWorkspaceFolderData | undefined, configSection: string, target: ConfigurationTarget): Promise<void>;
|
|
49
|
+
getSavedInputs(scope: StorageScope): Promise<{
|
|
50
|
+
[id: string]: IResolvedValue;
|
|
51
|
+
}>;
|
|
52
|
+
resetTrust(): void;
|
|
53
|
+
getTrust(collectionRef: McpCollectionReference): IObservable<boolean | undefined>;
|
|
54
|
+
private _promptForTrust;
|
|
55
|
+
private _promptForTrustOpenDialog;
|
|
56
|
+
private _updateStorageWithExpressionInputs;
|
|
57
|
+
private _replaceVariablesInLaunch;
|
|
58
|
+
resolveConnection({ collectionRef, definitionRef, forceTrust, logger }: IMcpResolveConnectionOptions): Promise<IMcpServerConnection | undefined>;
|
|
59
|
+
}
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
|
|
2
|
+
import { __decorate, __param } from '@codingame/monaco-vscode-api/external/tslib/tslib.es6';
|
|
3
|
+
import { Emitter } from '@codingame/monaco-vscode-api/vscode/vs/base/common/event';
|
|
4
|
+
import { StringSHA1 } from '@codingame/monaco-vscode-api/vscode/vs/base/common/hash';
|
|
5
|
+
import { MarkdownString } from '@codingame/monaco-vscode-api/vscode/vs/base/common/htmlContent';
|
|
6
|
+
import { Lazy } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lazy';
|
|
7
|
+
import { Disposable } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
|
|
8
|
+
import '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/index';
|
|
9
|
+
import { basename } from '@codingame/monaco-vscode-api/vscode/vs/base/common/resources';
|
|
10
|
+
import { localize } from '@codingame/monaco-vscode-api/vscode/vs/nls';
|
|
11
|
+
import { ConfigurationTarget } from '@codingame/monaco-vscode-api/vscode/vs/platform/configuration/common/configuration';
|
|
12
|
+
import { IDialogService } from '@codingame/monaco-vscode-api/vscode/vs/platform/dialogs/common/dialogs.service';
|
|
13
|
+
import { IInstantiationService } from '@codingame/monaco-vscode-api/vscode/vs/platform/instantiation/common/instantiation';
|
|
14
|
+
import '@codingame/monaco-vscode-api/vscode/vs/platform/notification/common/notification';
|
|
15
|
+
import { INotificationService } from '@codingame/monaco-vscode-api/vscode/vs/platform/notification/common/notification.service';
|
|
16
|
+
import { observableMemento } from '@codingame/monaco-vscode-ec21d4de-4d65-574c-8715-bb1a6bbad376-common/vscode/vs/platform/observable/common/observableMemento';
|
|
17
|
+
import { IProductService } from '@codingame/monaco-vscode-api/vscode/vs/platform/product/common/productService.service';
|
|
18
|
+
import { StorageScope, StorageTarget } from '@codingame/monaco-vscode-api/vscode/vs/platform/storage/common/storage';
|
|
19
|
+
import { IStorageService } from '@codingame/monaco-vscode-api/vscode/vs/platform/storage/common/storage.service';
|
|
20
|
+
import { IConfigurationResolverService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/configurationResolver/common/configurationResolver.service';
|
|
21
|
+
import { ConfigurationResolverExpression } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/configurationResolver/common/configurationResolverExpression';
|
|
22
|
+
import { IEditorService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/editor/common/editorService.service';
|
|
23
|
+
import { McpRegistryInputStorage } from './mcpRegistryInputStorage.js';
|
|
24
|
+
import { McpServerConnection } from './mcpServerConnection.js';
|
|
25
|
+
import { LazyCollectionState } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/mcp/common/mcpTypes';
|
|
26
|
+
import Severity from '@codingame/monaco-vscode-api/vscode/vs/base/common/severity';
|
|
27
|
+
import { observableValue } from '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/base';
|
|
28
|
+
import { derived } from '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/derived';
|
|
29
|
+
|
|
30
|
+
const createTrustMemento = observableMemento({
|
|
31
|
+
defaultValue: {},
|
|
32
|
+
key: 'mcp.trustedCollections'
|
|
33
|
+
});
|
|
34
|
+
const collectionPrefixLen = 3;
|
|
35
|
+
let McpRegistry = class McpRegistry extends Disposable {
|
|
36
|
+
get delegates() {
|
|
37
|
+
return this._delegates;
|
|
38
|
+
}
|
|
39
|
+
constructor(_instantiationService, _configurationResolverService, _dialogService, _storageService, _productService, _notificationService, _editorService) {
|
|
40
|
+
super();
|
|
41
|
+
this._instantiationService = _instantiationService;
|
|
42
|
+
this._configurationResolverService = _configurationResolverService;
|
|
43
|
+
this._dialogService = _dialogService;
|
|
44
|
+
this._storageService = _storageService;
|
|
45
|
+
this._productService = _productService;
|
|
46
|
+
this._notificationService = _notificationService;
|
|
47
|
+
this._editorService = _editorService;
|
|
48
|
+
this._trustPrompts = ( new Map());
|
|
49
|
+
this._collections = observableValue('collections', []);
|
|
50
|
+
this._delegates = [];
|
|
51
|
+
this.collections = this._collections;
|
|
52
|
+
this._collectionToPrefixes = ( this._collections.map(c => {
|
|
53
|
+
const hashes = ( c.map((collection) => {
|
|
54
|
+
const sha = ( new StringSHA1());
|
|
55
|
+
sha.update(collection.id);
|
|
56
|
+
return { view: 0, hash: sha.digest(), collection };
|
|
57
|
+
}));
|
|
58
|
+
const view = (h) => h.hash.slice(h.view, h.view + collectionPrefixLen);
|
|
59
|
+
let collided = false;
|
|
60
|
+
do {
|
|
61
|
+
hashes.sort((a, b) => view(a).localeCompare(view(b)) || a.collection.id.localeCompare(b.collection.id));
|
|
62
|
+
collided = false;
|
|
63
|
+
for (let i = 1; i < hashes.length; i++) {
|
|
64
|
+
const prev = hashes[i - 1];
|
|
65
|
+
const curr = hashes[i];
|
|
66
|
+
if (view(prev) === view(curr) && curr.view + collectionPrefixLen < curr.hash.length) {
|
|
67
|
+
curr.view++;
|
|
68
|
+
collided = true;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
} while (collided);
|
|
72
|
+
return Object.fromEntries(( hashes.map(h => [h.collection.id, view(h) + '.'])));
|
|
73
|
+
}));
|
|
74
|
+
this._workspaceStorage = ( new Lazy(
|
|
75
|
+
() => this._register(this._instantiationService.createInstance(McpRegistryInputStorage, StorageScope.WORKSPACE, StorageTarget.USER))
|
|
76
|
+
));
|
|
77
|
+
this._profileStorage = ( new Lazy(
|
|
78
|
+
() => this._register(this._instantiationService.createInstance(McpRegistryInputStorage, StorageScope.PROFILE, StorageTarget.USER))
|
|
79
|
+
));
|
|
80
|
+
this._trustMemento = ( new Lazy(
|
|
81
|
+
() => this._register(createTrustMemento(StorageScope.APPLICATION, StorageTarget.MACHINE, this._storageService))
|
|
82
|
+
));
|
|
83
|
+
this._lazyCollectionsToUpdate = ( new Set());
|
|
84
|
+
this._ongoingLazyActivations = observableValue(this, 0);
|
|
85
|
+
this.lazyCollectionState = derived(reader => {
|
|
86
|
+
if (this._ongoingLazyActivations.read(reader) > 0) {
|
|
87
|
+
return LazyCollectionState.LoadingUnknown;
|
|
88
|
+
}
|
|
89
|
+
const collections = this._collections.read(reader);
|
|
90
|
+
return ( collections.some(c => c.lazy && c.lazy.isCached === false)) ? LazyCollectionState.HasUnknown : LazyCollectionState.AllKnown;
|
|
91
|
+
});
|
|
92
|
+
this._onDidChangeInputs = this._register(( new Emitter()));
|
|
93
|
+
this.onDidChangeInputs = this._onDidChangeInputs.event;
|
|
94
|
+
}
|
|
95
|
+
registerDelegate(delegate) {
|
|
96
|
+
this._delegates.push(delegate);
|
|
97
|
+
this._delegates.sort((a, b) => b.priority - a.priority);
|
|
98
|
+
return {
|
|
99
|
+
dispose: () => {
|
|
100
|
+
const index = this._delegates.indexOf(delegate);
|
|
101
|
+
if (index !== -1) {
|
|
102
|
+
this._delegates.splice(index, 1);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
registerCollection(collection) {
|
|
108
|
+
const currentCollections = this._collections.get();
|
|
109
|
+
const toReplace = currentCollections.find(c => c.lazy && c.id === collection.id);
|
|
110
|
+
if (toReplace) {
|
|
111
|
+
this._lazyCollectionsToUpdate.add(collection.id);
|
|
112
|
+
this._collections.set(( currentCollections.map(c => c === toReplace ? collection : c)), undefined);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
this._collections.set([...currentCollections, collection], undefined);
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
dispose: () => {
|
|
119
|
+
const currentCollections = this._collections.get();
|
|
120
|
+
this._collections.set(currentCollections.filter(c => c !== collection), undefined);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
collectionToolPrefix(collection) {
|
|
125
|
+
return ( this._collectionToPrefixes.map(p => p[collection.id] ?? ''));
|
|
126
|
+
}
|
|
127
|
+
async discoverCollections() {
|
|
128
|
+
const toDiscover = this._collections.get().filter(c => c.lazy && !c.lazy.isCached);
|
|
129
|
+
this._ongoingLazyActivations.set(this._ongoingLazyActivations.get() + 1, undefined);
|
|
130
|
+
await Promise.all(( toDiscover.map(c => c.lazy?.load()))).finally(() => {
|
|
131
|
+
this._ongoingLazyActivations.set(this._ongoingLazyActivations.get() - 1, undefined);
|
|
132
|
+
});
|
|
133
|
+
const found = [];
|
|
134
|
+
const current = this._collections.get();
|
|
135
|
+
for (const collection of toDiscover) {
|
|
136
|
+
const rec = current.find(c => c.id === collection.id);
|
|
137
|
+
if (!rec) ;
|
|
138
|
+
else if (rec.lazy) {
|
|
139
|
+
rec.lazy.removed?.();
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
found.push(rec);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return found;
|
|
146
|
+
}
|
|
147
|
+
_getInputStorage(scope) {
|
|
148
|
+
return scope === StorageScope.WORKSPACE ? this._workspaceStorage.value : this._profileStorage.value;
|
|
149
|
+
}
|
|
150
|
+
_getInputStorageInConfigTarget(configTarget) {
|
|
151
|
+
return this._getInputStorage(configTarget === ConfigurationTarget.WORKSPACE || configTarget === ConfigurationTarget.WORKSPACE_FOLDER
|
|
152
|
+
? StorageScope.WORKSPACE
|
|
153
|
+
: StorageScope.PROFILE);
|
|
154
|
+
}
|
|
155
|
+
async clearSavedInputs(scope, inputId) {
|
|
156
|
+
const storage = this._getInputStorage(scope);
|
|
157
|
+
if (inputId) {
|
|
158
|
+
await storage.clear(inputId);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
storage.clearAll();
|
|
162
|
+
}
|
|
163
|
+
this._onDidChangeInputs.fire();
|
|
164
|
+
}
|
|
165
|
+
async editSavedInput(inputId, folderData, configSection, target) {
|
|
166
|
+
const storage = this._getInputStorageInConfigTarget(target);
|
|
167
|
+
const expr = ConfigurationResolverExpression.parse(inputId);
|
|
168
|
+
const stored = await storage.getMap();
|
|
169
|
+
const previous = stored[inputId].value;
|
|
170
|
+
await this._configurationResolverService.resolveWithInteraction(folderData, expr, configSection, previous ? { [inputId.slice(2, -1)]: previous } : {}, target);
|
|
171
|
+
await this._updateStorageWithExpressionInputs(storage, expr);
|
|
172
|
+
}
|
|
173
|
+
getSavedInputs(scope) {
|
|
174
|
+
return this._getInputStorage(scope).getMap();
|
|
175
|
+
}
|
|
176
|
+
resetTrust() {
|
|
177
|
+
this._trustMemento.value.set({}, undefined);
|
|
178
|
+
}
|
|
179
|
+
getTrust(collectionRef) {
|
|
180
|
+
return derived(reader => {
|
|
181
|
+
const collection = this._collections.read(reader).find(c => c.id === collectionRef.id);
|
|
182
|
+
if (!collection || collection.isTrustedByDefault) {
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
const memento = this._trustMemento.value.read(reader);
|
|
186
|
+
return memento.hasOwnProperty(collection.id) ? memento[collection.id] : undefined;
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
_promptForTrust(collection) {
|
|
190
|
+
let resultPromise = this._trustPrompts.get(collection.id);
|
|
191
|
+
resultPromise ??= this._promptForTrustOpenDialog(collection).finally(() => {
|
|
192
|
+
this._trustPrompts.delete(collection.id);
|
|
193
|
+
});
|
|
194
|
+
this._trustPrompts.set(collection.id, resultPromise);
|
|
195
|
+
return resultPromise;
|
|
196
|
+
}
|
|
197
|
+
async _promptForTrustOpenDialog(collection) {
|
|
198
|
+
const originURI = collection.presentation?.origin;
|
|
199
|
+
const labelWithOrigin = originURI ? `[\`${basename(originURI)}\`](${originURI})` : collection.label;
|
|
200
|
+
const result = await this._dialogService.prompt({
|
|
201
|
+
message: ( localize(7655, 'Trust MCP servers from {0}?', collection.label)),
|
|
202
|
+
custom: {
|
|
203
|
+
markdownDetails: [{
|
|
204
|
+
markdown: ( new MarkdownString(( localize(
|
|
205
|
+
7656,
|
|
206
|
+
'{0} discovered Model Context Protocol servers from {1} (`{2}`). {0} can use their capabilities in Chat.\n\nDo you want to allow running MCP servers from {3}?',
|
|
207
|
+
this._productService.nameShort,
|
|
208
|
+
collection.label,
|
|
209
|
+
( collection.serverDefinitions.get().map(s => s.label)).join('`, `'),
|
|
210
|
+
labelWithOrigin
|
|
211
|
+
)))),
|
|
212
|
+
dismissOnLinkClick: true,
|
|
213
|
+
}]
|
|
214
|
+
},
|
|
215
|
+
buttons: [
|
|
216
|
+
{ label: ( localize(7657, 'Trust')), run: () => true },
|
|
217
|
+
{ label: ( localize(7658, 'Do not trust')), run: () => false }
|
|
218
|
+
],
|
|
219
|
+
});
|
|
220
|
+
return result.result;
|
|
221
|
+
}
|
|
222
|
+
async _updateStorageWithExpressionInputs(inputStorage, expr) {
|
|
223
|
+
const secrets = {};
|
|
224
|
+
const inputs = {};
|
|
225
|
+
for (const [replacement, resolved] of expr.resolved()) {
|
|
226
|
+
if (resolved.input?.type === 'promptString' && resolved.input.password) {
|
|
227
|
+
secrets[replacement.id] = resolved;
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
inputs[replacement.id] = resolved;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
inputStorage.setPlainText(inputs);
|
|
234
|
+
await inputStorage.setSecrets(secrets);
|
|
235
|
+
this._onDidChangeInputs.fire();
|
|
236
|
+
}
|
|
237
|
+
async _replaceVariablesInLaunch(definition, launch) {
|
|
238
|
+
if (!definition.variableReplacement) {
|
|
239
|
+
return launch;
|
|
240
|
+
}
|
|
241
|
+
const { section, target, folder } = definition.variableReplacement;
|
|
242
|
+
const inputStorage = this._getInputStorageInConfigTarget(target);
|
|
243
|
+
const previouslyStored = await inputStorage.getMap();
|
|
244
|
+
const expr = ConfigurationResolverExpression.parse(launch);
|
|
245
|
+
for (const replacement of expr.unresolved()) {
|
|
246
|
+
if (previouslyStored.hasOwnProperty(replacement.id)) {
|
|
247
|
+
expr.resolve(replacement, previouslyStored[replacement.id]);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
await this._configurationResolverService.resolveWithInteraction(folder, expr, section, undefined, target);
|
|
251
|
+
await this._updateStorageWithExpressionInputs(inputStorage, expr);
|
|
252
|
+
return await this._configurationResolverService.resolveAsync(folder, expr);
|
|
253
|
+
}
|
|
254
|
+
async resolveConnection({ collectionRef, definitionRef, forceTrust, logger }) {
|
|
255
|
+
const collection = this._collections.get().find(c => c.id === collectionRef.id);
|
|
256
|
+
const definition = collection?.serverDefinitions.get().find(s => s.id === definitionRef.id);
|
|
257
|
+
if (!collection || !definition) {
|
|
258
|
+
throw ( new Error(
|
|
259
|
+
`Collection or definition not found for ${collectionRef.id} and ${definitionRef.id}`
|
|
260
|
+
));
|
|
261
|
+
}
|
|
262
|
+
const delegate = this._delegates.find(d => d.canStart(collection, definition));
|
|
263
|
+
if (!delegate) {
|
|
264
|
+
throw ( new Error('No delegate found that can handle the connection'));
|
|
265
|
+
}
|
|
266
|
+
if (!collection.isTrustedByDefault) {
|
|
267
|
+
const memento = this._trustMemento.value.get();
|
|
268
|
+
const trusted = memento.hasOwnProperty(collection.id) ? memento[collection.id] : undefined;
|
|
269
|
+
if (trusted) ;
|
|
270
|
+
else if (trusted === undefined || forceTrust) {
|
|
271
|
+
const trustValue = await this._promptForTrust(collection);
|
|
272
|
+
if (trustValue !== undefined) {
|
|
273
|
+
this._trustMemento.value.set({ ...memento, [collection.id]: trustValue }, undefined);
|
|
274
|
+
}
|
|
275
|
+
if (!trustValue) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
return undefined;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
let launch;
|
|
284
|
+
try {
|
|
285
|
+
launch = await this._replaceVariablesInLaunch(definition, definition.launch);
|
|
286
|
+
}
|
|
287
|
+
catch (e) {
|
|
288
|
+
this._notificationService.notify({
|
|
289
|
+
severity: Severity.Error,
|
|
290
|
+
message: ( localize(7659, 'Error starting {0}: {1}', definition.label, String(e))),
|
|
291
|
+
actions: {
|
|
292
|
+
primary: collection.presentation?.origin && [
|
|
293
|
+
{
|
|
294
|
+
id: 'mcp.launchError.openConfig',
|
|
295
|
+
class: undefined,
|
|
296
|
+
enabled: true,
|
|
297
|
+
tooltip: '',
|
|
298
|
+
label: ( localize(7660, 'Open Configuration')),
|
|
299
|
+
run: () => this._editorService.openEditor({
|
|
300
|
+
resource: collection.presentation.origin,
|
|
301
|
+
options: { selection: definition.presentation?.origin?.range }
|
|
302
|
+
}),
|
|
303
|
+
}
|
|
304
|
+
]
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
return this._instantiationService.createInstance(McpServerConnection, collection, definition, delegate, launch, logger);
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
McpRegistry = ( __decorate([
|
|
313
|
+
( __param(0, IInstantiationService)),
|
|
314
|
+
( __param(1, IConfigurationResolverService)),
|
|
315
|
+
( __param(2, IDialogService)),
|
|
316
|
+
( __param(3, IStorageService)),
|
|
317
|
+
( __param(4, IProductService)),
|
|
318
|
+
( __param(5, INotificationService)),
|
|
319
|
+
( __param(6, IEditorService))
|
|
320
|
+
], McpRegistry));
|
|
321
|
+
|
|
322
|
+
export { McpRegistry };
|