@codingame/monaco-vscode-mcp-service-override 26.2.2 → 28.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.
Files changed (66) hide show
  1. package/index.js +8 -2
  2. package/package.json +2 -2
  3. package/vscode/src/vs/base/common/jsonRpcProtocol.d.ts +66 -0
  4. package/vscode/src/vs/base/common/jsonRpcProtocol.js +216 -0
  5. package/vscode/src/vs/platform/mcp/common/allowedMcpServersService.js +1 -1
  6. package/vscode/src/vs/platform/mcp/common/mcpGalleryService.js +2 -2
  7. package/vscode/src/vs/platform/mcp/common/mcpGateway.d.ts +39 -0
  8. package/vscode/src/vs/platform/mcp/common/mcpGateway.js +6 -0
  9. package/vscode/src/vs/platform/mcp/common/mcpResourceScannerService.d.ts +3 -1
  10. package/vscode/src/vs/platform/mcp/common/mcpResourceScannerService.js +12 -5
  11. package/vscode/src/vs/workbench/contrib/mcp/browser/mcp.contribution.js +15 -5
  12. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpAddContextContribution.js +2 -2
  13. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpCommands.js +58 -58
  14. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpElicitationService.js +27 -28
  15. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpGatewayService.d.ts +20 -0
  16. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpGatewayService.js +51 -0
  17. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpGatewayToolBrokerContribution.d.ts +7 -0
  18. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpGatewayToolBrokerContribution.js +16 -0
  19. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpLanguageFeatures.js +18 -18
  20. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpMigration.js +4 -4
  21. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpResourceQuickAccess.js +8 -8
  22. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServersView.d.ts +4 -1
  23. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServersView.js +42 -24
  24. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpWorkbenchService.d.ts +1 -1
  25. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpWorkbenchService.js +13 -12
  26. package/vscode/src/vs/workbench/contrib/mcp/common/discovery/extensionMcpDiscovery.js +4 -4
  27. package/vscode/src/vs/workbench/contrib/mcp/common/discovery/installedMcpServersDiscovery.js +3 -1
  28. package/vscode/src/vs/workbench/contrib/mcp/common/discovery/nativeMcpDiscoveryAbstract.js +1 -1
  29. package/vscode/src/vs/workbench/contrib/mcp/common/discovery/nativeMcpDiscoveryAdapters.js +2 -1
  30. package/vscode/src/vs/workbench/contrib/mcp/common/discovery/pluginMcpDiscovery.d.ts +15 -0
  31. package/vscode/src/vs/workbench/contrib/mcp/common/discovery/pluginMcpDiscovery.js +106 -0
  32. package/vscode/src/vs/workbench/contrib/mcp/common/mcpContextKeys.js +4 -4
  33. package/vscode/src/vs/workbench/contrib/mcp/common/mcpGatewayToolBrokerChannel.d.ts +39 -0
  34. package/vscode/src/vs/workbench/contrib/mcp/common/mcpGatewayToolBrokerChannel.js +302 -0
  35. package/vscode/src/vs/workbench/contrib/mcp/common/mcpLanguageModelToolContribution.js +25 -17
  36. package/vscode/src/vs/workbench/contrib/mcp/common/mcpRegistry.d.ts +3 -1
  37. package/vscode/src/vs/workbench/contrib/mcp/common/mcpRegistry.js +27 -18
  38. package/vscode/src/vs/workbench/contrib/mcp/common/mcpSamplingLog.js +1 -1
  39. package/vscode/src/vs/workbench/contrib/mcp/common/mcpSamplingService.d.ts +1 -0
  40. package/vscode/src/vs/workbench/contrib/mcp/common/mcpSamplingService.js +28 -18
  41. package/vscode/src/vs/workbench/contrib/mcp/common/mcpSandboxService.d.ts +47 -0
  42. package/vscode/src/vs/workbench/contrib/mcp/common/mcpSandboxService.js +385 -0
  43. package/vscode/src/vs/workbench/contrib/mcp/common/mcpServerConnection.d.ts +6 -1
  44. package/vscode/src/vs/workbench/contrib/mcp/common/mcpServerConnection.js +61 -3
  45. package/vscode/src/vs/workbench/contrib/mcp/common/mcpServerRequestHandler.d.ts +4 -20
  46. package/vscode/src/vs/workbench/contrib/mcp/common/mcpServerRequestHandler.js +95 -145
  47. package/vscode/src/vs/workbench/services/authentication/browser/authenticationMcpService.js +9 -9
  48. package/vscode/src/vs/workbench/services/mcp/browser/mcpWorkbenchManagementService.d.ts +1 -1
  49. package/vscode/src/vs/workbench/services/mcp/browser/mcpWorkbenchManagementService.js +2 -2
  50. package/vscode/src/vs/platform/mcp/common/mcpManagementIpc.d.ts +0 -42
  51. package/vscode/src/vs/platform/mcp/common/mcpManagementIpc.js +0 -105
  52. package/vscode/src/vs/platform/mcp/common/mcpManagementService.d.ts +0 -130
  53. package/vscode/src/vs/platform/mcp/common/mcpManagementService.js +0 -665
  54. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServerActions.d.ts +0 -259
  55. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServerActions.js +0 -1225
  56. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServerEditor.d.ts +0 -72
  57. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServerEditor.js +0 -996
  58. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServerEditorInput.d.ts +0 -17
  59. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServerEditorInput.js +0 -49
  60. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServerIcons.d.ts +0 -5
  61. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServerIcons.js +0 -12
  62. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServerWidgets.d.ts +0 -88
  63. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServerWidgets.js +0 -464
  64. package/vscode/src/vs/workbench/contrib/mcp/browser/media/mcpServerEditor.css +0 -94
  65. package/vscode/src/vs/workbench/services/mcp/common/mcpWorkbenchManagementService.d.ts +0 -87
  66. package/vscode/src/vs/workbench/services/mcp/common/mcpWorkbenchManagementService.js +0 -702
