Files
mesh-tools/node-tools/test/fixtures/whole-bundle.py
T
jschoubben d9fe2568de T3 whole: the tool runner is started by its entry against an embedded bus
main's body is `serve(ctx)`, which the process calls with the service manager's signals and one integration test calls with a
credential file and the node-engine's environment: it serves a bundle's tool and seat verbs over a seat list read from a stand-in of
the seat mesh-catalog, waits a verb its definition's timeout, and rereads the list for a verb the first read does not name.

Builds: design 47 H §774, §760, H-A-16, H-A-61

Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
2026-11-20 02:44:40 +01:00

40 lines
2.1 KiB
Python
Executable File

#!/usr/bin/env python3
# A tools bundle for the tool runner's whole test (design 47 H §774): MCP over stdio, no SDK. A tool `who`, the seat node-desk's verbs
# `who` (answers at once) and `slow` (answers after three seconds), and a tool `reach` that asks the seat verb node-desk.fresh as the
# bundle does, through the runtime's `mesh/ask`, and says what came back.
import json, sys, time
def say(m):
m["jsonrpc"] = "2.0"; sys.stdout.write(json.dumps(m) + "\n"); sys.stdout.flush()
def text(rid, value):
say({"id": rid, "result": {"content": [{"type": "text", "text": json.dumps(value)}]}})
TOOLS = [
{"name": "who", "description": "the module's own tool", "inputSchema": {"type": "object", "properties": {}}},
{"name": "reach", "description": "asks the seat verb node-desk.fresh", "inputSchema": {"type": "object", "properties": {}}},
{"name": "node-desk.who", "description": "the seat's verb", "inputSchema": {"type": "object", "properties": {}}},
{"name": "node-desk.slow", "description": "the seat's verb that answers late", "inputSchema": {"type": "object", "properties": {}}},
]
for line in sys.stdin:
req = json.loads(line); rid = req.get("id"); m = req.get("method"); p = req.get("params") or {}
if m == "initialize":
say({"id": rid, "result": {"protocolVersion": "2025-03-26", "capabilities": {"tools": {}}, "serverInfo": {"name": "ledger", "version": "1"}}})
elif m == "tools/list":
say({"id": rid, "result": {"tools": TOOLS}})
elif m == "tools/call":
name = p.get("name")
if name == "node-desk.slow":
time.sleep(3)
if name == "reach":
say({"id": "q1", "method": "mesh/ask", "params": {"key": "seat:node-desk.fresh", "body": {}}})
for answer in sys.stdin:
a = json.loads(answer)
if a.get("id") == "q1":
text(rid, a.get("result") if "error" not in a else {"error": a["error"]})
break
else:
text(rid, {"tool": name})
elif rid is not None:
say({"id": rid, "result": {}})