@theia/plugin-ext 1.63.0-next.24 → 1.63.0-next.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/common/lm-protocol.d.ts +103 -0
- package/lib/common/lm-protocol.d.ts.map +1 -0
- package/lib/common/lm-protocol.js +21 -0
- package/lib/common/lm-protocol.js.map +1 -0
- package/lib/common/plugin-api-rpc.d.ts +3 -0
- package/lib/common/plugin-api-rpc.d.ts.map +1 -1
- package/lib/common/plugin-api-rpc.js +4 -2
- package/lib/common/plugin-api-rpc.js.map +1 -1
- package/lib/common/plugin-protocol.d.ts +6 -0
- package/lib/common/plugin-protocol.d.ts.map +1 -1
- package/lib/common/plugin-protocol.js.map +1 -1
- package/lib/hosted/node/plugin-host-module.d.ts.map +1 -1
- package/lib/hosted/node/plugin-host-module.js +2 -0
- package/lib/hosted/node/plugin-host-module.js.map +1 -1
- package/lib/main/browser/lm-main.d.ts +17 -0
- package/lib/main/browser/lm-main.d.ts.map +1 -0
- package/lib/main/browser/lm-main.js +119 -0
- package/lib/main/browser/lm-main.js.map +1 -0
- package/lib/main/browser/main-context.d.ts.map +1 -1
- package/lib/main/browser/main-context.js +3 -0
- package/lib/main/browser/main-context.js.map +1 -1
- package/lib/plugin/lm-ext.d.ts +52 -0
- package/lib/plugin/lm-ext.d.ts.map +1 -0
- package/lib/plugin/lm-ext.js +131 -0
- package/lib/plugin/lm-ext.js.map +1 -0
- package/lib/plugin/plugin-context.d.ts.map +1 -1
- package/lib/plugin/plugin-context.js +11 -2
- package/lib/plugin/plugin-context.js.map +1 -1
- package/lib/plugin/types-impl.d.ts +79 -0
- package/lib/plugin/types-impl.d.ts.map +1 -1
- package/lib/plugin/types-impl.js +43 -1
- package/lib/plugin/types-impl.js.map +1 -1
- package/package.json +29 -28
- package/src/common/lm-protocol.ts +137 -0
- package/src/common/plugin-api-rpc.ts +5 -2
- package/src/common/plugin-protocol.ts +7 -0
- package/src/hosted/node/plugin-host-module.ts +2 -0
- package/src/main/browser/lm-main.ts +136 -0
- package/src/main/browser/main-context.ts +4 -0
- package/src/plugin/lm-ext.ts +158 -0
- package/src/plugin/plugin-context.ts +15 -3
- package/src/plugin/types-impl.ts +104 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2025 EclipseSource.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { UriComponents } from './uri-components';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Protocol interfaces for MCP server definition providers.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
export interface McpStdioServerDefinitionDto {
|
|
24
|
+
/**
|
|
25
|
+
* The human-readable name of the server.
|
|
26
|
+
*/
|
|
27
|
+
readonly label: string;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The working directory used to start the server.
|
|
31
|
+
*/
|
|
32
|
+
cwd?: UriComponents;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The command used to start the server. Node.js-based servers may use
|
|
36
|
+
* `process.execPath` to use the editor's version of Node.js to run the script.
|
|
37
|
+
*/
|
|
38
|
+
command: string;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Additional command-line arguments passed to the server.
|
|
42
|
+
*/
|
|
43
|
+
args?: string[];
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Optional additional environment information for the server. Variables
|
|
47
|
+
* in this environment will overwrite or remove (if null) the default
|
|
48
|
+
* environment variables of the editor's extension host.
|
|
49
|
+
*/
|
|
50
|
+
env?: Record<string, string | number | null>;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Optional version identification for the server. If this changes, the
|
|
54
|
+
* editor will indicate that tools have changed and prompt to refresh them.
|
|
55
|
+
*/
|
|
56
|
+
version?: string;
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* McpHttpServerDefinition represents an MCP server available using the
|
|
62
|
+
* Streamable HTTP transport.
|
|
63
|
+
*/
|
|
64
|
+
export interface McpHttpServerDefinitionDto {
|
|
65
|
+
/**
|
|
66
|
+
* The human-readable name of the server.
|
|
67
|
+
*/
|
|
68
|
+
readonly label: string;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The URI of the server. The editor will make a POST request to this URI
|
|
72
|
+
* to begin each session.
|
|
73
|
+
*/
|
|
74
|
+
uri: UriComponents;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Optional additional heads included with each request to the server.
|
|
78
|
+
*/
|
|
79
|
+
headers?: Record<string, string>;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Optional version identification for the server. If this changes, the
|
|
83
|
+
* editor will indicate that tools have changed and prompt to refresh them.
|
|
84
|
+
*/
|
|
85
|
+
version?: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Definitions that describe different types of Model Context Protocol servers,
|
|
90
|
+
* which can be returned from the {@link McpServerDefinitionProvider}.
|
|
91
|
+
*/
|
|
92
|
+
export type McpServerDefinitionDto = McpStdioServerDefinitionDto | McpHttpServerDefinitionDto;
|
|
93
|
+
export const isMcpHttpServerDefinitionDto = (definition: McpServerDefinitionDto): definition is McpHttpServerDefinitionDto => 'uri' in definition;
|
|
94
|
+
/**
|
|
95
|
+
* Main side of the MCP server definition registry.
|
|
96
|
+
*/
|
|
97
|
+
export interface McpServerDefinitionRegistryMain {
|
|
98
|
+
/**
|
|
99
|
+
* Register an MCP server definition provider.
|
|
100
|
+
*/
|
|
101
|
+
$registerMcpServerDefinitionProvider(handle: number, name: string): void;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Unregister an MCP server definition provider.
|
|
105
|
+
*/
|
|
106
|
+
$unregisterMcpServerDefinitionProvider(handle: number): void;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Notify that server definitions have changed.
|
|
110
|
+
*/
|
|
111
|
+
$onDidChangeMcpServerDefinitions(handle: number): void;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Get server definitions from a provider.
|
|
115
|
+
*/
|
|
116
|
+
$getServerDefinitions(handle: number): Promise<McpServerDefinitionDto[]>;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Resolve a server definition.
|
|
120
|
+
*/
|
|
121
|
+
$resolveServerDefinition(handle: number, server: McpServerDefinitionDto): Promise<McpServerDefinitionDto | undefined>;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Extension side of the MCP server definition registry.
|
|
126
|
+
*/
|
|
127
|
+
export interface McpServerDefinitionRegistryExt {
|
|
128
|
+
/**
|
|
129
|
+
* Request server definitions from a provider.
|
|
130
|
+
*/
|
|
131
|
+
$provideServerDefinitions(handle: number): Promise<McpServerDefinitionDto[]>;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Resolve a server definition from a provider.
|
|
135
|
+
*/
|
|
136
|
+
$resolveServerDefinition(handle: number, server: McpServerDefinitionDto): Promise<McpServerDefinitionDto | undefined>;
|
|
137
|
+
}
|
|
@@ -127,6 +127,7 @@ import { AccessibilityInformation } from '@theia/core/lib/common/accessibility';
|
|
|
127
127
|
import { TreeDelta } from '@theia/test/lib/common/tree-delta';
|
|
128
128
|
import { TestItemDTO, TestOutputDTO, TestRunDTO, TestRunProfileDTO, TestRunRequestDTO, TestStateChangeDTO } from './test-types';
|
|
129
129
|
import { ArgumentProcessor } from './commands';
|
|
130
|
+
import { McpServerDefinitionRegistryMain, McpServerDefinitionRegistryExt } from './lm-protocol';
|
|
130
131
|
|
|
131
132
|
export interface PreferenceData {
|
|
132
133
|
[scope: number]: any;
|
|
@@ -2346,7 +2347,8 @@ export const PLUGIN_RPC_CONTEXT = {
|
|
|
2346
2347
|
TELEMETRY_MAIN: createProxyIdentifier<TelemetryMain>('TelemetryMain'),
|
|
2347
2348
|
LOCALIZATION_MAIN: createProxyIdentifier<LocalizationMain>('LocalizationMain'),
|
|
2348
2349
|
TESTING_MAIN: createProxyIdentifier<TestingMain>('TestingMain'),
|
|
2349
|
-
URI_MAIN: createProxyIdentifier<UriMain>('UriMain')
|
|
2350
|
+
URI_MAIN: createProxyIdentifier<UriMain>('UriMain'),
|
|
2351
|
+
MCP_SERVER_DEFINITION_REGISTRY_MAIN: createProxyIdentifier<McpServerDefinitionRegistryMain>('McpServerDefinitionRegistryMain')
|
|
2350
2352
|
};
|
|
2351
2353
|
|
|
2352
2354
|
export const MAIN_RPC_CONTEXT = {
|
|
@@ -2389,7 +2391,8 @@ export const MAIN_RPC_CONTEXT = {
|
|
|
2389
2391
|
TABS_EXT: createProxyIdentifier<TabsExt>('TabsExt'),
|
|
2390
2392
|
TELEMETRY_EXT: createProxyIdentifier<TelemetryExt>('TelemetryExt)'),
|
|
2391
2393
|
TESTING_EXT: createProxyIdentifier<TestingExt>('TestingExt'),
|
|
2392
|
-
URI_EXT: createProxyIdentifier<UriExt>('UriExt')
|
|
2394
|
+
URI_EXT: createProxyIdentifier<UriExt>('UriExt'),
|
|
2395
|
+
MCP_SERVER_DEFINITION_REGISTRY_EXT: createProxyIdentifier<McpServerDefinitionRegistryExt>('McpServerDefinitionRegistryExt')
|
|
2393
2396
|
};
|
|
2394
2397
|
|
|
2395
2398
|
export interface TasksExt {
|
|
@@ -104,6 +104,7 @@ export interface PluginPackageContribution {
|
|
|
104
104
|
notebooks?: PluginPackageNotebook[];
|
|
105
105
|
notebookRenderer?: PluginNotebookRendererContribution[];
|
|
106
106
|
notebookPreload?: PluginPackageNotebookPreload[];
|
|
107
|
+
mcpServerDefinitionProviders?: PluginPackageMcpServerDefinitionProviderContribution[];
|
|
107
108
|
}
|
|
108
109
|
|
|
109
110
|
export interface PluginPackageNotebook {
|
|
@@ -126,6 +127,12 @@ export interface PluginPackageNotebookPreload {
|
|
|
126
127
|
entrypoint: string;
|
|
127
128
|
}
|
|
128
129
|
|
|
130
|
+
export interface PluginPackageMcpServerDefinitionProviderContribution {
|
|
131
|
+
id: string;
|
|
132
|
+
label: string;
|
|
133
|
+
description?: string;
|
|
134
|
+
}
|
|
135
|
+
|
|
129
136
|
export interface PluginPackageAuthenticationProvider {
|
|
130
137
|
id: string;
|
|
131
138
|
label: string;
|
|
@@ -36,6 +36,7 @@ import { WebviewsExtImpl } from '../../plugin/webviews';
|
|
|
36
36
|
import { TerminalServiceExtImpl } from '../../plugin/terminal-ext';
|
|
37
37
|
import { InternalSecretsExt, SecretsExtImpl } from '../../plugin/secrets-ext';
|
|
38
38
|
import { setupPluginHostLogger } from './plugin-host-logger';
|
|
39
|
+
import { LmExtImpl } from '../../plugin/lm-ext';
|
|
39
40
|
|
|
40
41
|
export default new ContainerModule(bind => {
|
|
41
42
|
const channel = new IPCChannel();
|
|
@@ -63,6 +64,7 @@ export default new ContainerModule(bind => {
|
|
|
63
64
|
bind(SecretsExtImpl).toSelf().inSingletonScope();
|
|
64
65
|
bind(PreferenceRegistryExtImpl).toSelf().inSingletonScope();
|
|
65
66
|
bind(DebugExtImpl).toSelf().inSingletonScope();
|
|
67
|
+
bind(LmExtImpl).toSelf().inSingletonScope();
|
|
66
68
|
bind(EditorsAndDocumentsExtImpl).toSelf().inSingletonScope();
|
|
67
69
|
bind(WorkspaceExtImpl).toSelf().inSingletonScope();
|
|
68
70
|
bind(MessageRegistryExt).toSelf().inSingletonScope();
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2025 EclipseSource
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { interfaces } from '@theia/core/shared/inversify';
|
|
18
|
+
import { RPCProtocol } from '../../common/rpc-protocol';
|
|
19
|
+
import {
|
|
20
|
+
McpServerDefinitionRegistryMain,
|
|
21
|
+
McpServerDefinitionRegistryExt,
|
|
22
|
+
McpServerDefinitionDto,
|
|
23
|
+
isMcpHttpServerDefinitionDto,
|
|
24
|
+
} from '../../common/lm-protocol';
|
|
25
|
+
import { MAIN_RPC_CONTEXT } from '../../common/plugin-api-rpc';
|
|
26
|
+
import { MCPServerManager, MCPServerDescription } from '@theia/ai-mcp/lib/common';
|
|
27
|
+
|
|
28
|
+
export class McpServerDefinitionRegistryMainImpl implements McpServerDefinitionRegistryMain {
|
|
29
|
+
private readonly proxy: McpServerDefinitionRegistryExt;
|
|
30
|
+
private readonly providers = new Map<number, string>();
|
|
31
|
+
private readonly mcpServerManager: MCPServerManager | undefined;
|
|
32
|
+
|
|
33
|
+
constructor(
|
|
34
|
+
rpc: RPCProtocol,
|
|
35
|
+
container: interfaces.Container
|
|
36
|
+
) {
|
|
37
|
+
this.proxy = rpc.getProxy(MAIN_RPC_CONTEXT.MCP_SERVER_DEFINITION_REGISTRY_EXT);
|
|
38
|
+
try {
|
|
39
|
+
this.mcpServerManager = container.get(MCPServerManager);
|
|
40
|
+
} catch {
|
|
41
|
+
// MCP Server Manager is optional
|
|
42
|
+
this.mcpServerManager = undefined;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
$registerMcpServerDefinitionProvider(handle: number, name: string): void {
|
|
47
|
+
this.providers.set(handle, name);
|
|
48
|
+
this.loadServerDefinitions(handle);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
$unregisterMcpServerDefinitionProvider(handle: number): void {
|
|
52
|
+
if (!this.mcpServerManager) {
|
|
53
|
+
console.warn('MCP Server Manager not available - MCP server definitions will not be loaded');
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const provider = this.providers.get(handle);
|
|
57
|
+
if (!provider) {
|
|
58
|
+
console.warn(`No MCP Server provider found for handle '${handle}' - MCP server definitions will not be loaded`);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
this.mcpServerManager.removeServer(provider);
|
|
62
|
+
this.providers.delete(handle);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
$onDidChangeMcpServerDefinitions(handle: number): void {
|
|
66
|
+
// Reload server definitions when provider reports changes
|
|
67
|
+
this.loadServerDefinitions(handle);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async $getServerDefinitions(handle: number): Promise<McpServerDefinitionDto[]> {
|
|
71
|
+
try {
|
|
72
|
+
return await this.proxy.$provideServerDefinitions(handle);
|
|
73
|
+
} catch (error) {
|
|
74
|
+
console.error('Error getting MCP server definitions:', error);
|
|
75
|
+
return [];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async $resolveServerDefinition(handle: number, server: McpServerDefinitionDto): Promise<McpServerDefinitionDto | undefined> {
|
|
80
|
+
try {
|
|
81
|
+
return await this.proxy.$resolveServerDefinition(handle, server);
|
|
82
|
+
} catch (error) {
|
|
83
|
+
console.error('Error resolving MCP server definition:', error);
|
|
84
|
+
return server;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private async loadServerDefinitions(handle: number): Promise<void> {
|
|
89
|
+
if (!this.mcpServerManager) {
|
|
90
|
+
console.warn('MCP Server Manager not available - MCP server definitions will not be loaded');
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
const definitions = await this.$getServerDefinitions(handle);
|
|
96
|
+
|
|
97
|
+
for (const definition of definitions) {
|
|
98
|
+
const resolved = await this.$resolveServerDefinition(handle, definition);
|
|
99
|
+
if (resolved) {
|
|
100
|
+
const mcpServerDescription = this.convertToMcpServerDescription(resolved);
|
|
101
|
+
this.mcpServerManager.addOrUpdateServer(mcpServerDescription);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
} catch (error) {
|
|
105
|
+
console.error('Error loading MCP server definitions:', error);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
private convertToMcpServerDescription(definition: McpServerDefinitionDto): MCPServerDescription {
|
|
110
|
+
if (isMcpHttpServerDefinitionDto(definition)) {
|
|
111
|
+
// For HTTP servers, we would need to create a bridge or adapter
|
|
112
|
+
// For now, we'll create a placeholder stdio server that could proxy to HTTP
|
|
113
|
+
console.warn(`HTTP transport not yet supported for MCP server '${definition.label}'. Skipping.`);
|
|
114
|
+
throw new Error(`HTTP transport not yet supported for MCP server '${definition.label}'`);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Convert env values to strings, filtering out null values
|
|
118
|
+
let convertedEnv: Record<string, string> | undefined;
|
|
119
|
+
if (definition.env) {
|
|
120
|
+
convertedEnv = {};
|
|
121
|
+
for (const [key, value] of Object.entries(definition.env)) {
|
|
122
|
+
if (value !== null) {
|
|
123
|
+
convertedEnv[key] = String(value);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
name: definition.label,
|
|
130
|
+
command: definition.command!,
|
|
131
|
+
args: definition.args,
|
|
132
|
+
env: convertedEnv,
|
|
133
|
+
autostart: false, // Extensions should manage their own server lifecycle
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
}
|
|
@@ -67,6 +67,7 @@ import { TestingMainImpl } from './test-main';
|
|
|
67
67
|
import { UriMainImpl } from './uri-main';
|
|
68
68
|
import { LoggerMainImpl } from './logger-main';
|
|
69
69
|
import { MonacoEditorProvider } from '@theia/monaco/lib/browser/monaco-editor-provider';
|
|
70
|
+
import { McpServerDefinitionRegistryMainImpl } from './lm-main';
|
|
70
71
|
|
|
71
72
|
export function setUpPluginApi(rpc: RPCProtocol, container: interfaces.Container): void {
|
|
72
73
|
const loggerMain = new LoggerMainImpl(container);
|
|
@@ -213,4 +214,7 @@ export function setUpPluginApi(rpc: RPCProtocol, container: interfaces.Container
|
|
|
213
214
|
|
|
214
215
|
const uriMain = new UriMainImpl(rpc, container);
|
|
215
216
|
rpc.set(PLUGIN_RPC_CONTEXT.URI_MAIN, uriMain);
|
|
217
|
+
|
|
218
|
+
const mcpServerDefinitionRegistryMain = new McpServerDefinitionRegistryMainImpl(rpc, container);
|
|
219
|
+
rpc.set(PLUGIN_RPC_CONTEXT.MCP_SERVER_DEFINITION_REGISTRY_MAIN, mcpServerDefinitionRegistryMain);
|
|
216
220
|
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2025 EclipseSource.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import type * as theia from '@theia/plugin';
|
|
18
|
+
import { Disposable } from '@theia/core/lib/common/disposable';
|
|
19
|
+
import { RPCProtocol } from '../common/rpc-protocol';
|
|
20
|
+
import {
|
|
21
|
+
McpServerDefinitionRegistryExt,
|
|
22
|
+
McpServerDefinitionRegistryMain,
|
|
23
|
+
McpServerDefinitionDto,
|
|
24
|
+
isMcpHttpServerDefinitionDto,
|
|
25
|
+
} from '../common/lm-protocol';
|
|
26
|
+
import { PLUGIN_RPC_CONTEXT } from '../common/plugin-api-rpc';
|
|
27
|
+
import { PluginPackageMcpServerDefinitionProviderContribution } from '../common';
|
|
28
|
+
import { PluginLogger } from './logger';
|
|
29
|
+
import { McpHttpServerDefinition, McpServerDefinition, URI } from './types-impl';
|
|
30
|
+
|
|
31
|
+
// Local interfaces that match the proposed MCP API
|
|
32
|
+
interface McpServerDefinitionProvider {
|
|
33
|
+
readonly onDidChangeMcpServerDefinitions?: theia.Event<void>;
|
|
34
|
+
provideMcpServerDefinitions(): theia.ProviderResult<McpServerDefinition[]>;
|
|
35
|
+
resolveMcpServerDefinition?(server: McpServerDefinition): theia.ProviderResult<McpServerDefinition>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export class LmExtImpl implements McpServerDefinitionRegistryExt {
|
|
39
|
+
|
|
40
|
+
private proxy: McpServerDefinitionRegistryMain;
|
|
41
|
+
private logger: PluginLogger;
|
|
42
|
+
private readonly providers = new Map<number, McpServerDefinitionProvider>();
|
|
43
|
+
private readonly providerChangeListeners = new Map<number, Disposable>();
|
|
44
|
+
private handleCounter = 0;
|
|
45
|
+
private announcedMCPProviders: string[] = [];
|
|
46
|
+
|
|
47
|
+
constructor(protected readonly rpc: RPCProtocol) {
|
|
48
|
+
this.proxy = this.rpc.getProxy(PLUGIN_RPC_CONTEXT.MCP_SERVER_DEFINITION_REGISTRY_MAIN);
|
|
49
|
+
this.logger = new PluginLogger(this.rpc, 'lm');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
registerMcpServerDefinitionProvider(id: string, provider: McpServerDefinitionProvider): theia.Disposable {
|
|
53
|
+
if (this.announcedMCPProviders.indexOf(id) === -1) {
|
|
54
|
+
this.logger.warn(`An unknown McpProvider tried to register, please check the package.json: ${id}`);
|
|
55
|
+
}
|
|
56
|
+
const handle = this.handleCounter++;
|
|
57
|
+
this.providers.set(handle, provider);
|
|
58
|
+
|
|
59
|
+
this.proxy.$registerMcpServerDefinitionProvider(handle, id);
|
|
60
|
+
|
|
61
|
+
if (provider.onDidChangeMcpServerDefinitions) {
|
|
62
|
+
const changeListener = provider.onDidChangeMcpServerDefinitions(() => {
|
|
63
|
+
this.proxy.$onDidChangeMcpServerDefinitions(handle);
|
|
64
|
+
});
|
|
65
|
+
this.providerChangeListeners.set(handle, changeListener);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return Disposable.create(() => {
|
|
69
|
+
this.providers.delete(handle);
|
|
70
|
+
const changeListener = this.providerChangeListeners.get(handle);
|
|
71
|
+
if (changeListener) {
|
|
72
|
+
changeListener.dispose();
|
|
73
|
+
this.providerChangeListeners.delete(handle);
|
|
74
|
+
}
|
|
75
|
+
this.proxy.$unregisterMcpServerDefinitionProvider(handle);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async $provideServerDefinitions(handle: number): Promise<McpServerDefinitionDto[]> {
|
|
80
|
+
const provider = this.providers.get(handle);
|
|
81
|
+
if (!provider) {
|
|
82
|
+
return [];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
const definitions = await provider.provideMcpServerDefinitions();
|
|
87
|
+
if (!definitions) {
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return definitions.map(def => this.convertToDto(def));
|
|
92
|
+
} catch (error) {
|
|
93
|
+
this.logger.error('Error providing MCP server definitions:', error);
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async $resolveServerDefinition(handle: number, server: McpServerDefinitionDto): Promise<McpServerDefinitionDto | undefined> {
|
|
99
|
+
const provider = this.providers.get(handle);
|
|
100
|
+
if (!provider || !provider.resolveMcpServerDefinition) {
|
|
101
|
+
return server;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
try {
|
|
105
|
+
const definition = this.convertFromDto(server);
|
|
106
|
+
const resolved = await provider.resolveMcpServerDefinition(definition);
|
|
107
|
+
return resolved ? this.convertToDto(resolved) : undefined;
|
|
108
|
+
} catch (error) {
|
|
109
|
+
this.logger.error('Error resolving MCP server definition:', error);
|
|
110
|
+
return server;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
private convertToDto(definition: McpServerDefinition): McpServerDefinitionDto {
|
|
115
|
+
if (isMcpHttpServerDefinition(definition)) {
|
|
116
|
+
return {
|
|
117
|
+
label: definition.label,
|
|
118
|
+
headers: definition.headers,
|
|
119
|
+
uri: definition.uri,
|
|
120
|
+
version: definition.version
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
command: definition.command,
|
|
125
|
+
args: definition.args,
|
|
126
|
+
cwd: definition.cwd,
|
|
127
|
+
version: definition.version,
|
|
128
|
+
label: definition.label,
|
|
129
|
+
env: definition.env
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
private convertFromDto(dto: McpServerDefinitionDto): McpServerDefinition {
|
|
134
|
+
if (isMcpHttpServerDefinitionDto(dto)) {
|
|
135
|
+
return {
|
|
136
|
+
label: dto.label,
|
|
137
|
+
headers: dto.headers,
|
|
138
|
+
uri: URI.revive(dto.uri),
|
|
139
|
+
version: dto.version
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
command: dto.command,
|
|
144
|
+
args: dto.args,
|
|
145
|
+
cwd: URI.revive(dto.cwd),
|
|
146
|
+
version: dto.version,
|
|
147
|
+
label: dto.label,
|
|
148
|
+
env: dto.env
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
registerMcpContributions(mcpContributions: PluginPackageMcpServerDefinitionProviderContribution[]): void {
|
|
153
|
+
this.announcedMCPProviders = mcpContributions.map(contribution => contribution.id);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const isMcpHttpServerDefinition = (definition: McpServerDefinition): definition is McpHttpServerDefinition => 'uri' in definition;
|
|
158
|
+
|
|
@@ -238,7 +238,9 @@ import {
|
|
|
238
238
|
DebugVisualization,
|
|
239
239
|
TerminalShellExecutionCommandLineConfidence,
|
|
240
240
|
TerminalCompletionItemKind,
|
|
241
|
-
TerminalCompletionList
|
|
241
|
+
TerminalCompletionList,
|
|
242
|
+
McpHttpServerDefinition,
|
|
243
|
+
McpStdioServerDefinition
|
|
242
244
|
} from './types-impl';
|
|
243
245
|
import { AuthenticationExtImpl } from './authentication-ext';
|
|
244
246
|
import { SymbolKind } from '../common/plugin-api-rpc-model';
|
|
@@ -287,6 +289,7 @@ import { NotebookEditorsExtImpl } from './notebook/notebook-editors';
|
|
|
287
289
|
import { TestingExtImpl } from './tests';
|
|
288
290
|
import { UriExtImpl } from './uri-ext';
|
|
289
291
|
import { PluginLogger } from './logger';
|
|
292
|
+
import { LmExtImpl } from './lm-ext';
|
|
290
293
|
|
|
291
294
|
export function createAPIObject<T extends Object>(rawObject: T): T {
|
|
292
295
|
return new Proxy(rawObject, {
|
|
@@ -351,6 +354,7 @@ export function createAPIFactory(
|
|
|
351
354
|
const telemetryExt = rpc.set(MAIN_RPC_CONTEXT.TELEMETRY_EXT, new TelemetryExtImpl());
|
|
352
355
|
const testingExt = rpc.set(MAIN_RPC_CONTEXT.TESTING_EXT, new TestingExtImpl(rpc, commandRegistry));
|
|
353
356
|
const uriExt = rpc.set(MAIN_RPC_CONTEXT.URI_EXT, new UriExtImpl(rpc));
|
|
357
|
+
const lmExt = rpc.set(MAIN_RPC_CONTEXT.MCP_SERVER_DEFINITION_REGISTRY_EXT, new LmExtImpl(rpc));
|
|
354
358
|
rpc.set(MAIN_RPC_CONTEXT.DEBUG_EXT, debugExt);
|
|
355
359
|
|
|
356
360
|
const commandLogger = new PluginLogger(rpc, 'commands-plugin');
|
|
@@ -1342,6 +1346,9 @@ export function createAPIFactory(
|
|
|
1342
1346
|
}
|
|
1343
1347
|
};
|
|
1344
1348
|
|
|
1349
|
+
const mcpContributions = plugin.rawModel.contributes && plugin.rawModel.contributes.mcpServerDefinitionProviders || [];
|
|
1350
|
+
lmExt.registerMcpContributions(mcpContributions);
|
|
1351
|
+
|
|
1345
1352
|
const lm: typeof theia.lm = {
|
|
1346
1353
|
/** @stubbed LanguageModelChat */
|
|
1347
1354
|
selectChatModels(selector?: theia.LanguageModelChatSelector): Thenable<theia.LanguageModelChat[]> {
|
|
@@ -1358,7 +1365,10 @@ export function createAPIFactory(
|
|
|
1358
1365
|
return Disposable.NULL;
|
|
1359
1366
|
},
|
|
1360
1367
|
/** @stubbed LanguageModelTool */
|
|
1361
|
-
tools: []
|
|
1368
|
+
tools: [],
|
|
1369
|
+
registerMcpServerDefinitionProvider(id: string, provider: any): theia.Disposable {
|
|
1370
|
+
return lmExt.registerMcpServerDefinitionProvider(id, provider);
|
|
1371
|
+
}
|
|
1362
1372
|
};
|
|
1363
1373
|
|
|
1364
1374
|
return <typeof theia>{
|
|
@@ -1589,7 +1599,9 @@ export function createAPIFactory(
|
|
|
1589
1599
|
DebugVisualization,
|
|
1590
1600
|
TerminalShellExecutionCommandLineConfidence,
|
|
1591
1601
|
TerminalCompletionItemKind,
|
|
1592
|
-
TerminalCompletionList
|
|
1602
|
+
TerminalCompletionList,
|
|
1603
|
+
McpHttpServerDefinition,
|
|
1604
|
+
McpStdioServerDefinition
|
|
1593
1605
|
};
|
|
1594
1606
|
};
|
|
1595
1607
|
}
|
package/src/plugin/types-impl.ts
CHANGED
|
@@ -4135,3 +4135,107 @@ export enum TerminalShellExecutionCommandLineConfidence {
|
|
|
4135
4135
|
}
|
|
4136
4136
|
|
|
4137
4137
|
// #endregion
|
|
4138
|
+
|
|
4139
|
+
/**
|
|
4140
|
+
* McpStdioServerDefinition represents an MCP server available by running
|
|
4141
|
+
* a local process and operating on its stdin and stdout streams. The process
|
|
4142
|
+
* will be spawned as a child process of the extension host and by default
|
|
4143
|
+
* will not run in a shell environment.
|
|
4144
|
+
*/
|
|
4145
|
+
export class McpStdioServerDefinition {
|
|
4146
|
+
/**
|
|
4147
|
+
* The human-readable name of the server.
|
|
4148
|
+
*/
|
|
4149
|
+
readonly label: string;
|
|
4150
|
+
|
|
4151
|
+
/**
|
|
4152
|
+
* The working directory used to start the server.
|
|
4153
|
+
*/
|
|
4154
|
+
cwd?: URI;
|
|
4155
|
+
|
|
4156
|
+
/**
|
|
4157
|
+
* The command used to start the server. Node.js-based servers may use
|
|
4158
|
+
* `process.execPath` to use the editor's version of Node.js to run the script.
|
|
4159
|
+
*/
|
|
4160
|
+
command: string;
|
|
4161
|
+
|
|
4162
|
+
/**
|
|
4163
|
+
* Additional command-line arguments passed to the server.
|
|
4164
|
+
*/
|
|
4165
|
+
args?: string[];
|
|
4166
|
+
|
|
4167
|
+
/**
|
|
4168
|
+
* Optional additional environment information for the server. Variables
|
|
4169
|
+
* in this environment will overwrite or remove (if null) the default
|
|
4170
|
+
* environment variables of the editor's extension host.
|
|
4171
|
+
*/
|
|
4172
|
+
env?: Record<string, string | number | null>;
|
|
4173
|
+
|
|
4174
|
+
/**
|
|
4175
|
+
* Optional version identification for the server. If this changes, the
|
|
4176
|
+
* editor will indicate that tools have changed and prompt to refresh them.
|
|
4177
|
+
*/
|
|
4178
|
+
version?: string;
|
|
4179
|
+
|
|
4180
|
+
/**
|
|
4181
|
+
* @param label The human-readable name of the server.
|
|
4182
|
+
* @param command The command used to start the server.
|
|
4183
|
+
* @param args Additional command-line arguments passed to the server.
|
|
4184
|
+
* @param env Optional additional environment information for the server.
|
|
4185
|
+
* @param version Optional version identification for the server.
|
|
4186
|
+
*/
|
|
4187
|
+
constructor(label: string, command: string, args?: string[], env?: Record<string, string | number | null>, version?: string) {
|
|
4188
|
+
this.label = label;
|
|
4189
|
+
this.command = command;
|
|
4190
|
+
this.args = args;
|
|
4191
|
+
this.env = env;
|
|
4192
|
+
this.version = version;
|
|
4193
|
+
}
|
|
4194
|
+
}
|
|
4195
|
+
|
|
4196
|
+
/**
|
|
4197
|
+
* McpHttpServerDefinition represents an MCP server available using the
|
|
4198
|
+
* Streamable HTTP transport.
|
|
4199
|
+
*/
|
|
4200
|
+
export class McpHttpServerDefinition {
|
|
4201
|
+
/**
|
|
4202
|
+
* The human-readable name of the server.
|
|
4203
|
+
*/
|
|
4204
|
+
readonly label: string;
|
|
4205
|
+
|
|
4206
|
+
/**
|
|
4207
|
+
* The URI of the server. The editor will make a POST request to this URI
|
|
4208
|
+
* to begin each session.
|
|
4209
|
+
*/
|
|
4210
|
+
uri: URI;
|
|
4211
|
+
|
|
4212
|
+
/**
|
|
4213
|
+
* Optional additional heads included with each request to the server.
|
|
4214
|
+
*/
|
|
4215
|
+
headers?: Record<string, string>;
|
|
4216
|
+
|
|
4217
|
+
/**
|
|
4218
|
+
* Optional version identification for the server. If this changes, the
|
|
4219
|
+
* editor will indicate that tools have changed and prompt to refresh them.
|
|
4220
|
+
*/
|
|
4221
|
+
version?: string;
|
|
4222
|
+
|
|
4223
|
+
/**
|
|
4224
|
+
* @param label The human-readable name of the server.
|
|
4225
|
+
* @param uri The URI of the server.
|
|
4226
|
+
* @param headers Optional additional heads included with each request to the server.
|
|
4227
|
+
*/
|
|
4228
|
+
constructor(label: string, uri: URI, headers?: Record<string, string>, version?: string) {
|
|
4229
|
+
this.label = label;
|
|
4230
|
+
this.uri = uri;
|
|
4231
|
+
this.headers = headers;
|
|
4232
|
+
this.version = version;
|
|
4233
|
+
};
|
|
4234
|
+
}
|
|
4235
|
+
|
|
4236
|
+
/**
|
|
4237
|
+
* Definitions that describe different types of Model Context Protocol servers,
|
|
4238
|
+
* which can be returned from the {@link McpServerDefinitionProvider}.
|
|
4239
|
+
*/
|
|
4240
|
+
export type McpServerDefinition = McpStdioServerDefinition | McpHttpServerDefinition;
|
|
4241
|
+
|