Repository navigation
fix(mcp): ask the user before initializing a project that has no index - #351
Merged
Merged
Conversation
An agent that met a project without an index was told to build one itself. The no-project tool text said "run `codegraph init` there" or "run `codegraph init` in the project", and the server instructions only said to offer `codegraph init .` without saying that the user decides (#269). The no-default text and the explicit-projectPath error now say: if the project has no CodeGraph index yet, tell the user so, offer to run `codegraph init .` in the project directory, and do not run it without the user's consent. The rest of each message (projectPath, --path, the truncated-scan note) is unchanged, and the text that lists indexed sub-projects still does not mention init. The Limitations bullet of the server instructions gives the same rule, so the instructions string of reference/golden/mcp/initialize.json changes in that one bullet and is recorded in the new v0.56.1 regeneration log of docs/equivalence.md. docs/mcp.md describes the rule. The skill told agents to follow the recovery command a CLI command prints, which for a project without an index is `codegraph init`; it now says that case is the user's decision. Verified: the new tests in roots.rs and instructions.rs, the extended server.rs, rmcp_handler.rs, rmcp_roots.rs and codegraph-rs http_serve tests, golden_mcp and rmcp_parity all failed on the old text and pass now. cargo test -p codegraph-mcp --locked passes (548 tests). The codegraph-rs http_serve, rmcp_serve_direct, zed_bare_serve, batch_m_failed_open_recovery and skill_install tests and the embedded skill unit tests pass. Clippy with -D warnings passes on codegraph-mcp and codegraph-rs. scripts/regen-goldens.sh --check with the release codegraph and bench binaries of this tree reports all 32 corpora identical. A stdio session of the release binary in an unindexed directory returns the new text for both cases.
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #351 +/- ##
=======================================
Coverage 96.40% 96.40%
=======================================
Files 368 368
Lines 254382 254436 +54
=======================================
+ Hits 245229 245283 +54
Misses 9153 9153
... and 2 files with indirect coverage changes 🚀 New features to boost your workflow:
|
Merged
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.
Summary
When a CodeGraph MCP tool finds no indexed project, its text no longer tells the agent to run
codegraph inititself. It now says that if the project has no CodeGraph index yet, the agent should tell the user so, offer to runcodegraph init .in the project directory, and not run it without the user's consent. The Limitations bullet of the server instructions returned byinitializegives the same rule.crates/codegraph-mcp/src/roots.rs:not_indexed_messageappends the consent sentence to the explicit-projectPatherror and to the no-default text. TheprojectPathand--pathremedies, the sub-project candidate list and the truncated-scan note are unchanged. The candidate-list text still does not mention init.crates/codegraph-mcp/src/instructions.rs: the Limitations bullet. The module doc notes that this bullet is this repository's own wording.reference/golden/mcp/initialize.json: theinstructionsstring changes in that one bullet.docs/mcp.mdandskills/codegraph/SKILL.mddescribe the rule. In the skill, "follow the recovery command a failed command prints" no longer covers a project that was never indexed.docs/equivalence.md: a new v0.56.1 regeneration log with theinitialize.jsonrow.Why
#269, option A (owner decision OD-C8): CodeGraph does not create an index on its own, and when a project has none the agent tells the user and offers
codegraph init. Before this change the tool text said "runcodegraph initthere" or "runcodegraph initin the project", and the instructions only said "offer to runcodegraph init .". Neither said the user decides. Opt-in automatic init (option B) is planned separately and is not in this PR.Verification
Red, at 8166929 with only the test and golden expectations changed:
cargo test -p codegraph-mcp --locked --lib:roots::tests::not_indexed_messages_offer_init_only_with_the_users_consent,instructions::tests::instructions_offer_init_only_with_the_users_consent,server::tests::tools_call_without_a_default_returns_success_text,server::tests::tools_call_bogus_project_path_returns_actionable_error_resultandrmcp_handler::handler_tests::call_tool_bad_project_path_returns_error_resultfailed on the old text, for examplegot: No indexed project resolved. Pass a `projectPath` argument, run `codegraph init` in the project, or start the server with `--path <project>`.--test golden_mcp(initialize_matches_golden) and--test rmcp_parityfailed with "instructions must be byte-identical".--test rmcp_roots(rmcp_does_not_adopt_unindexed_client_root,rmcp_http_no_roots_never_adopts) failed on the old text.cargo test -p codegraph-rs --locked --test http_serve -- serve_http_global_without_projectpath_returns_actionable_errorfailed: the realserve --httpserver returned the old text.Green, on the tree committed as 58f66f4:
cargo test -p codegraph-mcp --locked --no-fail-fast: 548 passed, 0 failed.cargo test -p codegraph-rs --locked --test http_serve --test rmcp_serve_direct --test zed_bare_serve --test batch_m_failed_open_recovery --test skill_install: all pass.cargo test -p codegraph-rs --locked --bin codegraph -- installer::skill: 19 passed.cargo clippy -p codegraph-mcp -p codegraph-rs --all-targets --locked -- -D warnings,cargo fmt --all --check,python3 scripts/docs-check.pyand the oxfmt check are clean.scripts/regen-goldens.sh --checkwith this tree's releasecodegraphandbench: all 32 corpora identical.Notes
instructionsstring ininitialize.json.invalid_config_messagefor an unsafeCODEGRAPH_DIR, and the viewer hint.src/mcp/server-instructions.ts, unchanged since f9fcc2c through 461a5d87) tells the agent to stop calling codegraph tools for an unindexed project and never runcodegraph inititself. Under OD-C8, this repository instead offers the command and runs it only after the user agrees.The pre-push
make pre-cipassed on 58f66f4.