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,