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.
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.
/*---------------------------------------------------------------------------------------------
allowedMcpServersService.ts ×7
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Disposable } from '../../../base/common/lifecycle.js';
import * as nls from '../../../nls.js';
import { createCommandUri, IMarkdownString, MarkdownString } from '../../../base/common/htmlContent.js';
import { IConfigurationService } from '../../configuration/common/configuration.js';
import { Emitter } from '../../../base/common/event.js';
import { hasKey } from '../../../base/common/types.js';
import { checkMcpServerAllowed, getMcpServerMatchers, IMcpServerIdentity, McpServerAllowResult } from './allowedMcpServers.js';
import { IAllowedMcpServersService, IGalleryMcpServer, IInstallableMcpServer, ILocalMcpServer, mcpAccessConfig, mcpAllowedServersConfig, mcpDeniedServersConfig, McpAccessValue } from './mcpManagement.js';
import { McpServerType } from './mcpPlatformTypes.js';
export class AllowedMcpServersService extends Disposable implements IAllowedMcpServersService {
_serviceBrand: undefined;
private _onDidChangeAllowedMcpServers = this._register(new Emitter<void>());
readonly onDidChangeAllowedMcpServers = this._onDidChangeAllowedMcpServers.event;
constructor(
@IConfigurationService private readonly configurationService: IConfigurationService
) {
super();
this._register(this.configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration(mcpAccessConfig) || e.affectsConfiguration(mcpAllowedServersConfig) || e.affectsConfiguration(mcpDeniedServersConfig)) {
this._onDidChangeAllowedMcpServers.fire();
}
}
isAllowed(mcpServer: IGalleryMcpServer | ILocalMcpServer | IInstallableMcpServer): true | IMarkdownString {
}
isServerAllowed(identity: IMcpServerIdentity): true | IMarkdownString {
if (this.configurationService.getValue(mcpAccessConfig) === McpAccessValue.None) {
const settingsCommandLink = createCommandUri('workbench.action.openSettings', { query: `@id:${mcpAccessConfig}` }).toString();
allowedMcpServersService.ts ×1
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));
}
const allowlist = getMcpServerMatchers(this.configurationService.getValue(mcpAllowedServersConfig));
const denylist = getMcpServerMatchers(this.configurationService.getValue(mcpDeniedServersConfig));
switch (checkMcpServerAllowed(allowlist, denylist, identity)) {
case McpServerAllowResult.Denied:
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
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
return true;
private toIdentity(mcpServer: IGalleryMcpServer | ILocalMcpServer | IInstallableMcpServer): IMcpServerIdentity {
const config = mcpServer.config;
if (config.type === McpServerType.REMOTE) {
}
return { name: mcpServer.name, command: [config.command, ...(config.args ?? [])] };
allowedMcpServersService.ts ×4
}
// Gallery server: match by name or a remote URL; the local command invocation is only
// known once the server is installed with a resolved configuration.
return { name: mcpServer.name, url: mcpServer.configuration.remotes?.[0]?.url };
allowedMcpServersService.ts ×4
}