// src/mcp-entry.ts // The one reading of "does this MCP server entry start node9, and how". // // node9 owns two kinds of entries in an agent's MCP config: its own server // (`node9 mcp-server`) and the wraps (`node9 mcp-gateway --upstream `). // Several pieces of code must recognise them: the inventory (status, pins, the // daemon's reconciler), the setup and teardown flows, doctor's wiring table and // posture. Each used to carry its own test, and they disagreed: an entry that // pins its Node (` mcp-server`, the only form that starts // where the agent's PATH holds an old Node) was node9's to posture and a // third-party server to everything else, so the reconciler nudged about // node9's own server and `mcp gateway --all` offered to wrap it. // // A leaf module on purpose: no imports from setup, agent-wiring or mcp-wrap, // which already import each other. // ── Wrap vocabulary ─────────────────────────────────────────────────────────── // The subcommand that actually accepts `--upstream`. `node9 mcp` is a PARENT // command (gateway | ungateway | status | pin) and has no such option, so a // wrap written as `node9 mcp --upstream ` dies on startup with // `error: unknown option '--upstream'`. Every agent's wrap carried that form. // // The damage is worse than lost governance: node9 REPLACES the user's server // command, so the wrap also broke the very server it was meant to protect. // Found 2026-09-22 in Codex's own log, not in ours — node9 had no idea the // server it wrapped was failing to start. export const MCP_WRAP_SUBCOMMAND = 'mcp-gateway'; export const LEGACY_MCP_WRAP_SUBCOMMAND = 'mcp'; const MCP_SERVER_SUBCOMMAND = 'mcp-server'; // Recognises the legacy subcommand too. An install still carrying it must read // back as OURS — otherwise teardown stops unwrapping it and the user is left // with a dead server and no way to undo it. export function isMcpWrapSubcommand(arg: unknown): boolean { return arg === MCP_WRAP_SUBCOMMAND || arg === LEGACY_MCP_WRAP_SUBCOMMAND; } // ── Launch forms ────────────────────────────────────────────────────────────── export type Node9LaunchForm = /** The node9 bin: bare `node9`, a path to it, or a Windows wrapper. */ | 'bin' /** `~/.node9/bin/node9`, the fixed path that pins the Node. */ | 'launcher' /** `~/.node9/bin/hook`, the hook shim, used as an MCP command. */ | 'hook-shim' /** A Node runtime in front of the node9 script: `node