@theia/ai-mcp 1.57.0-next.112
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/README.md +91 -0
- package/lib/browser/mcp-command-contribution.d.ts +21 -0
- package/lib/browser/mcp-command-contribution.d.ts.map +1 -0
- package/lib/browser/mcp-command-contribution.js +114 -0
- package/lib/browser/mcp-command-contribution.js.map +1 -0
- package/lib/browser/mcp-frontend-application-contribution.d.ts +30 -0
- package/lib/browser/mcp-frontend-application-contribution.d.ts.map +1 -0
- package/lib/browser/mcp-frontend-application-contribution.js +145 -0
- package/lib/browser/mcp-frontend-application-contribution.js.map +1 -0
- package/lib/browser/mcp-frontend-module.d.ts +4 -0
- package/lib/browser/mcp-frontend-module.d.ts.map +1 -0
- package/lib/browser/mcp-frontend-module.js +36 -0
- package/lib/browser/mcp-frontend-module.js.map +1 -0
- package/lib/browser/mcp-frontend-service.d.ts +15 -0
- package/lib/browser/mcp-frontend-service.d.ts.map +1 -0
- package/lib/browser/mcp-frontend-service.js +88 -0
- package/lib/browser/mcp-frontend-service.js.map +1 -0
- package/lib/browser/mcp-preferences.d.ts +4 -0
- package/lib/browser/mcp-preferences.d.ts.map +1 -0
- package/lib/browser/mcp-preferences.js +90 -0
- package/lib/browser/mcp-preferences.js.map +1 -0
- package/lib/common/index.d.ts +2 -0
- package/lib/common/index.d.ts.map +1 -0
- package/lib/common/index.js +20 -0
- package/lib/common/index.js.map +1 -0
- package/lib/common/mcp-server-manager.d.ts +42 -0
- package/lib/common/mcp-server-manager.d.ts.map +1 -0
- package/lib/common/mcp-server-manager.js +21 -0
- package/lib/common/mcp-server-manager.js.map +1 -0
- package/lib/node/mcp-backend-module.d.ts +4 -0
- package/lib/node/mcp-backend-module.d.ts.map +1 -0
- package/lib/node/mcp-backend-module.js +34 -0
- package/lib/node/mcp-backend-module.js.map +1 -0
- package/lib/node/mcp-server-manager-impl.d.ts +14 -0
- package/lib/node/mcp-server-manager-impl.d.ts.map +1 -0
- package/lib/node/mcp-server-manager-impl.js +93 -0
- package/lib/node/mcp-server-manager-impl.js.map +1 -0
- package/lib/node/mcp-server.d.ts +19 -0
- package/lib/node/mcp-server.d.ts.map +1 -0
- package/lib/node/mcp-server.js +97 -0
- package/lib/node/mcp-server.js.map +1 -0
- package/lib/package.spec.d.ts +1 -0
- package/lib/package.spec.d.ts.map +1 -0
- package/lib/package.spec.js +26 -0
- package/lib/package.spec.js.map +1 -0
- package/package.json +50 -0
- package/src/browser/mcp-command-contribution.ts +106 -0
- package/src/browser/mcp-frontend-application-contribution.ts +158 -0
- package/src/browser/mcp-frontend-module.ts +35 -0
- package/src/browser/mcp-frontend-service.ts +87 -0
- package/src/browser/mcp-preferences.ts +90 -0
- package/src/common/index.ts +16 -0
- package/src/common/mcp-server-manager.ts +63 -0
- package/src/node/mcp-backend-module.ts +37 -0
- package/src/node/mcp-server-manager-impl.ts +93 -0
- package/src/node/mcp-server.ts +111 -0
- package/src/package.spec.ts +28 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
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
|
+
import { injectable } from '@theia/core/shared/inversify';
|
|
17
|
+
import { MCPServerDescription, MCPServerManager } from '../common/mcp-server-manager';
|
|
18
|
+
import { MCPServer } from './mcp-server';
|
|
19
|
+
|
|
20
|
+
@injectable()
|
|
21
|
+
export class MCPServerManagerImpl implements MCPServerManager {
|
|
22
|
+
|
|
23
|
+
protected servers: Map<string, MCPServer> = new Map();
|
|
24
|
+
|
|
25
|
+
async stopServer(serverName: string): Promise<void> {
|
|
26
|
+
const server = this.servers.get(serverName);
|
|
27
|
+
if (!server) {
|
|
28
|
+
throw new Error(`MCP server "${serverName}" not found.`);
|
|
29
|
+
}
|
|
30
|
+
server.stop();
|
|
31
|
+
console.log(`MCP server "${serverName}" stopped.`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async getStartedServers(): Promise<string[]> {
|
|
35
|
+
const startedServers: string[] = [];
|
|
36
|
+
for (const [name, server] of this.servers.entries()) {
|
|
37
|
+
if (server.isStarted()) {
|
|
38
|
+
startedServers.push(name);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return startedServers;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
callTool(serverName: string, toolName: string, arg_string: string): ReturnType<MCPServer['callTool']> {
|
|
45
|
+
const server = this.servers.get(serverName);
|
|
46
|
+
if (!server) {
|
|
47
|
+
throw new Error(`MCP server "${toolName}" not found.`);
|
|
48
|
+
}
|
|
49
|
+
return server.callTool(toolName, arg_string);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async startServer(serverName: string): Promise<void> {
|
|
53
|
+
const server = this.servers.get(serverName);
|
|
54
|
+
if (!server) {
|
|
55
|
+
throw new Error(`MCP server "${serverName}" not found.`);
|
|
56
|
+
}
|
|
57
|
+
await server.start();
|
|
58
|
+
}
|
|
59
|
+
async getServerNames(): Promise<string[]> {
|
|
60
|
+
return Array.from(this.servers.keys());
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public async getTools(serverName: string): ReturnType<MCPServer['getTools']> {
|
|
64
|
+
const server = this.servers.get(serverName);
|
|
65
|
+
if (!server) {
|
|
66
|
+
throw new Error(`MCP server "${serverName}" not found.`);
|
|
67
|
+
}
|
|
68
|
+
return server.getTools();
|
|
69
|
+
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
addOrUpdateServer(description: MCPServerDescription): void {
|
|
73
|
+
const { name, command, args, env } = description;
|
|
74
|
+
const existingServer = this.servers.get(name);
|
|
75
|
+
|
|
76
|
+
if (existingServer) {
|
|
77
|
+
existingServer.update(command, args, env);
|
|
78
|
+
} else {
|
|
79
|
+
const newServer = new MCPServer(name, command, args, env);
|
|
80
|
+
this.servers.set(name, newServer);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
removeServer(name: string): void {
|
|
85
|
+
const server = this.servers.get(name);
|
|
86
|
+
if (server) {
|
|
87
|
+
server.stop();
|
|
88
|
+
this.servers.delete(name);
|
|
89
|
+
} else {
|
|
90
|
+
console.warn(`MCP server "${name}" not found.`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
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
|
+
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio';
|
|
17
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
18
|
+
|
|
19
|
+
export class MCPServer {
|
|
20
|
+
private name: string;
|
|
21
|
+
private command: string;
|
|
22
|
+
private args?: string[];
|
|
23
|
+
private client: Client;
|
|
24
|
+
private env?: { [key: string]: string };
|
|
25
|
+
private started: boolean = false;
|
|
26
|
+
|
|
27
|
+
constructor(name: string, command: string, args?: string[], env?: Record<string, string>) {
|
|
28
|
+
this.name = name;
|
|
29
|
+
this.command = command;
|
|
30
|
+
this.args = args;
|
|
31
|
+
this.env = env;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
isStarted(): boolean {
|
|
35
|
+
return this.started;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async start(): Promise<void> {
|
|
39
|
+
if (this.started) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
console.log(`Starting server "${this.name}" with command: ${this.command} and args: ${this.args?.join(' ')} and env: ${JSON.stringify(this.env)}`);
|
|
43
|
+
// Filter process.env to exclude undefined values
|
|
44
|
+
const sanitizedEnv: Record<string, string> = Object.fromEntries(
|
|
45
|
+
Object.entries(process.env).filter((entry): entry is [string, string] => entry[1] !== undefined)
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const mergedEnv: Record<string, string> = {
|
|
49
|
+
...sanitizedEnv,
|
|
50
|
+
...(this.env || {})
|
|
51
|
+
};
|
|
52
|
+
const transport = new StdioClientTransport({
|
|
53
|
+
command: this.command,
|
|
54
|
+
args: this.args,
|
|
55
|
+
env: mergedEnv,
|
|
56
|
+
});
|
|
57
|
+
transport.onerror = error => {
|
|
58
|
+
console.error('Error: ' + error);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
this.client = new Client({
|
|
62
|
+
name: 'theia-client',
|
|
63
|
+
version: '1.0.0',
|
|
64
|
+
}, {
|
|
65
|
+
capabilities: {}
|
|
66
|
+
});
|
|
67
|
+
this.client.onerror = error => {
|
|
68
|
+
console.error('Error in MCP client: ' + error);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
await this.client.connect(transport);
|
|
72
|
+
this.started = true;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async callTool(toolName: string, arg_string: string): ReturnType<Client['callTool']> {
|
|
76
|
+
let args;
|
|
77
|
+
try {
|
|
78
|
+
args = JSON.parse(arg_string);
|
|
79
|
+
} catch (error) {
|
|
80
|
+
console.error(
|
|
81
|
+
`Failed to parse arguments for calling tool "${toolName}" in MCP server "${this.name}" with command "${this.command}".
|
|
82
|
+
Invalid JSON: ${arg_string}`,
|
|
83
|
+
error
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
const params = {
|
|
87
|
+
name: toolName,
|
|
88
|
+
arguments: args,
|
|
89
|
+
};
|
|
90
|
+
return this.client.callTool(params);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async getTools(): ReturnType<Client['listTools']> {
|
|
94
|
+
return this.client.listTools();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
update(command: string, args?: string[], env?: { [key: string]: string }): void {
|
|
98
|
+
this.command = command;
|
|
99
|
+
this.args = args;
|
|
100
|
+
this.env = env;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
stop(): void {
|
|
104
|
+
if (!this.started || !this.client) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
console.log(`Stopping MCP server "${this.name}"`);
|
|
108
|
+
this.client.close();
|
|
109
|
+
this.started = false;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 EclipseSource GmbH and others.
|
|
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
|
+
/* note: this bogus test file is required so that
|
|
18
|
+
we are able to run mocha unit tests on this
|
|
19
|
+
package, without having any actual unit tests in it.
|
|
20
|
+
This way a coverage report will be generated,
|
|
21
|
+
showing 0% coverage, instead of no report.
|
|
22
|
+
This file can be removed once we have real unit
|
|
23
|
+
tests in place. */
|
|
24
|
+
|
|
25
|
+
describe('ai-mcp package', () => {
|
|
26
|
+
|
|
27
|
+
it('support code coverage statistics', () => true);
|
|
28
|
+
});
|