mcpService.ts ×13

Frontier kind: Code frontier

unlabeled · c_d95442c3455e

53 tests · 39943 LOC · 188 files · introduces 0 tests · 111 LOC · 3 files

Introduces — evidence that enters the hierarchy at this concept

Code
16 ranges111 lines · 3 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
3629 ranges39943 lines · 188 files · Browse complete extent
All tests (intent)
53 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.

3 files ranked by introduced lines: 111 introduced LOC across 16 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/workbench/contrib/mcp/common/mcpService.ts 83 introduced LOC · 13 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- mcpService.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 { RunOnceScheduler } from '../../../../base/common/async.js';
7 > import { CancellationToken, CancellationTokenSource } from '../../../../base/common/cancellation.js';
8 > import { Disposable, DisposableStore, toDisposable } from '../../../../base/common/lifecycle.js';
9 > import { autorun, derived, IObservable, ISettableObservable, observableValue, transaction } from '../../../../base/common/observable.js';
10 > import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';
11 > import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
12 > import { ILogService } from '../../../../platform/log/common/log.js';
13 > import { mcpAutoStartConfig, McpAutoStartValue } from '../../../../platform/mcp/common/mcpManagement.js';
14 > import { observableConfigValue } from '../../../../platform/observable/common/platformObservableUtils.js';
15 > import { IStorageService, StorageScope } from '../../../../platform/storage/common/storage.js';
16 > import { CollisionEnablementModel, EnablementModel, isContributionEnabled } from '../../chat/common/enablement.js';
17 > import { McpCollisionBehavior, mcpServerCollisionBehaviorSection } from './mcpConfiguration.js';
18 > import { IMcpRegistry } from './mcpRegistryTypes.js';
19 > import { McpPrefixGenerator, McpServer, McpServerMetadataCache } from './mcpServer.js';
20 > import { IAutostartResult, IMcpServer, IMcpService, McpCollectionDefinition, McpConnectionState, McpDefinitionReference, McpServerCacheState, McpServerDefinition, McpStartServerInteraction, UserInteractionRequiredError } from './mcpTypes.js';
21 > import { startServerAndWaitForLiveTools } from './mcpTypesUtils.js';
22 >
23 > type IMcpServerRec = { object: IMcpServer };
24 >
25 > export class McpService extends Disposable implements IMcpService {
26 >
27 > declare _serviceBrand: undefined;
28 >
29 > private readonly _currentAutoStarts = new Set<CancellationTokenSource>();
30 > private readonly _servers = observableValue<readonly IMcpServerRec[]>(this, []);
31 > public readonly servers: IObservable<readonly IMcpServer[]> = this._servers.map(servers => servers.map(s => s.object));
32 >
33 > private readonly _prefixGenerator = new McpPrefixGenerator();
34 >
35 > public get lazyCollectionState() { return this._mcpRegistry.lazyCollectionState; }
36 >
37 > public readonly enablementModel: McpCollisionEnablementModel;
38 >
39 > protected readonly userCache: McpServerMetadataCache;
40 > protected readonly workspaceCache: McpServerMetadataCache;
41 >
42 > constructor(
43 @IInstantiationService private readonly _instantiationService: IInstantiationService,
44 @IMcpRegistry private readonly _mcpRegistry: IMcpRegistry,
67 }));
68 }
70 > public cancelAutostart(): void {
71 for (const cts of this._currentAutoStarts) {
72 cts.cancel();
73 }
74 }
76 > public autostart(_token?: CancellationToken): IObservable<IAutostartResult> {
77 const autoStartConfig = this.configurationService.getValue<McpAutoStartValue>(mcpAutoStartConfig);
78 if (autoStartConfig === McpAutoStartValue.Never) {
101 return state;
102 }
104 > private async _autostart(autoStartConfig: McpAutoStartValue, state: ISettableObservable<IAutostartResult>, token: CancellationToken) {
105 await this._activateCollections();
106
156 }));
157 }
159 > public resetCaches(): void {
160 this.userCache.reset();
161 this.workspaceCache.reset();
162 }
164 > public resetTrust(): void {
165 this.resetCaches(); // same difference now
166 }
168 > public async activateCollections(): Promise<void> {
169 await this._activateCollections();
170 }
172 > private async _activateCollections() {
173 const collections = await this._mcpRegistry.discoverCollections();
174 this.updateCollectedServers();
175 return new Set(collections.map(c => c.id));
176 }
178 > public updateCollectedServers() {
179 const definitions = this._mcpRegistry.collections.get().flatMap(collectionDefinition =>
180 collectionDefinition.serverDefinitions.get().map(serverDefinition => {
227 });
228 }
230 > public override dispose(): void {
231 this._servers.get().forEach(s => s.object.dispose());
232 super.dispose();
233 }
234 > } mcpService.ts
235 >
236 function defsEqual(server: IMcpServer, def: { serverDefinition: McpServerDefinition; collectionDefinition: McpCollectionDefinition }) {
237 return server.collection.id === def.collectionDefinition.id && server.definition.id === def.serverDefinition.id;
238 }
240 > /**
241 > * Wraps an {@link EnablementModel} with collision-aware defaults and
242 > * mutual-exclusion logic for MCP servers with the same label.
243 > *
244 > * When collision behavior is `disable`:
245 > * - Servers whose label collides with a higher-priority server are disabled
246 > * by default (unless the user has explicitly toggled them).
247 > * - Enabling a colliding server disables all other servers with the same label.
248 > *
249 > * When collision behavior is `suffix`, delegates everything unchanged.
250 > */
251 > export class McpCollisionEnablementModel extends CollisionEnablementModel {
252 >
253 > /**
254 > * For each server definition ID, the list of all definition IDs that share
255 > * the same (case-insensitive) label, in priority order (lowest collection
256 > * order first). Empty when collision behavior is `suffix`.
257 > */
258 > constructor(
259 base: EnablementModel,
260 registry: IMcpRegistry,
src/vs/base/common/observableInternal/observables/observableFromEvent.ts 17 introduced LOC · 1 range

Open complete file

47
48 export function observableFromEventOpts<T, TArgs = unknown>(
49 > options: IDebugNameData & { observableFromEvent.ts
50 > equalsFn?: EqualityComparer<T>;
51 > getTransaction?: () => ITransaction | undefined;
52 > },
53 > event: Event<TArgs>,
54 > getValue: (args: TArgs | undefined) => T,
55 > debugLocation = DebugLocation.ofCaller()
56 > ): IObservable<T> {
57 > return new FromEventObservable(
58 > new DebugNameData(options.owner, options.debugName, options.debugReferenceFn ?? getValue),
59 > event,
60 > getValue,
61 > () => options.getTransaction?.() ?? FromEventObservable.globalTransaction,
62 > options.equalsFn ?? strictEquals,
63 > debugLocation
64 > );
65 > }
66
67 export class FromEventObservable<TArgs, T> extends BaseObservable<T> {
src/vs/platform/observable/common/platformObservableUtils.ts 11 introduced LOC · 2 ranges

Open complete file

11 /** Creates an observable update when a configuration key updates. */
12 export function observableConfigValue<T>(
13 > key: string, platformObservableUtils.ts
14 > defaultValue: T,
15 > configurationService: IConfigurationService,
16 > debugLocation = DebugLocation.ofCaller(),
17 > ): IObservable<T> {
18 > return observableFromEventOpts({ debugName: () => `Configuration Key "${key}"`, },
19 > (handleChange) => configurationService.onDidChangeConfiguration(e => {
20 if (e.affectsConfiguration(key)) {
21 handleChange(e);
22 }
23 }),
24 > () => configurationService.getValue<T>(key) ?? defaultValue, platformObservableUtils.ts
25 > debugLocation,
26 > );
27 > }
28
29 /** Update the configuration key with a value derived from observables. */