Skip to content

fix(cli): default serve --mcp project to the current directory#25

Merged
sunerpy merged 1 commit into
mainfrom
fix/mcp-serve-default-cwd
Jun 22, 2026
Merged

fix(cli): default serve --mcp project to the current directory#25
sunerpy merged 1 commit into
mainfrom
fix/mcp-serve-default-cwd

Conversation

@sunerpy

@sunerpy sunerpy commented Jun 22, 2026

Copy link
Copy Markdown
Owner

Summary

codegraph serve --mcp (without --path) advertised zero MCP tools, so every agent the installer configures (opencode, Cursor, …) registered 0 codegraph_* tools — the server connected but tools/list returned [].

Root cause: the installer injects exactly args: ["serve", "--mcp"] (no --path). In cmd_serve, an absent --path left default_project = Nonehas_default_codegraph() false → tools/list served an empty array. The CLI never defaulted the project to the current directory (unlike resolve_required_project).

Fix: default the MCP project to the cwd (resolved up to the nearest .codegraph/) when --path is absent, using the non-bailing resolver so an unindexed cwd still starts and serves an empty list (upstream parity preserved). The golden-pinned tools/list gating, has_default_codegraph, schemas.rs, and tools_list.json are untouched.

-let project = path.map(|p| resolve_project_path_optional(&absolute_path(p)));
+let project = Some(resolve_project_path_optional(&absolute_path(
+    path.unwrap_or_else(|| PathBuf::from(".")),
+)));

Verification

  • Added 2 MCP tests: indexed default project → tools/list has 4 tools; unindexed → empty (upstream parity).
  • End-to-end через opencode: with the fixed binary on PATH, opencode launched codegraph serve --mcp (no --path) from an indexed repo, registered the tools, and successfully invoked codegraph_search (returned cmd_serve @ main.rs). Raw MCP handshake from an indexed cwd also returns 4 tools (search/callers/node/explore) — before the fix it returned 0.
  • cargo test --workspace, cargo clippy --workspace --all-targets -- -D warnings, cargo fmt --all --check, bash scripts/guardrail.sh all clean; golden equivalence (codegraph-bench) unchanged; Windows x86_64 cross-compile green.

Note

fix(cli): → release-please will cut a patch (v0.5.2). Restores codegraph MCP tools for all agent integrations.

The installer launches `serve --mcp` without `--path`, leaving
default_project None -> McpServer serves an empty tools/list, so every
agent (opencode/Cursor/...) registered 0 codegraph_* tools.

Default the project to the current working directory (resolved up to the
nearest .codegraph/) using the non-bailing resolver, so `serve --mcp`
launched in an indexed project root resolves Some(project) and tools/list
returns the tool set. An unindexed cwd still starts the server and serves
an empty tools/list.

tools/list gating (has_default_codegraph) is unchanged and remains
golden-pinned to upstream; the fix is only in how cmd_serve resolves the
default project path.
@sunerpy sunerpy merged commit 26be9df into main Jun 22, 2026
4 checks passed
@sunerpy sunerpy deleted the fix/mcp-serve-default-cwd branch June 22, 2026 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant