Repository navigation
feat(mcp): support autoindex prefixes in xerj_search - #2137
Conversation
Agents using the CLI's --prefix vocabulary over MCP silently searched ax-* because xerj_search only resolved its index argument. Resolve prefix as <prefix>-* for both the mapping pre-read and the actual search, and refuse ambiguous scope or malformed prefix arguments before HTTP. Preserve the existing explicit-index and default behavior. Four targeted regressions failed before the fix, including the observed GET /ax-*/_mapping and POST /ax-*/_search requests for a custom prefix. The complete MCP crate suite passes with 113 tests. A real-node regression seeds two corpora and checks prefix/default/index isolation with both plain and DSL queries; the transport fixture checks that invalid scope makes no HTTP requests. Document the contract and regenerate the published schema from the candidate release MCP binary. Formatting and scoped Clippy pass. Full build and compatibility evidence is recorded in the pull request. Written by an AI coding agent (OpenAI Codex), run by Jarvis636431. Refs xerj-org#2080: prefix support only; local definition lookup remains open.
Upstream merged xerj-org#2123, xerj-org#2124, xerj-org#2125 and xerj-org#2128 while the prefix work was being validated. xerj-org#2125 changes the same mapping pre-read in xerj_search. Resolve that overlap by keeping upstream's plain-query detection and response demotion, while passing the already-validated prefix scope to the mapping read. Preserve the upstream authorship and history through a merge. Add a custom-prefix/code-corpus regression proving the test-path penalty still applies. On the composed tree the MCP crate suite passes 123 tests (116 library and 7 integration/schema tests); scoped strict Clippy passes. The effective diff against upstream still contains only prefix support, its tests, README/changelog text, and the generated schema. Build and conformance evidence is recorded in the pull request. Written by an AI coding agent (OpenAI Codex), run by Jarvis636431.
Upstream published rc.98 and added the autoindex removal MCP tool during prefix validation. Preserve that tool and the new index-deletion guidance in the schema descriptions, and regenerate the schema from the composed candidate's real tools/list. Keep the prefix feature under Unreleased: it did not ship in rc.98. Resolve only the changelog and search-index description overlap. The MCP crate suite passes 124 tests (117 library and 7 integration/schema tests), strict scoped Clippy passes, and the scoped release MCP build passes. The generated schema is checked against both debug and release binaries; all 20 upstream tools are retained. The full conformance run and explicit environment limits are recorded in the PR. The effective contribution remains five files and adds no tool names or dependencies. Written by an AI coding agent (OpenAI Codex), run by Jarvis636431.
|
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Xerj Merger.
|
|
Xerj Merger made the fix: I merged main into the branch (fast-forward, no force-push). The only conflict was CHANGELOG: your Review: Local CI on main + #2137 + #2138 (same tree as this head): fmt, clippy |
Motivation: issue #2080. Agents pass the --prefix they used with xerj autoindex. MCP xerj_search grew a prefix argument in #2137, but it built {prefix}-* from the raw string. Autoindex stores a sanitized prefix (My_Proj becomes my-proj), so the typed characters search a pattern that does not exist. xerj search and xerj def had the same gap. Root cause: three copies of format!("{prefix}-*"), and none of them called dataset::sanitize_prefix / index_prefix_error, which is how xerj autoindex --prefix names indices. Change: resolve_prefix in xerj-autoindex is the one function. xerj search, xerj def, and MCP xerj_search call it. My_Proj searches my-proj-*, and a trailing -* is not part of the prefix. A prefix that cannot name an index is refused before any request. Passing both index and prefix is still an error. Passing neither still searches ax-*, the CLI default when --prefix is omitted. Refusing that case would break every caller of the default corpus (#962). The tool description says so. Evidence (rustc 1.97.1, from engine/, cargo --locked -j 4): - cargo test -p xerj-autoindex --lib: 1619 passed, 0 failed, 2 ignored - cargo test -p xerj-mcp: 117 lib tests, hub_tools, published_schema_drift (4), search_exact_phrase, and search_prefix, 0 failed - cargo clippy -p xerj-autoindex --lib -- -D warnings: exit 0 - cargo clippy -p xerj-mcp --all-targets -- -D warnings: exit 0 - cargo fmt --all with rustfmt 1.97.1 Not run: a release build, and the ES-YAML suite. This does not change the engine wire protocol; the client requests a different index pattern. Refs #2080. The xerj_def MCP tool is #2166. Co-authored-by: xerj-org <xerj-org@users.noreply.github.com>
MCP agents can scope xerj_search by prefix after #2137, but still cannot call the local definition workflow: xerj_def returns unknown tool. The existing xerj_hub_def instead requires a named Hub pack. Extract the CLI query/candidate-window and response-finalization helpers in xerj-autoindex/src/def.rs. The new xerj-mcp/src/def.rs adapter uses them after validating symbol, scope, filters, k and token budget before HTTP. It preserves mapping guards, local kind/visibility ranking and location deduplication, returning declarations and locators in the ES envelope. HTTP errors remain tool errors, malformed successes are refused, and empty hits remain success. No persistent schema or mutation path changes. Add real-node and HTTP-fixture regressions plus a CLI/MCP parity smoke in CI. Generate the published schema from the release binary and document the local-vs-Hub distinction and output/filter semantics. Before implementation, the local_def regression failed with "unknown tool: xerj_def". Afterward, all 129 MCP tests pass, including the five new regressions. Three real-entrypoint parity comparisons pass. Scoped release builds, strict Clippy, rustfmt, schema drift, SEO and workflow-timeout gates pass. ES-YAML: 1438 passed, 0 failed, 10 skipped (75 catch-lenient), using an isolated ci-test node. Full autoindex tests: 1621 passed, 10 failed, 5 ignored. All ten failures also reproduce with the unmodified upstream autoindex source at b64d9cb; they concern non-UTF8 filenames and PDF worker/spool fixtures on macOS. No claim of a green full autoindex suite or performance improvement. Implemented and verified with JoyCode, an AI coding agent.
Written by an AI coding agent (OpenAI Codex), run by @Jarvis636431.
xerj_searchignored the CLI-styleprefixargument and searched the defaultax-*corpus. It now accepts{"prefix":"project","query":"retry policy"}and searchesproject-*, using that same scope for mapping discovery and the final search. The expansion followsengine/crates/xerj-autoindex/src/search.rs:692.Non-empty
indexandprefixare mutually exclusive. Empty or non-string prefixes return an MCP tool error before any HTTP request; surrounding whitespace is trimmed and null is treated as omitted. Existing explicit-index and defaultax-*behavior is preserved.prefixis not forwarded into the ES request body. README, changelog, and the generated MCP schema document the argument.Refs #2080 — prefix support only. The 8000 local
xerj_defrequest remains unimplemented; this PR should not close the issue.Verified
cargo test --locked -p xerj-mcp --lib search_prefix -- --nocapturefailed all four new tests: the builder used/ax-*/_search, mapping discovery usedGET /ax-*/_mapping, conflicting scope arguments were accepted, and invalid arguments attempted HTTP.28de5cfc,TMPDIR=/private/tmp cargo test --locked --offline -p xerj-mcppassed all 124 tests: 117 library tests and 7 integration/schema tests, with 0 failures. The new real-node test seeds bothproject-docsandax-otherwith matching text and checks custom prefix, default scope, and explicit index for plain-string and DSL queries. The transport tests independently check both HTTP paths and zero requests on invalid scope arguments. A new combination regression proves prefix-scoped code searches retain upstream's test-path demotion.TMPDIR=/private/tmp cargo test --locked --offline --profile ci-test -p xerj-mcp --lib search_prefixpassed all 5 focused regressions on the composed tree in the optimized CI test profile.cargo fmt --all,cargo fmt --all --check, andcargo clippy --locked --offline -p xerj-mcp --all-targets -- -D warningspassed.cargo build --locked --offline --release -j 32 -p xerj-mcppassed on the composed tree.cargo build --locked --offline --profile ci-test -j 8 -p xerj-server -p es-yaml-runnerpassed on the final rc.98 tree. Against the candidate server in a fresh temporary data directory,./target/ci-test/es-yaml-runner --url <isolated-loopback-node> --dir tests/es-compat-yaml/yamlcompleted with 1438 passed, 0 failed, 10 skipped (exit 0), including 75 cases under the existing catch-lenient policy. The node stopped normally (exit 0).scripts/mcp-schema-check.sh --writeregenerated the schema from the candidate debugxerj-mcp; subsequent checks against both debug and release binaries passed with the same 20 tools. On this macOS host a temporary Python timeout wrapper supplied the script's missingtimeoutcommand; no repository script was changed.Environment and site checks
The first library-test run with the host's default temporary directory failed the existing
loopback_url_with_no_auth_picks_up_the_local_admin_keyassertion because/var/...and/private/var/...were compared as strings. The complete crate suite passed withTMPDIR=/private/tmp; that unrelated test was not changed.All applicable SEO workflow checks, factcheck fixture/self-tests and content checks, the critical-level site audit, and the landing constants guard passed. After the rc.98 merge was committed,
gen_sitemap.py --checkmatched andseo_lint.pyreported 0 gate violations. No additional website changes were needed beyond the generated tool schema.Review and limits
Started independently from upstream main
e1348b4d, then merged upstream search fixes and the rc.98 release, ending at base28de5cfc. The mapping-read overlap preserves upstream's plain-query detection and ranking path while using the resolved prefix scope for the GET. The later description/schema overlap preserves the new upstream removal tool and deletion guidance. The prefix changelog entry stays under Unreleased, not the rc.98 release. The effective diff remains five files containing only the prefix feature, its tests, docs, and generated schema. No new dependencies or tool names. Scope resolution is shared by mapping discovery and request construction, and the request is read-only. Existing index selection, DSL forwarding, lexical query shaping, auth, token budgets, and recovery behavior are preserved.No stored-state schema, journal, migration, publication lifecycle, telemetry, execution identity, optimization, feature gate, cluster behavior, or operational recipe changes. The durable-state/migration, optional-accelerator, identity, telemetry, feature-gate, performance, cluster, and operational-recipe audits are therefore not applicable. Tests use isolated temporary data directories and loopback endpoints; no external models or corpus downloads are required by the new coverage.
Not verified: Windows/Linux execution or external MCP clients. No performance claims; no claim that #2080's definition-lookup work is complete.