@codingame/monaco-vscode-mcp-service-override 38.1.3 → 39.0.1

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 (46) hide show
  1. package/common.js +1 -1
  2. package/package.json +2 -2
  3. package/vscode/src/vs/platform/mcp/common/allowedMcpServers.d.ts +33 -2
  4. package/vscode/src/vs/platform/mcp/common/allowedMcpServers.js +19 -14
  5. package/vscode/src/vs/platform/mcp/common/allowedMcpServersService.d.ts +3 -1
  6. package/vscode/src/vs/platform/mcp/common/allowedMcpServersService.js +126 -42
  7. package/vscode/src/vs/workbench/api/browser/mainThreadMcp.d.ts +1 -0
  8. package/vscode/src/vs/workbench/api/browser/mainThreadMcp.js +41 -24
  9. package/vscode/src/vs/workbench/contrib/mcp/browser/mcp.contribution.js +5 -4
  10. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpAddContextContribution.js +2 -2
  11. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpCommands.d.ts +12 -7
  12. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpCommands.js +271 -128
  13. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpDiscovery.d.ts +2 -1
  14. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpDiscovery.js +11 -3
  15. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpElicitationService.js +25 -25
  16. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpLanguageFeatures.js +38 -37
  17. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpMigration.js +11 -5
  18. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpResourceQuickAccess.js +8 -8
  19. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServerConfigurationFormAccessibility.js +7 -7
  20. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServerEditor.js +37 -37
  21. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServerEditorInput.js +2 -2
  22. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServerIcons.js +5 -5
  23. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServerWidgets.js +6 -5
  24. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpServersView.js +16 -10
  25. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpWorkbenchService.d.ts +11 -4
  26. package/vscode/src/vs/workbench/contrib/mcp/browser/mcpWorkbenchService.js +165 -69
  27. package/vscode/src/vs/workbench/contrib/mcp/common/discovery/extensionMcpDiscovery.js +4 -4
  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 +12 -1
  30. package/vscode/src/vs/workbench/contrib/mcp/common/mcpContextKeys.js +4 -4
  31. package/vscode/src/vs/workbench/contrib/mcp/common/mcpEditorAffordanceState.js +1 -0
  32. package/vscode/src/vs/workbench/contrib/mcp/common/mcpEnvironmentVariableExpansion.js +4 -1
  33. package/vscode/src/vs/workbench/contrib/mcp/common/mcpLanguageModelToolContribution.js +6 -6
  34. package/vscode/src/vs/workbench/contrib/mcp/common/mcpRegistry.js +13 -13
  35. package/vscode/src/vs/workbench/contrib/mcp/common/mcpSamplingLog.js +1 -1
  36. package/vscode/src/vs/workbench/contrib/mcp/common/mcpSamplingService.js +11 -11
  37. package/vscode/src/vs/workbench/contrib/mcp/common/mcpSandboxService.js +4 -4
  38. package/vscode/src/vs/workbench/contrib/mcp/common/mcpServerConnection.d.ts +4 -1
  39. package/vscode/src/vs/workbench/contrib/mcp/common/mcpServerConnection.js +10 -7
  40. package/vscode/src/vs/workbench/contrib/mcp/common/mcpService.d.ts +2 -1
  41. package/vscode/src/vs/workbench/contrib/mcp/common/mcpService.js +7 -3
  42. package/vscode/src/vs/workbench/services/authentication/browser/authenticationMcpService.js +11 -10
  43. package/vscode/src/vs/workbench/services/mcp/browser/mcpWorkbenchManagementService.d.ts +2 -1
  44. package/vscode/src/vs/workbench/services/mcp/browser/mcpWorkbenchManagementService.js +6 -3
  45. package/vscode/src/vs/platform/mcp/common/mcpGalleryService.d.ts +0 -50
  46. package/vscode/src/vs/platform/mcp/common/mcpGalleryService.js +0 -914
package/common.js CHANGED
@@ -3,7 +3,7 @@ import '@codingame/monaco-vscode-api/vscode/vs/editor/standalone/browser/standal
3
3
  import { SyncDescriptor } from '@codingame/monaco-vscode-api/vscode/vs/platform/instantiation/common/descriptors';
4
4
  import { AllowedMcpServersService } from './vscode/src/vs/platform/mcp/common/allowedMcpServersService.js';
5
5
  import { IMcpGalleryManifestService } from '@codingame/monaco-vscode-api/vscode/vs/platform/mcp/common/mcpGalleryManifest.service';
6
- import { McpGalleryService } from './vscode/src/vs/platform/mcp/common/mcpGalleryService.js';
6
+ import { McpGalleryService } from '@codingame/monaco-vscode-api/vscode/vs/platform/mcp/common/mcpGalleryService';
7
7
  import { IAllowedMcpServersService, IMcpGalleryService } from '@codingame/monaco-vscode-api/vscode/vs/platform/mcp/common/mcpManagement.service';
8
8
  import { McpResourceScannerService } from '@codingame/monaco-vscode-api/vscode/vs/platform/mcp/common/mcpResourceScannerService';
9
9
  import { IMcpResourceScannerService } from '@codingame/monaco-vscode-api/vscode/vs/platform/mcp/common/mcpResourceScannerService.service';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codingame/monaco-vscode-mcp-service-override",
