#!/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": {}})