src/vs/platform/mcp/common/allowedMcpServersService.ts

69 LOC · 63 covered · 6 uncovered · 17 ranges · 12 concepts · 8 introducers · 7 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the fileallowedMcpServersService.ts ×1 · 3 introduced LOCallowedMcpServersService…allowedMcpServersService.test|title=AllowedMcpServersService isAllowed matches an installable stdio server by its command|occurrence=1 · 0 introduced LOCallowedMcpServersService…allowedMcpServersService.ts ×1 · 2 introduced LOCallowedMcpServersService…allowedMcpServersService.ts ×4 · 9 introduced LOCallowedMcpServersService…allowedMcpServersService.test|title=AllowedMcpServersService denylist blocks by remote URL wildcard even without an allowlist|occurrence=1 · 0 introduced LOCallowedMcpServersService…allowedMcpServersService.test|title=AllowedMcpServersService allowlist permits only matching servers|occurrence=1 · 0 introduced LOCallowedMcpServersService…allowedMcpServersService.ts ×1 · 1 introduced LOCallowedMcpServersService…allowedMcpServersService.test|title=AllowedMcpServersService denylist blocks a matching server even when it is also allowed|occurrence=1 · 0 introduced LOCallowedMcpServersService…allowedMcpServersService.ts ×1 · 1 introduced LOCallowedMcpServersService…allowedMcpServersService.ts ×1 · 2 introduced LOCallowedMcpServersService…allowedMcpServersService.ts ×1 · 5 introduced LOCallowedMcpServersService…allowedMcpServersService.ts ×7 · 40 introduced LOCallowedMcpServersService…allowedMcpServersService.test|title=AllowedMcpServersService allowlist permits only matching servers|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/mcp/test/common/allowedMcpServersService.test|title=AllowedMcpServersService allowlist permits only matching servers|occurrence=1allowedMcpServersService…allowedMcpServersService.test|title=AllowedMcpServersService allows any server when nothing is configured|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/mcp/test/common/allowedMcpServersService.test|title=AllowedMcpServersService allows any server when nothing is configured|occurrence=1allowedMcpServersService…allowedMcpServersService.test|title=AllowedMcpServersService blocks all servers when access is None|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/mcp/test/common/allowedMcpServersService.test|title=AllowedMcpServersService blocks all servers when access is None|occurrence=1allowedMcpServersService…allowedMcpServersService.test|title=AllowedMcpServersService denylist blocks a matching server even when it is also allowed|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/mcp/test/common/allowedMcpServersService.test|title=AllowedMcpServersService denylist blocks a matching server even when it is also allowed|occurrence=1allowedMcpServersService…allowedMcpServersService.test|title=AllowedMcpServersService denylist blocks by remote URL wildcard even without an allowlist|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/mcp/test/common/allowedMcpServersService.test|title=AllowedMcpServersService denylist blocks by remote URL wildcard even without an allowlist|occurrence=1allowedMcpServersService…allowedMcpServersService.test|title=AllowedMcpServersService isAllowed matches an installable remote server by its URL|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/mcp/test/common/allowedMcpServersService.test|title=AllowedMcpServersService isAllowed matches an installable remote server by its URL|occurrence=1allowedMcpServersService…allowedMcpServersService.test|title=AllowedMcpServersService isAllowed matches an installable stdio server by its command|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/mcp/test/common/allowedMcpServersService.test|title=AllowedMcpServersService isAllowed matches an installable stdio server by its command|occurrence=1allowedMcpServersService…Focused file · src/vs/platform/mcp/common/allowedMcpServersService.ts · 69 LOCcommon/allowedMcpServers…

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- allowedMcpServersService.ts ×7
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 { Disposable } from '../../../base/common/lifecycle.js';
7 > import * as nls from '../../../nls.js';
8 > import { createCommandUri, IMarkdownString, MarkdownString } from '../../../base/common/htmlContent.js';
9 > import { IConfigurationService } from '../../configuration/common/configuration.js';
10 > import { Emitter } from '../../../base/common/event.js';
11 > import { hasKey } from '../../../base/common/types.js';
12 > import { checkMcpServerAllowed, getMcpServerMatchers, IMcpServerIdentity, McpServerAllowResult } from './allowedMcpServers.js';
13 > import { IAllowedMcpServersService, IGalleryMcpServer, IInstallableMcpServer, ILocalMcpServer, mcpAccessConfig, mcpAllowedServersConfig, mcpDeniedServersConfig, McpAccessValue } from './mcpManagement.js';
14 > import { McpServerType } from './mcpPlatformTypes.js';
15 >
16 > export class AllowedMcpServersService extends Disposable implements IAllowedMcpServersService {
17 >
18 > _serviceBrand: undefined;
19 >
20 > private _onDidChangeAllowedMcpServers = this._register(new Emitter<void>());
21 > readonly onDidChangeAllowedMcpServers = this._onDidChangeAllowedMcpServers.event;
22 >
23 > constructor(
24 > @IConfigurationService private readonly configurationService: IConfigurationService
25 > ) {
26 > super();
27 > this._register(this.configurationService.onDidChangeConfiguration(e => {
28 if (e.affectsConfiguration(mcpAccessConfig) || e.affectsConfiguration(mcpAllowedServersConfig) || e.affectsConfiguration(mcpDeniedServersConfig)) {
29 this._onDidChangeAllowedMcpServers.fire();
30 }
32 > }
33 >
34 > isAllowed(mcpServer: IGalleryMcpServer | ILocalMcpServer | IInstallableMcpServer): true | IMarkdownString {
35 > return this.isServerAllowed(this.toIdentity(mcpServer)); allowedMcpServersService.ts ×4
36 > }
38 > isServerAllowed(identity: IMcpServerIdentity): true | IMarkdownString {
39 > if (this.configurationService.getValue(mcpAccessConfig) === McpAccessValue.None) {
40 > const settingsCommandLink = createCommandUri('workbench.action.openSettings', { query: `@id:${mcpAccessConfig}` }).toString(); allowedMcpServersService.ts ×1
41 > return new MarkdownString(nls.localize('mcp servers are not allowed', "Model Context Protocol servers are disabled in the Editor. Please check your [settings]({0}).", settingsCommandLink));
42 > }
44 > const allowlist = getMcpServerMatchers(this.configurationService.getValue(mcpAllowedServersConfig));
45 > const denylist = getMcpServerMatchers(this.configurationService.getValue(mcpDeniedServersConfig));
46 > switch (checkMcpServerAllowed(allowlist, denylist, identity)) {
47 > case McpServerAllowResult.Denied:
48 > return new MarkdownString(nls.localize('mcp server is denied', "This Model Context Protocol server is blocked by your organization's policy. Please contact your administrator for more information.")); allowedMcpServersService.ts ×1
49 > case McpServerAllowResult.NotAllowed: allowedMcpServersService.ts ×7
50 > return new MarkdownString(nls.localize('mcp server not in allowlist', "This Model Context Protocol server is not in the list of servers allowed by your organization. Please contact your administrator for more information.")); allowedMcpServersService.ts ×1
53 > return true;
55 >
56 > private toIdentity(mcpServer: IGalleryMcpServer | ILocalMcpServer | IInstallableMcpServer): IMcpServerIdentity {
57 > if (hasKey(mcpServer, { config: true })) { allowedMcpServersService.ts ×4
58 > const config = mcpServer.config;
59 > if (config.type === McpServerType.REMOTE) {
60 > return { name: mcpServer.name, url: config.url }; allowedMcpServersService.ts ×1
61 > }
62 > return { name: mcpServer.name, command: [config.command, ...(config.args ?? [])] }; allowedMcpServersService.ts ×4
63 > }
64
65 // Gallery server: match by name or a remote URL; the local command invocation is only
66 // known once the server is installed with a resolved configuration.
67 > return { name: mcpServer.name, url: mcpServer.configuration.remotes?.[0]?.url }; allowedMcpServersService.ts ×4
68 > }