{"record":{"id":"5524276bd2e5448a","repo":"Hmbown/CodeWhale","slug":"mcp-sse-post-rejected-transport-sse-endpoint-s","errorCode":null,"errorMessage":"MCP SSE POST rejected (transport=sse endpoint={} status={}): {}","messagePattern":"MCP SSE POST rejected \\(transport=sse endpoint=(.+?) status=(.+?)\\): (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/mcp/sse.rs","lineNumber":306,"sourceCode":"            format!(\n                \"MCP SSE POST send failed (transport=sse endpoint={})\",\n                mask_url_secrets(&endpoint)\n            )\n        })?;\n        let status = response.status();\n        if !status.is_success() {\n            let body_excerpt = bounded_body_excerpt(response, ERROR_BODY_PREVIEW_BYTES).await;\n            let stale_session = is_mcp_stale_session_body(&body_excerpt);\n            let body_excerpt = self.auth.server_error_preview(&body_excerpt);\n            if stale_session {\n                anyhow::bail!(\n                    \"MCP session expired (transport=sse endpoint={} status={}): {}\",\n                    mask_url_secrets(&endpoint),\n                    status,\n                    body_excerpt\n                );\n            }\n            anyhow::bail!(\n                \"MCP SSE POST rejected (transport=sse endpoint={} status={}): {}\",\n                mask_url_secrets(&endpoint),\n                status,\n                body_excerpt\n            );\n        }\n        Ok(())\n    }\n\n    async fn recv(&mut self) -> Result<Vec<u8>> {\n        loop {\n            match self.receiver.recv().await.context(\"SSE transport closed\")? {\n                SseInbound::Endpoint(endpoint) => {\n                    self.store_endpoint(&endpoint)?;\n                }\n                SseInbound::Message(msg) => return Ok(msg),\n            }\n        }","sourceCodeStart":288,"sourceCodeEnd":324,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/8880682c63083a91624de936797efa3ce9e498fd/crates/tui/src/mcp/sse.rs#L288-L324","documentation":"The POST delivering a JSON-RPC message to the SSE endpoint returned a non-2xx status that is NOT classified as a stale session (no 'session expired/invalid' text in the body). The message carries the masked endpoint URL, the status, and a bounded, secret-scrubbed body excerpt for diagnosis.","triggerScenarios":"POST to the endpoint event's URL answers 401/403 (auth header rejected), 400 (server rejects the JSON-RPC payload), 413, or a 5xx while processing a specific tool call.","commonSituations":"Token expired or revoked between connect and send; gateway rules (size, auth) on the POST route; server-side exception triggered by one particular tool call or resource read.","solutions":["Read the status and body excerpt embedded in the message — they state the actual failure","On 401/403: refresh OAuth credentials and reconnect","On 400: log the exact request JSON; the payload likely violates the server's schema for that method","On 5xx: check server logs and retry with backoff once the server recovers"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"```rust\nfn sse_post_status(err: &anyhow::Error) -> Option<u16> {\n    let msg = format!(\"{err:#}\");\n    msg.split(\"status=\").nth(1)?.split(']').next()?  // e.g. \"404): ...\"\n        .chars().take_while(char::is_ascii_digit)\n        .collect::<String>().parse().ok()\n}\n```","tryCatchPattern":"```rust\nmatch transport.send(payload).await {\n    Err(e) if e.to_string().contains(\"MCP SSE POST rejected\") => match sse_post_status(&e) {\n        Some(s) if (500..600).contains(&s) => retry_with_backoff().await,\n        Some(401) | Some(403) => reauthenticate_and_reconnect().await,\n        _ => { log_body_excerpt(&e); return Err(e); }\n    },\n    other => other,\n}\n```","preventionTips":["Log the embedded body excerpt verbatim — it is already bounded and secret-scrubbed","Refresh auth before long sessions to avoid mid-session 401/403 POST failures"],"tags":["mcp","sse","http","send-failure"],"backgroundTag":null,"analyzedSha":"8880682c63083a91624de936797efa3ce9e498fd","analyzedAt":"2026-08-16T11:31:27.956Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}