# Minimal stdio MCP server: records its own lifetime so the driver can see when Codex stops it.
import json, os, sys, time, signal
log = os.environ["STUB_LOG"]
def note(msg):
    with open(log, "a") as f: f.write(f"{time.time():.1f} pid={os.getpid()} {msg}\n")
note("started")
signal.signal(signal.SIGTERM, lambda *a: (note("SIGTERM"), sys.exit(0)))
for line in sys.stdin:
    try: req = json.loads(line)
    except Exception: continue
    if "id" not in req: continue
    m = req.get("method")
    if m == "initialize":
        res = {"protocolVersion": req["params"].get("protocolVersion", "2025-06-18"), "capabilities": {"tools": {}}, "serverInfo": {"name": "stub", "version": "0"}}
    elif m == "tools/list": res = {"tools": []}
    else: res = {}
    sys.stdout.write(json.dumps({"jsonrpc": "2.0", "id": req["id"], "result": res}) + "\n"); sys.stdout.flush()
note("stdin closed")
