Path: blob/main/src/vs/platform/mcp/common/allowedMcpServersService.ts
5292 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { Disposable } from '../../../base/common/lifecycle.js';6import * as nls from '../../../nls.js';7import { createCommandUri, IMarkdownString, MarkdownString } from '../../../base/common/htmlContent.js';8import { IConfigurationService } from '../../configuration/common/configuration.js';9import { Emitter } from '../../../base/common/event.js';10import { IAllowedMcpServersService, IGalleryMcpServer, IInstallableMcpServer, ILocalMcpServer, mcpAccessConfig, McpAccessValue } from './mcpManagement.js';1112export class AllowedMcpServersService extends Disposable implements IAllowedMcpServersService {1314_serviceBrand: undefined;1516private _onDidChangeAllowedMcpServers = this._register(new Emitter<void>());17readonly onDidChangeAllowedMcpServers = this._onDidChangeAllowedMcpServers.event;1819constructor(20@IConfigurationService private readonly configurationService: IConfigurationService21) {22super();23this._register(this.configurationService.onDidChangeConfiguration(e => {24if (e.affectsConfiguration(mcpAccessConfig)) {25this._onDidChangeAllowedMcpServers.fire();26}27}));28}2930isAllowed(mcpServer: IGalleryMcpServer | ILocalMcpServer | IInstallableMcpServer): true | IMarkdownString {31if (this.configurationService.getValue(mcpAccessConfig) !== McpAccessValue.None) {32return true;33}3435const settingsCommandLink = createCommandUri('workbench.action.openSettings', { query: `@id:${mcpAccessConfig}` }).toString();36return new MarkdownString(nls.localize('mcp servers are not allowed', "Model Context Protocol servers are disabled in the Editor. Please check your [settings]({0}).", settingsCommandLink));37}38}394041