Path: blob/main/src/vs/platform/mcp/common/mcpManagement.ts
3294 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 { IPager } 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 repositoryUrl?: string;26readonly readmeUrl?: URI;27readonly publisher?: string;28readonly publisherDisplayName?: string;29readonly icon?: {30readonly dark: string;31readonly light: string;32};33readonly codicon?: string;34readonly manifest?: IGalleryMcpServerConfiguration;35readonly source: InstallSource;36}3738export interface IMcpServerInput {39readonly description?: string;40readonly is_required?: boolean;41readonly format?: 'string' | 'number' | 'boolean' | 'filepath';42readonly value?: string;43readonly is_secret?: boolean;44readonly default?: string;45readonly choices?: readonly string[];46}4748export interface IMcpServerVariableInput extends IMcpServerInput {49readonly variables?: Record<string, IMcpServerInput>;50}5152export interface IMcpServerPositionalArgument extends IMcpServerVariableInput {53readonly type: 'positional';54readonly value_hint: string;55readonly is_repeatable: boolean;56}5758export interface IMcpServerNamedArgument extends IMcpServerVariableInput {59readonly type: 'named';60readonly name: string;61readonly is_repeatable: boolean;62}6364export interface IMcpServerKeyValueInput extends IMcpServerVariableInput {65readonly name: string;66readonly value: string;67}6869export type IMcpServerArgument = IMcpServerPositionalArgument | IMcpServerNamedArgument;7071export const enum RegistryType {72NODE = 'npm',73PYTHON = 'pypi',74DOCKER = 'docker-hub',75NUGET = 'nuget',76REMOTE = 'remote',77MCPB = 'mcpb',78}7980export interface IMcpServerPackage {81readonly registry_type: RegistryType;82readonly registry_base_url?: string;83readonly identifier: string;84readonly version: string;85readonly file_sha256?: string;86readonly runtime_hint?: string;87readonly package_arguments?: readonly IMcpServerArgument[];88readonly runtime_arguments?: readonly IMcpServerArgument[];89readonly environment_variables?: ReadonlyArray<IMcpServerKeyValueInput>;90}9192export interface IMcpServerRemote {93readonly url: string;94readonly transport_type?: 'streamable' | 'sse';95readonly headers?: ReadonlyArray<IMcpServerKeyValueInput>;96}9798export interface IGalleryMcpServerConfiguration {99readonly packages?: readonly IMcpServerPackage[];100readonly remotes?: readonly IMcpServerRemote[];101}102103export const enum GalleryMcpServerStatus {104Active = 'active',105Deprecated = 'deprecated'106}107108export interface IGalleryMcpServer {109readonly id: string;110readonly name: string;111readonly displayName: string;112readonly description: string;113readonly version: string;114readonly isLatest: boolean;115readonly status: GalleryMcpServerStatus;116readonly url?: string;117readonly codicon?: string;118readonly icon?: {119readonly dark: string;120readonly light: string;121};122readonly lastUpdated?: number;123readonly publishDate?: number;124readonly releaseDate?: number;125readonly repositoryUrl?: string;126readonly configuration?: IGalleryMcpServerConfiguration;127readonly readmeUrl?: string;128readonly readme?: string;129readonly publisher: string;130readonly publisherDisplayName?: string;131readonly publisherDomain?: { link: string; verified: boolean };132readonly ratingCount?: number;133readonly topics?: readonly string[];134readonly license?: string;135readonly starsCount?: number;136}137138export interface IQueryOptions {139text?: string;140sortBy?: SortBy;141sortOrder?: SortOrder;142}143144export const IMcpGalleryService = createDecorator<IMcpGalleryService>('IMcpGalleryService');145export interface IMcpGalleryService {146readonly _serviceBrand: undefined;147isEnabled(): boolean;148query(options?: IQueryOptions, token?: CancellationToken): Promise<IPager<IGalleryMcpServer>>;149getMcpServersFromVSCodeGallery(servers: string[]): Promise<IGalleryMcpServer[]>;150getMcpServersFromGallery(urls: string[]): Promise<IGalleryMcpServer[]>;151getMcpServer(url: string): Promise<IGalleryMcpServer | undefined>;152getMcpServerConfiguration(extension: IGalleryMcpServer, token: CancellationToken): Promise<IGalleryMcpServerConfiguration>;153getReadme(extension: IGalleryMcpServer, token: CancellationToken): Promise<string>;154}155156export interface InstallMcpServerEvent {157readonly name: string;158readonly mcpResource: URI;159readonly source?: IGalleryMcpServer;160}161162export interface InstallMcpServerResult {163readonly name: string;164readonly mcpResource: URI;165readonly source?: IGalleryMcpServer;166readonly local?: ILocalMcpServer;167readonly error?: Error;168}169170export interface UninstallMcpServerEvent {171readonly name: string;172readonly mcpResource: URI;173}174175export interface DidUninstallMcpServerEvent {176readonly name: string;177readonly mcpResource: URI;178readonly error?: string;179}180181export type InstallOptions = {182packageType?: RegistryType;183mcpResource?: URI;184};185186export type UninstallOptions = {187mcpResource?: URI;188};189190export interface IInstallableMcpServer {191readonly name: string;192readonly config: IMcpServerConfiguration;193readonly inputs?: IMcpServerVariable[];194}195196export const IMcpManagementService = createDecorator<IMcpManagementService>('IMcpManagementService');197export interface IMcpManagementService {198readonly _serviceBrand: undefined;199readonly onInstallMcpServer: Event<InstallMcpServerEvent>;200readonly onDidInstallMcpServers: Event<readonly InstallMcpServerResult[]>;201readonly onDidUpdateMcpServers: Event<readonly InstallMcpServerResult[]>;202readonly onUninstallMcpServer: Event<UninstallMcpServerEvent>;203readonly onDidUninstallMcpServer: Event<DidUninstallMcpServerEvent>;204getInstalled(mcpResource?: URI): Promise<ILocalMcpServer[]>;205canInstall(server: IGalleryMcpServer | IInstallableMcpServer): true | IMarkdownString;206install(server: IInstallableMcpServer, options?: InstallOptions): Promise<ILocalMcpServer>;207installFromGallery(server: IGalleryMcpServer, options?: InstallOptions): Promise<ILocalMcpServer>;208updateMetadata(local: ILocalMcpServer, server: IGalleryMcpServer, profileLocation?: URI): Promise<ILocalMcpServer>;209uninstall(server: ILocalMcpServer, options?: UninstallOptions): Promise<void>;210211getMcpServerConfigurationFromManifest(manifest: IGalleryMcpServerConfiguration, packageType: RegistryType): Omit<IInstallableMcpServer, 'name'>;212}213214export const IAllowedMcpServersService = createDecorator<IAllowedMcpServersService>('IAllowedMcpServersService');215export interface IAllowedMcpServersService {216readonly _serviceBrand: undefined;217218readonly onDidChangeAllowedMcpServers: Event<void>;219isAllowed(mcpServer: IGalleryMcpServer | ILocalMcpServer | IInstallableMcpServer): true | IMarkdownString;220}221222export const mcpAccessConfig = 'chat.mcp.access';223export const mcpGalleryServiceUrlConfig = 'chat.mcp.gallery.serviceUrl';224export const mcpAutoStartConfig = 'chat.mcp.autostart';225226export const enum McpAutoStartValue {227Never = 'never',228OnlyNew = 'onlyNew',229NewAndOutdated = 'newAndOutdated',230}231232export const enum McpAccessValue {233None = 'none',234Registry = 'registry',235All = 'all',236}237238239