Skip to content

feat(mcp): always expose tools and require projectPath when no default project (#94)#95

Merged
sunerpy merged 2 commits into
mainfrom
feat/mcp-autodetect-no-default-tools
Jun 30, 2026
Merged

feat(mcp): always expose tools and require projectPath when no default project (#94)#95
sunerpy merged 2 commits into
mainfrom
feat/mcp-autodetect-no-default-tools

Conversation

@sunerpy

@sunerpy sunerpy commented Jun 30, 2026

Copy link
Copy Markdown
Owner

Fixes #94.

Problem

In 通义灵码 (Lingma) — a roots-less IDE that launches the MCP server from a fixed working directory and sends no rootUri/workspaceFolders/rootstools/list returned an empty array unless -p <path> was set. But -p is shared across every IDE window, so it pins all windows to one project. Users were stuck: no -p → 0 tools; with -p → wrong project in every other window.

Fix (forward-port colby #964 + #993)

  • #964 (always-expose): tools/list now ALWAYS returns the visible tool surface, even when no project is resolved. Removes the 0-tools dead end.
  • #993 (required projectPath): when no default project resolves, each listed tool's inputSchema.required gains projectPath, nudging the agent to pass it per call. When a default project IS resolved, projectPath stays optional (byte-identical to the golden).

This reverses the earlier c450fd95 "empty list when unindexed" behavior, which was the #94 root cause.

Honest scope

This removes the dead end and provides the supported escape hatch (projectPath per call, or -p). For the foreign-cwd Lingma case, per-call usability depends on the agent supplying projectPath — it is not zero-config per-window auto-binding (Lingma sends no workspace signal and supports no ${workspaceFolder}; the deterministic alternative would need a per-project config file, deliberately out of scope). Documented as a known limitation in docs/mcp.md#project-resolution.

Changes

  • crates/codegraph-mcp/src/schemas.rs: pure, idempotent with_required_project_path (handles all three required-array shapes) + visible_tool_definitions_requiring_project_path; unit tests.
  • crates/codegraph-mcp/src/server.rs: tools/list dispatch arm always-exposes; stale doc comments rewritten.
  • crates/codegraph-mcp/tests/golden_mcp.rs: flipped+renamed the two empty-list tests, added a no-default McpServer::new(None) test, asserted projectPath stays optional in the indexed guard.
  • docs/mcp.md + README.md: honest always-list + projectPath-nudge story.

Invariants

  • Golden reference/ BYTE-IDENTICAL (roundtrip uses an indexed project; the change only affects the no-default path no golden frame exercises). handle_tools_call untouched. No auto-indexing, no new tool/env var/schema migration, no per-project file, no hand version bump.

Verification

  • make ci green; cargo test -p codegraph-mcp + -p codegraph-bench green; git diff --quiet reference/ exit 0.
  • Hands-on QA across 4 launch contexts (unindexed / nested-under-indexed / $HOME too-broad / residual tools/call with & without projectPath) — all behave per the honest framing.
  • Plan reviewed by triple Momus + dual-oracle Final Wave (compliance, scope, code quality, honesty) — all APPROVE.

sunerpy added 2 commits June 30, 2026 21:33
…t project (#94)

tools/list previously returned an empty array when no default project was
resolved (unindexed cwd / roots-less client), so 通义灵码 (Lingma) showed 0
tools unless -p was set -- and -p is shared across every IDE window.

Forward-port colby #964 (PR#966) + #993 (PR#1007): tools/list now ALWAYS
exposes the visible tool surface. When a default project is resolved,
projectPath stays optional (byte-identical to the golden). When none is
resolved, the same tools are listed with projectPath marked required in each
inputSchema so the agent supplies it per call. Reverses the c450fd95
empty-when-unindexed behavior.

- schemas.rs: pure idempotent with_required_project_path transform handling
  all three required-array shapes (with-keys / empty / absent) +
  visible_tool_definitions_requiring_project_path; unit tests for each.
- server.rs: tools/list dispatch arm always-exposes; rewrote the stale
  has_default_codegraph doc comment.
- golden_mcp.rs: flipped+renamed the two empty-list tests, added a
  no-default McpServer::new(None) test, and asserted projectPath stays
  optional in the indexed-default guard.

Golden reference/ byte-identical (roundtrip uses an indexed project).
@sunerpy sunerpy merged commit f4ec1bc into main Jun 30, 2026
4 checks passed
@sunerpy sunerpy deleted the feat/mcp-autodetect-no-default-tools branch June 30, 2026 13:53
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.

mcp必须设置路径才显示工具

1 participant