#!/usr/bin/env node /** * MCP spawn-tee — in-process stderr capture + lifecycle observability. * * Claude Code spawns each MCP server itself; the platform never holds a * ChildProcess handle. This shim sits between Claude Code and the real MCP * server: Claude Code runs `node `, and the shim runs the * real entry IN ITS OWN PROCESS via dynamic import() — one node runtime, not * two. Before importing, it replaces process.stderr.write with a tee so every * stderr byte the server writes is mirrored to the log sinks; stdin and stdout * (the JSON-RPC channel) are never touched. * * Claude Code CLI → shim (this file) = node running in-process * stdin/stdout : untouched (JSON-RPC channel) * stderr : process.stderr.write teed → raw sink + passthrough * * Destinations: * - `${LOG_DIR}/mcp--.log` — raw stderr + lifecycle lines. * The sole raw sink. Task 1721 retired the per-date twin: its date was * pinned at spawn, no reader ever parsed it, and a since-removed stderr * tee wrote the same file, so every line landed twice. * - `${LOG_DIR}/mcp--nosession.log` — the same, for a spawn with * no SESSION_ID (enumeration). One fixed file per server. * - `server.log` via the loopback log-ingest route — best-effort mirror of * the [mcp-helper] lifecycle lines. * * Lifecycle lines, correlation key `session= server=` — unchanged: * [mcp-helper] op=spawn ... pid= entry= * [mcp-helper] op=boot ... head= * [mcp-helper] op=exit ... code= signal= lifetimeMs= stderr-tail= * * Process model (Task 989): the shim IS the server's process. op=exit fires * from process.on("exit"), so it covers a normal exit, a non-zero exit, an * uncaught throw (code 1), and a catchable-signal exit (SIGTERM/SIGINT/SIGHUP, * whose handlers record the signal name). An external SIGKILL is uncatchable * and leaves no op=exit line — the per-session stderr tail already on disk and * Claude Code's own transport-drop are the evidence for that death mode. * * The shim never writes to fd 1 (stdout) — that is the JSON-RPC channel. */ export {}; //# sourceMappingURL=index.d.ts.map