-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
79 lines (68 loc) · 2.77 KB
/
Copy pathserver.js
File metadata and controls
79 lines (68 loc) · 2.77 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
/**
* A plain MCP server with zero auth code.
* Three tools: list_files, read_file, write_file.
* The gateway handles all authentication in front of this.
*/
const express = require("express");
const app = express();
app.use(express.json());
// In-memory file store
const files = {
"hello.txt": "Hello from the MCP server!",
"secret.txt": "This file requires WRITE_DATA permission to modify.",
};
// JSON-RPC handler
app.post("/mcp", (req, res) => {
const { id, method, params } = req.body;
// Log auth headers from the gateway (if present)
const verified = req.headers["x-bolyra-verified"];
const did = req.headers["x-bolyra-did"];
if (verified) {
console.log(`[server] Verified agent: ${did || "unknown"}`);
}
if (method === "initialize") {
return res.json({
jsonrpc: "2.0", id,
result: {
protocolVersion: "2025-06-18",
serverInfo: { name: "quickstart-server", version: "1.0.0" },
capabilities: { tools: { listChanged: false } },
},
});
}
if (method === "tools/list") {
return res.json({
jsonrpc: "2.0", id,
result: {
tools: [
{ name: "list_files", description: "List all files", inputSchema: { type: "object", properties: {} } },
{ name: "read_file", description: "Read a file", inputSchema: { type: "object", properties: { name: { type: "string" } }, required: ["name"] } },
{ name: "write_file", description: "Write a file", inputSchema: { type: "object", properties: { name: { type: "string" }, content: { type: "string" } }, required: ["name", "content"] } },
],
},
});
}
if (method === "tools/call") {
const tool = params?.name;
const args = params?.arguments || {};
if (tool === "list_files") {
return res.json({ jsonrpc: "2.0", id, result: { content: [{ type: "text", text: Object.keys(files).join("\n") }] } });
}
if (tool === "read_file") {
const text = files[args.name];
if (!text) return res.json({ jsonrpc: "2.0", id, error: { code: -32602, message: `File not found: ${args.name}` } });
return res.json({ jsonrpc: "2.0", id, result: { content: [{ type: "text", text }] } });
}
if (tool === "write_file") {
files[args.name] = args.content;
return res.json({ jsonrpc: "2.0", id, result: { content: [{ type: "text", text: `Wrote ${args.name}` }] } });
}
return res.json({ jsonrpc: "2.0", id, error: { code: -32601, message: `Unknown tool: ${tool}` } });
}
res.json({ jsonrpc: "2.0", id, error: { code: -32601, message: `Unknown method: ${method}` } });
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`[server] MCP server running on http://localhost:${PORT}/mcp`);
console.log("[server] No auth code here -- the gateway handles that.");
});