{"record":{"id":"53484eaec5fe2a15","repo":"Hmbown/CodeWhale","slug":"mcp-sse-rejected-transport-http-url-status","errorCode":null,"errorMessage":"MCP SSE rejected (transport=http url={} status={}): {}","messagePattern":"MCP SSE rejected \\(transport=http url=(.+?) status=(.+?)\\): (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/mcp/sse.rs","lineNumber":124,"sourceCode":"            &headers,\n        );\n        let response = tokio::select! {\n            biased;\n            _ = cancel_token.cancelled() => {\n                anyhow::bail!(\"MCP SSE connect cancelled before the request completed\")\n            }\n            response = client.send(request) => response.with_context(|| {\n                format!(\n                    \"MCP SSE connect failed (transport=http url={})\",\n                    mask_url_secrets(&url),\n                )\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 body_excerpt = auth.server_error_preview(&body_excerpt);\n            anyhow::bail!(\n                \"MCP SSE rejected (transport=http url={} status={}): {}\",\n                mask_url_secrets(&url),\n                status,\n                body_excerpt,\n            );\n        }\n\n        let mut stream = response.bytes_stream();\n        use futures_util::StreamExt;\n        // Raw byte buffer so a multi-byte UTF-8 char split across reads is not\n        // corrupted, and bounded so a separator-less server cannot OOM us.\n        let mut buffer: Vec<u8> = Vec::new();\n\n        loop {\n            if cancel_token.is_cancelled() {\n                tracing::debug!(\"SSE loop cancelled\");\n                break;\n            }","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/mcp/sse.rs#L106-L142","documentation":"The MCP SSE endpoint answered the initial HTTP request with a non-success status. The error includes the masked URL, HTTP status, and a bounded body excerpt (filtered through the auth layer to strip secrets), then aborts the connect.","triggerScenarios":"Server returns 401/403 (missing or expired auth), 404 (wrong path), 5xx (server error) on the SSE endpoint URL; calling the SSE URL behind a reverse proxy that rejects the request.","commonSituations":"Expired OAuth token or revoked access; wrong SSE path in the MCP server config (e.g. `/mcp` vs `/sse`); server down or behind an authenticating proxy returning 403.","solutions":["Read the status and body excerpt: 401/403 → re-run OAuth or fix bearer token; 404 → fix the URL path in the server config; 5xx → retry later or check server health","Verify the configured URL is the SSE endpoint the server actually exposes","Check proxy/auth middleware in front of the MCP server allows the SSE route and Accept header"],"exampleFix":"// before\n{\"mcpServers\": {\"x\": {\"url\": \"https://host/api/mcp/stream\"}}}\n// after\n{\"mcpServers\": {\"x\": {\"url\": \"https://host/sse\"}}}","handlingStrategy":"try-catch","validationCode":"// pre-flight\nlet resp = reqwest::Client::new().get(&url).send().await?;\nif !resp.status().is_success() {\n    return Err(anyhow!(\"MCP endpoint unhealthy: {}\", resp.status()));\n}","typeGuard":null,"tryCatchPattern":"match run_sse_loop(...).await {\n    Err(e) if e.to_string().contains(\"status=\") => {\n        if e.to_string().contains(\"status=401\") || e.to_string().contains(\"status=403\") {\n            // re-run OAuth then retry once\n        } else { return Err(e); }\n    }\n    other => other?,\n}","preventionTips":["Pre-flight check the SSE URL returns a success status","Re-authenticate before the token expires","Confirm the URL path is the server's actual SSE endpoint"],"tags":["mcp","sse","http","auth"],"backgroundTag":"http-error-response","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"}