Skip to content

armgit / xerj

Public Imported from GitHub
0

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.

fix(mcp): filter map globs before catalog limit (#1591)

ammann9c0809076a1f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f693ad6cd..a2fc64c2a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+### Fixed
+
+- `xerj_map` applies index-name globs before its 100-dataset response cap, so
+ unrelated larger datasets cannot hide a matching catalog entry.
+
## [1.0.0-rc.96] - 2026-10-15
Window since v1.0.0-rc.95: a fix-and-honesty sweep across search tie order,
diff --git a/engine/crates/xerj-mcp/src/lib.rs b/engine/crates/xerj-mcp/src/lib.rs
index c9317bf55..afe9223c5 100644
--- a/engine/crates/xerj-mcp/src/lib.rs
+++ b/engine/crates/xerj-mcp/src/lib.rs
@@ -996,7 +996,7 @@ pub fn tool_specs() -> Value {
"type": "string",
"description": "Index name or `*`-glob (e.g. `ax-logs`, `ax-*`). Default: every \
catalogued index. An exact name filters engine-side; a glob filters \
- client-side over the catalog's index names."
+ against the catalog before the 100-index limit."
},
"max_bytes": {
"type": "integer",
diff --git a/engine/crates/xerj-mcp/src/map.rs b/engine/crates/xerj-mcp/src/map.rs
index 91160104d..914783174 100644
--- a/engine/crates/xerj-mcp/src/map.rs
+++ b/engine/crates/xerj-mcp/src/map.rs
@@ -88,14 +88,17 @@ pub(crate) fn parse_args(args: &Value) -> Result<MapArgs, String> {
Ok(MapArgs { index, max_bytes })
}
-/// The `_search` body for the catalog read. A pattern without a `*` becomes
-/// an engine-side `term` on `index_name` (exact); a glob filters client-side
-/// — one less engine query behaviour for this proxy to assume, and index
-/// counts are small.
+/// The `_search` body for the catalog read. Filter exact names with `term`
+/// and globs with `wildcard` before the 100-result cap. Filtering a glob only
+/// after the fetch could hide a matching dataset behind 100 larger ones.
pub(crate) fn catalog_body(args: &MapArgs) -> Value {
let mut must = vec![json!({ "term": { "doc_kind": "dataset" } })];
- if let Some(name) = args.index.as_deref().filter(|p| !p.contains('*')) {
- must.push(json!({ "term": { "index_name": name } }));
+ if let Some(name) = args.index.as_deref() {
+ if name.contains('*') {
+ must.push(json!({ "wildcard": { "index_name": name } }));
+ } else {
+ must.push(json!({ "term": { "index_name": name } }));
+ }
}
json!({
"query": { "bool": { "must": must } },
@@ -318,7 +321,8 @@ pub(crate) fn render_response(resp: &Value, args: &MapArgs) -> String {
.and_then(Value::as_u64)
.unwrap_or(hits.len() as u64);
- // Pattern filtering (glob only; exact names were filtered engine-side).
+ // Keep the local glob check so only the tool's documented `*` syntax
+ // reaches the response even if the engine supports more wildcard syntax.
let docs: Vec<Value> = hits
.iter()
.filter_map(|h| h.get("_source").cloned())
@@ -716,7 +720,7 @@ mod tests {
}
#[test]
- fn exact_names_filter_engine_side_and_globs_client_side() {
+ fn exact_names_and_globs_filter_engine_side() {
let f = r#"[{"name":"a","es_type":"keyword","cardinality_est":1,"coverage":1.0,"examples":["a"]}]"#;
let hits = vec![
dataset_doc("ax-logs", 10, f),
@@ -729,9 +733,13 @@ mod tests {
let body = catalog_body(&args(Some("ax-logs")));
assert_eq!(body["query"]["bool"]["must"].as_array().unwrap().len(), 2);
- // Glob: no engine-side term; the client filter keeps only matches.
+ // A glob must filter before the 100-result cap: otherwise a matching
+ // low-record dataset can be omitted by unrelated larger datasets.
let body = catalog_body(&args(Some("ax-*")));
- assert_eq!(body["query"]["bool"]["must"].as_array().unwrap().len(), 1);
+ assert_eq!(
+ body["query"]["bool"]["must"][1],
+ json!({ "wildcard": { "index_name": "ax-*" } })
+ );
let out: Value =
serde_json::from_str(&render_response(&resp, &args(Some("ax-*")))).unwrap();
assert_eq!(out["matched"], 2);
diff --git a/landing/docs/agents/schemas/mcp-tools.json b/landing/docs/agents/schemas/mcp-tools.json
index ce68e576d..7692b9245 100644
--- a/landing/docs/agents/schemas/mcp-tools.json
+++ b/landing/docs/agents/schemas/mcp-tools.json
@@ -512,7 +512,7 @@
"properties": {
"index": {
"type": "string",
- "description": "Index name or `*`-glob (e.g. `ax-logs`, `ax-*`). Default: every catalogued index. An exact name filters engine-side; a glob filters client-side over the catalog's index names."
+ "description": "Index name or `*`-glob (e.g. `ax-logs`, `ax-*`). Default: every catalogued index. An exact name filters engine-side; a glob filters against the catalog before the 100-index limit."
},
"max_bytes": {
"type": "integer",