@robota-sdk/agent-transport-mcp 3.0.0-beta.43
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/LICENSE +21 -0
- package/README.md +50 -0
- package/dist/node/index.cjs +130 -0
- package/dist/node/index.d.cts +42 -0
- package/dist/node/index.d.ts +42 -0
- package/dist/node/index.js +103 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Robota Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# @robota-sdk/agent-transport-mcp
|
|
2
|
+
|
|
3
|
+
MCP transport adapter for exposing `InteractiveSession` as a Model Context Protocol server. Allows MCP-compatible clients (Claude, other agents) to interact with a Robota agent via the standard MCP tool protocol.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @robota-sdk/agent-transport-mcp
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { createAgentMcpServer } from '@robota-sdk/agent-transport-mcp';
|
|
15
|
+
import { InteractiveSession, SystemCommandExecutor } from '@robota-sdk/agent-sdk';
|
|
16
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
17
|
+
|
|
18
|
+
const mcpServer = createAgentMcpServer({
|
|
19
|
+
name: 'robota-agent',
|
|
20
|
+
version: '1.0.0',
|
|
21
|
+
session: interactiveSession,
|
|
22
|
+
commandExecutor,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Connect via stdio (subprocess / Claude Desktop)
|
|
26
|
+
await mcpServer.connect(new StdioServerTransport());
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## MCP Tools
|
|
30
|
+
|
|
31
|
+
Each tool maps directly to an `InteractiveSession` operation or a system command.
|
|
32
|
+
|
|
33
|
+
| Tool Name | Input | Description |
|
|
34
|
+
| ----------------- | -------------------- | --------------------------------------- |
|
|
35
|
+
| `submit` | `{ prompt: string }` | Submit a prompt, wait for full response |
|
|
36
|
+
| `command_help` | `{ args?: string }` | Show available commands |
|
|
37
|
+
| `command_clear` | `{ args?: string }` | Clear conversation history |
|
|
38
|
+
| `command_compact` | `{ args?: string }` | Compress the context window |
|
|
39
|
+
| `command_mode` | `{ args?: string }` | Show or change permission mode |
|
|
40
|
+
| `command_model` | `{ args?: string }` | Change the active AI model |
|
|
41
|
+
| `command_context` | `{ args?: string }` | Show context window info |
|
|
42
|
+
| ... | ... | One tool per registered system command |
|
|
43
|
+
|
|
44
|
+
The `submit` tool waits for the session to reach `complete` or `interrupted` state before returning, so MCP clients receive a single text response rather than a stream.
|
|
45
|
+
|
|
46
|
+
## Dependencies
|
|
47
|
+
|
|
48
|
+
- `@robota-sdk/agent-sdk` — `InteractiveSession`, `SystemCommandExecutor`
|
|
49
|
+
- `@modelcontextprotocol/sdk` — MCP server implementation
|
|
50
|
+
- `zod` — input schema definitions
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
createAgentMcpServer: () => createAgentMcpServer
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
|
|
27
|
+
// src/mcp-server.ts
|
|
28
|
+
var import_server = require("@modelcontextprotocol/sdk/server/index.js");
|
|
29
|
+
var import_types = require("@modelcontextprotocol/sdk/types.js");
|
|
30
|
+
function createAgentMcpServer(options) {
|
|
31
|
+
const { name, version, session, commandExecutor, exposeCommands = true } = options;
|
|
32
|
+
const server = new import_server.Server({ name, version }, { capabilities: { tools: {} } });
|
|
33
|
+
const tools = [
|
|
34
|
+
{
|
|
35
|
+
name: "submit",
|
|
36
|
+
description: "Submit a prompt to the AI agent and wait for the response",
|
|
37
|
+
inputSchema: {
|
|
38
|
+
type: "object",
|
|
39
|
+
properties: {
|
|
40
|
+
prompt: { type: "string", description: "The prompt to send to the agent" }
|
|
41
|
+
},
|
|
42
|
+
required: ["prompt"]
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
];
|
|
46
|
+
if (exposeCommands) {
|
|
47
|
+
for (const cmd of commandExecutor.listCommands()) {
|
|
48
|
+
tools.push({
|
|
49
|
+
name: `command_${cmd.name}`,
|
|
50
|
+
description: cmd.description,
|
|
51
|
+
inputSchema: {
|
|
52
|
+
type: "object",
|
|
53
|
+
properties: {
|
|
54
|
+
args: { type: "string", description: "Command arguments" }
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
server.setRequestHandler(import_types.ListToolsRequestSchema, async () => ({
|
|
61
|
+
tools
|
|
62
|
+
}));
|
|
63
|
+
server.setRequestHandler(import_types.CallToolRequestSchema, async (request) => {
|
|
64
|
+
const { name: toolName, arguments: toolArgs } = request.params;
|
|
65
|
+
if (toolName === "submit") {
|
|
66
|
+
const prompt = toolArgs?.prompt;
|
|
67
|
+
if (!prompt) {
|
|
68
|
+
return {
|
|
69
|
+
content: [{ type: "text", text: "Error: prompt is required" }],
|
|
70
|
+
isError: true
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
const result = await waitForCompletion(session, prompt);
|
|
74
|
+
return {
|
|
75
|
+
content: [{ type: "text", text: result.response }]
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
if (toolName.startsWith("command_")) {
|
|
79
|
+
const cmdName = toolName.slice("command_".length);
|
|
80
|
+
const args = toolArgs?.args ?? "";
|
|
81
|
+
const result = await commandExecutor.execute(cmdName, session, args);
|
|
82
|
+
return {
|
|
83
|
+
content: [
|
|
84
|
+
{
|
|
85
|
+
type: "text",
|
|
86
|
+
text: result?.message ?? `Unknown command: ${cmdName}`
|
|
87
|
+
}
|
|
88
|
+
],
|
|
89
|
+
isError: !result
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
content: [{ type: "text", text: `Unknown tool: ${toolName}` }],
|
|
94
|
+
isError: true
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
return server;
|
|
98
|
+
}
|
|
99
|
+
function waitForCompletion(session, prompt) {
|
|
100
|
+
return new Promise((resolve, reject) => {
|
|
101
|
+
const onComplete = (result) => {
|
|
102
|
+
cleanup();
|
|
103
|
+
resolve(result);
|
|
104
|
+
};
|
|
105
|
+
const onInterrupted = (result) => {
|
|
106
|
+
cleanup();
|
|
107
|
+
resolve(result);
|
|
108
|
+
};
|
|
109
|
+
const onError = (error) => {
|
|
110
|
+
cleanup();
|
|
111
|
+
reject(error);
|
|
112
|
+
};
|
|
113
|
+
const cleanup = () => {
|
|
114
|
+
session.off("complete", onComplete);
|
|
115
|
+
session.off("interrupted", onInterrupted);
|
|
116
|
+
session.off("error", onError);
|
|
117
|
+
};
|
|
118
|
+
session.on("complete", onComplete);
|
|
119
|
+
session.on("interrupted", onInterrupted);
|
|
120
|
+
session.on("error", onError);
|
|
121
|
+
session.submit(prompt).catch((err) => {
|
|
122
|
+
cleanup();
|
|
123
|
+
reject(err instanceof Error ? err : new Error(String(err)));
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
128
|
+
0 && (module.exports = {
|
|
129
|
+
createAgentMcpServer
|
|
130
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
|
+
import { InteractiveSession, SystemCommandExecutor } from '@robota-sdk/agent-sdk';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* MCP transport adapter — exposes InteractiveSession as an MCP server.
|
|
6
|
+
*
|
|
7
|
+
* Uses the low-level MCP Server class to avoid TypeScript depth issues
|
|
8
|
+
* with McpServer.registerTool() generics. Registers tools/list and
|
|
9
|
+
* tools/call handlers directly.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
interface IAgentMcpOptions {
|
|
13
|
+
/** Name for the MCP server. */
|
|
14
|
+
name: string;
|
|
15
|
+
/** Version string. */
|
|
16
|
+
version: string;
|
|
17
|
+
/** InteractiveSession to expose. */
|
|
18
|
+
session: InteractiveSession;
|
|
19
|
+
/** System command executor. */
|
|
20
|
+
commandExecutor: SystemCommandExecutor;
|
|
21
|
+
/** If true, register each system command as a separate MCP tool. Default: true. */
|
|
22
|
+
exposeCommands?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Create an MCP server that exposes InteractiveSession over Model Context Protocol.
|
|
26
|
+
*
|
|
27
|
+
* Usage:
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const server = createAgentMcpServer({
|
|
30
|
+
* name: 'robota-agent',
|
|
31
|
+
* version: '1.0.0',
|
|
32
|
+
* session: interactiveSession,
|
|
33
|
+
* commandExecutor,
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
37
|
+
* await server.connect(new StdioServerTransport());
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
declare function createAgentMcpServer(options: IAgentMcpOptions): Server;
|
|
41
|
+
|
|
42
|
+
export { type IAgentMcpOptions, createAgentMcpServer };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
|
+
import { InteractiveSession, SystemCommandExecutor } from '@robota-sdk/agent-sdk';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* MCP transport adapter — exposes InteractiveSession as an MCP server.
|
|
6
|
+
*
|
|
7
|
+
* Uses the low-level MCP Server class to avoid TypeScript depth issues
|
|
8
|
+
* with McpServer.registerTool() generics. Registers tools/list and
|
|
9
|
+
* tools/call handlers directly.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
interface IAgentMcpOptions {
|
|
13
|
+
/** Name for the MCP server. */
|
|
14
|
+
name: string;
|
|
15
|
+
/** Version string. */
|
|
16
|
+
version: string;
|
|
17
|
+
/** InteractiveSession to expose. */
|
|
18
|
+
session: InteractiveSession;
|
|
19
|
+
/** System command executor. */
|
|
20
|
+
commandExecutor: SystemCommandExecutor;
|
|
21
|
+
/** If true, register each system command as a separate MCP tool. Default: true. */
|
|
22
|
+
exposeCommands?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Create an MCP server that exposes InteractiveSession over Model Context Protocol.
|
|
26
|
+
*
|
|
27
|
+
* Usage:
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const server = createAgentMcpServer({
|
|
30
|
+
* name: 'robota-agent',
|
|
31
|
+
* version: '1.0.0',
|
|
32
|
+
* session: interactiveSession,
|
|
33
|
+
* commandExecutor,
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
37
|
+
* await server.connect(new StdioServerTransport());
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
declare function createAgentMcpServer(options: IAgentMcpOptions): Server;
|
|
41
|
+
|
|
42
|
+
export { type IAgentMcpOptions, createAgentMcpServer };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// src/mcp-server.ts
|
|
2
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
3
|
+
import { ListToolsRequestSchema, CallToolRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
4
|
+
function createAgentMcpServer(options) {
|
|
5
|
+
const { name, version, session, commandExecutor, exposeCommands = true } = options;
|
|
6
|
+
const server = new Server({ name, version }, { capabilities: { tools: {} } });
|
|
7
|
+
const tools = [
|
|
8
|
+
{
|
|
9
|
+
name: "submit",
|
|
10
|
+
description: "Submit a prompt to the AI agent and wait for the response",
|
|
11
|
+
inputSchema: {
|
|
12
|
+
type: "object",
|
|
13
|
+
properties: {
|
|
14
|
+
prompt: { type: "string", description: "The prompt to send to the agent" }
|
|
15
|
+
},
|
|
16
|
+
required: ["prompt"]
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
];
|
|
20
|
+
if (exposeCommands) {
|
|
21
|
+
for (const cmd of commandExecutor.listCommands()) {
|
|
22
|
+
tools.push({
|
|
23
|
+
name: `command_${cmd.name}`,
|
|
24
|
+
description: cmd.description,
|
|
25
|
+
inputSchema: {
|
|
26
|
+
type: "object",
|
|
27
|
+
properties: {
|
|
28
|
+
args: { type: "string", description: "Command arguments" }
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
35
|
+
tools
|
|
36
|
+
}));
|
|
37
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
38
|
+
const { name: toolName, arguments: toolArgs } = request.params;
|
|
39
|
+
if (toolName === "submit") {
|
|
40
|
+
const prompt = toolArgs?.prompt;
|
|
41
|
+
if (!prompt) {
|
|
42
|
+
return {
|
|
43
|
+
content: [{ type: "text", text: "Error: prompt is required" }],
|
|
44
|
+
isError: true
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const result = await waitForCompletion(session, prompt);
|
|
48
|
+
return {
|
|
49
|
+
content: [{ type: "text", text: result.response }]
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
if (toolName.startsWith("command_")) {
|
|
53
|
+
const cmdName = toolName.slice("command_".length);
|
|
54
|
+
const args = toolArgs?.args ?? "";
|
|
55
|
+
const result = await commandExecutor.execute(cmdName, session, args);
|
|
56
|
+
return {
|
|
57
|
+
content: [
|
|
58
|
+
{
|
|
59
|
+
type: "text",
|
|
60
|
+
text: result?.message ?? `Unknown command: ${cmdName}`
|
|
61
|
+
}
|
|
62
|
+
],
|
|
63
|
+
isError: !result
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
content: [{ type: "text", text: `Unknown tool: ${toolName}` }],
|
|
68
|
+
isError: true
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
return server;
|
|
72
|
+
}
|
|
73
|
+
function waitForCompletion(session, prompt) {
|
|
74
|
+
return new Promise((resolve, reject) => {
|
|
75
|
+
const onComplete = (result) => {
|
|
76
|
+
cleanup();
|
|
77
|
+
resolve(result);
|
|
78
|
+
};
|
|
79
|
+
const onInterrupted = (result) => {
|
|
80
|
+
cleanup();
|
|
81
|
+
resolve(result);
|
|
82
|
+
};
|
|
83
|
+
const onError = (error) => {
|
|
84
|
+
cleanup();
|
|
85
|
+
reject(error);
|
|
86
|
+
};
|
|
87
|
+
const cleanup = () => {
|
|
88
|
+
session.off("complete", onComplete);
|
|
89
|
+
session.off("interrupted", onInterrupted);
|
|
90
|
+
session.off("error", onError);
|
|
91
|
+
};
|
|
92
|
+
session.on("complete", onComplete);
|
|
93
|
+
session.on("interrupted", onInterrupted);
|
|
94
|
+
session.on("error", onError);
|
|
95
|
+
session.submit(prompt).catch((err) => {
|
|
96
|
+
cleanup();
|
|
97
|
+
reject(err instanceof Error ? err : new Error(String(err)));
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
export {
|
|
102
|
+
createAgentMcpServer
|
|
103
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@robota-sdk/agent-transport-mcp",
|
|
3
|
+
"version": "3.0.0-beta.43",
|
|
4
|
+
"description": "MCP transport adapter for exposing InteractiveSession as an MCP server",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/node/index.js",
|
|
7
|
+
"types": "dist/node/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/node/index.d.ts",
|
|
11
|
+
"node": {
|
|
12
|
+
"import": "./dist/node/index.js",
|
|
13
|
+
"require": "./dist/node/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"default": {
|
|
16
|
+
"import": "./dist/node/index.js",
|
|
17
|
+
"require": "./dist/node/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@modelcontextprotocol/sdk": "^1.28.0",
|
|
26
|
+
"zod": "^3.24.4",
|
|
27
|
+
"@robota-sdk/agent-sdk": "3.0.0-beta.43"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"rimraf": "^5.0.5",
|
|
31
|
+
"tsup": "^8.0.1",
|
|
32
|
+
"typescript": "^5.3.3",
|
|
33
|
+
"vitest": "^1.6.1"
|
|
34
|
+
},
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --out-dir dist/node --clean",
|
|
41
|
+
"test": "vitest run --passWithNoTests",
|
|
42
|
+
"typecheck": "tsc --noEmit",
|
|
43
|
+
"lint": "eslint src/ --ext .ts",
|
|
44
|
+
"clean": "rimraf dist"
|
|
45
|
+
}
|
|
46
|
+
}
|