Repository navigation
feat(mcp): expose local definition lookup - #2166
Conversation
MCP agents can scope xerj_search by prefix after xerj-org#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.
The new xerj_def adapter makes the MCP registry serve 21 tools, or 18 without the three Hub tools. The English README and generated schema already described it, but the agent guide, Chinese README and website references still listed 20 tools and omitted local definition lookup. Synchronize those five documentation surfaces with the implemented scope, lexical ranking, filters, token budget and response fields. Distinguish local-node lookup from named Hub-pack lookup and preserve historical version-specific measurements rather than rewriting their tool counts. Verified: SEO workflow gates, fact-check self-test and fixtures, landing constants guard, schema-based tool enumeration and JSON examples, and git diff --check pass. SEO lint reports zero gate violations; existing article/style warnings remain. No engine code or install flow changes. Written by OpenAI Codex, an AI coding agent, run by Jarvis636431.
|
Thanks for this! Build + Test is red on one test: |
Adding xerj_def increases the served registry to 21 tools with a Hub key and 18 without one. The server and MCP help already derive their counts from tool_specs(), but the server regression still expected 20 and 17, failing Build + Test before its help assertions. Update both exact-count assertions and their comment while retaining the checks that both help surfaces match the actual registry. This follow-up changes test code only; no runtime behavior, workflow, or documentation changes. Verified: the original regression failed with 21 vs 20, and the pre-fix test executable failed with XERJ_HUB_PUBKEY=none at 18 vs 17. After the fix, the focused test passes in both configurations; all 104 xerj-server binary unit tests pass in the ci-test profile. cargo fmt --all -- --check and git diff --check pass. Release build, ES-YAML, and workspace tests were not rerun for this test-only follow-up; final merge-ref CI remains required. Written by OpenAI Codex, an AI coding agent, run by Jarvis636431.
|
Thanks for catching this! Fixed and pushed in 0b64196. Both help surfaces already derive their counts from the live tool registry; the stale values were the server regression's exact-count assertions. Updated those and the comment to 21 tools with a Hub key / 18 without, retaining both help-consistency assertions. Verified locally:
This follow-up changes only test code. I did not rerun the release build, ES-YAML suite, or workspace suite locally; the pushed commit still needs final CI validation. Understood about the workflow change requiring a maintainer to perform the final merge. This follow-up was prepared and verified with OpenAI Codex. |
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>
Motivation: PR #2243 conflicted with main after #2228 (sparse pin harvest), #2227 (semantic_text highlight), and #2166 (xerj_def) landed. The journal-resume fix for #2239 has to stay, and so does the behavior those commits added. Conflict: CHANGELOG.md, Unreleased / Fixed. Both entries are kept: the #2239 corpus-index resume note, then main's #1947 semantic highlight note. The Added section already had both MCP entries. engine/crates/xerj-autoindex/src/xc.rs auto-merged. Main's checkout_at_sha_paths sparse harvest and this branch's find_unfinished_build / resume mode are both in the file. No .github file was hand-edited; ci.yml came in as main left it. Verified from engine/ with rustc 1.97.1: cargo test --profile ci-test -p xerj-autoindex -j 2 lib 1644 passed, 0 failed, 2 ignored. Integration targets 0 failed. a_kill_mid_index_resumes_the_journal_and_records_a_verified_build and corpus_add_from_paths_harvests_only_those_directories both ok. Co-authored-by: xerj-org <xerj-org@users.noreply.github.com>
Written by AI coding agents (OpenAI Codex for review and documentation), run by @Jarvis636431, who has reviewed and confirmed the implementation's validation.
What this changes, and why
MCP callers can use
xerj_searchwith a prefix after #2137, but callingxerj_defstill returns "unknown tool".xerj_hub_defrequires a named Hub pack and does not expose the local CLI workflow.Add
xerj_deffor local autoindexed data. Extract and reuse the existing CLI definition query and response-finalization helpers inengine/crates/xerj-autoindex/src/def.rs, preserving mapping guards, lexical kind/visibility ranking, the bounded candidate window, and location deduplication. The adapter accepts symbol/capability phrases, prefix or index scope, kind/language filters, k and a token budget. It validates arguments before HTTP, preserves search HTTP errors, refuses malformed success responses, and treats no matches as a successful empty hit list.Return the ES envelope with declarations and locators; totals remain eng 8000 ine matches before deduplication. Add HTTP-fixture and real-node regressions, a CLI/MCP parity check in CI, the generated tool schema, and consistent references in the English/Chinese README, agent guide and website. The registry now has 21 tools, or 18 without Hub tools.
Closes #2080; the prefix portion was already merged in #2137.
Ancestry and scope
Based on upstream main
6c5f08f5. Original implementation:df61f3b5; merge of upstream:c91ffc4b; documentation follow-up:17f9dc8f. The merge changed no implementation or test code. This is independent of unmerged prerequisite work and preserves upstream history. No new dependency, persistent schema, mutation path, or ES endpoint is introduced.Known documentation overlap: open PRs #1909 and #1925 also edit
landing/llms.txt. This branch changes only the tool inventory and local-definition contract there; those PRs need coordination before merging.Evidence
Independently rerun during this review:
cd engine && TMPDIR=/private/tmp cargo test --offline -p xerj-mcp: 129 tests passed, including all five local-definition regressions.TMPDIR=/private/tmp python3 scripts/mcp-def-smoke.py engine/target/ci-test/xerj: all three CLI/MCP request and ranked-response comparisons passed.cd engine && cargo fmt --all -- --check: passed.xerj-mcprealtools/listoutput compared as parsed JSON with the published schema: exact match, 21 tools. Used a Python subprocess timeout because GNUtimeoutis unavailable on this macOS host..github/workflows/seo.yml, plusfactcheck.py --fixture-checkandlanding-constants-guard.sh: passed. Existing article/style warnings remain; SEO lint has zero gate violations and the report-only audit has zero critical findings.workflow-timeout-guard.pyandgit diff --check: passed.The first sandboxed MCP run could not bind loopback ports and also encountered macOS temporary-path aliasing. Repeating with loopback allowed and
TMPDIR=/private/tmppassed; no source change was made for those environment failures.Earlier implementation validation, recorded in
df61f3b5and explicitly confirmed by the operator, not independently rerun in this review:b64d9cb0and concern non-UTF8 filenames and PDF worker/spool fixtures on macOS. The full autoindex suite is not claimed green.Contribution review
Reviewed the effective upstream diff and ancestry under
docs/CONTRIBUTION_REVIEW.md. Existing search/default/index behavior and upstream workflows are preserved. Relevant tests cover scope isolation, auth forwarding, missing/numeric mapping fields, legacy passages, ranking/deduplication, no match, invalid arguments before HTTP, malformed responses, HTTP errors and token budgeting. CI runs the real-entrypoint parity script without downloading a model or corpus.N/A: durable-state migration, recovery, destructive failure atomicity, optional accelerators, feature gates and performance measurement: this adds a read-only MCP adapter over existing CLI behavior and makes no such changes or performance claim. No new ES-compatible server behavior requires a YAML case. Installation/deployment recipes are unchanged.
Provenance and limits
Verified in this review: the commands and static review listed above. Earlier full-build/conformance and failing-before evidence is operator-confirmed and identified separately.
Not rerun here: full autoindex, ES-YAML, release builds, Clippy, failing-before mutation, full first-time-agent/persona harness, or live-site deployment validation. The final follow-up changes only reference documentation; it does not change setup or onboarding. Other host platforms and MCP clients were not exercised in this review. CI must validate the final PR merge ref.
No
Co-Authored-Bytrailers were added.