1
>
/*---------------------------------------------------------------------------------------------
allowedMcpServers.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { equals } from '../../../base/common/arrays.js';
7
>
import { escapeRegExpCharacters } from '../../../base/common/strings.js';
8
>
import { isObject, isString } from '../../../base/common/types.js';
9
>
10
>
/**
11
>
* A single entry in the `chat.mcp.allowedServers` allowlist. Identifies an MCP server by exactly
12
>
* one strategy: its configured name, a remote server URL pattern (supporting `*` wildcards), or a
13
>
* local stdio command invocation (matched as an ordered argument list). Delivered as JSON via user
14
>
* settings or enterprise managed settings and validated at match time, so only the field matching
15
>
* the intended strategy is meaningful.
16
>
*/
17
>
export interface IMcpServerMatcher {
18
>
readonly serverName?: string;
19
>
readonly serverUrl?: string;
20
>
readonly serverCommand?: readonly string[];
21
>
}
22
>
23
>
/**
24
>
* Normalized identity of an MCP server used for allowlist matching. Both the install-time and the
25
>
* runtime enforcement paths reduce their server representation to this shape: `url` is set for
26
>
* remote (HTTP/SSE) servers and `command` (the full `[command, ...args]` invocation) for local
27
>
* stdio servers.
28
>
*/
29
>
export interface IMcpServerIdentity {
30
>
readonly name: string;
31
>
readonly url?: string;
32
>
readonly command?: readonly string[];
33
>
}
34
>
35
>
/**
36
>
* The result of evaluating an MCP server against the allow/deny lists.
37
>
*/
38
>
export const enum McpServerAllowResult {
39
>
/** Permitted: not denied, and either no allowlist is configured or it matches one. */
40
>
Allowed,
41
>
/** Blocked because it matches a deny entry (deny always wins). */
42
>
Denied,
43
>
/** Blocked because an allowlist is configured and it matches no entry. */
44
>
NotAllowed,
45
>
}
46
>
47
>
/**
48
>
* Coerces a resolved `chat.mcp.allowedServers` / `chat.mcp.deniedServers` configuration value into a
49
>
* list of matchers. Returns `undefined` (meaning "not configured") when the value is not an array —
50
>
* which is also how an unset setting surfaces (the registered `null` default). Malformed matcher
51
>
* entries (non-objects, or entries that do not carry exactly one valid matching field) are dropped
52
>
* so a bad payload degrades to "no match" rather than throwing during matching.
53
>
*/
54
>
export function getMcpServerMatchers(value: unknown): readonly IMcpServerMatcher[] | undefined {
55
if (!Array.isArray(value)) {
56
return undefined;