3
- "version": "38.1.3",
3
+ "version": "39.0.1",
4
4
  "private": false,
5
5
  "description": "VSCode public API plugged on the monaco editor - mcp service-override",
6
6
  "keywords": [],
@@ -15,7 +15,7 @@
15
15
  },
16
16
  "type": "module",
17
17
  "dependencies": {
18
- "@codingame/monaco-vscode-api": "38.1.3"
18
+ "@codingame/monaco-vscode-api": "39.0.1"
19
19
  },
20
20
  "main": "index.js",
21
21
  "module": "index.js",
@@ -10,6 +10,35 @@ export interface IMcpServerMatcher {
10
10
  readonly serverUrl?: string;
11
11
  readonly serverCommand?: readonly string[];
12
12
  }
13
+ /**
14
+ * Maps strings in the allow/deny lists to those same strings with environment variables filled in by the host that runs or connects to the server.
15
+ * Before starting a server or sending a request, use these values in place of the original policy strings and check the actual command or URL against the lists: a matching deny blocks it, a configured allowlist must admit it, and a missing required value blocks it.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * // Policy: allow ["${NODE}", "${SCRIPT_DIR}/approved.js"]
20
+ * // deny ["${NODE}", "${SCRIPT_DIR}/blocked.js"]
21
+ * // Each command/argument string containing variables gets its own entry, not the array
22
+ * const policyValues = {
23
+ * '${NODE}': '/usr/bin/node',
24
+ * '${SCRIPT_DIR}/approved.js': '/opt/scripts/approved.js',
25
+ * '${SCRIPT_DIR}/blocked.js': '/opt/scripts/blocked.js',
26
+ * };
27
+ *
28
+ * // Replace each policy array element using its entry, leaving literal elements unchanged
29
+ * // Then compare the resulting array with the actual [command, ...args], in order
30
+ * // ["/usr/bin/node", "/opt/scripts/approved.js"] -> allowed
31
+ * // ["/usr/bin/node", "/opt/scripts/blocked.js"] -> denied
32
+ * // ["/usr/bin/node", "/opt/scripts/other.js"] -> not allowed
33
+ * // Missing policyValues["${NODE}"] -> blocked before execution
34
+ *
35
+ * // A URL policy works the same way
36
+ * // Policy: allow "https://${HOST}/mcp", with HOST=trusted.example
37
+ * // policyValues: { "https://${HOST}/mcp": "https://trusted.example/mcp" }
38
+ * // A request to https://other.example/mcp is still blocked, including redirects
39
+ * ```
40
+ */
41
+ export type McpServerPolicyValues = Readonly<Record<string, string>>;
13
42
  /**
14
43
  * Normalized identity of an MCP server used for allowlist matching. Both the install-time and the
15
44
  * runtime enforcement paths reduce their server representation to this shape: `url` is set for
@@ -20,6 +49,8 @@ export interface IMcpServerIdentity {
20
49
  readonly name: string;
21
50
  readonly url?: string;
22
51
  readonly command?: readonly string[];
52
+ /** Values to substitute into the allow/deny lists, not into this server's command or URL. Providing them does not mean the server is allowed; the allowed-servers service must check it before execution. */
53
+ readonly policyValues?: McpServerPolicyValues;
23
54
  }
24
55
  /**
25
56
  * The result of evaluating an MCP server against the allow/deny lists.
@@ -46,7 +77,7 @@ export declare function getMcpServerMatchers(value: unknown): readonly IMcpServe
46
77
  */
47
78
  export declare function isMcpServerMatched(matchers: readonly IMcpServerMatcher[] | undefined, identity: IMcpServerIdentity): boolean;
48
79
  /**
49
- * Evaluates an MCP server against the allow and deny lists. Deny always takes precedence; an unset
50
- * (`undefined`) allowlist imposes no restriction, while a configured allowlist requires a match.
80
+ * Evaluates one allowlist layer using the runtime's transport-specific name fallback; deny entries
81
+ * remain additive. An unset allowlist imposes no restriction, while an empty allowlist admits none.
51
82
  */
52
83
  export declare function checkMcpServerAllowed(allowlist: readonly IMcpServerMatcher[] | undefined, denylist: readonly IMcpServerMatcher[] | undefined, identity: IMcpServerIdentity): McpServerAllowResult;
@@ -30,26 +30,29 @@ function isValidMatcher(entry) {
30
30
  return (hasName ? 1 : 0) + (hasUrl ? 1 : 0) + (hasCommand ? 1 : 0) === 1;
31
31
  }
32
32
  function isMcpServerMatched(matchers, identity) {
33
- return !!matchers && ( matchers.some(matcher => matchesMatcher(matcher, identity)));
33
+ return !!matchers && ( matchers.some(
34
+ matcher => matchesMatcher(matcher, identity, value => identity.policyValues?.[value] ?? value)
35
+ ));
34
36
  }
