@haibun/mcp 1.67.0
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 +164 -0
- package/build/example-usage.d.ts +9 -0
- package/build/example-usage.d.ts.map +1 -0
- package/build/example-usage.js +34 -0
- package/build/example-usage.js.map +1 -0
- package/build/lib/mcp-executor-server.d.ts +20 -0
- package/build/lib/mcp-executor-server.d.ts.map +1 -0
- package/build/lib/mcp-executor-server.js +134 -0
- package/build/lib/mcp-executor-server.js.map +1 -0
- package/build/mcp-client-prompter.d.ts +2 -0
- package/build/mcp-client-prompter.d.ts.map +1 -0
- package/build/mcp-client-prompter.js +2 -0
- package/build/mcp-client-prompter.js.map +1 -0
- package/build/mcp-client-stepper.d.ts +85 -0
- package/build/mcp-client-stepper.d.ts.map +1 -0
- package/build/mcp-client-stepper.js +280 -0
- package/build/mcp-client-stepper.js.map +1 -0
- package/build/mcp-server-stepper.d.ts +37 -0
- package/build/mcp-server-stepper.d.ts.map +1 -0
- package/build/mcp-server-stepper.js +64 -0
- package/build/mcp-server-stepper.js.map +1 -0
- package/build/mcp-test-stepper.d.ts +9 -0
- package/build/mcp-test-stepper.d.ts.map +1 -0
- package/build/mcp-test-stepper.js +20 -0
- package/build/mcp-test-stepper.js.map +1 -0
- package/build/mcp-test-utils.d.ts +12 -0
- package/build/mcp-test-utils.d.ts.map +1 -0
- package/build/mcp-test-utils.js +33 -0
- package/build/mcp-test-utils.js.map +1 -0
- package/build/prompt-handler-stepper.d.ts +2 -0
- package/build/prompt-handler-stepper.d.ts.map +1 -0
- package/build/prompt-handler-stepper.js +2 -0
- package/build/prompt-handler-stepper.js.map +1 -0
- package/build/test-constants.d.ts +2 -0
- package/build/test-constants.d.ts.map +1 -0
- package/build/test-constants.js +2 -0
- package/build/test-constants.js.map +1 -0
- package/package.json +40 -0
package/README.md
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# Haibun MCP Module
|
|
2
|
+
|
|
3
|
+
Enables agents to interact with Haibun steppers through the standardized [Model Context Protocol (MCP)](https://modelcontextprotocol.io/).
|
|
4
|
+
|
|
5
|
+
This module provides both server and client capabilities for MCP integration with Haibun.
|
|
6
|
+
|
|
7
|
+
## MCP Server
|
|
8
|
+
|
|
9
|
+
The **MCP Server** automatically exposes all available Haibun steppers as MCP tools, allowing external agents to:
|
|
10
|
+
|
|
11
|
+
- **Discover available steppers** through MCP's tool listing protocol
|
|
12
|
+
- **Execute any stepper functionality** available in your workspace
|
|
13
|
+
|
|
14
|
+
### Remote Execution Support
|
|
15
|
+
|
|
16
|
+
The MCP server can connect to a remote Haibun execution context via HTTP. This is particularly useful when:
|
|
17
|
+
|
|
18
|
+
- You want to pause execution and interact via an IDE or other tools
|
|
19
|
+
- Multiple agents need to share the same execution context
|
|
20
|
+
|
|
21
|
+
#### Configuration
|
|
22
|
+
|
|
23
|
+
⚠️ **Security Requirement**: ACCESS_TOKEN is mandatory when enabling remote execution. The system will fail fast if a port is configured without proper authentication.
|
|
24
|
+
|
|
25
|
+
To enable remote execution, configure both the HTTP executor and MCP server with matching ports and tokens:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# Start Haibun with remote executor enabled and access token
|
|
29
|
+
HAIBUN_O_WEBPLAYWRIGHT_STORAGE=StorageMem \
|
|
30
|
+
HAIBUN_O_HTTPEXECUTORSTEPPER_LISTEN_PORT=8124 \
|
|
31
|
+
HAIBUN_O_HTTPEXECUTORSTEPPER_ACCESS_TOKEN=your-secret-token \
|
|
32
|
+
node modules/cli/build/cli.js --cwd modules/mcp/runtime cli
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
If you want the MCP server to connect to a remote execution endpoint, configure it explicitly:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
# Configure MCP server to use remote execution
|
|
39
|
+
HAIBUN_O_MCPSERVERSTEPPER_REMOTE_PORT=8124 \
|
|
40
|
+
HAIBUN_O_MCPSERVERSTEPPER_ACCESS_TOKEN=your-secret-token \
|
|
41
|
+
node modules/cli/build/cli.js --cwd modules/mcp/test tests
|
|
42
|
+
```
|
|
43
|
+
#### Remote Execution API
|
|
44
|
+
|
|
45
|
+
When the HTTP executor is running, you can interact with it directly via HTTP API. All requests require authentication via the ACCESS_TOKEN.
|
|
46
|
+
|
|
47
|
+
**Execute a step:**
|
|
48
|
+
```bash
|
|
49
|
+
curl -X POST http://localhost:8124/execute-step \
|
|
50
|
+
-H "Content-Type: application/json" \
|
|
51
|
+
-H "Authorization: Bearer your-secret-token" \
|
|
52
|
+
-d '{
|
|
53
|
+
"statement": "I set MY_VAR to hello world",
|
|
54
|
+
"source": "curl"
|
|
55
|
+
}'
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Starting an MCP Server
|
|
59
|
+
|
|
60
|
+
The MCP Server is a Haibun stepper. For a basic example with representative steppers:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
# Basic local execution
|
|
64
|
+
HAIBUN_O_WEBPLAYWRIGHT_STORAGE=StorageMem \
|
|
65
|
+
node modules/cli/build/cli.js --cwd modules/mcp/runtime local
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Or with remote execution enabled:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
# With remote execution capability
|
|
72
|
+
HAIBUN_O_WEBPLAYWRIGHT_STORAGE=StorageMem \
|
|
73
|
+
HAIBUN_O_HTTPEXECUTORSTEPPER_LISTEN_PORT=8124 \
|
|
74
|
+
HAIBUN_O_HTTPEXECUTORSTEPPER_ACCESS_TOKEN=your-secret-token \
|
|
75
|
+
node modules/cli/build/cli.js --cwd modules/mcp/runtime http
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Using from External MCP Clients
|
|
79
|
+
Any MCP-compatible client can discover and call the exposed tools. The exact tools available depend on which Haibun modules are configured in your workspace.
|
|
80
|
+
|
|
81
|
+
### Server Control from Haibun Features
|
|
82
|
+
```gherkin
|
|
83
|
+
Feature: MCP Server Management
|
|
84
|
+
Scenario: Start and stop MCP server
|
|
85
|
+
Given I serve mcp tools from steppers
|
|
86
|
+
|
|
87
|
+
The server is now running and exposing tools to external MCP clients.
|
|
88
|
+
|
|
89
|
+
When I stop mcp tools
|
|
90
|
+
The server is stopped.
|
|
91
|
+
|
|
92
|
+
Scenario: Enable remote execution API
|
|
93
|
+
Given I enable remote executor
|
|
94
|
+
|
|
95
|
+
Now external MCP servers can connect to this execution context via HTTP.
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## MCP Client
|
|
99
|
+
|
|
100
|
+
The **MCP Client** allows Haibun features to connect to external MCP servers and discover their available tools.
|
|
101
|
+
|
|
102
|
+
### Client Usage from Haibun Features
|
|
103
|
+
```gherkin
|
|
104
|
+
Feature: External MCP Integration
|
|
105
|
+
Scenario: List tools from external server
|
|
106
|
+
When I list mcp tools
|
|
107
|
+
|
|
108
|
+
This discovers all tools available from the configured MCP server.
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Client Configuration
|
|
112
|
+
The client requires server connection parameters to be configured via module options:
|
|
113
|
+
```json
|
|
114
|
+
{
|
|
115
|
+
"MCPClientStepper": {
|
|
116
|
+
"SERVER": "{\"command\": \"node\", \"args\": [\"server.js\"], \"env\": {}}"
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Examples
|
|
122
|
+
|
|
123
|
+
## VSCode config
|
|
124
|
+
|
|
125
|
+
```
|
|
126
|
+
"mcp": {
|
|
127
|
+
"servers": {
|
|
128
|
+
"haibun-mcp": {
|
|
129
|
+
"type": "stdio",
|
|
130
|
+
"command": "tsx",
|
|
131
|
+
"cwd": "~",
|
|
132
|
+
"args": [
|
|
133
|
+
"modules/cli/build/cli.js",
|
|
134
|
+
"-c",
|
|
135
|
+
"./modules/mcp/runtime/config.json",
|
|
136
|
+
"./modules/mcp/runtime/http"
|
|
137
|
+
],
|
|
138
|
+
"env": {
|
|
139
|
+
"HAIBUN_O_MCPSERVERSTEPPER_REMOTE_PORT": "8125",
|
|
140
|
+
"HAIBUN_O_MCPSERVERSTEPPER_ACCESS_TOKEN": "some-great-password",
|
|
141
|
+
"HAIBUN_O_HTTPEXECUTORSTEPPER_LISTEN_PORT": "8125",
|
|
142
|
+
"HAIBUN_O_HTTPEXECUTORSTEPPER_ACCESS_TOKEN": "some-great-password",
|
|
143
|
+
"HAIBUN_O_WEBPLAYWRIGHT_STORAGE": "StorageMem"
|
|
144
|
+
},
|
|
145
|
+
"dev": {
|
|
146
|
+
"watch": "modules/**/build/**/*.js",
|
|
147
|
+
"debug": {
|
|
148
|
+
"type": "node"
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Server Tools
|
|
155
|
+
Depending on which Haibun modules you have configured, you might see tools like:
|
|
156
|
+
|
|
157
|
+
- `VariablesStepper-set` - Set variable values
|
|
158
|
+
- `VariablesStepper-display` - Display variable values
|
|
159
|
+
- `WebPlaywright-gotoPage` - Navigate to web pages
|
|
160
|
+
- `Haibun-comment` - Add comments
|
|
161
|
+
- Any locally configured steppers
|
|
162
|
+
|
|
163
|
+
### Client Tools
|
|
164
|
+
- `list mcp tools` - Discover tools available from external MCP servers
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Prompter } from '@haibun/core/build/lib/prompter.js';
|
|
2
|
+
/**
|
|
3
|
+
* Example of how to add an MCP client as a subscriber to handle prompts.
|
|
4
|
+
* This allows external MCP servers to respond to interactive prompts in Haibun.
|
|
5
|
+
*/
|
|
6
|
+
declare const prompter: Prompter;
|
|
7
|
+
declare const mcpPrompter: import("./mcp-client-prompter.js").MCPClientPrompter;
|
|
8
|
+
export { prompter, mcpPrompter };
|
|
9
|
+
//# sourceMappingURL=example-usage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"example-usage.d.ts","sourceRoot":"","sources":["../src/example-usage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAG9D;;;GAGG;AAGH,QAAA,MAAM,QAAQ,UAAiB,CAAC;AAIhC,QAAA,MAAM,WAAW,sDAKhB,CAAC;AAwBF,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Prompter } from '@haibun/core/build/lib/prompter.js';
|
|
2
|
+
import { createMCPClientPrompter } from './mcp-client-prompter.js';
|
|
3
|
+
/**
|
|
4
|
+
* Example of how to add an MCP client as a subscriber to handle prompts.
|
|
5
|
+
* This allows external MCP servers to respond to interactive prompts in Haibun.
|
|
6
|
+
*/
|
|
7
|
+
// Create a prompter instance
|
|
8
|
+
const prompter = new Prompter();
|
|
9
|
+
// Create an MCP client prompter that connects to an MCP server
|
|
10
|
+
// The MCP server should implement a tool called "PromptHandler-handlePrompt"
|
|
11
|
+
const mcpPrompter = createMCPClientPrompter('node', // Command to run the MCP server
|
|
12
|
+
['path/to/your/mcp-server.js'], // Arguments for the MCP server
|
|
13
|
+
{}, // Environment variables
|
|
14
|
+
'haibun-prompt-client' // Client name
|
|
15
|
+
);
|
|
16
|
+
// Subscribe the MCP client as a prompter
|
|
17
|
+
prompter.subscribe(mcpPrompter);
|
|
18
|
+
// Now when prompter.prompt() is called, it will try the MCP client first,
|
|
19
|
+
// and if that fails or returns undefined, it will fall back to other prompters
|
|
20
|
+
// like the ReadlinePrompter
|
|
21
|
+
// Example usage:
|
|
22
|
+
async function examplePrompt() {
|
|
23
|
+
const response = await prompter.prompt({
|
|
24
|
+
message: "Please select an option",
|
|
25
|
+
options: ["Yes", "No", "Cancel"]
|
|
26
|
+
});
|
|
27
|
+
console.log("User response:", response);
|
|
28
|
+
}
|
|
29
|
+
// Clean up when done
|
|
30
|
+
process.on('exit', () => {
|
|
31
|
+
mcpPrompter.close();
|
|
32
|
+
});
|
|
33
|
+
export { prompter, mcpPrompter };
|
|
34
|
+
//# sourceMappingURL=example-usage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"example-usage.js","sourceRoot":"","sources":["../src/example-usage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAC9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAEnE;;;GAGG;AAEH,6BAA6B;AAC7B,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;AAEhC,+DAA+D;AAC/D,6EAA6E;AAC7E,MAAM,WAAW,GAAG,uBAAuB,CAC1C,MAAM,EAAG,gCAAgC;AACzC,CAAC,4BAA4B,CAAC,EAAG,+BAA+B;AAChE,EAAE,EAAG,wBAAwB;AAC7B,sBAAsB,CAAE,cAAc;CACtC,CAAC;AAEF,yCAAyC;AACzC,QAAQ,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;AAEhC,0EAA0E;AAC1E,+EAA+E;AAC/E,4BAA4B;AAE5B,iBAAiB;AACjB,KAAK,UAAU,aAAa;IAC3B,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC;QACtC,OAAO,EAAE,yBAAyB;QAClC,OAAO,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,QAAQ,CAAC;KAChC,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC;AACzC,CAAC;AAED,qBAAqB;AACrB,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE;IACvB,WAAW,CAAC,KAAK,EAAE,CAAC;AACrB,CAAC,CAAC,CAAC;AAEH,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { AStepper } from "@haibun/core/build/lib/astepper.js";
|
|
3
|
+
import { TWorld } from "@haibun/core/build/lib/defs.js";
|
|
4
|
+
interface RemoteExecutorConfig {
|
|
5
|
+
url: string;
|
|
6
|
+
accessToken?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class MCPExecutorServer {
|
|
9
|
+
private steppers;
|
|
10
|
+
private world;
|
|
11
|
+
private remoteConfig?;
|
|
12
|
+
server: McpServer;
|
|
13
|
+
constructor(steppers: AStepper[], world: TWorld, remoteConfig?: RemoteExecutorConfig);
|
|
14
|
+
start(): Promise<void>;
|
|
15
|
+
registerSteppers(): void;
|
|
16
|
+
private createToolHandler;
|
|
17
|
+
private executeViaRemoteApi;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=mcp-executor-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-executor-server.d.ts","sourceRoot":"","sources":["../../src/lib/mcp-executor-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAKpE,OAAO,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAG9D,OAAO,EAAE,MAAM,EAA6B,MAAM,gCAAgC,CAAC;AAMnF,UAAU,oBAAoB;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,qBAAa,iBAAiB;IAEjB,OAAO,CAAC,QAAQ;IAAc,OAAO,CAAC,KAAK;IAAU,OAAO,CAAC,YAAY,CAAC;IADtF,MAAM,EAAE,SAAS,CAAC;gBACE,QAAQ,EAAE,QAAQ,EAAE,EAAU,KAAK,EAAE,MAAM,EAAU,YAAY,CAAC,EAAE,oBAAoB;IAEtG,KAAK;IAeX,gBAAgB;IA8BhB,OAAO,CAAC,iBAAiB;YA+CX,mBAAmB;CAyCjC"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { namedInterpolation } from "@haibun/core/build/lib/namedVars.js";
|
|
5
|
+
import { currentVersion as version } from '@haibun/core/build/currentVersion.js';
|
|
6
|
+
import { constructorName } from "@haibun/core/build/lib/util/index.js";
|
|
7
|
+
import { resolveAndExecuteStatement } from "@haibun/core/build/lib/util/resolveAndExecuteStatement.js";
|
|
8
|
+
export class MCPExecutorServer {
|
|
9
|
+
steppers;
|
|
10
|
+
world;
|
|
11
|
+
remoteConfig;
|
|
12
|
+
server;
|
|
13
|
+
constructor(steppers, world, remoteConfig) {
|
|
14
|
+
this.steppers = steppers;
|
|
15
|
+
this.world = world;
|
|
16
|
+
this.remoteConfig = remoteConfig;
|
|
17
|
+
}
|
|
18
|
+
async start() {
|
|
19
|
+
this.server = new McpServer({
|
|
20
|
+
name: "haibun-mcp",
|
|
21
|
+
version,
|
|
22
|
+
capabilities: {
|
|
23
|
+
resources: {},
|
|
24
|
+
tools: {},
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
this.registerSteppers();
|
|
28
|
+
const transport = new StdioServerTransport();
|
|
29
|
+
await this.server.connect(transport);
|
|
30
|
+
}
|
|
31
|
+
registerSteppers() {
|
|
32
|
+
for (const stepper of this.steppers) {
|
|
33
|
+
const stepperName = constructorName(stepper);
|
|
34
|
+
for (const [stepName, stepDef] of Object.entries(stepper.steps)) {
|
|
35
|
+
const variables = {};
|
|
36
|
+
if (stepDef.gwta) {
|
|
37
|
+
const { stepVariables } = namedInterpolation(stepDef.gwta);
|
|
38
|
+
if (Array.isArray(stepVariables)) {
|
|
39
|
+
for (const v of stepVariables) {
|
|
40
|
+
variables[v.name] = v.type === 'number' ? z.number() : z.string();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const toolDescription = {
|
|
45
|
+
description: stepName,
|
|
46
|
+
title: (stepDef.gwta || stepDef.match?.toString() || stepDef.exact || stepName),
|
|
47
|
+
};
|
|
48
|
+
if (Object.keys(variables).length > 0) {
|
|
49
|
+
toolDescription.inputSchema = variables;
|
|
50
|
+
}
|
|
51
|
+
const toolName = `${stepperName}-${stepName}`;
|
|
52
|
+
this.server.registerTool(toolName, toolDescription, this.createToolHandler(stepperName, stepName, stepDef));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
createToolHandler(stepperName, stepName, stepDef) {
|
|
57
|
+
return async (input) => {
|
|
58
|
+
try {
|
|
59
|
+
let statement = stepDef.gwta || stepDef.exact || stepDef.match?.toString();
|
|
60
|
+
if (stepDef.gwta && Object.keys(input).length > 0) {
|
|
61
|
+
for (const [key, value] of Object.entries(input)) {
|
|
62
|
+
const pattern = new RegExp(`\\{${key}(:[^}]*)?\\}`, 'g');
|
|
63
|
+
statement = statement.replace(pattern, String(value));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const stepResult = this.remoteConfig
|
|
67
|
+
? await this.executeViaRemoteApi(statement, `/mcp/${stepperName}-${stepName}`)
|
|
68
|
+
: await resolveAndExecuteStatement(statement, `/mcp/${stepperName}-${stepName}`, this.steppers, this.world);
|
|
69
|
+
return {
|
|
70
|
+
content: [{
|
|
71
|
+
type: "text",
|
|
72
|
+
text: JSON.stringify({
|
|
73
|
+
stepName,
|
|
74
|
+
stepperName,
|
|
75
|
+
input,
|
|
76
|
+
result: stepResult,
|
|
77
|
+
success: stepResult.ok !== false
|
|
78
|
+
}, null, 2)
|
|
79
|
+
}]
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
84
|
+
return {
|
|
85
|
+
content: [{
|
|
86
|
+
type: "text",
|
|
87
|
+
text: JSON.stringify({
|
|
88
|
+
stepName,
|
|
89
|
+
stepperName,
|
|
90
|
+
input,
|
|
91
|
+
error: errorMessage,
|
|
92
|
+
success: false
|
|
93
|
+
}, null, 2)
|
|
94
|
+
}]
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
async executeViaRemoteApi(statement, source) {
|
|
100
|
+
const headers = {
|
|
101
|
+
'Content-Type': 'application/json',
|
|
102
|
+
};
|
|
103
|
+
if (this.remoteConfig.accessToken) {
|
|
104
|
+
headers.Authorization = `Bearer ${this.remoteConfig.accessToken}`;
|
|
105
|
+
}
|
|
106
|
+
const maxRetries = 3;
|
|
107
|
+
const retryDelay = 1000;
|
|
108
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
109
|
+
try {
|
|
110
|
+
const response = await fetch(`${this.remoteConfig.url}/execute-step`, {
|
|
111
|
+
method: 'POST',
|
|
112
|
+
headers,
|
|
113
|
+
body: JSON.stringify({ statement, source })
|
|
114
|
+
});
|
|
115
|
+
if (!response.ok) {
|
|
116
|
+
const errorText = await response.text();
|
|
117
|
+
throw new Error(`Remote execution failed: ${response.status} ${errorText}`);
|
|
118
|
+
}
|
|
119
|
+
const responseData = await response.json();
|
|
120
|
+
return responseData;
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
124
|
+
if (attempt === maxRetries) {
|
|
125
|
+
throw new Error(`Remote execution failed after ${maxRetries} attempts: ${errorMessage}`);
|
|
126
|
+
}
|
|
127
|
+
// Log retry attempt and wait before retrying
|
|
128
|
+
console.warn(`Remote execution attempt ${attempt} failed: ${errorMessage}. Retrying in ${retryDelay}ms...`);
|
|
129
|
+
await new Promise(resolve => setTimeout(resolve, retryDelay));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=mcp-executor-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-executor-server.js","sourceRoot":"","sources":["../../src/lib/mcp-executor-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAA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,EAAE,CAAC;gBAChB,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBAE5E,IAAI,OAAO,KAAK,UAAU,EAAE,CAAC;oBAC5B,MAAM,IAAI,KAAK,CAAC,iCAAiC,UAAU,cAAc,YAAY,EAAE,CAAC,CAAC;gBAC1F,CAAC;gBAED,6CAA6C;gBAC7C,OAAO,CAAC,IAAI,CAAC,4BAA4B,OAAO,YAAY,YAAY,iBAAiB,UAAU,OAAO,CAAC,CAAC;gBAC5G,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC;YAC/D,CAAC;QACF,CAAC;IACF,CAAC;CACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-client-prompter.d.ts","sourceRoot":"","sources":["../src/mcp-client-prompter.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-client-prompter.js","sourceRoot":"","sources":["../src/mcp-client-prompter.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { StdioServerParameters } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
2
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
3
|
+
import { BasePromptManager } from '@haibun/core/build/lib/base-prompt-manager.js';
|
|
4
|
+
import { AStepper, IHasCycles, IHasOptions } from '@haibun/core/build/lib/astepper.js';
|
|
5
|
+
import { TWorld, TNamed, TFeatureStep, IStepperCycles } from '@haibun/core/build/lib/defs.js';
|
|
6
|
+
import { TPrompt, TPromptResponse } from '@haibun/core/build/lib/prompter.js';
|
|
7
|
+
declare class MCPClientPrompter extends BasePromptManager {
|
|
8
|
+
private serverParameters;
|
|
9
|
+
private client?;
|
|
10
|
+
private isConnected;
|
|
11
|
+
constructor(serverParameters: StdioServerParameters);
|
|
12
|
+
protected showPrompt(prompt: TPrompt): void;
|
|
13
|
+
protected hidePrompt(id: string): void;
|
|
14
|
+
private ensureConnection;
|
|
15
|
+
prompt(prompt: TPrompt): Promise<TPromptResponse>;
|
|
16
|
+
close(): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
declare class MCPClientStepper extends AStepper implements IHasOptions, IHasCycles {
|
|
19
|
+
static SERVER: string;
|
|
20
|
+
cycles: IStepperCycles;
|
|
21
|
+
options: {
|
|
22
|
+
[MCPClientStepper.SERVER]: {
|
|
23
|
+
desc: string;
|
|
24
|
+
parse: (input: string) => {
|
|
25
|
+
parseError: string;
|
|
26
|
+
result?: undefined;
|
|
27
|
+
} | {
|
|
28
|
+
result: string;
|
|
29
|
+
parseError?: undefined;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
serverParameters: StdioServerParameters;
|
|
34
|
+
client?: Client<{
|
|
35
|
+
method: string;
|
|
36
|
+
params?: {
|
|
37
|
+
[x: string]: unknown;
|
|
38
|
+
_meta?: {
|
|
39
|
+
[x: string]: unknown;
|
|
40
|
+
progressToken?: string | number;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
}, {
|
|
44
|
+
method: string;
|
|
45
|
+
params?: {
|
|
46
|
+
[x: string]: unknown;
|
|
47
|
+
_meta?: {
|
|
48
|
+
[x: string]: unknown;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
}, {
|
|
52
|
+
[x: string]: unknown;
|
|
53
|
+
_meta?: {
|
|
54
|
+
[x: string]: unknown;
|
|
55
|
+
};
|
|
56
|
+
}>;
|
|
57
|
+
isConnected: boolean;
|
|
58
|
+
mcpPrompter?: MCPClientPrompter;
|
|
59
|
+
setWorld(world: TWorld, steppers: AStepper[]): Promise<void>;
|
|
60
|
+
private ensureConnection;
|
|
61
|
+
steps: {
|
|
62
|
+
registerMcpPrompter: {
|
|
63
|
+
gwta: string;
|
|
64
|
+
action: (named: TNamed, featureStep: TFeatureStep) => Promise<import("@haibun/core/build/lib/defs.js").TOKActionResult | import("@haibun/core/build/lib/defs.js").TNotOKActionResult>;
|
|
65
|
+
};
|
|
66
|
+
unregisterMcpPrompter: {
|
|
67
|
+
gwta: string;
|
|
68
|
+
action: (named: TNamed, featureStep: TFeatureStep) => Promise<import("@haibun/core/build/lib/defs.js").TOKActionResult | import("@haibun/core/build/lib/defs.js").TNotOKActionResult>;
|
|
69
|
+
};
|
|
70
|
+
listMcpTools: {
|
|
71
|
+
gwta: string;
|
|
72
|
+
action: (named: TNamed, featureStep: TFeatureStep) => Promise<import("@haibun/core/build/lib/defs.js").TOKActionResult | import("@haibun/core/build/lib/defs.js").TNotOKActionResult>;
|
|
73
|
+
};
|
|
74
|
+
promptViaMcp: {
|
|
75
|
+
gwta: string;
|
|
76
|
+
action: ({ message, options }: TNamed, featureStep: TFeatureStep) => Promise<import("@haibun/core/build/lib/defs.js").TOKActionResult | import("@haibun/core/build/lib/defs.js").TNotOKActionResult>;
|
|
77
|
+
};
|
|
78
|
+
promptViaMcpWithContext: {
|
|
79
|
+
gwta: string;
|
|
80
|
+
action: ({ message, context, options }: TNamed, featureStep: TFeatureStep) => Promise<import("@haibun/core/build/lib/defs.js").TOKActionResult | import("@haibun/core/build/lib/defs.js").TNotOKActionResult>;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
export default MCPClientStepper;
|
|
85
|
+
//# sourceMappingURL=mcp-client-stepper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-client-stepper.d.ts","sourceRoot":"","sources":["../src/mcp-client-stepper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,qBAAqB,EAAE,MAAM,2CAA2C,CAAC;AACxG,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAEnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,+CAA+C,C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AAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;YAAC,KAAK,CAAC,EAAE;gBAAE,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;aAAE,CAAC;SAAE,CAAC;KAAE,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE;YAAE,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;SAAE,CAAC;KAAE,CAAC,CAAC;IACvS,WAAW,UAAS;IACpB,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE;YAUpC,gBAAgB;IAW9B,KAAK;;;4BAGmB,MAAM,eAAe,YAAY;;;;4BAmBjC,MAAM,eAAe,YAAY;;;;4BAoBjC,MAAM,eAAe,YAAY;;;;2CAelB,MAAM,eAAe,YAAY;;;;oDAoDxB,MAAM,eAAe,YAAY;;MA0DhF;CACD;AAED,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
2
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
3
|
+
import { BasePromptManager } from '@haibun/core/build/lib/base-prompt-manager.js';
|
|
4
|
+
import { AStepper } from '@haibun/core/build/lib/astepper.js';
|
|
5
|
+
import { actionNotOK, actionOK, getStepperOption, stringOrError } from '@haibun/core/build/lib/util/index.js';
|
|
6
|
+
import { currentVersion as version } from '@haibun/core/build/currentVersion.js';
|
|
7
|
+
import { EExecutionMessageType } from '@haibun/core/build/lib/interfaces/logger.js';
|
|
8
|
+
class MCPClientPrompter extends BasePromptManager {
|
|
9
|
+
serverParameters;
|
|
10
|
+
client;
|
|
11
|
+
isConnected = false;
|
|
12
|
+
constructor(serverParameters) {
|
|
13
|
+
super();
|
|
14
|
+
this.serverParameters = serverParameters;
|
|
15
|
+
}
|
|
16
|
+
showPrompt(prompt) { }
|
|
17
|
+
hidePrompt(id) { }
|
|
18
|
+
async ensureConnection() {
|
|
19
|
+
if (this.isConnected && this.client) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
this.client = new Client({ name: "haibun-mcp-prompter", version });
|
|
23
|
+
const transport = new StdioClientTransport(this.serverParameters);
|
|
24
|
+
await this.client.connect(transport);
|
|
25
|
+
this.isConnected = true;
|
|
26
|
+
}
|
|
27
|
+
async prompt(prompt) {
|
|
28
|
+
try {
|
|
29
|
+
await this.ensureConnection();
|
|
30
|
+
if (!this.client) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
const result = await this.client.callTool({
|
|
34
|
+
name: 'handlePrompt',
|
|
35
|
+
arguments: {
|
|
36
|
+
message: prompt.message,
|
|
37
|
+
context: prompt.context ? JSON.stringify(prompt.context) : undefined,
|
|
38
|
+
options: prompt.options || []
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
if (result.content && Array.isArray(result.content) && result.content.length > 0) {
|
|
42
|
+
const content = result.content[0];
|
|
43
|
+
if (content.type === 'text') {
|
|
44
|
+
try {
|
|
45
|
+
const responseData = JSON.parse(content.text);
|
|
46
|
+
return responseData.response;
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return content.text;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
console.debug(`MCP prompter failed: ${error}`);
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async close() {
|
|
61
|
+
if (this.client && this.isConnected) {
|
|
62
|
+
await this.client.close();
|
|
63
|
+
this.isConnected = false;
|
|
64
|
+
this.client = undefined;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const cycles = (mcs) => ({
|
|
69
|
+
async endFeature() {
|
|
70
|
+
if (mcs.client && mcs.isConnected) {
|
|
71
|
+
await this.client.close();
|
|
72
|
+
mcs.isConnected = false;
|
|
73
|
+
mcs.client = undefined;
|
|
74
|
+
}
|
|
75
|
+
if (mcs.mcpPrompter) {
|
|
76
|
+
await mcs.mcpPrompter.close();
|
|
77
|
+
mcs.mcpPrompter = undefined;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
class MCPClientStepper extends AStepper {
|
|
82
|
+
static SERVER = 'SERVER';
|
|
83
|
+
cycles = cycles(this);
|
|
84
|
+
options = {
|
|
85
|
+
[MCPClientStepper.SERVER]: {
|
|
86
|
+
desc: `MCP server to start (stdio)`,
|
|
87
|
+
parse: (input) => stringOrError(input)
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
serverParameters;
|
|
91
|
+
client;
|
|
92
|
+
isConnected = false;
|
|
93
|
+
mcpPrompter;
|
|
94
|
+
async setWorld(world, steppers) {
|
|
95
|
+
await super.setWorld(world, steppers);
|
|
96
|
+
const serverJson = getStepperOption(this, MCPClientStepper.SERVER, this.world.moduleOptions);
|
|
97
|
+
try {
|
|
98
|
+
this.serverParameters = JSON.parse(serverJson);
|
|
99
|
+
}
|
|
100
|
+
catch (e) {
|
|
101
|
+
throw new Error(`Failed to parse ${MCPClientStepper.SERVER} option: ${e}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async ensureConnection() {
|
|
105
|
+
if (this.isConnected && this.client) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
this.client = new Client({ name: "haibun-mcp-client", version });
|
|
109
|
+
const transport = new StdioClientTransport(this.serverParameters);
|
|
110
|
+
await this.client.connect(transport);
|
|
111
|
+
this.isConnected = true;
|
|
112
|
+
}
|
|
113
|
+
steps = {
|
|
114
|
+
registerMcpPrompter: {
|
|
115
|
+
gwta: `register mcp prompter`,
|
|
116
|
+
action: async (named, featureStep) => {
|
|
117
|
+
try {
|
|
118
|
+
if (!this.mcpPrompter) {
|
|
119
|
+
this.mcpPrompter = new MCPClientPrompter(this.serverParameters);
|
|
120
|
+
this.world.prompter.subscribe(this.mcpPrompter);
|
|
121
|
+
}
|
|
122
|
+
const messageContext = {
|
|
123
|
+
incident: EExecutionMessageType.ACTION,
|
|
124
|
+
incidentDetails: { registered: true }
|
|
125
|
+
};
|
|
126
|
+
return actionOK({ messageContext });
|
|
127
|
+
}
|
|
128
|
+
catch (e) {
|
|
129
|
+
console.error(e);
|
|
130
|
+
return actionNotOK(`Failed to register MCP prompter: ${e}`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
unregisterMcpPrompter: {
|
|
135
|
+
gwta: `unregister mcp prompter`,
|
|
136
|
+
action: async (named, featureStep) => {
|
|
137
|
+
try {
|
|
138
|
+
if (this.mcpPrompter) {
|
|
139
|
+
this.world.prompter.unsubscribe(this.mcpPrompter);
|
|
140
|
+
await this.mcpPrompter.close();
|
|
141
|
+
this.mcpPrompter = undefined;
|
|
142
|
+
}
|
|
143
|
+
const messageContext = {
|
|
144
|
+
incident: EExecutionMessageType.ACTION,
|
|
145
|
+
incidentDetails: { unregistered: true }
|
|
146
|
+
};
|
|
147
|
+
return actionOK({ messageContext });
|
|
148
|
+
}
|
|
149
|
+
catch (e) {
|
|
150
|
+
console.error(e);
|
|
151
|
+
return actionNotOK(`Failed to unregister MCP prompter: ${e}`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
listMcpTools: {
|
|
156
|
+
gwta: `list mcp tools`,
|
|
157
|
+
action: async (named, featureStep) => {
|
|
158
|
+
try {
|
|
159
|
+
await this.ensureConnection();
|
|
160
|
+
const toolsResult = await this.client.listTools();
|
|
161
|
+
const tools = Array.isArray(toolsResult) ? toolsResult : (toolsResult.tools || []);
|
|
162
|
+
const messageContext = { incident: EExecutionMessageType.ACTION, incidentDetails: { tools } };
|
|
163
|
+
return actionOK({ messageContext });
|
|
164
|
+
}
|
|
165
|
+
catch (e) {
|
|
166
|
+
console.error(e);
|
|
167
|
+
return actionNotOK(`Failed to list MCP tools: ${e}`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
promptViaMcp: {
|
|
172
|
+
gwta: `prompt via mcp {message} with options {options}`,
|
|
173
|
+
action: async ({ message, options }, featureStep) => {
|
|
174
|
+
try {
|
|
175
|
+
await this.ensureConnection();
|
|
176
|
+
const prompt = {
|
|
177
|
+
id: 'test-' + Math.random().toString(36).slice(2),
|
|
178
|
+
message,
|
|
179
|
+
options: options ? options.split(',').map(o => o.trim()) : undefined
|
|
180
|
+
};
|
|
181
|
+
// Try to call a prompt handling tool on the MCP server
|
|
182
|
+
const result = await this.client.callTool({
|
|
183
|
+
name: 'handlePrompt',
|
|
184
|
+
arguments: {
|
|
185
|
+
message: prompt.message,
|
|
186
|
+
context: prompt.context ? JSON.stringify(prompt.context) : undefined,
|
|
187
|
+
options: prompt.options || []
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
// Parse the response from the MCP tool
|
|
191
|
+
if (result.content && Array.isArray(result.content) && result.content.length > 0) {
|
|
192
|
+
const content = result.content[0];
|
|
193
|
+
if (content.type === 'text') {
|
|
194
|
+
try {
|
|
195
|
+
const responseData = JSON.parse(content.text);
|
|
196
|
+
const messageContext = {
|
|
197
|
+
incident: EExecutionMessageType.ACTION,
|
|
198
|
+
incidentDetails: { response: responseData.response }
|
|
199
|
+
};
|
|
200
|
+
return actionOK({ messageContext });
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
// If parsing fails, return the text directly
|
|
204
|
+
const messageContext = {
|
|
205
|
+
incident: EExecutionMessageType.ACTION,
|
|
206
|
+
incidentDetails: { response: content.text }
|
|
207
|
+
};
|
|
208
|
+
return actionOK({ messageContext });
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return actionNotOK('No response received from MCP server');
|
|
213
|
+
}
|
|
214
|
+
catch (e) {
|
|
215
|
+
console.error(e);
|
|
216
|
+
return actionNotOK(`Failed to prompt via MCP: ${e}`);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
promptViaMcpWithContext: {
|
|
221
|
+
gwta: `prompt via mcp {message} with context {context} and options {options}`,
|
|
222
|
+
action: async ({ message, context, options }, featureStep) => {
|
|
223
|
+
try {
|
|
224
|
+
await this.ensureConnection();
|
|
225
|
+
let parsedContext;
|
|
226
|
+
try {
|
|
227
|
+
parsedContext = JSON.parse(context);
|
|
228
|
+
}
|
|
229
|
+
catch {
|
|
230
|
+
parsedContext = context;
|
|
231
|
+
}
|
|
232
|
+
const prompt = {
|
|
233
|
+
id: 'test-' + Math.random().toString(36).slice(2),
|
|
234
|
+
message,
|
|
235
|
+
context: parsedContext,
|
|
236
|
+
options: options ? options.split(',').map(o => o.trim()) : undefined
|
|
237
|
+
};
|
|
238
|
+
// Try to call a prompt handling tool on the MCP server
|
|
239
|
+
const result = await this.client.callTool({
|
|
240
|
+
name: 'handlePrompt',
|
|
241
|
+
arguments: {
|
|
242
|
+
message: prompt.message,
|
|
243
|
+
context: JSON.stringify(prompt.context),
|
|
244
|
+
options: prompt.options || []
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
// Parse the response from the MCP tool
|
|
248
|
+
if (result.content && Array.isArray(result.content) && result.content.length > 0) {
|
|
249
|
+
const content = result.content[0];
|
|
250
|
+
if (content.type === 'text') {
|
|
251
|
+
try {
|
|
252
|
+
const responseData = JSON.parse(content.text);
|
|
253
|
+
const messageContext = {
|
|
254
|
+
incident: EExecutionMessageType.ACTION,
|
|
255
|
+
incidentDetails: { response: responseData.response }
|
|
256
|
+
};
|
|
257
|
+
return actionOK({ messageContext });
|
|
258
|
+
}
|
|
259
|
+
catch {
|
|
260
|
+
// If parsing fails, return the text directly
|
|
261
|
+
const messageContext = {
|
|
262
|
+
incident: EExecutionMessageType.ACTION,
|
|
263
|
+
incidentDetails: { response: content.text }
|
|
264
|
+
};
|
|
265
|
+
return actionOK({ messageContext });
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return actionNotOK('No response received from MCP server');
|
|
270
|
+
}
|
|
271
|
+
catch (e) {
|
|
272
|
+
console.error(e);
|
|
273
|
+
return actionNotOK(`Failed to prompt via MCP: ${e}`);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
export default MCPClientStepper;
|
|
280
|
+
//# sourceMappingURL=mcp-client-stepper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-client-stepper.js","sourceRoot":"","sources":["../src/mcp-client-stepper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAyB,MAAM,2CAA2C,CAAC;AACxG,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAEnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,+CAA+C,CAAC;AAClF,OAAO,EAAE,QAAQ,EAA2B,MAAM,oCAAoC,CAAC;AAEvF,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAC9G,OAAO,EAAE,cAAc,IAAI,OAAO,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAmB,MAAM,6CAA6C,CAAC;AAGrG,MAAM,iBAAkB,SAAQ,iBAAiB;IAI5B;IAHZ,MAAM,CAAyB;IAC/B,WAAW,GAAG,KAAK,CAAC;IAE5B,YAAoB,gBAAuC;QAC1D,KAAK,EAAE,CAAC;QADW,qBAAgB,GAAhB,gBAAgB,CAAuB;IAE3D,CAAC;IAES,UAAU,CAAC,MAAe,IAAS,CAAC;IACpC,UAAU,CAAC,EAAU,IAAS,CAAC;IAEjC,KAAK,CAAC,gBAAgB;QAC7B,IAAI,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,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,CAAC;oBACZ,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;oBACjB,OAAO,WAAW,CAAC,6BAA6B,CAAC,EAAE,CAAC,CAAC;gBACtD,CAAC;YACF,CAAC;SACD;KACD,CAAA;;AAGF,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { AStepper, IHasOptions } from '@haibun/core/build/lib/astepper.js';
|
|
2
|
+
import { TWorld } from '@haibun/core/build/lib/defs.js';
|
|
3
|
+
import { MCPExecutorServer } from './lib/mcp-executor-server.js';
|
|
4
|
+
declare class MCPServerStepper extends AStepper implements IHasOptions {
|
|
5
|
+
steppers: AStepper[];
|
|
6
|
+
mcpServer: MCPExecutorServer;
|
|
7
|
+
remotePort: number;
|
|
8
|
+
accessToken: string;
|
|
9
|
+
options: {
|
|
10
|
+
REMOTE_PORT: {
|
|
11
|
+
desc: string;
|
|
12
|
+
parse: (port: string) => {
|
|
13
|
+
result: number;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
ACCESS_TOKEN: {
|
|
17
|
+
desc: string;
|
|
18
|
+
parse: (token: string) => {
|
|
19
|
+
result: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
setWorld(world: TWorld, steppers: AStepper[]): Promise<void>;
|
|
24
|
+
private getRemoteConfig;
|
|
25
|
+
steps: {
|
|
26
|
+
startMcpTools: {
|
|
27
|
+
gwta: string;
|
|
28
|
+
action: () => Promise<import("@haibun/core/build/lib/defs.js").TOKActionResult>;
|
|
29
|
+
};
|
|
30
|
+
stopMcpTools: {
|
|
31
|
+
gwta: string;
|
|
32
|
+
action: () => Promise<import("@haibun/core/build/lib/defs.js").TOKActionResult | import("@haibun/core/build/lib/defs.js").TNotOKActionResult>;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export default MCPServerStepper;
|
|
37
|
+
//# sourceMappingURL=mcp-server-stepper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-server-stepper.d.ts","sourceRoot":"","sources":["../src/mcp-server-stepper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAM,MAAM,EAAE,MAAM,gCAAgC,CAAC;AAE5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEjE,cAAM,gBAAiB,SAAQ,QAAS,YAAW,WAAW;IAC7D,QAAQ,EAAE,QAAQ,EAAE,CAAC;IACrB,SAAS,EAAE,iBAAiB,CAAC;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IAEpB,OAAO;;;0BAGS,MAAM;;;;;;2BAIL,MAAM;;;;MAErB;IAEI,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE;IAYlD,OAAO,CAAC,eAAe;IAWvB,KAAK;;;;;;;;;MAuBJ;CACD;AAED,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { AStepper } from '@haibun/core/build/lib/astepper.js';
|
|
2
|
+
import { OK } from '@haibun/core/build/lib/defs.js';
|
|
3
|
+
import { actionNotOK, getStepperOption, intOrError } from '@haibun/core/build/lib/util/index.js';
|
|
4
|
+
import { MCPExecutorServer } from './lib/mcp-executor-server.js';
|
|
5
|
+
class MCPServerStepper extends AStepper {
|
|
6
|
+
steppers;
|
|
7
|
+
mcpServer;
|
|
8
|
+
remotePort;
|
|
9
|
+
accessToken;
|
|
10
|
+
options = {
|
|
11
|
+
REMOTE_PORT: {
|
|
12
|
+
desc: 'Port for remote execution API',
|
|
13
|
+
parse: (port) => ({ result: parseInt(port, 10) }),
|
|
14
|
+
},
|
|
15
|
+
ACCESS_TOKEN: {
|
|
16
|
+
desc: 'Access token for remote execution API authentication',
|
|
17
|
+
parse: (token) => ({ result: token }),
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
async setWorld(world, steppers) {
|
|
21
|
+
await super.setWorld(world, steppers);
|
|
22
|
+
this.steppers = steppers;
|
|
23
|
+
this.remotePort = intOrError(getStepperOption(this, 'REMOTE_PORT', world.moduleOptions) || '').result || NaN;
|
|
24
|
+
this.accessToken = getStepperOption(this, 'ACCESS_TOKEN', world.moduleOptions);
|
|
25
|
+
if (!isNaN(this.remotePort) && !this.accessToken) {
|
|
26
|
+
throw new Error('ACCESS_TOKEN is required when REMOTE_PORT is configured for remote execution');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
getRemoteConfig() {
|
|
30
|
+
if (!isNaN(this.remotePort)) {
|
|
31
|
+
return {
|
|
32
|
+
url: `http://localhost:${this.remotePort}`,
|
|
33
|
+
accessToken: this.accessToken
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
steps = {
|
|
39
|
+
startMcpTools: {
|
|
40
|
+
gwta: `serve mcp tools from steppers`,
|
|
41
|
+
action: async () => {
|
|
42
|
+
const remoteConfig = this.getRemoteConfig();
|
|
43
|
+
this.mcpServer = new MCPExecutorServer(this.steppers, this.world, remoteConfig);
|
|
44
|
+
void this.mcpServer.start();
|
|
45
|
+
return Promise.resolve(OK);
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
stopMcpTools: {
|
|
49
|
+
gwta: `stop mcp tools`,
|
|
50
|
+
action: async () => {
|
|
51
|
+
if (this.mcpServer) {
|
|
52
|
+
await this.mcpServer.server.close();
|
|
53
|
+
this.mcpServer = undefined;
|
|
54
|
+
return OK;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
return actionNotOK('MCP server is not running');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export default MCPServerStepper;
|
|
64
|
+
//# sourceMappingURL=mcp-server-stepper.js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|
+
import { TStepperStep } from '@haibun/core/build/lib/defs.js';
|
|
3
|
+
declare class TestStepper extends AStepper {
|
|
4
|
+
steps: {
|
|
5
|
+
[name: string]: TStepperStep;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export default TestStepper;
|
|
9
|
+
//# sourceMappingURL=mcp-test-stepper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-test-stepper.d.ts","sourceRoot":"","sources":["../src/mcp-test-stepper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAM,MAAM,gCAAgC,CAAC;AAElE,cAAM,WAAY,SAAQ,QAAQ;IACjC,KAAK,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAAC;KAAE,CAatC;CACF;AAED,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AStepper } from '@haibun/core/build/lib/astepper.js';
|
|
2
|
+
import { OK } from '@haibun/core/build/lib/defs.js';
|
|
3
|
+
class TestStepper extends AStepper {
|
|
4
|
+
steps = {
|
|
5
|
+
yourTestPhrasePasses: {
|
|
6
|
+
gwta: 'your test phrase passes',
|
|
7
|
+
action: async () => {
|
|
8
|
+
return Promise.resolve(OK);
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
yourTestPhraseFails: {
|
|
12
|
+
gwta: 'your test phrase fails',
|
|
13
|
+
action: async () => {
|
|
14
|
+
return Promise.resolve(OK);
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export default TestStepper;
|
|
20
|
+
//# sourceMappingURL=mcp-test-stepper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-test-stepper.js","sourceRoot":"","sources":["../src/mcp-test-stepper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAC9D,OAAO,EAAgB,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAElE,MAAM,WAAY,SAAQ,QAAQ;IACjC,KAAK,GAAsC;QAC1C,oBAAoB,EAAE;YACrB,IAAI,EAAE,yBAAyB;YAC/B,MAAM,EAAE,KAAK,IAAI,EAAE;gBAClB,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YAC5B,CAAC;SACD;QACD,mBAAmB,EAAE;YACpB,IAAI,EAAE,wBAAwB;YAC9B,MAAM,EAAE,KAAK,IAAI,EAAE;gBAClB,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YAC5B,CAAC;SACD;KACD,CAAC;CACF;AAED,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const runtimeStdio: (port?: number) => string;
|
|
2
|
+
export declare const TEST_PORTS: {
|
|
3
|
+
readonly MCP_REMOTE_EXECUTOR: 12300;
|
|
4
|
+
readonly MCP_REMOTE_EXECUTION: 12310;
|
|
5
|
+
readonly MCP_CLIENT_LIST_TOOLS: 12342;
|
|
6
|
+
readonly MCP_CLIENT_PROMPTER: 12341;
|
|
7
|
+
readonly MCP_TOOL_EXECUTION: 12350;
|
|
8
|
+
readonly MCP_TOOL_EXECUTION_ALT: 12351;
|
|
9
|
+
readonly MCP_CLIENT_LIFECYCLE: 12360;
|
|
10
|
+
readonly MCP_HTTP_PROMPTER_TEST: 12370;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=mcp-test-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-test-utils.d.ts","sourceRoot":"","sources":["../src/mcp-test-utils.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,WAoBzC,CAAA;AAGD,eAAO,MAAM,UAAU;;;;;;;;;CASb,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// used to configure the client to start the STUDIO server, which is a Haibun stepper
|
|
2
|
+
export const runtimeStdio = (port) => {
|
|
3
|
+
const listening = port ? {
|
|
4
|
+
'HAIBUN_O_HTTPEXECUTORSTEPPER_LISTEN_PORT': port.toString(),
|
|
5
|
+
'HAIBUN_O_HTTPEXECUTORSTEPPER_ACCESS_TOKEN': 'test-token-client'
|
|
6
|
+
} : {};
|
|
7
|
+
const config = {
|
|
8
|
+
command: process.execPath,
|
|
9
|
+
env: {
|
|
10
|
+
'HAIBUN_O_WEBPLAYWRIGHT_STORAGE': 'StorageMem',
|
|
11
|
+
'HAIBUN_O_WEBPLAYWRIGHT_HEADLESS': 'true',
|
|
12
|
+
...listening
|
|
13
|
+
},
|
|
14
|
+
args: [
|
|
15
|
+
"modules/cli/build/cli.js",
|
|
16
|
+
'--cwd',
|
|
17
|
+
'modules/mcp/runtime',
|
|
18
|
+
port ? 'http' : 'local',
|
|
19
|
+
],
|
|
20
|
+
};
|
|
21
|
+
return JSON.stringify(config, null, 2);
|
|
22
|
+
};
|
|
23
|
+
export const TEST_PORTS = {
|
|
24
|
+
MCP_REMOTE_EXECUTOR: 12300,
|
|
25
|
+
MCP_REMOTE_EXECUTION: 12310,
|
|
26
|
+
MCP_CLIENT_LIST_TOOLS: 12342,
|
|
27
|
+
MCP_CLIENT_PROMPTER: 12341,
|
|
28
|
+
MCP_TOOL_EXECUTION: 12350,
|
|
29
|
+
MCP_TOOL_EXECUTION_ALT: 12351,
|
|
30
|
+
MCP_CLIENT_LIFECYCLE: 12360,
|
|
31
|
+
MCP_HTTP_PROMPTER_TEST: 12370,
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=mcp-test-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-test-utils.js","sourceRoot":"","sources":["../src/mcp-test-utils.ts"],"names":[],"mappings":"AAEA,qFAAqF;AACrF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAa,EAAE,EAAE;IAC7C,MAAM,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC;QACxB,0CAA0C,EAAE,IAAI,CAAC,QAAQ,EAAE;QAC3D,2CAA2C,EAAE,mBAAmB;KAChE,CAAC,CAAC,CAAC,EAAE,CAAC;IACP,MAAM,MAAM,GAA0B;QACrC,OAAO,EAAE,OAAO,CAAC,QAAQ;QACzB,GAAG,EAAE;YACJ,gCAAgC,EAAE,YAAY;YAC9C,iCAAiC,EAAE,MAAM;YACzC,GAAG,SAAS;SACZ;QACD,IAAI,EAAE;YACL,0BAA0B;YAC1B,OAAO;YACP,qBAAqB;YACrB,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO;SACvB;KACD,CAAA;IACD,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AACxC,CAAC,CAAA;AAGD,MAAM,CAAC,MAAM,UAAU,GAAG;IACzB,mBAAmB,EAAE,KAAK;IAC1B,oBAAoB,EAAE,KAAK;IAC3B,qBAAqB,EAAE,KAAK;IAC5B,mBAAmB,EAAE,KAAK;IAC1B,kBAAkB,EAAE,KAAK;IACzB,sBAAsB,EAAE,KAAK;IAC7B,oBAAoB,EAAE,KAAK;IAC3B,sBAAsB,EAAE,KAAK;CACpB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-handler-stepper.d.ts","sourceRoot":"","sources":["../src/prompt-handler-stepper.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-handler-stepper.js","sourceRoot":"","sources":["../src/prompt-handler-stepper.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-constants.d.ts","sourceRoot":"","sources":["../src/test-constants.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-constants.js","sourceRoot":"","sources":["../src/test-constants.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@haibun/mcp",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.67.0",
|
|
5
|
+
"description": "haibun mcp server and client steppers",
|
|
6
|
+
"main": "build/mcp-server-stepper.js",
|
|
7
|
+
"files": ["build/**"],
|
|
8
|
+
"scripts": {
|
|
9
|
+
"prepublishOnly": "tsc -b .",
|
|
10
|
+
"build": "tsc -b .",
|
|
11
|
+
"build-watch": "tsc -b --watch .",
|
|
12
|
+
"lint": "eslint -c .eslintrc.json --ext .ts,.js src",
|
|
13
|
+
"preversion": "npm run lint",
|
|
14
|
+
"test": "vitest run",
|
|
15
|
+
"test-watch": "vitest"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [],
|
|
18
|
+
"author": "",
|
|
19
|
+
"license": "ISC",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@haibun/core": "1.67.0",
|
|
22
|
+
"@modelcontextprotocol/sdk": "^1.13.0",
|
|
23
|
+
"zod": "^3.25.67"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@haibun/storage-mem": "1.67.0",
|
|
27
|
+
"@types/node": "^22.14.0",
|
|
28
|
+
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
29
|
+
"@typescript-eslint/parser": "^7.18.0",
|
|
30
|
+
"eslint": "^8.57.0",
|
|
31
|
+
"eslint-config-airbnb-typescript": "^18.0.0",
|
|
32
|
+
"eslint-config-prettier": "^10.1.1",
|
|
33
|
+
"eslint-plugin-import": "^2.31.0",
|
|
34
|
+
"eslint-plugin-prefer-arrow": "^1.2.3",
|
|
35
|
+
"eslint-plugin-prettier": "^5.2.6",
|
|
36
|
+
"prettier": "^3.5.3",
|
|
37
|
+
"typescript": "^5.8.2",
|
|
38
|
+
"vitest": "^3.1.1"
|
|
39
|
+
}
|
|
40
|
+
}
|