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: hide hub tools without a key, and correct the docs that disagree with the build (#1629)
xerj-orga808eefe1f20
diff --git a/engine/crates/xerj-autoindex/src/init.rs b/engine/crates/xerj-autoindex/src/init.rsindex 07ec1aa80..53f54f6a4 100644--- a/engine/crates/xerj-autoindex/src/init.rs+++ b/engine/crates/xerj-autoindex/src/init.rs@@ -15,7 +15,28 @@ use serde_json::{json, Value};use std::fs;use std::path::{Path, PathBuf};-const USAGE: &str = "\+/// `--help` for `xerj init`. `hub` is this build's [`xerj_common::hub::hub_key_configured`]:+/// a build with no signing key does not write the hub teaching files and must+/// not tell the reader that `xerj "<question>"` asks the hub (that command+/// exits 5 there).+fn usage(hub: bool) -> String {+ let hub_skill = if hub {+ " .claude/skills/xerj-hub/SKILL.md\n teach `xerj \"<question>\"`: when to ask the\n hub, `--def`, the MCP registration per client\n"+ } else {+ ""+ };+ let hub_rule = if hub {+ " .cursor/rules/xerj-hub.mdc the hub teaching file for Cursor (if .cursor/)\n"+ } else {+ ""+ };+ let hub_next = if hub {+ "Public libraries,\nstandards and advisories need no indexing: `xerj \"<question>\"` asks the hub.\n"+ } else {+ "This build has no hub signing key, so `xerj \"<question>\"` is not available\n(it exits 5). For public libraries, use `xerj corpus` and `xerj code`.\n"+ };+ format!(+ "\xerj init — wire XERJ into the coding agents installed in this projectUSAGE:@@ -27,12 +48,8 @@ config for each — with a .bak backup for any file it edits:.mcp.json register the `xerj mcp` server (Claude Codeproject scope; merged, other servers kept).claude/skills/xerj/SKILL.md teach `xerj search` / `xerj def` (10 lines)- .claude/skills/xerj-hub/SKILL.md- teach `xerj \"<question>\"`: when to ask the- hub, `--def`, the MCP registration per client- .cursor/rules/xerj.mdc same teaching file for Cursor (if .cursor/)- .cursor/rules/xerj-hub.mdc the hub teaching file for Cursor (if .cursor/)- AGENTS.md a short XERJ section (appended if the file+{hub_skill} .cursor/rules/xerj.mdc same teaching file for Cursor (if .cursor/)+{hub_rule} AGENTS.md a short XERJ section (appended if the fileexists, created otherwise)The teaching files carry an `xerj-init-version` marker. A re-run upgrades one@@ -48,15 +65,15 @@ OPTIONS:After init: restart the agent session so it picks up the new tools, then`xerj autoindex <folder> --prefix <name>` anything you want searchable.Pass that same `--prefix <name>` to `xerj search` and `xerj def`; without it-they search the default `ax` prefix. Public libraries,-standards and advisories need no indexing: `xerj \"<question>\"` asks the hub.-init also prints the MCP registration line for each client.+they search the default `ax` prefix. {hub_next}init also prints the MCP registration line for each client.Auth: nothing secret is written (`.mcp.json` is meant to be committed). For aloopback node the MCP server reads <data-dir>/admin.key by itself and says soon stderr; for any other node add \"XERJ_AUTH\": \"ApiKey <key>\" to the envblock — init prints which case you are in.-";+"+ )+}/// The ten-line teaching file. One idea per line, no filler: what the tools/// are, when to reach for them, what comes back.@@ -448,13 +465,16 @@ pub fn run_init_cli() -> i32 {while let Some(a) = it.next() {match a.as_str() {"-h" | "--help" => {- print!("{USAGE}");+ print!("{}", usage(xerj_common::hub::hub_key_configured()));return 0;}"--url" => url = it.next().unwrap_or(url),"--dry-run" => dry = true,other => {- eprintln!("xerj init: unexpected argument '{other}'\n\n{USAGE}");+ eprintln!(+ "xerj init: unexpected argument '{other}'\n\n{}",+ usage(xerj_common::hub::hub_key_configured())+ );return 2;}}@@ -1010,9 +1030,12 @@ mod tests {assert!(printed.contains("xerj_search"));}- /// `--help` lists every file init can write, the hub pair included.+ /// `--help` lists every file init can write. The hub pair is listed only+ /// when this build can verify hub packs; otherwise the help must not+ /// teach `xerj "<question>"`, which exits 5.#[test]fn help_lists_every_file_init_writes() {+ let with_hub = usage(true);for file in [".mcp.json",".claude/skills/xerj/SKILL.md",@@ -1021,13 +1044,36 @@ mod tests {".cursor/rules/xerj-hub.mdc","AGENTS.md",] {- assert!(USAGE.contains(file), "--help does not list {file}");+ assert!(with_hub.contains(file), "--help does not list {file}");}assert!(- USAGE.contains("xerj autoindex <folder> --prefix <name>"),- "{USAGE}"+ with_hub.contains("xerj autoindex <folder> --prefix <name>"),+ "{with_hub}"+ );+ assert!(with_hub.contains("default `ax` prefix"), "{with_hub}");+ assert!(with_hub.contains("asks the hub"), "{with_hub}");++ let no_hub = usage(false);+ for file in [+ ".mcp.json",+ ".claude/skills/xerj/SKILL.md",+ ".cursor/rules/xerj.mdc",+ "AGENTS.md",+ ] {+ assert!(no_hub.contains(file), "--help does not list {file}");+ }+ assert!(+ !no_hub.contains("xerj-hub"),+ "a no-key build must not list hub teaching files it will not write:\n{no_hub}"+ );+ assert!(+ !no_hub.contains(r#"asks the hub"#),+ "a no-key build must not say the hub answers:\n{no_hub}"+ );+ assert!(+ no_hub.contains("exits 5") && no_hub.contains("xerj code"),+ "{no_hub}");- assert!(USAGE.contains("default `ax` prefix"), "{USAGE}");}// ── the version marker: upgrade only what init wrote and nobody edited ──diff --git a/engine/crates/xerj-mcp/src/lib.rs b/engine/crates/xerj-mcp/src/lib.rsindex 281ed49a7..ef4788305 100644--- a/engine/crates/xerj-mcp/src/lib.rs+++ b/engine/crates/xerj-mcp/src/lib.rs@@ -118,21 +118,7 @@ USAGE:xerj mcp [OPTIONS] (or the standalone binary: xerj-mcp [OPTIONS])Speaks MCP over stdio (newline-delimited JSON-RPC 2.0 on stdin/stdout) and-proxies thirteen tools — xerj_search, xerj_semantic_search, xerj_vector_search,-xerj_hybrid_search, xerj_memory_store, xerj_memory_recall, xerj_brain_ego,-xerj_brain_link, xerj_brain_unlink, xerj_brain_overview, xerj_code_search,-xerj_map, xerj_plan — to a-XERJ node that-is ALREADY RUNNING. This command does not start a node; start one first with-`xerj --data-dir ./data`.--It also serves three Corpus Hub tools — xerj_hub_find, xerj_hub_def,-xerj_hub_ask — which run the `xerj ask` flow: answered from packs already on-this machine (a tool call never downloads one; it names the `xerj hub pull`-line instead), from the catalogue already cached (never fetched; with none-cached they say to run `xerj hub sync`). Like `xerj ask`, they use the node above when it answers and-otherwise the automatic hub node.-+@@TOOLS@@OPTIONS:--url <URL> Base URL of the XERJ ES-compatible listener.Overrides XERJ_URL. Default: http://localhost:9200@@ -187,6 +173,57 @@ pub fn help_text(feedback: bool) -> String {"{first}\n{}USAGE:{rest}",xerj_common::feedback::block(feedback))+ .replace("@@TOOLS@@", &tools_paragraph(hub_tools_served()))+}++/// Whether this process serves the `xerj_hub_*` tools. A build with no hub+/// signing key cannot verify a pack, so those tools are omitted from+/// `tools/list` and from this help — advertising them only produced a call+/// that exits with the no-key message.+fn hub_tools_served() -> bool {+ xerj_common::hub::hub_key_configured()+}++/// The tool sentence in `--help`. The count and the names are `tool_specs()`,+/// the same list `tools/list` returns, so this screen cannot say "thirteen"+/// while the root help says however many tools are actually served.+fn tools_paragraph(include_hub: bool) -> String {+ let specs = tool_specs_with(include_hub);+ let names: Vec<&str> = specs+ .as_array()+ .map(|tools| {+ tools+ .iter()+ .filter_map(|t| t.get("name").and_then(Value::as_str))+ .collect()+ })+ .unwrap_or_default();+ let list = names.join(", ");+ let mut para = format!(+ "proxies {n} tools — {list} — to a\n\+ XERJ node that\n\+ is ALREADY RUNNING. This command does not start a node; start one first with\n\+ `xerj --insecure --data-dir ~/xerj-data`.\n",+ n = names.len(),+ );+ let hub: Vec<&str> = names+ .iter()+ .copied()+ .filter(|n| n.starts_with("xerj_hub_"))+ .collect();+ if !hub.is_empty() {+ para.push_str(&format!(+ "\nIt also serves {n} Corpus Hub tools — {list} — which run the `xerj ask` flow: \+ answered from packs already on\n\+ this machine (a tool call never downloads one; it names the `xerj hub pull`\n\+ line instead), from the catalogue already cached (never fetched; with none\n\+ cached they say to run `xerj hub sync`). Like `xerj ask`, they use the node above when it answers and\n\+ otherwise the automatic hub node.\n",+ n = hub.len(),+ list = hub.join(", "),+ ));+ }+ para}/// Resolve the `Authorization` header value every proxied request will carry.@@ -630,9 +667,11 @@ fn max_tokens_arg_schema() -> Value {})}-/// The sixteen tool specifications advertised via `tools/list` (the three-/// `xerj_hub_*` specs come from `hub::specs`, appended last). Input schemas-/// are plain JSON Schema; every property maps onto a field the engine accepts.+/// The tool specifications advertised via `tools/list`. The three `xerj_hub_*`+/// specs (`hub::specs`, appended last) are included only when this process+/// has a hub signing key; without one they cannot answer and are not listed.+/// Input schemas are plain JSON Schema; every property maps onto a field the+/// engine accepts.////// Public because this is the single source of truth for the published/// agent-facing schema at `landing/docs/agents/schemas/mcp-tools.json`, which@@ -640,6 +679,12 @@ fn max_tokens_arg_schema() -> Value {/// once advertised six tools while the binary served ten — nobody noticed,/// because nothing compared them.pub fn tool_specs() -> Value {+ tool_specs_with(hub_tools_served())+}++/// [`tool_specs`] with the hub tools forced in or out. Tests use this so they+/// do not have to mutate `XERJ_HUB_PUBKEY`, which is process-global.+pub fn tool_specs_with(include_hub: bool) -> Value {let mut specs = json!([{"name": "xerj_search",@@ -1104,8 +1149,10 @@ pub fn tool_specs() -> Value {}}]);- if let Value::Array(tools) = &mut specs {- tools.extend(hub::specs());+ if include_hub {+ if let Value::Array(tools) = &mut specs {+ tools.extend(hub::specs());+ }}specs}@@ -1164,10 +1211,16 @@ async fn call_tool(ctx: &Ctx, msg: &Value) -> Value {"xerj_code_search" => return run_code_search(ctx, &args).await,// Corpus Hub v2 (plan §7): the `xerj ask` flow itself, not a proxy.hub_tool if hub_tool.starts_with("xerj_hub_") => {+ // Hidden from tools/list when there is no key. A client that still+ // calls one (a cached tool list) gets the same sentence `xerj ask`+ // prints, not a catalogue fetch that cannot be verified.+ if !hub_tools_served() {+ return tool_text(xerj_common::hub::NO_HUB_KEY_MESSAGE.to_string(), true);+ }return match hub::call(ctx, hub_tool, &args).await {Some(result) => result,None => tool_text(format!("unknown tool: {hub_tool}"), true),- }+ };}other => return tool_text(format!("unknown tool: {other}"), true),};@@ -2813,7 +2866,7 @@ mod tests {#[test]fn tools_list_has_all_sixteen() {- let specs = tool_specs();+ let specs = tool_specs_with(true);let names: Vec<&str> = specs.as_array().unwrap()@@ -2855,6 +2908,41 @@ mod tests {}}+ /// A process with no hub signing key must not advertise tools that can+ /// only answer with the no-key message. The count `--help` prints is that+ /// same list, so the two cannot disagree.+ #[test]+ fn hub_tools_are_hidden_without_a_hub_key_and_help_counts_them() {+ let names = |include_hub: bool| -> Vec<String> {+ tool_specs_with(include_hub)+ .as_array()+ .unwrap()+ .iter()+ .map(|t| t["name"].as_str().unwrap().to_string())+ .collect()+ };+ let without = names(false);+ assert_eq!(without.len(), 13, "{without:?}");+ assert!(+ without.iter().all(|n| !n.starts_with("xerj_hub_")),+ "{without:?}"+ );+ let with = names(true);+ assert_eq!(with.len(), 16, "{with:?}");+ for n in ["xerj_hub_find", "xerj_hub_def", "xerj_hub_ask"] {+ assert!(with.iter().any(|name| name == n), "missing {n}");+ }++ let help = tools_paragraph(false);+ assert!(help.contains("proxies 13 tools"), "{help}");+ assert!(!help.contains("xerj_hub_"), "{help}");+ assert!(help.contains("~/xerj-data"), "{help}");+ let help = tools_paragraph(true);+ assert!(help.contains("proxies 16 tools"), "{help}");+ assert!(help.contains("xerj_hub_ask"), "{help}");+ assert!(help.contains("serves 3 Corpus Hub tools"), "{help}");+ }+/// #1055: the field map is an orientation tool an agent calls before it/// writes DSL — its description must say what to reach for, what the/// facts ARE (sampled, not exhaustive), and how the byte cap trims.diff --git a/engine/crates/xerj-mcp/tests/published_schema_drift.rs b/engine/crates/xerj-mcp/tests/published_schema_drift.rsindex d98375bf7..52c93064f 100644--- a/engine/crates/xerj-mcp/tests/published_schema_drift.rs+++ b/engine/crates/xerj-mcp/tests/published_schema_drift.rs@@ -70,7 +70,11 @@ fn names(tools: &Value) -> Vec<String> {/// The headline check: same tools, same order.#[test]fn published_tool_names_match_the_server() {- let served = names(&xerj_mcp::tool_specs());+ // The published file is the with-key tool list. A process with+ // `XERJ_HUB_PUBKEY=none` omits the three hub tools from `tool_specs()`;+ // that omission is covered in the library tests, and must not look like+ // the committed schema drifted.+ let served = names(&xerj_mcp::tool_specs_with(true));let doc = names(&published()["tools"]);assert_eq!(doc, served,@@ -87,7 +91,7 @@ fn published_tool_names_match_the_server() {/// the brain tools' honesty sentences live there.#[test]fn published_schemas_match_the_server_exactly() {- let served = xerj_mcp::tool_specs();+ let served = xerj_mcp::tool_specs_with(true);let doc = published()["tools"].clone();let served_by_name: std::collections::BTreeMap<String, &Value> = serveddiff --git a/engine/crates/xerj-query/src/error.rs b/engine/crates/xerj-query/src/error.rsindex 73737bb58..e17dcefef 100644--- a/engine/crates/xerj-query/src/error.rs+++ b/engine/crates/xerj-query/src/error.rs@@ -42,7 +42,7 @@ pub enum QueryError {pub enum ParseError {#[error("{0}")]Invalid(String),- #[error("unknown query type `{0}` — see https://xerj.io/docs/query-dsl for supported types")]+ #[error("unknown query type `{0}` — see https://xerj.org/docs/queries for supported types")]UnknownQueryType(String),}@@ -68,3 +68,18 @@ impl ParseError {/// Convenience alias — every public function in this crate returns this.pub type Result<T> = std::result::Result<T, QueryError>;++#[cfg(test)]+mod tests {+ use super::*;++ #[test]+ fn unknown_query_type_points_at_the_live_query_list() {+ let msg = ParseError::unknown_query_type("nope").to_string();+ assert!(msg.contains("https://xerj.org/docs/queries"), "{msg}");+ assert!(+ !msg.contains("xerj.io"),+ "the error must not link a host that does not resolve: {msg}"+ );+ }+}diff --git a/engine/crates/xerj-server/src/main.rs b/engine/crates/xerj-server/src/main.rsindex bfb9a2dfc..db4621d01 100644--- a/engine/crates/xerj-server/src/main.rs+++ b/engine/crates/xerj-server/src/main.rs@@ -2296,12 +2296,24 @@ mod decide_flag_tests {fn help_counts_the_mcp_tools_actually_served() {// #1443: the help said "exposes 13 tools" while `tools/list` served 16.let served = super::mcp_tool_count();- assert!(served >= 16, "tool_specs() shrank to {served}");+ if xerj_common::hub::hub_key_configured() {+ assert!(served >= 16, "tool_specs() shrank to {served}");+ } else {+ assert_eq!(+ served, 13,+ "a no-key process must not count the hub tools it does not serve"+ );+ }let help = help_text(false);assert!(help.contains(&format!("exposes {served} tools")),"help must state the served tool count {served}, got:\n{help}");+ let mcp_help = xerj_mcp::help_text(false);+ assert!(+ mcp_help.contains(&format!("proxies {served} tools")),+ "xerj mcp --help must state the same count {served}, got:\n{mcp_help}"+ );}#[test]diff --git a/landing/get b/landing/getindex d3c69b42f..84bdb8cd4 100644--- a/landing/get+++ b/landing/get@@ -215,10 +215,10 @@ fisay ""say "${BOLD}xerj ${tag}${RST} is ready."case ":${PATH}:" in- *":${dir}:"*) say " ${DIM}start it:${RST} xerj --insecure --data-dir ./data" ;;+ *":${dir}:"*) say " ${DIM}start it:${RST} xerj --insecure --data-dir ~/xerj-data" ;;*) say " ${DIM}${dir} is not on your PATH — either add it:${RST}"say " export PATH=\"${dir}:\$PATH\""- say " ${DIM}or run it directly:${RST} ${dest} --insecure --data-dir ./data" ;;+ say " ${DIM}or run it directly:${RST} ${dest} --insecure --data-dir ~/xerj-data" ;;esacsay ""say " ${DIM}then open the console:${RST} http://localhost:9200/_xerj-console/"diff --git a/landing/get.ps1 b/landing/get.ps1index e34c0db4c..440077a2d 100644--- a/landing/get.ps1+++ b/landing/get.ps1@@ -148,7 +148,7 @@# --- next steps --------------------------------------------------------------Write-Host ""Write-Host "xerj $tag is ready." -ForegroundColor White- Write-Host " start it: xerj --insecure --data-dir .\data"+ Write-Host " start it: xerj --insecure --data-dir `$HOME\xerj-data"Write-Host " then open the console: http://localhost:9200/_xerj-console/"Write-Host " docs: https://xerj.org/docs/ - source: https://github.com/$Repo"Write-Host ""