Files
mesh-tools/node-tools/test/fixtures/caller-echo.py
T
jschoubben 2365e41811 Copy the kept call's ask id from its request header into the call's _meta as mesh/ask
Every tool call and seat verb the tool runner serves hands the bundle the ask id the kept call set
in the header x-ask (stdio.AskHeader) under _meta mesh/ask (stdio.MetaAsk), beside mesh/call; a call
whose header carries none names none.

Builds: design 47 H2 §775, H-A-351
2026-11-21 23:14:53 +01:00

27 lines
1.5 KiB
Python
Executable File

#!/usr/bin/env python3
# A tools bundle that says who the runtime said called it (novox/hq issue 365): MCP over stdio, no SDK. Its tool
# and its seat verb answer the caller the call's `_meta` named — "" when it named none —, the id of the call in flight
# it named (novox/hq ADR 0597 §7), the ask id it named under mesh/ask — null when it named none (design 47 H2 §775, H-A-351) —,
# and the arguments as given.
import json, sys
def say(m):
m["jsonrpc"] = "2.0"; sys.stdout.write(json.dumps(m) + "\n"); sys.stdout.flush()
TOOLS = [
{"name": "who", "description": "who called", "inputSchema": {"type": "object", "properties": {}}},
{"name": "node-desk.who", "description": "who called the seat's verb", "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":
meta = p.get("_meta") or {}
said = {"caller": meta.get("mesh/caller", ""), "call": meta.get("mesh/call", ""), "ask": meta.get("mesh/ask"), "arguments": p.get("arguments") or {}}
say({"id": rid, "result": {"content": [{"type": "text", "text": json.dumps(said)}]}})
elif rid is not None:
say({"id": rid, "result": {}})