code wiki / (root) / nx_mcp_stdio.nx

nx_mcp_stdio.nx

buildroot/runtime/nx_mcp_stdio.nx

21774 B413 linesdepth 21pulls 150 transitivereach 1 importersview sourcekind tooltopic mcp
docsdependenciesstructsconstsfunctions

about

MCP stdio to sovereign HTTPS. The server remains the authority for discovery and capability checks. Each request runs in a child so the current TLS allocator cannot accumulate across a long session. FAILURE SEMANTICS (lane conn, 2026-09-11). A per-request failure -- a child that exits non-zero, the SIGALRM deadline, a non-2xx HTTP status, an over-budget response, a response-id mismatch, or a TLS/transport failure -- produces a JSON-RPC 2.0 error response for THAT request id on the protocol fd, and the connector KEEPS SERVING every other request. Two mechanisms, one shape: * the request CHILD self-reports soft failures (it knows the http status / byte limit) by writing a correlated error to its own pipe and exiting 0, so the parent forwards it like any response; * the PARENT (mp_recover_pump) turns a child that died WITHOUT self-reporting -- a crash, or the SIGALRM deadline killing it -- into a correlated error from that slot's pending id and continues. An oversized OR malformed request line is consumed to its newline and answered with -32600 for its id when the id is readable from the retained prefix; otherwise a stderr diagnostic. Notifications (no id) never get a response. Only broken stdin/stdout, poll failure, or allocation failure ends the process. Protocol-fd isolation (stdout dup'd away to stderr for library chatter, the real protocol pipe held on a private fd) and response-id correlation are preserved. No magic numbers: every code/limit is named.

dependencies 6 imports · 1 importers

nx_mcp_transport.nx nx_mcp_route.nx nx_mcp_sse.nx nx_request_pool.nx nx_mcp_control.nx nx_mcp_pending.nx nx_mcp_stdio.nx nx_mcp_queue_canonical_gate_t230.n

imports: nx_mcp_transport.nxnx_mcp_route.nxnx_mcp_sse.nxnx_request_pool.nxnx_mcp_control.nxnx_mcp_pending.nx

imported by: nx_mcp_queue_canonical_gate_t230.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main mr_equal mr_len ms_number mr_config mr_len ↻ mr_equal ↻ mc_puts mq_default_budget mq_new rp_new nx_ra_new sys_mmap nxa_die sys_write sys_exit nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable sys_write ↻ nxa_dump_sizes sys_write ↻ sys_munmap nx_ra_set_budget nx_ra_kind_is_valid nx_ra_set_max_share nx_ra_kind_is_valid ↻ ms_dispatch_queue mq_expire mq_unlink mq_error mpe_write_error mpe_write_error_detail mpe_slen mpe_cat

structs

56struct NxMcpErr { code: i64, stage: *u8, cause: *u8, measured: i64, next: *u8, http_data:*u8, http_n:i64 }

consts

24const MS_F_DUPFD_CLOEXEC: i64 = 1030
25const MS_FIRST_PRIVATE_FD: i64 = 3
26const MS_STDIN: i64 = 0
27const MS_STDOUT: i64 = 1
28const MS_STDERR: i64 = 2
33const MS_OK: i64 = 0
34const MS_DUP: i64 = 0 - 1
35const MS_FATAL: i64 = 10
39const MSE_CODE_TRANSPORT: i64 = 0 - 32001
40const MSE_CODE_HTTPSTATUS: i64 = 0 - 32002
41const MSE_CODE_PARSE: i64 = 0 - 32003
42const MSE_CODE_BODY: i64 = 0 - 32004
43const MSE_CODE_RESPSIZE: i64 = 0 - 32005
44const MSE_CODE_IDENTITY: i64 = 0 - 32006
45const MSE_CODE_TRUSTSTORE: i64 = 0 - 32007
46const MSE_CODE_CREDENTIAL: i64 = 0 - 32008
47const MSE_CODE_URL: i64 = 0 - 32009
48const MSE_CODE_ROUTE: i64 = 0 - 32010
49const MSE_CODE_PROTOWRITE: i64 = 0 - 32011
50const MSO_CODE_DUP: i64 = 0 - 32013
51const MSO_CODE_INVALID: i64 = 0 - 32600

functions

58func ms_number(s: *u8) -> i64
called by 1: main
73func ms_has_id(src: *u8, n: i64) -> i64
called by 1: ms_exchange
107func ms_exchange(base: *u8, capfile: *u8, body: *u8, body_n: i64, response_cap: i64, protocol_fd: i64, timeout_secs: i64, err: *NxMcpErr) -> i64
208func ms_request(base: *u8, capfile: *u8, body: *u8, body_n: i64, response_cap: i64, protocol_fd: i64, timeout_secs: i64, argc: i64, argv: *i64, route_first: i64, pool: *NxRequestPool, pending: *u8, control: *NxMcpControl) -> i64
243func ms_drain(pool: *NxRequestPool, pending: *u8, protocol_fd: i64, timeout_secs: i64) -> i64
calls 1: mp_recover_pump
251func ms_dispatch_queue(q:*NxMcpQueue,pool:*NxRequestPool,pending:*u8,protocol_fd:i64,timeout_secs:i64,response_cap:i64,argc:i64,argv:*i64,route_first:i64)->i64
269func main(argc: i64, argv: *i64) -> i64