Path: blob/main/src/vs/platform/mcp/common/allowedMcpServersService.ts
3294 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 { URI } from '../../../base/common/uri.js';7import * as nls from '../../../nls.js';8import { IMarkdownString, MarkdownString } from '../../../base/common/htmlContent.js';9import { IConfigurationService } from '../../configuration/common/configuration.js';10import { Emitter } from '../../../base/common/event.js';11import { IAllowedMcpServersService, IGalleryMcpServer, IInstallableMcpServer, ILocalMcpServer, mcpAccessConfig, McpAccessValue } from './mcpManagement.js';1213export class AllowedMcpServersService extends Disposable implements IAllowedMcpServersService {1415_serviceBrand: undefined;1617private _onDidChangeAllowedMcpServers = this._register(new Emitter<void>());18readonly onDidChangeAllowedMcpServers = this._onDidChangeAllowedMcpServers.event;1920constructor(21@IConfigurationService private readonly configurationService: IConfigurationService22) {23super();24this._register(this.configurationService.onDidChangeConfiguration(e => {25if (e.affectsConfiguration(mcpAccessConfig)) {26this._onDidChangeAllowedMcpServers.fire();27}28}));29}3031isAllowed(mcpServer: IGalleryMcpServer | ILocalMcpServer | IInstallableMcpServer): true | IMarkdownString {32if (this.configurationService.getValue(mcpAccessConfig) !== McpAccessValue.None) {33return true;34}3536const settingsCommandLink = URI.parse(`command:workbench.action.openSettings?${encodeURIComponent(JSON.stringify({ query: `@id:${mcpAccessConfig}` }))}`).toString();37return new MarkdownString(nls.localize('mcp servers are not allowed', "Model Context Protocol servers are disabled in the Editor. Please check your [settings]({0}).", settingsCommandLink));38}39}404142