|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 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 | +declare module 'vscode' { |
| 6 | + |
| 7 | + // https://github.com/microsoft/vscode/issues/243522 |
| 8 | + |
| 9 | + /** |
| 10 | + * McpStdioServerDefinition represents an MCP server available by running |
| 11 | + * a local process and listening to its stdin and stdout streams. |
| 12 | + */ |
| 13 | + export class McpStdioServerDefinition { |
| 14 | + /** |
| 15 | + * The human-readable name of the server. |
| 16 | + */ |
| 17 | + label: string; |
| 18 | + |
| 19 | + /** |
| 20 | + * The working directory used to start the server. |
| 21 | + */ |
| 22 | + cwd?: Uri; |
| 23 | + |
| 24 | + /** |
| 25 | + * The command used to start the server. Node.js-based servers may use |
| 26 | + * `process.execPath` to use the editor's version of Node.js to run the script. |
| 27 | + */ |
| 28 | + command: string; |
| 29 | + /** |
| 30 | + * Additional command-line arguments passed to the server. |
| 31 | + */ |
| 32 | + args: string[]; |
| 33 | + |
| 34 | + /** |
| 35 | + * Optional additional environment information for the server. Variables |
| 36 | + * in this environment will overwrite or remove (if null) the default |
| 37 | + * environment variables. |
| 38 | + */ |
| 39 | + env: Record<string, string | number | null>; |
| 40 | + |
| 41 | + /** |
| 42 | + * Optional version identification for the server. If this changes, the |
| 43 | + * editor will indicate that tools have changed and prompt to refresh them. |
| 44 | + */ |
| 45 | + version?: string; |
| 46 | + |
| 47 | + /** |
| 48 | + * @param label The human-readable name of the server. |
| 49 | + * @param command The command used to start the server. |
| 50 | + * @param args Additional command-line arguments passed to the server. |
| 51 | + * @param env Optional additional environment information for the server. |
| 52 | + * @param version Optional version identification for the server. |
| 53 | + */ |
| 54 | + constructor(label: string, command: string, args?: string[], env?: Record<string, string | number | null>, version?: string); |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * McpHttpServerDefinition represents an MCP server available using the |
| 59 | + * Streamable HTTP transport. |
| 60 | + */ |
| 61 | + export class McpHttpServerDefinition { |
| 62 | + /** |
| 63 | + * The human-readable name of the server. |
| 64 | + */ |
| 65 | + label: string; |
| 66 | + |
| 67 | + /** |
| 68 | + * The URI of the server. The editor will make a POST request to this URI |
| 69 | + * to begin each session. |
| 70 | + */ |
| 71 | + uri: Uri; |
| 72 | + |
| 73 | + /** |
| 74 | + * Optional additional heads included with each request to the server. |
| 75 | + */ |
| 76 | + headers: Record<string, string>; |
| 77 | + |
| 78 | + /** |
| 79 | + * Optional version identification for the server. If this changes, the |
| 80 | + * editor will indicate that tools have changed and prompt to refresh them. |
| 81 | + */ |
| 82 | + version?: string; |
| 83 | + |
| 84 | + /** |
| 85 | + * @param label The human-readable name of the server. |
| 86 | + * @param uri The URI of the server. |
| 87 | + * @param headers Optional additional heads included with each request to the server. |
| 88 | + */ |
| 89 | + constructor(label: string, uri: Uri, headers?: Record<string, string>, version?: string); |
| 90 | + } |
| 91 | + |
| 92 | + export type McpServerDefinition = McpStdioServerDefinition | McpHttpServerDefinition; |
| 93 | + |
| 94 | + /** |
| 95 | + * A type that can provide server configurations. This may only be used in |
| 96 | + * conjunction with `contributes.modelContextServerCollections` in the |
| 97 | + * extension's package.json. |
| 98 | + * |
| 99 | + * To allow the editor to cache available servers, extensions should register |
| 100 | + * this before `activate()` resolves. |
| 101 | + */ |
| 102 | + export interface McpConfigurationProvider<T extends McpServerDefinition = McpServerDefinition> { |
| 103 | + /** |
| 104 | + * Optional event fired to signal that the set of available servers has changed. |
| 105 | + */ |
| 106 | + onDidChange?: Event<void>; |
| 107 | + |
| 108 | + /** |
| 109 | + * Provides available MCP servers. The editor will call this method eagerly |
| 110 | + * to ensure the availability of servers for the language model, and so |
| 111 | + * extensions should not take actions which would require user |
| 112 | + * interaction, such as authentication. |
| 113 | + * |
| 114 | + * @param token A cancellation token. |
| 115 | + * @returns An array of MCP available MCP servers |
| 116 | + */ |
| 117 | + provideMcpServerDefinitions(token: CancellationToken): ProviderResult<T[]>; |
| 118 | + |
| 119 | + /** |
| 120 | + * This function will be called when the editor needs to start MCP server. |
| 121 | + * At this point, the extension may take any actions which may require user |
| 122 | + * interaction, such as authentication. |
| 123 | + * |
| 124 | + * The extension may return undefined on error to indicate that the server |
| 125 | + * should not be started. |
| 126 | + * |
| 127 | + * @param server The MCP server to resolve |
| 128 | + * @param token A cancellation token. |
| 129 | + * @returns The given, resolved server or thenable that resolves to such. |
| 130 | + */ |
| 131 | + resolveMcpServerDefinition?(server: T, token: CancellationToken): ProviderResult<T>; |
| 132 | + } |
| 133 | + |
| 134 | + namespace lm { |
| 135 | + export function registerMcpConfigurationProvider(id: string, provider: McpConfigurationProvider): Disposable; |
| 136 | + } |
| 137 | +} |
0 commit comments