Repository navigation
fix(mcp): resolve xerj_search prefix the way autoindex stores it - #2235
Merged
Merged
Conversation
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>
cursor
Bot
force-pushed
the
cursor/mcp-search-prefix-resolve-4fe1
branch
from
October 23, 2026 04:24
4a225f6 to
aa87fbc
Compare
Owner
Author
|
Xerj Merger made the fix: |
cursor Bot
pushed a commit
that referenced
this pull request
Oct 23, 2026
The only conflict was CHANGELOG.md. Both sides added an Unreleased Fixed entry at the top of the section. Keep both: main's corpus-index journal resume (#2239) and this branch's Windows commit-space memory cap (#1122). The prefix-resolution Fixed entry from #2235 merged without a marker. Engine and common sources were not touched on main since the last merge and stayed as this branch left them. Co-authored-by: xerj-org <xerj-org@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Written by an AI coding agent (Cursor Grok 4.7).
What this changes, and why
Agents pass the
--prefixthey used withxerj autoindex. MCPxerj_searchgained aprefixargument in #2137, but it built{prefix}-*from the raw string. Autoindex stores a sanitized prefix (My_Projbecomesmy-proj), so those characters search a pattern that does not exist.xerj searchandxerj defhad the same gap: three copies offormat!("{prefix}-*"), and none of them calleddataset::sanitize_prefix/index_prefix_error, which is howxerj autoindex --prefixnames indices.resolve_prefixinxerj-autoindexis now the one function.xerj search,xerj def, and MCPxerj_searchcall it.projectsearchesproject-*.My_Projsearchesmy-proj-*. A trailing-*copied off an index name is not part of the prefix.[a-z0-9]character, or one that cannot name an index, is an error before any request.indexandprefixis an error. They name different scopes.ax-*, the CLI default when--prefixis omitted. Refusing that case would break every caller of the default corpus (xerj_search requires an index argument and no agent-facing doc says to pass ax-* #962). The tool description says so.The published MCP schema, README, and README.zh-CN describe that contract.
xerj_defis not added here; that tool is #2166.Refs #2080
Evidence
rustc 1.97.1, from
engine/,cargo --locked -j 4:cargo test -p xerj-autoindex --lib: 1619 passed, 0 failed, 2 ignoredcargo test -p xerj-mcp: 117 lib tests,hub_tools,published_schema_drift(4),search_exact_phrase, andsearch_prefix, 0 failed. The node test seedsproject-docs,my-proj-docs, andax-otherand checksprefix: project,prefix: My_Proj,prefix: project-*, the default, and an explicit index, for a plain string and a DSL query.cargo clippy -p xerj-autoindex --lib -- -D warnings: exit 0cargo clippy -p xerj-mcp --all-targets -- -D warnings: exit 0cargo fmt --allwith rustfmt 1.97.1Checks
cargo fmt --all(CI runsrustfmt --checkandclippy -D warnings)cargo build --release -j 32 -p <crate>cargo test -p <crate>passes (cargo checkis not sufficient — test code is interleaved with production code)docs/CONTRIBUTION_REVIEW.md. Ancestry ismainplus this commit. No durable state, migration, or recovery path changes. Existing explicit-index and defaultax-*search behavior is preserved. Failure of a bad prefix happens before HTTP, so no partial write.Not run: a release build of
xerj-mcp/xerj-autoindex, and the ES-YAML suite. Debug tests and clippy cover the crates that changed. The CLI binary was not invoked against a live node;run_search_cliandrun_def_clicallresolve_prefix, which the unit test and the MCP node test exercise.Provenance
tool_specs.