{"record":{"id":"d09585e2cd2be006","repo":"Hmbown/CodeWhale","slug":"mcp-response-content-length-len-exceeds-bytes","errorCode":null,"errorMessage":"MCP response Content-Length {len} exceeds {} bytes — aborting","messagePattern":"MCP response Content-Length (.+?) exceeds (.+?) bytes — aborting","errorType":"validation","errorClass":"StreamableSendError::Other","httpStatus":null,"severity":"error","filePath":"crates/tui/src/mcp/streamable_http.rs","lineNumber":169,"sourceCode":"                    mask_url_secrets(&self.url),\n                    status,\n                    body_excerpt,\n                )));\n            }\n\n            let content_type = response\n                .headers()\n                .get(CONTENT_TYPE)\n                .and_then(|value| value.to_str().ok())\n                .map(str::to_string);\n            // Reject an over-large declared body before reading anything (fast\n            // path), then bound the read itself so chunked / length-less\n            // responses cannot OOM us either — Content-Length alone does not\n            // protect against a server that streams without declaring a length.\n            if let Some(len) = response.content_length()\n                && len > MAX_MCP_RESPONSE_BYTES as u64\n            {\n                return Err(StreamableSendError::Other(anyhow::anyhow!(\n                    \"MCP response Content-Length {len} exceeds {} bytes — aborting\",\n                    MAX_MCP_RESPONSE_BYTES\n                )));\n            }\n            let body = read_body_capped(response, MAX_MCP_RESPONSE_BYTES)\n                .await\n                .map_err(StreamableSendError::Other)?;\n            return self\n                .store_response_body(content_type.as_deref(), &body)\n                .map_err(StreamableSendError::Other);\n        }\n    }\n\n    pub(super) async fn recv(&mut self) -> Result<Vec<u8>> {\n        self.pending_messages\n            .pop_front()\n            .context(\"MCP Streamable HTTP response queue is empty\")\n    }","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/mcp/streamable_http.rs#L151-L187","documentation":"MCP responses are capped at MAX_MCP_RESPONSE_BYTES to prevent memory exhaustion. When the HTTP response declares a Content-Length above the cap, the client aborts before reading any body and raises this error. A separate capped reader (read_body_capped) additionally guards against length-less/chunked oversized streams.","triggerScenarios":"send() receives a response whose content_length() exceeds MAX_MCP_RESPONSE_BYTES — i.e. the MCP server (or a proxy in front of it) returned a body larger than the configured maximum.","commonSituations":"A misconfigured endpoint returning a huge non-MCP payload (e.g. a data dump or log file); proxy injecting a large error page; genuinely huge tool result from a runaway server tool.","solutions":["Check what the server is returning — a multi-megabyte MCP response usually indicates a misbehaving tool or wrong endpoint","Fix or bound the server-side tool that produces the oversized response","If the deployment legitimately needs larger responses, raise MAX_MCP_RESPONSE_BYTES deliberately"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// before sending, sanity-check the endpoint returns bounded payloads:\n// HEAD the URL and reject if Content-Length exceeds MAX_MCP_RESPONSE_BYTES","typeGuard":null,"tryCatchPattern":"match client.send(request).await {\n    Err(e) if e.to_string().contains(\"exceeds\") && e.to_string().contains(\"aborting\") => {\n        // treat as server misbehavior; do not retry blindly, investigate the tool/endpoint\n    }\n    other => other?,\n}","preventionTips":["Bound tool outputs server-side so responses stay well under the cap","Verify the endpoint is a real MCP server, not an endpoint serving large files","Raise MAX_MCP_RESPONSE_BYTES only deliberately, with the deployment's memory budget in mind"],"tags":["http","response-size-limit","mcp","payload"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}