Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/mcp/common/allowedMcpServersService.ts
3294 views
1
/*---------------------------------------------------------------------------------------------
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 { URI } from '../../../base/common/uri.js';
8
import * as nls from '../../../nls.js';
9
import { IMarkdownString, MarkdownString } from '../../../base/common/htmlContent.js';
10
import { IConfigurationService } from '../../configuration/common/configuration.js';
11
import { Emitter } from '../../../base/common/event.js';
12
import { IAllowedMcpServersService, IGalleryMcpServer, IInstallableMcpServer, ILocalMcpServer, mcpAccessConfig, McpAccessValue } from './mcpManagement.js';
13
14
export class AllowedMcpServersService extends Disposable implements IAllowedMcpServersService {
15
16
_serviceBrand: undefined;
17
18
private _onDidChangeAllowedMcpServers = this._register(new Emitter<void>());
19
readonly onDidChangeAllowedMcpServers = this._onDidChangeAllowedMcpServers.event;
20
21
constructor(
22
@IConfigurationService private readonly configurationService: IConfigurationService
23
) {
24
super();
25
this._register(this.configurationService.onDidChangeConfiguration(e => {
26
if (e.affectsConfiguration(mcpAccessConfig)) {
27
this._onDidChangeAllowedMcpServers.fire();
28
}
29
}));
30
}
31
32
isAllowed(mcpServer: IGalleryMcpServer | ILocalMcpServer | IInstallableMcpServer): true | IMarkdownString {
33
if (this.configurationService.getValue(mcpAccessConfig) !== McpAccessValue.None) {
34
return true;
35
}
36
37
const settingsCommandLink = URI.parse(`command:workbench.action.openSettings?${encodeURIComponent(JSON.stringify({ query: `@id:${mcpAccessConfig}` }))}`).toString();
38
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));
39
}
40
}
41
42