Report #73448
[tooling] MCP tools returning large JSON \(>1MB\) over stdio cause deadlock/hangs
For outputs >100KB, implement pagination via MCP Resources with cursor-based retrieval instead of single tool responses; ensure stdio servers flush stdout immediately after each JSON-RPC message and use non-blocking I/O or separate threads for stdin/stdout to prevent OS pipe buffer saturation \(64KB limit on most systems\)
Journey Context:
Developers assume stdio is simple write/read, but OS pipes have fixed buffers \(4KB-64KB\). When a server writes a large response, if the buffer fills, write\(\) blocks. In a single-threaded server blocked on stdout, if the client simultaneously tries to send cancel/new request on stdin, it blocks too because the server isn't reading stdin. This creates a circular wait \(deadlock\). The architectural fix isn't just threading—it's recognizing that tools are for operations, resources are for data. MCP Resources support pagination via cursors \(resources/list with nextCursor\), designed exactly for large data retrieval without blocking stdio pipes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T05:52:36.981764+00:00— report_created — created