mcpRegistry.ts ×19

Frontier kind: Code frontier

unlabeled · c_2dfb62b4e75c

44 tests · 41888 LOC · 197 files · introduces 0 tests · 120 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
19 ranges120 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
3716 ranges41888 lines · 197 files · Browse complete extent
All tests (intent)
44 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

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 native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 120 introduced LOC across 19 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/workbench/contrib/mcp/common/mcpRegistry.ts 120 introduced LOC · 19 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- mcpRegistry.ts
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 { assertNever } from '../../../../base/common/assert.js';
7 > import { Codicon } from '../../../../base/common/codicons.js';
8 > import { Emitter } from '../../../../base/common/event.js';
9 > import { MarkdownString } from '../../../../base/common/htmlContent.js';
10 > import { Iterable } from '../../../../base/common/iterator.js';
11 > import { Lazy } from '../../../../base/common/lazy.js';
12 > import { Disposable, DisposableStore, IDisposable } from '../../../../base/common/lifecycle.js';
13 > import { derived, IObservable, observableValue, autorunSelfDisposable } from '../../../../base/common/observable.js';
14 > import { isDefined } from '../../../../base/common/types.js';
15 > import { URI } from '../../../../base/common/uri.js';
16 > import { localize } from '../../../../nls.js';
17 > import { ConfigurationTarget, IConfigurationService } from '../../../../platform/configuration/common/configuration.js';
18 > import { IDialogService } from '../../../../platform/dialogs/common/dialogs.js';
19 > import { ExtensionIdentifier } from '../../../../platform/extensions/common/extensions.js';
20 > import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
21 > import { ILabelService } from '../../../../platform/label/common/label.js';
22 > import { ILogService } from '../../../../platform/log/common/log.js';
23 > import { mcpAccessConfig, McpAccessValue } from '../../../../platform/mcp/common/mcpManagement.js';
24 > import { INotificationService, Severity } from '../../../../platform/notification/common/notification.js';
25 > import { observableConfigValue } from '../../../../platform/observable/common/platformObservableUtils.js';
26 > import { IQuickInputButton, IQuickInputService, IQuickPickItem } from '../../../../platform/quickinput/common/quickInput.js';
27 > import { StorageScope, StorageTarget } from '../../../../platform/storage/common/storage.js';
28 > import { IWorkspaceFolderData } from '../../../../platform/workspace/common/workspace.js';
29 > import { IWorkspaceTrustManagementService, IWorkspaceTrustRequestService } from '../../../../platform/workspace/common/workspaceTrust.js';
30 > import { IConfigurationResolverService } from '../../../services/configurationResolver/common/configurationResolver.js';
31 > import { ConfigurationResolverExpression, IResolvedValue } from '../../../services/configurationResolver/common/configurationResolverExpression.js';
32 > import { AUX_WINDOW_GROUP, IEditorService } from '../../../services/editor/common/editorService.js';
33 > import { IMcpDevModeDebugging } from './mcpDevMode.js';
34 > import { McpRegistryInputStorage } from './mcpRegistryInputStorage.js';
35 > import { IMcpHostDelegate, IMcpRegistry, IMcpResolveConnectionOptions } from './mcpRegistryTypes.js';
36 > import { IMcpSandboxService } from './mcpSandboxService.js';
37 > import { McpServerConnection } from './mcpServerConnection.js';
38 > import { IMcpServerConnection, LazyCollectionState, McpCollectionDefinition, McpDefinitionReference, McpServerDefinition, McpServerLaunch, McpServerTrust, McpStartServerInteraction, UserInteractionRequiredError } from './mcpTypes.js';
39 >
40 > const notTrustedNonce = '__vscode_not_trusted';
41 >
42 > export class McpRegistry extends Disposable implements IMcpRegistry {
43 > declare public readonly _serviceBrand: undefined;
44 >
45 > private readonly _collections = observableValue<readonly McpCollectionDefinition[]>('collections', []);
46 > private readonly _delegates = observableValue<readonly IMcpHostDelegate[]>('delegates', []);
47 > private readonly _mcpAccessValue: IObservable<string>;
48 > public readonly collections: IObservable<readonly McpCollectionDefinition[]> = derived(reader => {
49 if (this._mcpAccessValue.read(reader) === McpAccessValue.None) {
50 return [];
51 }
52 return this._collections.read(reader);
53 > }); mcpRegistry.ts
54 >
55 > private readonly _workspaceStorage = new Lazy(() => this._register(this._instantiationService.createInstance(McpRegistryInputStorage, StorageScope.WORKSPACE, StorageTarget.USER)));
56 > private readonly _profileStorage = new Lazy(() => this._register(this._instantiationService.createInstance(McpRegistryInputStorage, StorageScope.PROFILE, StorageTarget.USER)));
57 >
58 > private readonly _ongoingLazyActivations = observableValue(this, 0);
59 >
60 > public readonly lazyCollectionState = derived(reader => {
61 if (this._mcpAccessValue.read(reader) === McpAccessValue.None) {
62 return { state: LazyCollectionState.AllKnown, collections: [] };
69 const hasUnknown = collections.some(c => c.lazy && c.lazy.isCached === false);
70 return hasUnknown ? { state: LazyCollectionState.HasUnknown, collections: collections.filter(c => c.lazy && c.lazy.isCached === false) } : { state: LazyCollectionState.AllKnown, collections: [] };
71 > }); mcpRegistry.ts
72 >
73 > public get delegates(): IObservable<readonly IMcpHostDelegate[]> {
74 > return this._delegates;
75 > }
76 >
77 > private readonly _onDidChangeInputs = this._register(new Emitter<void>());
78 > public readonly onDidChangeInputs = this._onDidChangeInputs.event;
79 >
80 > constructor(
81 > @IInstantiationService private readonly _instantiationService: IInstantiationService,
82 > @IConfigurationResolverService private readonly _configurationResolverService: IConfigurationResolverService,
83 > @IDialogService private readonly _dialogService: IDialogService,
84 > @INotificationService private readonly _notificationService: INotificationService,
85 > @IEditorService private readonly _editorService: IEditorService,
86 > @IConfigurationService configurationService: IConfigurationService,
87 > @IQuickInputService private readonly _quickInputService: IQuickInputService,
88 > @ILabelService private readonly _labelService: ILabelService,
89 > @ILogService private readonly _logService: ILogService,
90 > @IMcpSandboxService private readonly _mcpSandboxService: IMcpSandboxService,
91 > @IWorkspaceTrustManagementService private readonly _workspaceTrustManagementService: IWorkspaceTrustManagementService,
92 > @IWorkspaceTrustRequestService private readonly _workspaceTrustRequestService: IWorkspaceTrustRequestService,
93 > ) {
94 > super();
95 > this._mcpAccessValue = observableConfigValue(mcpAccessConfig, McpAccessValue.All, configurationService);
96 > }
97 >
98 > public registerDelegate(delegate: IMcpHostDelegate): IDisposable {
99 const delegates = this._delegates.get().slice();
100 delegates.push(delegate);
109 };
110 }
112 > public registerCollection(collection: McpCollectionDefinition): IDisposable {
113 const currentCollections = this._collections.get();
114 const toReplace = currentCollections.find(c => c.id === collection.id);
131 };
132 }
134 > public getServerDefinition(collectionRef: McpDefinitionReference, definitionRef: McpDefinitionReference): IObservable<{ server: McpServerDefinition | undefined; collection: McpCollectionDefinition | undefined }> {
135 const collectionObs = this._collections.map(cols => cols.find(c => c.id === collectionRef.id));
136 return collectionObs.map((collection, reader) => {
139 });
140 }
142 > public async discoverCollections(): Promise<McpCollectionDefinition[]> {
143 const toDiscover = this._collections.get().filter(c => c.lazy && !c.lazy.isCached);
144
164 return found;
165 }
167 > private _getInputStorage(scope: StorageScope): McpRegistryInputStorage {
168 return scope === StorageScope.WORKSPACE ? this._workspaceStorage.value : this._profileStorage.value;
169 }
171 > private _getInputStorageInConfigTarget(configTarget: ConfigurationTarget): McpRegistryInputStorage {
172 return this._getInputStorage(
173 configTarget === ConfigurationTarget.WORKSPACE || configTarget === ConfigurationTarget.WORKSPACE_FOLDER
176 );
177 }
179 > public async clearSavedInputs(scope: StorageScope, inputId?: string) {
180 const storage = this._getInputStorage(scope);
181 if (inputId) {
187 this._onDidChangeInputs.fire();
188 }
190 > public async editSavedInput(inputId: string, folderData: IWorkspaceFolderData | undefined, configSection: string, target: ConfigurationTarget): Promise<void> {
191 const storage = this._getInputStorageInConfigTarget(target);
192 const expr = ConfigurationResolverExpression.parse(inputId);
197 await this._updateStorageWithExpressionInputs(storage, expr);
198 }
200 > public async setSavedInput(inputId: string, target: ConfigurationTarget, value: string): Promise<void> {
201 const storage = this._getInputStorageInConfigTarget(target);
202 const expr = ConfigurationResolverExpression.parse(inputId);
207 await this._updateStorageWithExpressionInputs(storage, expr);
208 }
210 > public getSavedInputs(scope: StorageScope): Promise<{ [id: string]: IResolvedValue }> {
211 return this._getInputStorage(scope).getMap();
212 }
214 > private async _checkTrust(collection: McpCollectionDefinition, definition: McpServerDefinition, {
215 trustNonceBearer,
216 interaction,
277 }
278 }
280 > private async _promptForTrust(definition: McpServerDefinition, collection: McpCollectionDefinition, interaction: McpStartServerInteraction | undefined, trustNonceBearer: { trustedAtNonce: string | undefined }): Promise<boolean> {
281 interaction ??= new McpStartServerInteraction();
282 interaction.participants.set(definition.id, { s: 'waiting', definition, collection });
307 return !!trustedDefinitionIds?.includes(definition.id);
308 }
310 > /**
311 > * Confirms with the user which of the provided definitions should be trusted.
312 > * Returns undefined if the user cancelled the flow, or the list of trusted
313 > * definition IDs otherwise.
314 > */
315 > protected async _promptForTrustOpenDialog(definitions: { definition: McpServerDefinition; collection: McpCollectionDefinition }[]): Promise<string[] | undefined> {
316 function labelFor(r: { definition: McpServerDefinition; collection: McpCollectionDefinition }) {
317 const originURI = r.definition.presentation?.origin?.uri || r.collection.presentation?.origin;
432 }).finally(() => store.dispose());
433 }
435 > private async _updateStorageWithExpressionInputs(inputStorage: McpRegistryInputStorage, expr: ConfigurationResolverExpression<unknown>): Promise<void> {
436 const secrets: Record<string, IResolvedValue> = {};
437 const inputs: Record<string, IResolvedValue> = {};
448 this._onDidChangeInputs.fire();
449 }
451 > private async _replaceVariablesInLaunch(delegate: IMcpHostDelegate, definition: McpServerDefinition, launch: McpServerLaunch, errorOnUserInteraction?: boolean) {
452 if (!definition.variableReplacement) {
453 return launch;
484 return await this._configurationResolverService.resolveAsync(folder, expr);
485 }
487 > public async resolveConnection(opts: IMcpResolveConnectionOptions): Promise<IMcpServerConnection | undefined> {
488 const { collectionRef, definitionRef, interaction, logger, debug } = opts;
489 let collection = this._collections.get().find(c => c.id === collectionRef.id);