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): accept plain query strings in xerj_batch_search (#2497)
Term5642e537cfaf6e
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex bb692b8fc..ec1c4f50e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -112,6 +112,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0### Fixed+- `xerj_batch_search` (and `xerj batch-search`) accept a plain string in+ `queries` as shorthand for `{"query": <string>}` (#2497). A string item+ used to fail alone with "arguments must be a JSON object", so an agent+ that sent `["a", "b"]` lost a call; the advertised schema now allows it.+- `xerj code` shows the part of a long definition that matched the query,not its first `--full` characters (#2464). The matching text could sitthousands of characters below the signature, so a hit named the rightdiff --git a/engine/crates/xerj-mcp/src/batch.rs b/engine/crates/xerj-mcp/src/batch.rsindex 4e2322df5..fe161ec08 100644--- a/engine/crates/xerj-mcp/src/batch.rs+++ b/engine/crates/xerj-mcp/src/batch.rs@@ -15,14 +15,14 @@ pub(crate) fn spec() -> Value {"type":"object", "additionalProperties":false,"properties":{"queries":{"type":"array","minItems":1,"maxItems":50,- "description":"Ordered queries. Duplicate keys are allowed; position is authoritative. Entire input is limited to 1 MiB.",- "items":{"type":"object","additionalProperties":false,"properties":{+ "description":"Ordered queries. A plain string item is shorthand for {\"query\": <string>}. Duplicate keys are allowed; position is authoritative. Entire input is limited to 1 MiB.",+ "items":{"anyOf":[{"type":"string","minLength":1},{"type":"object","additionalProperties":false,"properties":{"key":{"type":"string","description":"Optional correlation key, at most 256 UTF-8 bytes."},"query":{"oneOf":[{"type":"string","minLength":1},{"type":"object"}],"description":"Plain text or ES query clause. Cannot be combined with identifier/field."},"identifier":{"type":"string","minLength":1,"description":"Exact value, used verbatim in a term query; requires field."},"field":{"type":"string","minLength":1,"description":"Flat keyword field for identifier. Must be mapped as keyword wherever present; unreadable, absent or conflicting mappings fail this item."}- }, "oneOf":[{"required":["query"]},{"required":["identifier","field"]}]}},+ }, "oneOf":[{"required":["query"]},{"required":["identifier","field"]}]}]}},"index":{"type":"string","description":"Index or pattern; alternative to prefix. Defaults to ax-*."},"prefix":{"type":"string","description":"Autoindex prefix, e.g. project searches project-*. Cannot combine with index."},"size":{"type":"integer","minimum":1,"maximum":50,"default":3,"description":"Maximum hits per item."},@@ -393,6 +393,14 @@ pub(crate) async fn execute(ctx: &Ctx, args: &Value) -> Result<String, String> {limit,items,} = envelope(args)?;+ // #2497: a bare string item is shorthand for {"query": <string>}.+ let items: Vec<Value> = items+ .iter()+ .map(|item| match item {+ Value::String(s) => json!({ "query": s }),+ other => other.clone(),+ })+ .collect();// Validate locally before any I/O; invalid items do not sink siblings.let validation: Vec<_> = items.iter().map(validate_item).collect();let needs_mapping = items.iter().zip(&validation).any(|(item, valid)| {diff --git a/engine/crates/xerj-mcp/src/batch_cli.rs b/engine/crates/xerj-mcp/src/batch_cli.rsindex c2c2bd050..c22c0e8bb 100644--- a/engine/crates/xerj-mcp/src/batch_cli.rs+++ b/engine/crates/xerj-mcp/src/batch_cli.rs@@ -15,6 +15,7 @@ Read one JSON object (at most 1 MiB) using the xerj_batch_search schema:]}queries: 1..50 objects, each query (text or ES query clause) OR identifier+field.+A plain string item is shorthand for {\"query\": <string>}.Exact identifiers require a flat indexed keyword field. index/prefix, size(1..50, default 3) and optional max_tokens are shared by all items.Output is one JSON object with ordered results; position is zero-based anddiff --git a/engine/crates/xerj-mcp/tests/batch_search.rs b/engine/crates/xerj-mcp/tests/batch_search.rsindex 3d93d601e..dd91390bb 100644--- a/engine/crates/xerj-mcp/tests/batch_search.rs+++ b/engine/crates/xerj-mcp/tests/batch_search.rs@@ -114,6 +114,68 @@ async fn batch_preserves_positions_errors_duplicates_and_exact_ids() {let _ = server.await;}+/// #2497: a plain string item is shorthand for `{"query": <string>}`, not an+/// invalid item; a blank one still fails alone with the query error.+#[tokio::test]+async fn batch_accepts_plain_string_items_as_queries() {+ let requests = Arc::new(Mutex::new(Vec::<String>::new()));+ let seen = requests.clone();+ let app = Router::new().route(+ "/_msearch",+ axum::routing::post(move |text: String| {+ seen.lock().unwrap().push(text.clone());+ let hit = json!({"hits":{"total":{"value":1,"relation":"eq"},"hits":[{+ "_index":"docs","_id":"record-1","_source":{"body":"rotate the WAL"}}]}});+ async move {+ let searches = text.lines().count() / 2;+ Json(json!({"responses":vec![hit; searches]}))+ }+ }),+ );+ let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();+ let url = format!("http://{}", listener.local_addr().unwrap());+ let server = tokio::spawn(async move { axum::serve(listener, app).await.unwrap() });+ let result = body(+ &call(+ &url,+ json!({"index":"docs","queries":[+ "rotate the WAL",+ {"key":"object","query":"rotate the WAL"},+ " "+ ]}),+ )+ .await,+ );+ let items = result["results"].as_array().unwrap();+ assert_eq!(items.len(), 3, "{result}");+ assert_eq!(items[0]["position"], 0);+ assert_eq!(items[0]["status"], "hits", "{result}");+ assert!(items[0].get("key").is_none(), "{result}");+ assert_eq!(items[0]["hits"], items[1]["hits"]);+ assert_eq!(items[2]["status"], "error", "{result}");+ assert!(+ items[2]["error"]["message"]+ .as_str()+ .unwrap()+ .contains("non-blank"),+ "{result}"+ );+ {+ let requests = requests.lock().unwrap();+ let lines: Vec<Value> = requests[0]+ .lines()+ .map(|s| serde_json::from_str(s).unwrap())+ .collect();+ assert_eq!(lines.len(), 4, "the blank item never reaches the node");+ assert_eq!(+ lines[1], lines[3],+ "a string item searches exactly as its object form"+ );+ }+ server.abort();+ let _ = server.await;+}+#[tokio::test]async fn batch_rejects_invalid_envelopes_before_network() {for args in [diff --git a/landing/docs/agents/schemas/mcp-tools.json b/landing/docs/agents/schemas/mcp-tools.jsonindex 7162480bd..8d3ad02c5 100644--- a/landing/docs/agents/schemas/mcp-tools.json+++ b/landing/docs/agents/schemas/mcp-tools.json@@ -56,48 +56,56 @@"type": "array","minItems": 1,"maxItems": 50,- "description": "Ordered queries. Duplicate keys are allowed; position is authoritative. Entire input is limited to 1 MiB.",+ "description": "Ordered queries. A plain string item is shorthand for {\"query\": <string>}. Duplicate keys are allowed; position is authoritative. Entire input is limited to 1 MiB.","items": {- "type": "object",- "additionalProperties": false,- "properties": {- "key": {+ "anyOf": [+ {"type": "string",- "description": "Optional correlation key, at most 256 UTF-8 bytes."+ "minLength": 1},- "query": {+ {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "key": {+ "type": "string",+ "description": "Optional correlation key, at most 256 UTF-8 bytes."+ },+ "query": {+ "oneOf": [+ {+ "type": "string",+ "minLength": 1+ },+ {+ "type": "object"+ }+ ],+ "description": "Plain text or ES query clause. Cannot be combined with identifier/field."+ },+ "identifier": {+ "type": "string",+ "minLength": 1,+ "description": "Exact value, used verbatim in a term query; requires field."+ },+ "field": {+ "type": "string",+ "minLength": 1,+ "description": "Flat keyword field for identifier. Must be mapped as keyword wherever present; unreadable, absent or conflicting mappings fail this item."+ }+ },"oneOf": [{- "type": "string",- "minLength": 1+ "required": [+ "query"+ ]},{- "type": "object"+ "required": [+ "identifier",+ "field"+ ]}- ],- "description": "Plain text or ES query clause. Cannot be combined with identifier/field."- },- "identifier": {- "type": "string",- "minLength": 1,- "description": "Exact value, used verbatim in a term query; requires field."- },- "field": {- "type": "string",- "minLength": 1,- "description": "Flat keyword field for identifier. Must be mapped as keyword wherever present; unreadable, absent or conflicting mappings fail this item."- }- },- "oneOf": [- {- "required": [- "query"- ]- },- {- "required": [- "identifier",- "field"]}]