AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.
Rust agent-memoryai-agentsbm25claude-codeclicode-searchcursordatabaseelasticsearchfull-text-searchhybrid-searchjsonllocal-firstmcpmcp-servermodel-context-protocolragrustsearch-enginevector-search
fix(mcp): report a response body that could not be read (#2388)
Ahmet Adaklıb4c1d90fe46e
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 07b2dacaa..5cd28610f 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -67,6 +67,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0### Fixed+- `xerj mcp`: a proxied tool call whose response body cannot be read in+ full (the connection drops partway, or the request deadline fires+ mid-body) is now an error that names the URL and the cause. It used to+ come back as an empty *successful* result, which reads as "no matches".+- MCP calls to a loopback node (`127.0.0.1`, `localhost`, `::1`) no longerfollow `ALL_PROXY`, `HTTP_PROXY`, or `HTTPS_PROXY`. reqwest sends thoseaddresses through the proxy unless the client opts out, so a socks or HTTPdiff --git a/engine/crates/xerj-mcp/src/lib.rs b/engine/crates/xerj-mcp/src/lib.rsindex 59136b6d5..2e1b9e23f 100644--- a/engine/crates/xerj-mcp/src/lib.rs+++ b/engine/crates/xerj-mcp/src/lib.rs@@ -3378,7 +3378,21 @@ async fn engine_request(match req.send().await {Ok(resp) => {let status = resp.status();- let text = resp.text().await.unwrap_or_default();+ // The status line arrived, but the body may still fail (the+ // connection drops, the request deadline fires mid-body). An empty+ // string here would turn that into an empty *successful* result.+ let text = match resp.text().await {+ Ok(text) => text,+ Err(e) => {+ return tool_text(+ format!(+ "XERJ returned HTTP {status}, but the response body from {url} \+ could not be read: {e}"+ ),+ true,+ );+ }+ };if status.is_success() {let text = match demote_page {Some(page) => {@@ -3620,6 +3634,35 @@ mod tests {});}+ /// A 200 whose body cannot be read in full (the connection drops partway,+ /// or the request deadline fires mid-body) is a failure, not an empty+ /// successful result: an agent reading `isError: false` with no text would+ /// conclude the query matched nothing.+ #[tokio::test]+ async fn engine_request_reports_a_body_that_could_not_be_read() {+ let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();+ let addr = listener.local_addr().unwrap();+ tokio::spawn(async move {+ let Ok((mut sock, _)) = listener.accept().await else {+ return;+ };+ let mut buf = vec![0u8; 8192];+ let _ = tokio::io::AsyncReadExt::read(&mut sock, &mut buf).await;+ // Promise 100 bytes, send 12, hang up.+ let reply = "HTTP/1.1 200 OK\r\nContent-Length: 100\r\nContent-Type: application/json\r\n\r\n{\"hits\":{\"to";+ let _ = tokio::io::AsyncWriteExt::write_all(&mut sock, reply.as_bytes()).await;+ });+ let ctx = Ctx {+ client: reqwest::Client::new(),+ base_url: format!("http://{addr}"),+ auth: None,+ };+ let res = engine_request(&ctx, Method::Get, "/docs/_search", None, None, None, None).await;+ assert_eq!(res["isError"], true, "{res}");+ let text = res["content"][0]["text"].as_str().unwrap();+ assert!(text.contains("could not be read"), "{text}");+ }+/// #2284: the server already explained the flood-stage block. The tool/// text is that sentence, not `XERJ returned HTTP` plus the JSON.#[tokio::test]