@@ -25,16 +25,16 @@ import { IURLService } from '@codingame/monaco-vscode-api/vscode/vs/platform/url
25
25
  import { IUserDataProfilesService } from '@codingame/monaco-vscode-api/vscode/vs/platform/userDataProfile/common/userDataProfile.service';
26
26
  import { IWorkspaceContextService } from '@codingame/monaco-vscode-api/vscode/vs/platform/workspace/common/workspace.service';
27
27
  import { WORKSPACE_STANDALONE_CONFIGURATIONS, MCP_CONFIGURATION_KEY } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/configuration/common/configuration';
28
- import { ACTIVE_GROUP } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/editor/common/editorService';
28
+ import { MODAL_GROUP, ACTIVE_GROUP } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/editor/common/editorService';
29
29
  import { IEditorService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/editor/common/editorService.service';
30
30
  import { IWorkbenchEnvironmentService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/environment/common/environmentService.service';
31
- import { LocalMcpServerScope, USER_CONFIG_ID, REMOTE_USER_CONFIG_ID, WORKSPACE_CONFIG_ID, WORKSPACE_FOLDER_CONFIG_ID_PREFIX } from '../../../services/mcp/common/mcpWorkbenchManagementService.js';
31
+ import { LocalMcpServerScope, USER_CONFIG_ID, REMOTE_USER_CONFIG_ID, WORKSPACE_CONFIG_ID, WORKSPACE_FOLDER_CONFIG_ID_PREFIX } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/mcp/common/mcpWorkbenchManagementService';
32
32
  import { IWorkbenchMcpManagementService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/mcp/common/mcpWorkbenchManagementService.service';
33
33
  import { IRemoteAgentService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/remote/common/remoteAgentService.service';
34
34
  import { mcpConfigurationSection } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/mcp/common/mcpConfiguration';
35
35
  import { McpServerEnablementState, McpCollectionSortOrder, McpServerInstallState, McpServersGalleryStatusContext, HasInstalledMcpServersContext } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/mcp/common/mcpTypes';
36
36
  import { IMcpService, IMcpWorkbenchService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/mcp/common/mcpTypes.service';
37
- import { McpServerEditorInput } from './mcpServerEditorInput.js';
37
+ import { McpServerEditorInput } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/mcp/browser/mcpServerEditorInput';
38
38
  import { IMcpGalleryManifestService } from '@codingame/monaco-vscode-api/vscode/vs/platform/mcp/common/mcpGalleryManifest.service';
39
39
  import { IExtensionsWorkbenchService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/extensions/common/extensions.service';
40
40
  import '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/index';
@@ -442,7 +442,7 @@ let McpWorkbenchService = class McpWorkbenchService extends Disposable {
442
442
  const existing = result.get(server.name);
443
443
  if (existing) {
444
444
  this.logService.warn(( localize(
445
- 9487,
445
+ 10368,
446
446
  "Overwriting mcp server '{0}' from {1} with {2}.",
447
447
  server.name,
448
448
  server.mcpResource.path,
@@ -455,7 +455,7 @@ let McpWorkbenchService = class McpWorkbenchService extends Disposable {
455
455
  const existing = result.get(server.name);
456
456
  if (existing) {
457
457
  this.logService.warn(( localize(
458
- 9487,
458
+ 10368,
459
459
  "Overwriting mcp server '{0}' from {1} with {2}.",
460
460
  server.name,
461
461
  server.mcpResource.path,
@@ -468,7 +468,7 @@ let McpWorkbenchService = class McpWorkbenchService extends Disposable {
468
468
  }
469
469
  canInstall(mcpServer) {
470
470
  if (!(mcpServer instanceof McpWorkbenchServer)) {
471
- return ( new MarkdownString()).appendText(( localize(9488, "The provided object is not an mcp server.")));
471
+ return ( new MarkdownString()).appendText(( localize(10369, "The provided object is not an mcp server.")));
472
472
  }
473
473
  if (mcpServer.gallery) {
474
474
  const result = this.mcpManagementService.canInstall(mcpServer.gallery);
@@ -485,7 +485,7 @@ let McpWorkbenchService = class McpWorkbenchService extends Disposable {
485
485
  return result;
486
486
  }
487
487
  return ( new MarkdownString()).appendText(( localize(
488
- 9489,
488
+ 10370,
489
489
  "Cannot install the '{0}' MCP Server because it is not available in this setup.",
490
490
  mcpServer.label
491
491
  )));
@@ -592,7 +592,7 @@ let McpWorkbenchService = class McpWorkbenchService extends Disposable {
592
592
  id: USER_CONFIG_ID,
593
593
  key: "userLocalValue",
594
594
  target: ConfigurationTarget.USER_LOCAL,
595
- label: ( localize(9490, "Global in {0}", this.productService.nameShort)),
595
+ label: ( localize(10371, "Global in {0}", this.productService.nameShort)),
596
596
  scope: StorageScope.PROFILE,
597
597
  order: McpCollectionSortOrder.User,
598
598
  uri: mcpResource,
@@ -747,10 +747,11 @@ let McpWorkbenchService = class McpWorkbenchService extends Disposable {
747
747
  await this.extensionsWorkbenchService.openSearch(`@mcp ${searchValue}`, preserveFoucs);
748
748
  }
749
749
  async open(extension, options) {
750
+ const useModal = this.configurationService.getValue("extensions.allowOpenInModalEditor");
750
751
  await this.editorService.openEditor(
751
752
  this.instantiationService.createInstance(McpServerEditorInput, extension),
752
753
  options,
753
- ACTIVE_GROUP
754
+ useModal ? MODAL_GROUP : ACTIVE_GROUP
754
755
  );
755
756
  }
756
757
  getInstallState(extension) {
@@ -789,7 +790,7 @@ let McpWorkbenchService = class McpWorkbenchService extends Disposable {
789
790
  message: {
790
791
  severity: Severity.Warning,
791
792
  text: ( new MarkdownString(( localize(
792
- 9491,
793
+ 10372,
793
794
  "This MCP Server is disabled because MCP servers are configured to be disabled in the Editor. Please check your [settings]({0}).",
794
795
  settingsCommandLink
795
796
  ))))
@@ -803,7 +804,7 @@ let McpWorkbenchService = class McpWorkbenchService extends Disposable {
803
804
  message: {
804
805
  severity: Severity.Warning,
805
806
  text: ( new MarkdownString(( localize(
806
- 9492,
807
+ 10373,
807
808
  "This MCP Server is disabled because it is configured to be disabled in the Editor. Please check your [settings]({0}).",
808
809
  settingsCommandLink
809
810
  ))))
@@ -817,7 +818,7 @@ let McpWorkbenchService = class McpWorkbenchService extends Disposable {
817
818
  message: {
818
819
  severity: Severity.Warning,
819
820
  text: ( new MarkdownString(( localize(
820
- 9492,
821
+ 10373,
821
822
  "This MCP Server is disabled because it is configured to be disabled in the Editor. Please check your [settings]({0}).",
822
823
  settingsCommandLink
823
824
  ))))
@@ -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(9493, "Expected an array of MCP collections")));
144
+ user.collector.error(( localize(10374, "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(9494, "Expected 'id' to be a non-empty string.")));
149
+ user.collector.error(( localize(10375, "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(9495, "Expected 'label' to be a non-empty string.")));
153
+ user.collector.error(( localize(10376, "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(9496, "Expected 'when' to be a non-empty string.")));
157
+ user.collector.error(( localize(10377, "Expected 'when' to be a non-empty string.")));
158
158
  return false;
159
159
  }
160
160
  }
@@ -88,12 +88,14 @@ let InstalledMcpServersDiscovery = class InstalledMcpServersDiscovery extends Di
88
88
  args: config.args || [],
89
89
  env: config.env || {},
90
90
  envFile: config.envFile,
91
- cwd: config.cwd
91
+ cwd: config.cwd,
92
+ sandbox: server.rootSandbox
92
93
  };
93
94
  definitions[1].push({
94
95
  id: `${collectionId}.${server.name}`,
95
96
  label: server.name,
96
97
  launch,
98
+ sandboxEnabled: config.type === "http" ? undefined : config.sandboxEnabled,
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
- 9497,
89
+ 10378,
90
90
  " on {0}",
91
91
  labelService.getHostLabel(Schemas.vscodeRemote, remoteAuthority)
92
92
  ));
@@ -22,7 +22,8 @@ async function claudeConfigToServerDefinition(idPrefix, contents, cwd) {
22
22
  command: server.command,
23
23
  env: server.env || {},
24
24
  envFile: undefined,
25
- cwd: cwd?.fsPath
25
+ cwd: cwd?.fsPath,
26
+ sandbox: undefined
26
27
  };
27
28
  return {
28
29
  id: `${idPrefix}.${name}`,
@@ -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 { isDefined } from '@codingame/monaco-vscode-api/vscode/vs/base/common/types';
9
+ import { URI } from '@codingame/monaco-vscode-api/vscode/vs/base/common/uri';
10
+ import { ConfigurationTarget } from '@codingame/monaco-vscode-api/vscode/vs/platform/configuration/common/configuration';
11
+ import { McpServerType } from '@codingame/monaco-vscode-api/vscode/vs/platform/mcp/common/mcpPlatformTypes';
12
+ import { StorageScope } from '@codingame/monaco-vscode-api/vscode/vs/platform/storage/common/storage';
13
+ import { IAgentPluginService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/common/plugins/agentPluginService.service';
14
+ import { IMcpRegistry } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/mcp/common/mcpRegistryTypes.service';
15
+ import { McpCollectionSortOrder, McpServerTrust, McpServerTransportType } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/mcp/common/mcpTypes';
16
+ import { autorun } from '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/reactions/autorun';
17
+
18
+ let PluginMcpDiscovery = class PluginMcpDiscovery extends Disposable {
19
+ constructor(_agentPluginService, _mcpRegistry) {
20
+ super();
21
+ this._agentPluginService = _agentPluginService;
22
+ this._mcpRegistry = _mcpRegistry;
23
+ this.fromGallery = false;
24
+ this._collections = this._register(( new DisposableResourceMap()));
25
+ }
26
+ start() {
27
+ this._register(autorun(reader => {
28
+ const plugins = this._agentPluginService.plugins.read(reader);
29
+ const seen = ( new ResourceSet());
30
+ for (const plugin of plugins) {
31
+ seen.add(plugin.uri);
32
+ let collectionState = this._collections.get(plugin.uri);
33
+ if (!collectionState) {
34
+ collectionState = this.createCollectionState(plugin);
35
+ this._collections.set(plugin.uri, collectionState);
36
+ }
37
+ }
38
+ for (const [pluginUri] of this._collections) {
39
+ if (!( seen.has(pluginUri))) {
40
+ this._collections.deleteAndDispose(pluginUri);
41
+ }
42
+ }
43
+ }));
44
+ }
45
+ createCollectionState(plugin) {
46
+ const collectionId = `plugin.${plugin.uri}`;
47
+ return this._mcpRegistry.registerCollection({
48
+ id: collectionId,
49
+ label: `${plugin.label} (Agent Plugin)`,
50
+ remoteAuthority: plugin.uri.scheme === Schemas.vscodeRemote ? plugin.uri.authority : null,
51
+ configTarget: ConfigurationTarget.USER,
52
+ scope: StorageScope.PROFILE,
53
+ trustBehavior: McpServerTrust.Kind.Trusted,
54
+ serverDefinitions: ( plugin.mcpServerDefinitions.map(defs => ( defs.map(d => this._toServerDefinition(collectionId, d))).filter(isDefined))),
55
+ presentation: {
56
+ origin: plugin.uri,
57
+ order: McpCollectionSortOrder.Plugin
58
+ }
59
+ });
60
+ }
61
+ _toServerDefinition(
62
+ collectionId,
63
+ {
64
+ name,
65
+ configuration
66
+ }
67
+ ) {
68
+ const launch = this._toLaunch(configuration);
69
+ if (!launch) {
70
+ return undefined;
71
+ }
72
+ return {
73
+ id: `${collectionId}.${name}`,
74
+ label: name,
75
+ launch,
76
+ cacheNonce: String(hash(launch))
77
+ };
78
+ }
79
+ _toLaunch(config) {
80
+ if (config.type === McpServerType.LOCAL) {
81
+ return {
82
+ type: McpServerTransportType.Stdio,
83
+ command: config.command,
84
+ args: config.args ? [...config.args] : [],
85
+ env: config.env ? {
86
+ ...config.env
87
+ } : {},
88
+ envFile: config.envFile,
89
+ cwd: config.cwd,
90
+ sandbox: undefined
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(9529, "Context key that has the number of registered MCP servers"))
17
+ description: ( localize(10419, "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(9530, "Indicates whether there are MCP servers with unknown tools."))
21
+ description: ( localize(10420, "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(9531, "Indicates whether there are any MCP servers with errors."))
25
+ description: ( localize(10421, "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(9532, "Context key that has the number of registered MCP tools"))
29
+ description: ( localize(10422, "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,39 @@
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 { ILogService } from "@codingame/monaco-vscode-api/vscode/vs/platform/log/common/log.service";
6
+ import { IMcpService } from "@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/mcp/common/mcpTypes.service";
7
+ export declare class McpGatewayToolBrokerChannel extends Disposable implements IServerChannel<unknown> {
8
+ private readonly _mcpService;
9
+ private readonly _logService;
10
+ private readonly _startupGracePeriodMs;
11
+ private readonly _onDidChangeTools;
12
+ private readonly _onDidChangeResources;
13
+ private readonly _serverIdMap;
14
+ private _nextServerIndex;
15
+ /**
16
+ * Per-server promise that races server startup against the grace period timeout.
17
+ * Once set for a server, subsequent list calls await the already-resolved promise
18
+ * and return immediately instead of waiting again.
19
+ *
20
+ * The `resolved` flag tracks whether the promise has settled. If a server's
21
+ * cacheState regresses to Unknown/Outdated after the promise resolved (e.g.
22
+ * after a cache reset), `_waitForStartup` discards the stale entry and creates
23
+ * a fresh race so the server gets another chance to start.
24
+ */
25
+ private readonly _startupGrace;
26
+ constructor(_mcpService: IMcpService, _logService: ILogService, _startupGracePeriodMs?: number);
27
+ private _getServerIndex;
28
+ private _getServerByIndex;
29
+ private _waitForStartup;
30
+ private _shouldUseCachedData;
31
+ listen<T>(_ctx: unknown, event: string): Event<T>;
32
+ call<T>(_ctx: unknown, command: string, arg?: unknown, cancellationToken?: CancellationToken): Promise<T>;
33
+ private _listTools;
34
+ private _callTool;
35
+ private _listResources;
36
+ private _readResource;
37
+ private _listResourceTemplates;
38
+ private _ensureServerReady;
39
+ }
@@ -0,0 +1,302 @@
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, _logService, _startupGracePeriodMs = 5000) {
13
+ super();
14
+ this._mcpService = _mcpService;
15
+ this._logService = _logService;
16
+ this._startupGracePeriodMs = _startupGracePeriodMs;
17
+ this._onDidChangeTools = this._register(( new Emitter()));
18
+ this._onDidChangeResources = this._register(( new Emitter()));
19
+ this._serverIdMap = ( new Map());
20
+ this._nextServerIndex = 0;
21
+ this._startupGrace = ( new Map());
22
+ this._logService.debug("[McpGateway][ToolBroker] Initialized");
23
+ let toolsInitialized = false;
24
+ this._register(autorun(reader => {
25
+ for (const server of this._mcpService.servers.read(reader)) {
26
+ server.tools.read(reader);
27
+ }
28
+ if (toolsInitialized) {
29
+ this._logService.debug("[McpGateway][ToolBroker] Tools changed, firing onDidChangeTools");
30
+ this._onDidChangeTools.fire();
31
+ } else {
32
+ toolsInitialized = true;
33
+ }
34
+ }));
35
+ let resourcesInitialized = false;
36
+ this._register(autorun(reader => {
37
+ for (const server of this._mcpService.servers.read(reader)) {
38
+ server.capabilities.read(reader);
39
+ }
40
+ if (resourcesInitialized) {
41
+ this._logService.debug("[McpGateway][ToolBroker] Resources changed, firing onDidChangeResources");
42
+ this._onDidChangeResources.fire();
43
+ } else {
44
+ resourcesInitialized = true;
45
+ }
46
+ }));
47
+ }
48
+ _getServerIndex(server) {
49
+ const defId = server.definition.id;
50
+ let index = this._serverIdMap.get(defId);
51
+ if (index === undefined) {
52
+ index = this._nextServerIndex++;
53
+ this._serverIdMap.set(defId, index);
54
+ }
55
+ return index;
56
+ }
57
+ _getServerByIndex(serverIndex) {
58
+ for (const server of this._mcpService.servers.get()) {
59
+ if (this._getServerIndex(server) === serverIndex) {
60
+ return server;
61
+ }
62
+ }
63
+ return undefined;
64
+ }
65
+ _waitForStartup(server) {
66
+ const id = server.definition.id;
67
+ const existing = this._startupGrace.get(id);
68
+ if (existing?.resolved) {
69
+ const state = server.cacheState.get();
70
+ if (state === McpServerCacheState.Unknown || state === McpServerCacheState.Outdated) {
71
+ this._startupGrace.delete(id);
72
+ }
73
+ }
74
+ if (!( this._startupGrace.has(id))) {
75
+ const entry = {
76
+ promise: Promise.race([this._ensureServerReady(server), ( new Promise(resolve => setTimeout(() => resolve(false), this._startupGracePeriodMs)))]),
77
+ resolved: false
78
+ };
79
+ entry.promise.then(() => {
80
+ entry.resolved = true;
81
+ });
82
+ this._startupGrace.set(id, entry);
83
+ }
84
+ return this._startupGrace.get(id).promise;
85
+ }
86
+ async _shouldUseCachedData(server) {
87
+ const cacheState = server.cacheState.get();
88
+ if (cacheState === McpServerCacheState.Unknown || cacheState === McpServerCacheState.Outdated) {
89
+ await this._waitForStartup(server);
90
+ const newState = server.cacheState.get();
91
+ return newState === McpServerCacheState.Live || newState === McpServerCacheState.Cached || newState === McpServerCacheState.RefreshingFromCached;
92
+ }
93
+ return cacheState === McpServerCacheState.Live || cacheState === McpServerCacheState.Cached || cacheState === McpServerCacheState.RefreshingFromCached;
94
+ }
95
+ listen(_ctx, event) {
96
+ switch (event) {
97
+ case "onDidChangeTools":
98
+ return this._onDidChangeTools.event;
99
+ case "onDidChangeResources":
100
+ return this._onDidChangeResources.event;
101
+ }
102
+ throw ( new Error(`Invalid listen: ${event}`));
103
+ }
104
+ async call(_ctx, command, arg, cancellationToken) {
105
+ this._logService.debug(`[McpGateway][ToolBroker] IPC call: ${command}`);
106
+ switch (command) {
107
+ case "listTools":
108
+ {
109
+ const tools = await this._listTools();
110
+ return tools;
111
+ }
112
+ case "callTool":
113
+ {
114
+ const {
115
+ name,
116
+ args
117
+ } = arg;
118
+ const result = await this._callTool(name, args || {}, cancellationToken);
119
+ return result;
120
+ }
121
+ case "listResources":
122
+ {
123
+ const resources = await this._listResources();
124
+ return resources;
125
+ }
126
+ case "readResource":
127
+ {
128
+ const {
129
+ serverIndex,
130
+ uri
131
+ } = arg;
132
+ const result = await this._readResource(serverIndex, uri, cancellationToken);
133
+ return result;
134
+ }
135
+ case "listResourceTemplates":
136
+ {
137
+ const templates = await this._listResourceTemplates();
138
+ return templates;
139
+ }
140
+ }
141
+ throw ( new Error(`Invalid call: ${command}`));
142
+ }
143
+ async _listTools() {
144
+ const servers = this._mcpService.servers.get();
145
+ const perServer = await Promise.all(( servers.map(async server => {
146
+ if (!(await this._shouldUseCachedData(server))) {
147
+ this._logService.debug(
148
+ `[McpGateway][ToolBroker] Server '${server.definition.id}' not ready, skipping tool listing`
149
+ );
150
+ return [];
151
+ }
152
+ return ( server.tools.get().filter(t => t.visibility & McpToolVisibility.Model).map(t => t.definition));
153
+ })));
154
+ const mcpTools = perServer.flat();
155
+ this._logService.debug(
156
+ `[McpGateway][ToolBroker] listTools result: ${mcpTools.length} tool(s): [${( mcpTools.map(t => t.name)).join(", ")}]`
157
+ );
158
+ return mcpTools;
159
+ }
160
+ async _callTool(name, args, token = CancellationToken.None) {
161
+ this._logService.debug(
162
+ `[McpGateway][ToolBroker] callTool '${name}' with args: ${JSON.stringify(args)}`
163
+ );
164
+ for (const server of this._mcpService.servers.get()) {
165
+ const tool = server.tools.get().find(
166
+ t => t.definition.name === name && (t.visibility & McpToolVisibility.Model)
167
+ );
168
+ if (tool) {
169
+ this._logService.debug(
170
+ `[McpGateway][ToolBroker] Found tool '${name}' on server '${server.definition.id}' (index=${this._getServerIndex(server)})`
171
+ );
172
+ const result = await tool.call(args, undefined, token);
173
+ this._logService.debug(
174
+ `[McpGateway][ToolBroker] Tool '${name}' completed (isError=${result.isError ?? false}, content blocks=${result.content.length})`
175
+ );
176
+ return {
177
+ result,
178
+ serverIndex: this._getServerIndex(server)
179
+ };
180
+ }
181
+ }
182
+ this._logService.warn(`[McpGateway][ToolBroker] Tool '${name}' not found on any server`);
183
+ throw ( new Error(`Unknown tool: ${name}`));
184
+ }
185
+ async _listResources() {
186
+ const results = [];
187
+ const servers = this._mcpService.servers.get();
188
+ this._logService.debug(
189
+ `[McpGateway][ToolBroker] listResources: ${servers.length} server(s) known`
190
+ );
191
+ await Promise.all(( servers.map(async server => {
192
+ if (!(await this._shouldUseCachedData(server))) {
193
+ return;
194
+ }
195
+ const capabilities = server.capabilities.get();
196
+ if (!capabilities || !(capabilities & McpCapability.Resources)) {
197
+ this._logService.debug(
198
+ `[McpGateway][ToolBroker] Server '${server.definition.id}' has no resource capability, skipping`
199
+ );
200
+ return;
201
+ }
202
+ try {
203
+ const resources = await McpServer.callOn(server, h => h.listResources());
204
+ this._logService.debug(
205
+ `[McpGateway][ToolBroker] Server '${server.definition.id}' (index=${this._getServerIndex(server)}) listed ${resources.length} resource(s)`
206
+ );
207
+ results.push({
208
+ serverIndex: this._getServerIndex(server),
209
+ resources
210
+ });
211
+ } catch (error) {
212
+ this._logService.warn(
213
+ `[McpGateway][ToolBroker] Server '${server.definition.id}' failed to list resources`,
214
+ error
215
+ );
216
+ }
217
+ })));
218
+ this._logService.debug(
219
+ `[McpGateway][ToolBroker] listResources result: ${results.length} server(s) with resources`
220
+ );
221
+ return results;
222
+ }
223
+ async _readResource(serverIndex, uri, token = CancellationToken.None) {
224
+ const server = this._getServerByIndex(serverIndex);
225
+ if (!server) {
226
+ this._logService.warn(
227
+ `[McpGateway][ToolBroker] readResource: unknown server index ${serverIndex}`
228
+ );
229
+ throw ( new Error(`Unknown server index: ${serverIndex}`));
230
+ }
231
+ this._logService.debug(
232
+ `[McpGateway][ToolBroker] readResource '${uri}' from server '${server.definition.id}' (index=${serverIndex})`
233
+ );
234
+ const result = await McpServer.callOn(server, h => h.readResource({
235
+ uri
236
+ }, token), token);
237
+ this._logService.debug(
238
+ `[McpGateway][ToolBroker] readResource returned ${result.contents.length} content(s)`
239
+ );
240
+ return result;
241
+ }
242
+ async _listResourceTemplates() {
243
+ const results = [];
244
+ const servers = this._mcpService.servers.get();
245
+ this._logService.debug(
246
+ `[McpGateway][ToolBroker] listResourceTemplates: ${servers.length} server(s) known`
247
+ );
248
+ await Promise.all(( servers.map(async server => {
249
+ if (!(await this._shouldUseCachedData(server))) {
250
+ return;
251
+ }
252
+ const capabilities = server.capabilities.get();
253
+ if (!capabilities || !(capabilities & McpCapability.Resources)) {
254
+ return;
255
+ }
256
+ try {
257
+ const resourceTemplates = await McpServer.callOn(server, h => h.listResourceTemplates());
258
+ this._logService.debug(
259
+ `[McpGateway][ToolBroker] Server '${server.definition.id}' (index=${this._getServerIndex(server)}) listed ${resourceTemplates.length} resource template(s)`
260
+ );
261
+ results.push({
262
+ serverIndex: this._getServerIndex(server),
263
+ resourceTemplates
264
+ });
265
+ } catch (error) {
266
+ this._logService.warn(
267
+ `[McpGateway][ToolBroker] Server '${server.definition.id}' failed to list resource templates`,
268
+ error
269
+ );
270
+ }
271
+ })));
272
+ this._logService.debug(
273
+ `[McpGateway][ToolBroker] listResourceTemplates result: ${results.length} server(s) with templates`
274
+ );
275
+ return results;
276
+ }
277
+ async _ensureServerReady(server) {
278
+ const cacheState = server.cacheState.get();
279
+ if (cacheState !== McpServerCacheState.Unknown && cacheState !== McpServerCacheState.Outdated) {
280
+ return true;
281
+ }
282
+ this._logService.debug(
283
+ `[McpGateway][ToolBroker] Server '${server.definition.id}' not ready (cacheState=${cacheState}), starting...`
284
+ );
285
+ try {
286
+ const ready = await startServerAndWaitForLiveTools(server, {
287
+ promptType: "all-untrusted",
288
+ errorOnUserInteraction: true
289
+ });
290
+ this._logService.debug(`[McpGateway][ToolBroker] Server '${server.definition.id}' ready=${ready}`);
291
+ return ready;
292
+ } catch (error) {
293
+ this._logService.warn(
294
+ `[McpGateway][ToolBroker] Server '${server.definition.id}' failed to start`,
295
+ error
296
+ );
297
+ return false;
298
+ }
299
+ }
300
+ }
301
+
302
+ export { McpGatewayToolBrokerChannel };