35
37
  function checkMcpServerAllowed(allowlist, denylist, identity) {
36
38
  if (isMcpServerMatched(denylist, identity)) {
37
39
  return McpServerAllowResult.Denied;
38
40
  }
39
- if (allowlist !== undefined && !isMcpServerMatched(allowlist, identity)) {
41
+ const transportMatchers = identity.url !== undefined ? allowlist?.filter(matcher => isString(matcher.serverUrl)) : identity.command !== undefined ? allowlist?.filter(matcher => Array.isArray(matcher.serverCommand)) : undefined;
42
+ if (allowlist !== undefined && !isMcpServerMatched(transportMatchers?.length ? transportMatchers : allowlist, identity)) {
40
43
  return McpServerAllowResult.NotAllowed;
41
44
  }
42
45
  return McpServerAllowResult.Allowed;
43
46
  }
44
- function matchesMatcher(matcher, identity) {
47
+ function matchesMatcher(matcher, identity, resolve) {
45
48
  if (isString(matcher.serverName)) {
46
49
  return matcher.serverName === identity.name;
47
50
  }
48
51
  if (isString(matcher.serverUrl)) {
49
- return identity.url !== undefined && matchesUrlPattern(matcher.serverUrl, identity.url);
52
+ return identity.url !== undefined && matchesUrlPattern(resolve(matcher.serverUrl), identity.url);
50
53
  }
51
54
  if (Array.isArray(matcher.serverCommand)) {
52
- return identity.command !== undefined && equals(matcher.serverCommand, identity.command);
55
+ return identity.command !== undefined && equals(matcher.serverCommand.map(resolve), identity.command);
53
56
  }
54
57
  return false;
55
58
  }
@@ -58,16 +61,18 @@ function matchesUrlPattern(pattern, url) {
58
61
  if (destination === undefined) {
59
62
  return false;
60
63
  }
61
- if (!pattern.includes("*")) {
64
+ const schemeSeparator = ( pattern.indexOf("://"));
65
+ const originOnly = schemeSeparator >= 0 && findAuthorityEnd(pattern, schemeSeparator + 3) === pattern.length;
66
+ if (!pattern.includes("*") && !originOnly) {
62
67
  const expected = toNetworkDestinationUrl(pattern);
63
- return expected !== undefined && expected.toLowerCase() === destination.toLowerCase();
68
+ return expected !== undefined && expected === destination;
64
69
  }
65
- const normalizedPattern = toNetworkDestinationPattern(pattern);
70
+ const normalizedPattern = toNetworkDestinationPattern(originOnly ? `${pattern}/*` : pattern);
66
71
  if (normalizedPattern === undefined) {
67
72
  return false;
68
73
  }
69
74
  try {
70
- return ( new RegExp(buildUrlPatternRegexSource(normalizedPattern), "i")).test(destination);
75
+ return ( new RegExp(buildUrlPatternRegexSource(normalizedPattern))).test(destination);
71
76
  } catch {
72
77
  return false;
73
78
  }
@@ -78,7 +83,7 @@ function toNetworkDestinationUrl(url) {
78
83
  if (parsed.protocol === "http:" || parsed.protocol === "https:") {
79
84
  return parsed.origin + parsed.pathname + parsed.search;
80
85
  }
81
- return url;
86
+ return toNetworkDestinationPattern(url);
82
87
  } catch {
83
88
  return undefined;
84
89
  }
@@ -89,11 +94,11 @@ function toNetworkDestinationPattern(pattern) {
89
94
  return pattern;
90
95
  }
91
96
  const scheme = pattern.slice(0, schemeSeparator).toLowerCase();
92
- if (scheme !== "http" && scheme !== "https") {
93
- return pattern;
94
- }
95
97
  const rest = pattern.slice(schemeSeparator + 3);
96
98
  const authorityEnd = findAuthorityEnd(rest, 0);
99
+ if (scheme !== "http" && scheme !== "https") {
100
+ return `${scheme}://${rest.slice(0, authorityEnd).toLowerCase()}${rest.slice(authorityEnd)}`;
101
+ }
97
102
  let authority = rest.slice(0, authorityEnd);
98
103
  const userinfoEnd = authority.lastIndexOf("@");
99
104
  if (userinfoEnd >= 0) {
@@ -115,7 +120,7 @@ function toNetworkDestinationPattern(pattern) {
115
120
  } else if (afterAuthority.startsWith("?")) {
116
121
  afterAuthority = `/${afterAuthority}`;
117
122
  }
118
- return `${scheme}://${hostAndPort.host}${port !== undefined ? `:${port}` : ""}${afterAuthority}`;
123
+ return `${scheme}://${hostAndPort.host.toLowerCase()}${port !== undefined ? `:${port}` : ""}${afterAuthority}`;
119
124
  }
120
125
  function splitHostAndPort(authority) {
121
126
  if (authority.startsWith("[")) {
@@ -9,12 +9,14 @@ export declare class AllowedMcpServersService extends Disposable implements IAll
9
9
  _serviceBrand: undefined;
10
10
  private _onDidChangeAllowedMcpServers;
11
11
  readonly onDidChangeAllowedMcpServers: import("@codingame/monaco-vscode-api/vscode/vs/base/common/event").Event<void>;
12
+ get hasManagedAllowlist(): boolean;
12
13
  constructor(configurationService: IConfigurationService);
13
14
  isAllowed(mcpServer: IGalleryMcpServer | ILocalMcpServer | IInstallableMcpServer): true | IMarkdownString;
14
15
  isServerAllowedBeforeResolution(identity: IMcpServerIdentity): true | IMarkdownString;
15
16
  isServerAllowed(identity: IMcpServerIdentity): true | IMarkdownString;
17
+ getServerPolicyVariableValues(): readonly string[];
18
+ private getPolicyLists;
16
19
  private checkServerAllowed;
17
20
  private checkServerAllowedBeforeResolution;
18
21
  private getAllConfiguredMatchers;
19
- private toIdentity;
20
22
  }
@@ -1,18 +1,24 @@
1
1
 
2
2
  import { __decorate, __param } from '@codingame/monaco-vscode-api/external/tslib/tslib.es6';
3
3
  import { Disposable } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
4
+ import { toErrorMessage } from '@codingame/monaco-vscode-api/vscode/vs/base/common/errorMessage';
4
5
  import { localize } from '@codingame/monaco-vscode-api/vscode/vs/nls';
5
- import { createCommandUri, MarkdownString } from '@codingame/monaco-vscode-api/vscode/vs/base/common/htmlContent';
6
+ import { MarkdownString, createCommandUri } from '@codingame/monaco-vscode-api/vscode/vs/base/common/htmlContent';
6
7
  import { IConfigurationService } from '@codingame/monaco-vscode-api/vscode/vs/platform/configuration/common/configuration.service';
7
8
  import { hasConfigurationVariable } from '@codingame/monaco-vscode-api/vscode/vs/platform/configuration/common/configurationVariables';
8
9
  import { Emitter } from '@codingame/monaco-vscode-api/vscode/vs/base/common/event';
9
- import { isString, hasKey } from '@codingame/monaco-vscode-api/vscode/vs/base/common/types';
10
+ import { hasKey, isString, isStringArray } from '@codingame/monaco-vscode-api/vscode/vs/base/common/types';
10
11
  import { getMcpServerMatchers, checkMcpServerAllowed, McpServerAllowResult } from './allowedMcpServers.js';
11
- import { mcpAccessConfig, mcpAllowedServersConfig, mcpDeniedServersConfig, McpAccessValue, replaceMcpServerVariableReferences } from '@codingame/monaco-vscode-api/vscode/vs/platform/mcp/common/mcpManagement';
12
+ import { mcpAllowedServersConfig, mcpAccessConfig, mcpDeniedServersConfig, RegistryType, McpAccessValue } from '@codingame/monaco-vscode-api/vscode/vs/platform/mcp/common/mcpManagement';
12
13
  import { McpServerType } from '@codingame/monaco-vscode-api/vscode/vs/platform/mcp/common/mcpPlatformTypes';
13
14
  import { COPILOT_ALLOW_MANAGED_MCP_SERVERS_ONLY_CONFIG } from '@codingame/monaco-vscode-api/vscode/vs/platform/policy/common/copilotManagedSettings';
15
+ import { McpServerManifestParser } from '@codingame/monaco-vscode-api/vscode/vs/platform/mcp/common/mcpManagementService';
16
+ import { hasEnvVarReferences } from '@codingame/monaco-vscode-api/vscode/vs/platform/mcp/common/envVarResolution';
14
17
 
15
18
  let AllowedMcpServersService = class AllowedMcpServersService extends Disposable {
19
+ get hasManagedAllowlist() {
20
+ return Array.isArray(this.configurationService.inspect(mcpAllowedServersConfig).policyValue) || this.configurationService.inspect(COPILOT_ALLOW_MANAGED_MCP_SERVERS_ONLY_CONFIG).policyValue === true;
21
+ }
16
22
  constructor(configurationService) {
17
23
  super();
18
24
  this.configurationService = configurationService;
@@ -25,7 +31,62 @@ let AllowedMcpServersService = class AllowedMcpServersService extends Disposable
25
31
  }));
26
32
  }
27
33
  isAllowed(mcpServer) {
28
- return this.isServerAllowedBeforeResolution(this.toIdentity(mcpServer));
34
+ if (hasKey(mcpServer, {
35
+ config: true
36
+ })) {
37
+ const config = mcpServer.config;
38
+ const valid = config.type === McpServerType.REMOTE ? isString(config.url) && !!config.url.trim() : isString(config.command) && !!config.command.trim() && (config.args === undefined || isStringArray(config.args));
39
+ if (!valid) {
40
+ return (new MarkdownString(localize(
41
+ 2997,
42
+ "This Model Context Protocol server cannot be installed or run because its configuration is invalid."
43
+ )));
44
+ }
45
+ return this.isServerAllowedBeforeResolution(config.type === McpServerType.REMOTE ? {
46
+ name: mcpServer.name,
47
+ url: config.url
48
+ } : {
49
+ name: mcpServer.name,
50
+ command: [config.command, ...(config.args ?? [])]
51
+ });
52
+ }
53
+ const parser = ( new McpServerManifestParser());
54
+ let candidates;
55
+ try {
56
+ candidates = [
57
+ ...(mcpServer.configuration.remotes ?? []).map(remote => parser.getMcpServerConfigurationFromManifest({
58
+ remotes: [remote]
59
+ }, RegistryType.REMOTE)),
60
+ ...(mcpServer.configuration.packages ?? []).filter(p => [
61
+ RegistryType.NODE,
62
+ RegistryType.PYTHON,
63
+ RegistryType.DOCKER,
64
+ RegistryType.NUGET
65
+ ].includes(p.registryType)).map(p => parser.getMcpServerConfigurationFromManifest({
66
+ packages: [p]
67
+ }, p.registryType))
68
+ ];
69
+ } catch (error) {
70
+ return ( new MarkdownString()).appendText(( localize(
71
+ 2998,
72
+ "This Model Context Protocol server cannot be installed because its gallery configuration is invalid: {0}",
73
+ toErrorMessage(error)
74
+ )));
75
+ }
76
+ let result = this.isServerAllowedBeforeResolution({
77
+ name: mcpServer.name
78
+ });
79
+ for (const candidate of candidates) {
80
+ const allowed = this.isAllowed({
81
+ name: mcpServer.name,
82
+ config: candidate.mcpServerConfiguration.config
83
+ });
84
+ if (allowed === true) {
85
+ return true;
86
+ }
87
+ result = allowed;
88
+ }
89
+ return result;
29
90
  }
30
91
  isServerAllowedBeforeResolution(identity) {
31
92
  return this.checkServerAllowed(identity, "definition");
@@ -33,55 +94,100 @@ let AllowedMcpServersService = class AllowedMcpServersService extends Disposable
33
94
  isServerAllowed(identity) {
34
95
  return this.checkServerAllowed(identity, "resolved");
35
96
  }
97
+ getServerPolicyVariableValues() {
98
+ const {
99
+ allowlist,
100
+ denylist
101
+ } = this.getPolicyLists();
102
+ return [...( new Set([...(allowlist ?? []), ...(denylist ?? [])].flatMap(matcher => [
103
+ ...(matcher.serverCommand ?? []),
104
+ ...(matcher.serverUrl !== undefined ? [matcher.serverUrl] : [])
105
+ ].filter(value => hasEnvVarReferences(value)))))];
106
+ }
107
+ getPolicyLists() {
108
+ const managedOnly = this.configurationService.getValue(COPILOT_ALLOW_MANAGED_MCP_SERVERS_ONLY_CONFIG) === true;
109
+ return {
110
+ allowlist: managedOnly ? getMcpServerMatchers(this.configurationService.inspect(mcpAllowedServersConfig).policyValue) ?? [] : getMcpServerMatchers(this.configurationService.getValue(mcpAllowedServersConfig)),
111
+ denylist: managedOnly ? this.getAllConfiguredMatchers(mcpDeniedServersConfig) : getMcpServerMatchers(this.configurationService.getValue(mcpDeniedServersConfig))
112
+ };
113
+ }
36
114
  checkServerAllowed(identity, phase) {
37
115
  if (this.configurationService.getValue(mcpAccessConfig) === McpAccessValue.None) {
38
116
  const settingsCommandLink = ( createCommandUri("workbench.action.openSettings", {
39
117
  query: `@id:${mcpAccessConfig}`
40
118
  }).toString());
41
119
  return (new MarkdownString(localize(
42
- 2790,
120
+ 2999,
43
121
  "Model Context Protocol servers are disabled in the Editor. Please check your [settings]({0}).",
44
122
  settingsCommandLink
45
123
  )));
46
124
  }
47
- const managedOnly = this.configurationService.getValue(COPILOT_ALLOW_MANAGED_MCP_SERVERS_ONLY_CONFIG) === true;
48
- const allowlist = managedOnly ? getMcpServerMatchers(this.configurationService.inspect(mcpAllowedServersConfig).policyValue) ?? [] : getMcpServerMatchers(this.configurationService.getValue(mcpAllowedServersConfig));
49
- const denylist = managedOnly ? this.getAllConfiguredMatchers(mcpDeniedServersConfig) : getMcpServerMatchers(this.configurationService.getValue(mcpDeniedServersConfig));
50
- const result = phase === "definition" ? this.checkServerAllowedBeforeResolution(allowlist, denylist, identity) : checkMcpServerAllowed(allowlist, denylist, identity);
125
+ const {
126
+ allowlist,
127
+ denylist
128
+ } = this.getPolicyLists();
129
+ const unresolvedPolicy = ( [...(allowlist ?? []), ...(denylist ?? [])].some(matcher => ( [
130
+ ...(matcher.serverCommand ?? []),
131
+ ...(matcher.serverUrl !== undefined ? [matcher.serverUrl] : [])
132
+ ].some(
133
+ value => hasEnvVarReferences(value) && identity.policyValues?.[value] === undefined
134
+ ))));
135
+ if (phase === "resolved" && unresolvedPolicy) {
136
+ return (new MarkdownString(localize(
137
+ 3000,
138
+ "This Model Context Protocol server cannot run because its policy environment variables have not been resolved on the server host. Restart the server to try again."
139
+ )));
140
+ }
141
+ const result = phase === "definition" ? this.checkServerAllowedBeforeResolution(allowlist, denylist, identity, unresolvedPolicy) : checkMcpServerAllowed(allowlist, denylist, identity);
51
142
  switch (result) {
52
143
  case McpServerAllowResult.Denied:
53
144
  return (new MarkdownString(localize(
54
- 2791,
55
- "This Model Context Protocol server is blocked by your organization's policy. Please contact your administrator for more information."
145
+ 3001,
146
+ "This Model Context Protocol server is blocked by your organization. Contact your administrator for more information."
56
147
  )));
57
148
  case McpServerAllowResult.NotAllowed:
149
+ if (allowlist?.some(matcher => matcher.serverName === identity.name)) {
150
+ if (identity.url !== undefined) {
151
+ return (new MarkdownString(localize(
152
+ 3002,
153
+ "This Model Context Protocol server is not in the list of servers allowed by your organization. A name entry matches, but this allowlist contains URL entries, so the server must match an allowed URL. Please contact your administrator for more information."
154
+ )));
155
+ }
156
+ if (identity.command !== undefined) {
157
+ return (new MarkdownString(localize(
158
+ 3003,
159
+ "This Model Context Protocol server is not in the list of servers allowed by your organization. A name entry matches, but this allowlist contains command entries, so the server must match an allowed command and arguments. Please contact your administrator for more information."
160
+ )));
161
+ }
162
+ }
58
163
  return (new MarkdownString(localize(
59
- 2792,
164
+ 3004,
60
165
  "This Model Context Protocol server is not in the list of servers allowed by your organization. Please contact your administrator for more information."
61
166
  )));
62
167
  }
63
168
  return true;
64
169
  }
65
- checkServerAllowedBeforeResolution(allowlist, denylist, identity) {
66
- const unresolvedUrl = identity.url !== undefined && hasConfigurationVariable(identity.url);
67
- const unresolvedCommand = identity.command?.some(hasConfigurationVariable) ?? false;
170
+ checkServerAllowedBeforeResolution(allowlist, denylist, identity, unresolvedPolicy) {
171
+ const unresolvedUrl = identity.url !== undefined && (hasConfigurationVariable(identity.url) || unresolvedPolicy);
172
+ const unresolvedCommand = identity.command !== undefined && (( identity.command.some(hasConfigurationVariable)) || unresolvedPolicy);
68
173
  if (!unresolvedUrl && !unresolvedCommand) {
69
174
  return checkMcpServerAllowed(allowlist, denylist, identity);
70
175
  }
71
176
  const knownIdentity = {
72
177
  name: identity.name,
73
178
  url: unresolvedUrl ? undefined : identity.url,
74
- command: unresolvedCommand ? undefined : identity.command
179
+ command: unresolvedCommand ? undefined : identity.command,
180
+ policyValues: identity.policyValues
75
181
  };
76
182
  if (checkMcpServerAllowed(undefined, denylist, knownIdentity) === McpServerAllowResult.Denied) {
77
183
  return McpServerAllowResult.Denied;
78
184
  }
79
- if (allowlist === undefined || checkMcpServerAllowed(allowlist, undefined, knownIdentity) === McpServerAllowResult.Allowed) {
185
+ if (allowlist?.some(
186
+ matcher => (unresolvedUrl && isString(matcher.serverUrl)) || (unresolvedCommand && Array.isArray(matcher.serverCommand))
187
+ )) {
80
188
  return McpServerAllowResult.Allowed;
81
189
  }
82
- return ( allowlist.some(
83
- matcher => (unresolvedUrl && isString(matcher.serverUrl)) || (unresolvedCommand && Array.isArray(matcher.serverCommand))
84
- )) ? McpServerAllowResult.Allowed : McpServerAllowResult.NotAllowed;
190
+ return checkMcpServerAllowed(allowlist, undefined, knownIdentity);
85
191
  }
86
192
  getAllConfiguredMatchers(key) {
87
193
  const inspected = this.configurationService.inspect(key);
@@ -96,28 +202,6 @@ let AllowedMcpServersService = class AllowedMcpServersService extends Disposable
96
202
  inspected.policyValue
97
203
  ].flatMap(value => getMcpServerMatchers(value) ?? []);
98
204
  }
99
- toIdentity(mcpServer) {
100
- if (hasKey(mcpServer, {
101
- config: true
102
- })) {
103
- const config = mcpServer.config;
104
- if (config.type === McpServerType.REMOTE) {
105
- return {
106
- name: mcpServer.name,
107
- url: config.url
108
- };
109
- }
110
- return {
111
- name: mcpServer.name,
112
- command: [config.command, ...(config.args ?? [])]
113
- };
114
- }
115
- const remote = mcpServer.configuration.remotes?.[0];
116
- return {
117
- name: mcpServer.name,
118
- url: remote ? replaceMcpServerVariableReferences(remote.url, remote.variables) : undefined
119
- };
120
- }
121
205
  };
122
206
  AllowedMcpServersService = ( __decorate([( __param(0, IConfigurationService))], AllowedMcpServersService));
123
207
 
@@ -38,6 +38,7 @@ export declare class MainThreadMcp extends Disposable implements MainThreadMcpSh
38
38
  private readonly _servers;
39
39
  private readonly _serverDefinitions;
40
40
  private readonly _serverRequestUrls;
41
+ private readonly _serverPolicyValues;
41
42
  private readonly _serverAuthTracking;
42
43
  private readonly _proxy;
43
44
  private readonly _collectionDefinitions;
@@ -73,6 +73,7 @@ let MainThreadMcp = class MainThreadMcp extends Disposable {
73
73
  this._servers = ( new Map());
74
74
  this._serverDefinitions = ( new Map());
75
75
  this._serverRequestUrls = ( new Map());
76
+ this._serverPolicyValues = ( new Map());
76
77
  this._serverAuthTracking = ( new McpServerAuthTracker());
77
78
  this._collectionDefinitions = this._register(( new DisposableMap()));
78
79
  this._gateways = this._register(( new DisposableMap()));
@@ -89,7 +90,8 @@ let MainThreadMcp = class MainThreadMcp extends Disposable {
89
90
  for (const url of urls) {
90
91
  const allowed = this._allowedMcpServersService.isServerAllowed({
91
92
  name: definition.label,
92
- url
93
+ url,
94
+ policyValues: this._serverPolicyValues.get(id)
93
95
  });
94
96
  if (allowed !== true) {
95
97
  this.$onDidChangeState(id, {
@@ -133,15 +135,15 @@ let MainThreadMcp = class MainThreadMcp extends Disposable {
133
135
  );
134
136
  return McpServerLaunch.fromSerialized(ser);
135
137
  },
138
+ resolvePolicyVariables: values => proxy.$resolveMcpPolicyVariables(values),
136
139
  start: (_collection, serverDefiniton, resolveLaunch, options) => {
137
140
  const id = ++this._serverIdCounter;
138
- const launch = ( new ExtHostMcpServerLaunch(
139
- _extHostContext.extensionHostKind,
140
- () => proxy.$stopMcp(id),
141
- msg => proxy.$sendMessage(id, JSON.stringify(msg))
142
- ));
141
+ const launch = ( new ExtHostMcpServerLaunch(_extHostContext.extensionHostKind, id, proxy));
143
142
  this._servers.set(id, launch);
144
143
  this._serverDefinitions.set(id, serverDefiniton);
144
+ if (options?.policyValues) {
145
+ this._serverPolicyValues.set(id, options.policyValues);
146
+ }
145
147
  if (resolveLaunch.type === McpServerTransportType.HTTP) {
146
148
  this._serverRequestUrls.set(id, ( new Set([( resolveLaunch.uri.toString(true))])));
147
149
  }
@@ -234,9 +236,16 @@ let MainThreadMcp = class MainThreadMcp extends Disposable {
234
236
  if (!definition || !urls) {
235
237
  throw ( new CancellationError());
236
238
  }
239
+ const values = this._allowedMcpServersService.getServerPolicyVariableValues();
240
+ const policyValues = values.length ? await this._proxy.$resolveMcpPolicyVariables(values) : {};
241
+ if (!( this._serverDefinitions.has(id))) {
242
+ throw ( new CancellationError());
243
+ }
244
+ this._serverPolicyValues.set(id, policyValues);
237
245
  const allowed = this._allowedMcpServersService.isServerAllowed({
238
246
  name: definition.label,
239
- url
247
+ url,
248
+ policyValues
240
249
  });
241
250
  if (allowed !== true) {
242
251
  return allowed.value;
@@ -255,6 +264,7 @@ let MainThreadMcp = class MainThreadMcp extends Disposable {
255
264
  this._servers.delete(id);
256
265
  this._serverDefinitions.delete(id);
257
266
  this._serverRequestUrls.delete(id);
267
+ this._serverPolicyValues.delete(id);
258
268
  this._serverAuthTracking.untrack(id);
259
269
  }
260
270
  }
@@ -297,7 +307,7 @@ let MainThreadMcp = class MainThreadMcp extends Disposable {
297
307
  const resource = authDetails.resourceMetadata?.resource;
298
308
  if (!resource) {
299
309
  throw ( new Error(( localize(
300
- 6427,
310
+ 7828,
301
311
  "The enterprise-managed MCP server '{0}' did not advertise a protected-resource metadata document with a 'resource' identifier.",
302
312
  server.label
303
313
  ))));
@@ -306,7 +316,7 @@ let MainThreadMcp = class MainThreadMcp extends Disposable {
306
316
  const audience = resourceAuthServers[0];
307
317
  if (!audience) {
308
318
  throw ( new Error(( localize(
309
- 6428,
319
+ 7829,
310
320
  "The enterprise-managed MCP server '{0}' did not advertise an `authorization_servers` entry in its protected-resource metadata.",
311
321
  server.label
312
322
  ))));
@@ -386,7 +396,7 @@ let MainThreadMcp = class MainThreadMcp extends Disposable {
386
396
  const configuredIssuer = config.issuer?.trim();
387
397
  if (!configuredIssuer) {
388
398
  throw ( new Error(( localize(
389
- 6429,
399
+ 7830,
390
400
  "Enterprise-managed MCP authentication requires `mcp.enterpriseManagedAuth.idp.issuer` to be configured. Set it via enterprise policy (Windows Group Policy / macOS managed preferences / Linux `/etc/vscode/policy.json`) or, for local testing, by hand-editing `settings.json`."
391
401
  ))));
392
402
  }
@@ -395,14 +405,14 @@ let MainThreadMcp = class MainThreadMcp extends Disposable {
395
405
  parsed = ( URI.parse(configuredIssuer));
396
406
  } catch {
397
407
  throw ( new Error(( localize(
398
- 6430,
408
+ 7831,
399
409
  "Enterprise-managed MCP authentication requires `mcp.enterpriseManagedAuth.idp.issuer` to be a valid URL; got '{0}'.",
400
410
  configuredIssuer
401
411
  ))));
402
412
  }
403
413
  if (parsed.scheme !== "https" && parsed.scheme !== "http") {
404
414
  throw ( new Error(( localize(
405
- 6431,
415
+ 7832,
406
416
  "Enterprise-managed MCP authentication requires `mcp.enterpriseManagedAuth.idp.issuer` to use the `https` or `http` scheme; got '{0}'.",
407
417
  configuredIssuer
408
418
  ))));
@@ -507,9 +517,9 @@ let MainThreadMcp = class MainThreadMcp extends Disposable {
507
517
  }
508
518
  async continueWithIncorrectAccountPrompt(chosenAccountLabel, requestedAccountLabel) {
509
519
  const result = await this.dialogService.prompt({
510
- message: ( localize(6432, "Incorrect account detected")),
520
+ message: ( localize(7833, "Incorrect account detected")),
511
521
  detail: ( localize(
512
- 6433,
522
+ 7834,
513
523
  "The chosen account, {0}, does not match the requested account, {1}.",
514
524
  chosenAccountLabel,
515
525
  requestedAccountLabel
@@ -517,10 +527,10 @@ let MainThreadMcp = class MainThreadMcp extends Disposable {
517
527
  type: Severity.Warning,
518
528
  cancelButton: true,
519
529
  buttons: [{
520
- label: ( localize(6434, "Keep {0}", chosenAccountLabel)),
530
+ label: ( localize(7835, "Keep {0}", chosenAccountLabel)),
521
531
  run: () => chosenAccountLabel
522
532
  }, {
523
- label: ( localize(6435, "Login with {0}", requestedAccountLabel)),
533
+ label: ( localize(7836, "Login with {0}", requestedAccountLabel)),
524
534
  run: () => requestedAccountLabel
525
535
  }]
526
536
  });
@@ -562,13 +572,13 @@ let MainThreadMcp = class MainThreadMcp extends Disposable {
562
572
  } catch (e) {
563
573
  if (UserInteractionRequiredError.is(e)) {
564
574
  server.pushLog(LogLevel.Warning, ( localize(
565
- 6436,
575
+ 7837,
566
576
  "Authentication session for {0} removed, stopping server",
567
577
  providerLabel
568
578
  )));
569
579
  server.stop();
570
580
  } else {
571
- server.pushLog(LogLevel.Warning, ( localize(6437, "Unable to revalidate authentication for {0}.", providerLabel)));
581
+ server.pushLog(LogLevel.Warning, ( localize(7838, "Unable to revalidate authentication for {0}.", providerLabel)));
572
582
  }
573
583
  }
574
584
  }
@@ -611,18 +621,18 @@ let MainThreadMcp = class MainThreadMcp extends Disposable {
611
621
  }
612
622
  async loginPrompt(mcpLabel, providerLabel, recreatingSession) {
613
623
  const message = recreatingSession ? ( localize(
614
- 6438,
624
+ 7839,
615
625
  "The MCP Server Definition '{0}' wants you to authenticate to {1}.",
616
626
  mcpLabel,
617
627
  providerLabel
618
628
  )) : ( localize(
619
- 6439,
629
+ 7840,
620
630
  "The MCP Server Definition '{0}' wants to authenticate to {1}.",
621
631
  mcpLabel,
622
632
  providerLabel
623
633
  ));
624
634
  const buttons = [{
625
- label: ( localize(6440, "&&Allow")),
635
+ label: ( localize(7841, "&&Allow")),
626
636
  run() {
627
637
  return true;
628
638
  }
@@ -644,6 +654,7 @@ let MainThreadMcp = class MainThreadMcp extends Disposable {
644
654
  this._servers.clear();
645
655
  this._serverDefinitions.clear();
646
656
  this._serverRequestUrls.clear();
657
+ this._serverPolicyValues.clear();
647
658
  this._serverAuthTracking.clear();
648
659
  super.dispose();
649
660
  }
@@ -671,10 +682,10 @@ class ExtHostMcpServerLaunch extends Disposable {
671
682
  }
672
683
  }
673
684
  }
674
- constructor(extHostKind, stop, send) {
685
+ constructor(extHostKind, _serverId, _proxy) {
675
686
  super();
676
- this.stop = stop;
677
- this.send = send;
687
+ this._serverId = _serverId;
688
+ this._proxy = _proxy;
678
689
  this.state = observableValue("mcpServerState", {
679
690
  state: McpConnectionState.Kind.Starting
680
691
  });
@@ -689,6 +700,12 @@ class ExtHostMcpServerLaunch extends Disposable {
689
700
  );
690
701
  }));
691
702
  }
703
+ stop() {
704
+ return this._proxy.$stopMcp(this._serverId);
705
+ }
706
+ send(message) {
707
+ return this._proxy.$sendMessage(this._serverId, JSON.stringify(message));
708
+ }
692
709
  extHostDispose() {
693
710
  if (McpConnectionState.isRunning(this.state.get())) {
694
711
  this.pushLog(LogLevel.Warning, "Extension host shut down, server will stop.");