-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstub-server.mjs
More file actions
executable file
·91 lines (85 loc) · 2.21 KB
/
Copy pathstub-server.mjs
File metadata and controls
executable file
·91 lines (85 loc) · 2.21 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env node
// Package-verification stub for stdio MCP. Connect to
// https://api.twexapi.io/mcp for live requests.
import { createInterface } from "node:readline";
const SERVER_INFO = { name: "twexapi", version: "0.1.0" };
const JSONRPC = "2.0";
const LIVE =
"This package is a verification stub. Add https://api.twexapi.io/mcp to your MCP client. Use x-api-key or Bearer auth for live API access.";
const TOOLS = [
{
name: "explore",
description:
"Search the TwexAPI REST catalog. The live tool returns endpoint names, methods, paths, and safety flags. This stub returns setup guidance only.",
inputSchema: {
type: "object",
properties: {
query: { type: "string" },
category: { type: "string" },
include_writes: { type: "boolean" },
},
},
},
{
name: "twexapi_request",
description:
"Call an allowlisted TwexAPI REST endpoint. This stub does not send network requests.",
inputSchema: {
type: "object",
properties: {
method: { type: "string" },
path: { type: "string" },
query: { type: "object" },
body: {},
},
required: ["method", "path"],
},
},
];
function reply(id, result) {
process.stdout.write(JSON.stringify({ jsonrpc: JSONRPC, id, result }) + "\n");
}
function fail(id, message) {
process.stdout.write(
JSON.stringify({
jsonrpc: JSONRPC,
id,
error: { code: -32601, message },
}) + "\n",
);
}
const rl = createInterface({ input: process.stdin, terminal: false });
rl.on("line", (line) => {
let msg;
try {
msg = JSON.parse(line);
} catch {
return;
}
const { id, method } = msg;
if (method === "initialize") {
reply(id, {
protocolVersion: "2025-11-25",
capabilities: { tools: {} },
serverInfo: SERVER_INFO,
});
return;
}
if (method === "notifications/initialized") return;
if (method === "tools/list") {
reply(id, { tools: TOOLS });
return;
}
if (method === "tools/call") {
reply(id, {
content: [{ type: "text", text: LIVE }],
isError: false,
});
return;
}
if (method === "ping") {
reply(id, {});
return;
}
fail(id, `Unknown method: ${method}`);
});