fix(mcp): report never-indexed projects instead of a silent empty search - #1535
Open
wangzhengzhuo05 wants to merge 1 commit into
Open
Conversation
On a project whose last_indexed_at is NULL, search_notes and recent_activity returned an ordinary empty result, indistinguishable from an honest miss on an indexed project. Readiness already exists (ProjectIndexPhase/describe, used by bm status) but nothing under mcp/ read it. On the zero-result path only, read readiness via ProjectClient.get_status and, when the phase is NEVER_INDEXED, reuse ProjectIndexReadiness.describe so the wording cannot drift from bm status. search_notes JSON output carries index_phase; an unreadable readiness falls back to today's copy. Fixes basicmachines-co#1534 Signed-off-by: wangzhengzhuo05 <175673456+wangzhengzhuo05@users.noreply.github.com>
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
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.
What
On a project that has never been indexed (
project.last_indexed_at IS NULL), the MCP tools reported an ordinary empty result that is indistinguishable from an honest "no match" on an indexed project:search_notesreturnedresults: []plusNo results found for '<q>' in project '<p>'. Try broader or different terms, ...recent_activity(project-scoped) was empty and said nothing about the index.Both are vacuous negatives: files exist on disk, but nothing was ever searched. This defeats the "search before creating" convention agents rely on, and it is the state of every fresh install before the first index pass.
Why
The signal already exists —
ProjectIndexPhase.NEVER_INDEXEDandProjectIndexReadiness.describe()— and the CLI already uses it (bm status,bm project add). Nothing undersrc/basic_memory/mcp/readlast_indexed_at, so the MCP surface — the one agents actually read through — never asked.How
src/basic_memory/mcp/tools/search.py: on the zero-result path only, read readiness through the existing typed client (ProjectClient.get_status). When the phase isNEVER_INDEXED,_format_search_markdownreturns an honest sentence that reusesProjectIndexReadiness.describe(...)(so it cannot drift frombm status). The structured path carriesindex_phasein the returned payload.src/basic_memory/mcp/tools/recent_activity.py: the same guard for the project-scoped empty page, replacing the "you have no notes yet" onboarding (which would misread "never looked" as "no notes") with the never-indexed state.Tests
Added 3 tests (
tests/mcp/test_tool_search.py,tests/mcp/test_tool_recent_activity.py) that set up a project whoselast_indexed_atisNonewith a note on disk:search_notestext output names the never-indexed state and thebm project indexremedysearch_notes(output_format="json")carriesindex_phase == "never_indexed"recent_activitytext reports the never-indexed stateResults:
Both failures (
test_search_with_date_filter,test_recent_activity_format_relative_time_and_truncate_helpers) are pre-existing on cleanmain— confirmed by stashing this change and re-running them (same 2 failures), and they are unrelated to the touched code.uv run ruff checkanduv run ruff format --checkpass on all changed files.Mutation check
Disabling the readiness read (
index_readiness = None) makes all 3 new tests fail, and restoring it makes them pass — the tests genuinely guard the fix.Notes
Signed-off-byline.license/clacheck will need my one-time CLA acceptance from the GitHub bot link; the DCO check should pass on its own.Fixes #1534