{"record":{"id":"7a2090b66d6b20a5","repo":"openai/codex","slug":"mcp-response-body-exceeds-maximum-bytes-bytes","errorCode":null,"errorMessage":"MCP response body exceeds {maximum_bytes} bytes","messagePattern":"MCP response body exceeds (.+?) bytes","errorType":"exception","errorClass":"StreamableHttpClientAdapterError","httpStatus":null,"severity":"error","filePath":"codex-rs/rmcp-client/src/http_client_adapter.rs","lineNumber":112,"sourceCode":"\nimpl Drop for EventStreamCancellation {\n    fn drop(&mut self) {\n        self.cancellations\n            .lock()\n            .unwrap_or_else(PoisonError::into_inner)\n            .remove(&self.request_id);\n    }\n}\n\n#[derive(Debug, thiserror::Error)]\npub(crate) enum StreamableHttpClientAdapterError {\n    #[error(\"streamable HTTP session expired with 404 Not Found\")]\n    SessionExpired404,\n    #[error(transparent)]\n    HttpRequest(#[from] ExecServerError),\n    #[error(\"invalid HTTP header: {0}\")]\n    Header(String),\n    #[error(\"MCP response body exceeds {maximum_bytes} bytes\")]\n    ResponseTooLarge { maximum_bytes: usize },\n}\n\nimpl StreamableHttpClientAdapter {\n    pub(crate) fn new(\n        http_client: Arc<dyn HttpClient>,\n        default_headers: HeaderMap,\n        auth_provider: Option<SharedAuthProvider>,\n        has_configured_headers: bool,\n        redirect_mode: StreamableHttpRedirectMode,\n        initialize_deadline: Arc<Mutex<Option<Instant>>>,\n    ) -> Self {\n        Self {\n            http_client: Arc::new(SameOriginRedirectHttpClient::new(http_client)),\n            default_headers,\n            auth_provider,\n            event_stream_cancellations: Arc::default(),\n            has_configured_headers,","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/openai/codex/blob/339751715c64496cb86246bfb3935f40e309dd3d/codex-rs/rmcp-client/src/http_client_adapter.rs#L94-L130","documentation":"collect_body() buffers non-streaming JSON bodies — POST application/json responses, server/discover, and events/stream requests — and enforces a hard cap: MAX_MCP_STDIO_LINE_BYTES for discovery/modern-protocol (2026-07-28) requests and MAX_EVENT_NOTIFICATION_BYTES for event-stream requests. When the accumulated body would cross maximum_bytes, the adapter returns ResponseTooLarge with the limit instead of letting a hostile or misconfigured server exhaust orchestrator memory.","triggerScenarios":"A server/discover or modern-protocol JSON response, or an events/stream POST body, whose total size exceeds the configured maximum; raised at the first chunk that makes body.len() pass maximum_bytes in collect_body().","commonSituations":"Very large tools/list or discovery payloads (thousands of embedded tool schemas); servers inlining base64 blobs or whole resources into one response; a wrong endpoint returning an HTML page; proxies that buffer and re-send giant error payloads.","solutions":["Shrink the server response: paginate tools/list, trim tool descriptions/schemas, stop inlining large content","Verify the configured URL is a real MCP endpoint, not a page that returns a huge body","Move large payloads out-of-band (resource URIs fetched separately)","If you hit this on discovery only, check whether the server supports the modern protocol path so limits apply correctly"],"exampleFix":"# before: tools/list returns every tool with full schemas in one body -> ResponseTooLarge\n# after: request pages\n{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"tools/list\",\"params\":{\"cursor\":\"...\",\"limit\":100}}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"fn is_response_too_large(error: &rmcp::service::ServiceError) -> bool {\n    error.to_string().contains(\"MCP response body exceeds\")\n}","tryCatchPattern":"match client.list_tools(Default::default()).await {\n    Ok(tools) => Ok(tools),\n    Err(e) if e.to_string().contains(\"MCP response body exceeds\") => {\n        // server payload too big: reduce it (pagination/trimming), then retry\n        Err(anyhow!(e).context(\"MCP response too large; shrink server payload\"))\n    }\n    Err(e) => Err(e.into()),\n}","preventionTips":["Paginate tools/list and trim tool descriptions server-side","Never inline large base64 content in responses","Smoke-test your server with realistic data volumes before shipping","Watch this error in staging — it only appears with production-scale payloads"],"tags":["rust","mcp","streamable-http","response-size","memory-limit"],"backgroundTag":"response-body-too-large","analyzedSha":"339751715c64496cb86246bfb3935f40e309dd3d","analyzedAt":"2026-08-25T05:35:09.876Z","schemaVersion":2},"datasetVersion":"2026-08-25T06:17:31.827Z"}