-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecbox-mcp-provider.ts
More file actions
58 lines (51 loc) · 1.32 KB
/
execbox-mcp-provider.ts
File metadata and controls
58 lines (51 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import * as z from "zod";
import { openMcpToolProvider } from "@execbox/core/mcp";
import { QuickJsExecutor } from "@execbox/quickjs";
async function main(): Promise<void> {
const upstreamServer = new McpServer({
name: "upstream",
version: "1.0.0",
});
upstreamServer.registerTool(
"search-docs",
{
description: "Search documentation.",
inputSchema: {
query: z.string(),
},
outputSchema: {
hits: z.array(z.string()),
},
},
async (args) => ({
content: [{ text: `found ${args.query}`, type: "text" }],
structuredContent: {
hits: [args.query],
},
}),
);
const handle = await openMcpToolProvider({ server: upstreamServer });
try {
const executor = new QuickJsExecutor();
const execution = await executor.execute(
'(await mcp.search_docs({ query: "quickjs" })).structuredContent',
[handle.provider],
);
console.log("mcp provider example result");
console.log(
JSON.stringify(
{
execution,
namespace: handle.provider.name,
originalToSafeName: handle.provider.originalToSafeName,
},
null,
2,
),
);
} finally {
await handle.close();
}
}
void main();