Path: blob/main/src/vs/platform/mcp/common/mcpManagement.ts
5272 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 { CancellationToken } from '../../../base/common/cancellation.js';6import { Event } from '../../../base/common/event.js';7import { IMarkdownString } from '../../../base/common/htmlContent.js';8import { IIterativePager } from '../../../base/common/paging.js';9import { URI } from '../../../base/common/uri.js';10import { SortBy, SortOrder } from '../../extensionManagement/common/extensionManagement.js';11import { createDecorator } from '../../instantiation/common/instantiation.js';12import { IMcpServerConfiguration, IMcpServerVariable } from './mcpPlatformTypes.js';1314export type InstallSource = 'gallery' | 'local';1516export interface ILocalMcpServer {17readonly name: string;18readonly config: IMcpServerConfiguration;19readonly version?: string;20readonly mcpResource: URI;21readonly location?: URI;22readonly displayName?: string;23readonly description?: string;24readonly galleryUrl?: string;25readonly galleryId?: string;26readonly repositoryUrl?: string;27readonly readmeUrl?: URI;28readonly publisher?: string;29readonly publisherDisplayName?: string;30readonly icon?: {31readonly dark: string;32readonly light: string;33};34readonly codicon?: string;35readonly manifest?: IGalleryMcpServerConfiguration;36readonly source: InstallSource;37}3839export interface IMcpServerInput {40readonly description?: string;41readonly isRequired?: boolean;42readonly format?: 'string' | 'number' | 'boolean' | 'filepath';43readonly value?: string;44readonly isSecret?: boolean;45readonly default?: string;46readonly choices?: readonly string[];47}4849export interface IMcpServerVariableInput extends IMcpServerInput {50readonly variables?: Record<string, IMcpServerInput>;51}5253export interface IMcpServerPositionalArgument extends IMcpServerVariableInput {54readonly type: 'positional';55readonly valueHint?: string;56readonly isRepeated?: boolean;57}5859export interface IMcpServerNamedArgument extends IMcpServerVariableInput {60readonly type: 'named';61readonly name: string;62readonly isRepeated?: boolean;63}6465export interface IMcpServerKeyValueInput extends IMcpServerVariableInput {66readonly name: string;67readonly value?: string;68}6970export type IMcpServerArgument = IMcpServerPositionalArgument | IMcpServerNamedArgument;7172export const enum RegistryType {73NODE = 'npm',74PYTHON = 'pypi',75DOCKER = 'oci',76NUGET = 'nuget',77MCPB = 'mcpb',78REMOTE = 'remote'79}8081export const enum TransportType {82STDIO = 'stdio',83STREAMABLE_HTTP = 'streamable-http',84SSE = 'sse'85}8687export interface StdioTransport {88readonly type: TransportType.STDIO;89}9091export interface StreamableHttpTransport {92readonly type: TransportType.STREAMABLE_HTTP;93readonly url: string;94readonly headers?: ReadonlyArray<IMcpServerKeyValueInput>;95}9697export interface SseTransport {98readonly type: TransportType.SSE;99readonly url: string;100readonly headers?: ReadonlyArray<IMcpServerKeyValueInput>;101}102103export type Transport = StdioTransport | StreamableHttpTransport | SseTransport;104105export interface IMcpServerPackage {106readonly registryType: RegistryType;107readonly identifier: string;108readonly transport: Transport;109readonly version?: string;110readonly registryBaseUrl?: string;111readonly fileSha256?: string;112readonly packageArguments?: readonly IMcpServerArgument[];113readonly runtimeHint?: string;114readonly runtimeArguments?: readonly IMcpServerArgument[];115readonly environmentVariables?: ReadonlyArray<IMcpServerKeyValueInput>;116}117118export interface IGalleryMcpServerConfiguration {119readonly packages?: readonly IMcpServerPackage[];120readonly remotes?: ReadonlyArray<SseTransport | StreamableHttpTransport>;121}122123export const enum GalleryMcpServerStatus {124Active = 'active',125Deprecated = 'deprecated'126}127128export interface IGalleryMcpServer {129readonly name: string;130readonly displayName: string;131readonly description: string;132readonly version: string;133readonly isLatest: boolean;134readonly status: GalleryMcpServerStatus;135readonly id?: string;136readonly galleryUrl?: string;137readonly webUrl?: string;138readonly codicon?: string;139readonly icon?: {140readonly dark: string;141readonly light: string;142};143readonly lastUpdated?: number;144readonly publishDate?: number;145readonly repositoryUrl?: string;146readonly configuration: IGalleryMcpServerConfiguration;147readonly readmeUrl?: string;148readonly readme?: string;149readonly publisher: string;150readonly publisherDisplayName?: string;151readonly publisherUrl?: string;152readonly publisherDomain?: { link: string; verified: boolean };153readonly ratingCount?: number;154readonly topics?: readonly string[];155readonly license?: string;156readonly starsCount?: number;157}158159export interface IQueryOptions {160text?: string;161sortBy?: SortBy;162sortOrder?: SortOrder;163}164165export const IMcpGalleryService = createDecorator<IMcpGalleryService>('IMcpGalleryService');166export interface IMcpGalleryService {167readonly _serviceBrand: undefined;168isEnabled(): boolean;169query(options?: IQueryOptions, token?: CancellationToken): Promise<IIterativePager<IGalleryMcpServer>>;170getMcpServersFromGallery(infos: { name: string; id?: string }[]): Promise<IGalleryMcpServer[]>;171getMcpServer(url: string): Promise<IGalleryMcpServer | undefined>;172getReadme(extension: IGalleryMcpServer, token: CancellationToken): Promise<string>;173}174175export interface InstallMcpServerEvent {176readonly name: string;177readonly mcpResource: URI;178readonly source?: IGalleryMcpServer;179}180181export interface InstallMcpServerResult {182readonly name: string;183readonly mcpResource: URI;184readonly source?: IGalleryMcpServer;185readonly local?: ILocalMcpServer;186readonly error?: Error;187}188189export interface UninstallMcpServerEvent {190readonly name: string;191readonly mcpResource: URI;192}193194export interface DidUninstallMcpServerEvent {195readonly name: string;196readonly mcpResource: URI;197readonly error?: string;198}199200export type InstallOptions = {201packageType?: RegistryType;202mcpResource?: URI;203};204205export type UninstallOptions = {206mcpResource?: URI;207};208209export interface IInstallableMcpServer {210readonly name: string;211readonly config: IMcpServerConfiguration;212readonly inputs?: IMcpServerVariable[];213}214215export type McpServerConfiguration = Omit<IInstallableMcpServer, 'name'>;216export interface McpServerConfigurationParseResult {217readonly mcpServerConfiguration: McpServerConfiguration;218readonly notices: string[];219}220221export const IMcpManagementService = createDecorator<IMcpManagementService>('IMcpManagementService');222export interface IMcpManagementService {223readonly _serviceBrand: undefined;224readonly onInstallMcpServer: Event<InstallMcpServerEvent>;225readonly onDidInstallMcpServers: Event<readonly InstallMcpServerResult[]>;226readonly onDidUpdateMcpServers: Event<readonly InstallMcpServerResult[]>;227readonly onUninstallMcpServer: Event<UninstallMcpServerEvent>;228readonly onDidUninstallMcpServer: Event<DidUninstallMcpServerEvent>;229getInstalled(mcpResource?: URI): Promise<ILocalMcpServer[]>;230canInstall(server: IGalleryMcpServer | IInstallableMcpServer): true | IMarkdownString;231install(server: IInstallableMcpServer, options?: InstallOptions): Promise<ILocalMcpServer>;232installFromGallery(server: IGalleryMcpServer, options?: InstallOptions): Promise<ILocalMcpServer>;233updateMetadata(local: ILocalMcpServer, server: IGalleryMcpServer, profileLocation?: URI): Promise<ILocalMcpServer>;234uninstall(server: ILocalMcpServer, options?: UninstallOptions): Promise<void>;235236getMcpServerConfigurationFromManifest(manifest: IGalleryMcpServerConfiguration, packageType: RegistryType): McpServerConfigurationParseResult;237}238239export const IAllowedMcpServersService = createDecorator<IAllowedMcpServersService>('IAllowedMcpServersService');240export interface IAllowedMcpServersService {241readonly _serviceBrand: undefined;242243readonly onDidChangeAllowedMcpServers: Event<void>;244isAllowed(mcpServer: IGalleryMcpServer | ILocalMcpServer | IInstallableMcpServer): true | IMarkdownString;245}246247export const mcpAccessConfig = 'chat.mcp.access';248export const mcpGalleryServiceUrlConfig = 'chat.mcp.gallery.serviceUrl';249export const mcpGalleryServiceEnablementConfig = 'chat.mcp.gallery.enabled';250export const mcpAutoStartConfig = 'chat.mcp.autostart';251export const mcpAppsEnabledConfig = 'chat.mcp.apps.enabled';252253export interface IMcpGalleryConfig {254readonly serviceUrl?: string;255readonly enabled?: boolean;256readonly version?: string;257}258259export const enum McpAutoStartValue {260Never = 'never',261OnlyNew = 'onlyNew',262NewAndOutdated = 'newAndOutdated',263}264265export const enum McpAccessValue {266None = 'none',267Registry = 'registry',268All = 'all',269}270271272