Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

fix(mcp): accept a query argument as the symbol id in get_symbol (#3140)

Raghav Chamadiyabf8bd7e998f4
diff --git a/docs/agent/MCP_TOOLS.md b/docs/agent/MCP_TOOLS.md
index 1552c874e..951971f9d 100644
--- a/docs/agent/MCP_TOOLS.md
+++ b/docs/agent/MCP_TOOLS.md
@@ -195,7 +195,7 @@ Returns verified, line-numbered source for one symbol, a live line range, or an
| `reference` | object | none | A `continuation_reference` or `fetch_reference` this tool emitted; pass it unchanged |
| `context_lines` | int | `0` | Extra lines before and after, 0 to 50 |
| `depth` | int | `1` | 2 or 3 also returns the bodies it calls, transitively |
-| `query` | string | none | Omission refs only: keep stored lines matching this regex or substring |
+| `query` | string | none | Omission refs only: keep stored lines matching this regex or substring. With no `symbol_id` or `id`, it is read as `symbol_id` |
| `repo` | string | default repo | Workspace repo alias. `"all"` is not supported |
**Key return fields:** `source` (up to about 600 lines, each prefixed with its line number), start and end lines, `kind`, `truncated` with a continuation to pass back, `ambiguous` and `candidates` when several symbols match, `callee_bodies` (with `depth` above 1), `not_rendered` (bodies past the budget, each with a range read to fetch it), fallback lines from a live grep on a miss. A class or other container too large to serve whole returns `outlined: true`, its header in `source` and `members` (each member's `symbol_id`, signature and lines, with `members_total` when the list is capped) in place of the body, and no `_meta.complete`.
diff --git a/packages/server/src/repowise/server/mcp_server/tool_symbol.py b/packages/server/src/repowise/server/mcp_server/tool_symbol.py
index 9e67704dc..9122d0e7b 100644
--- a/packages/server/src/repowise/server/mcp_server/tool_symbol.py
+++ b/packages/server/src/repowise/server/mcp_server/tool_symbol.py
@@ -1006,7 +1006,8 @@ async def get_symbol(
live range, or an omission ref.
context_lines: extra lines before/after (0-50).
repo: usually omitted.
- query: omission refs only, regex/substring filter on lines.
+ query: omission refs only, regex/substring filter on lines. With
+ no id given, it is read as ``symbol_id``.
id: accepted alias for ``symbol_id``.
depth: 1 (default) is this symbol alone; 2-3 also returns the bodies
it calls, transitively, in ``callee_bodies``.
@@ -1035,10 +1036,14 @@ async def get_symbol(
# are given.
if not symbol_id and id:
symbol_id = id
+ elif not symbol_id and query and query.strip():
+ # Hosts that defer tool schemas let a model guess ``query`` for the id.
+ # The line filter needs an id to apply to, so alone it is the id.
+ symbol_id, query = query, None
if not symbol_id or not symbol_id.strip():
return {
"symbol_id": symbol_id,
- "error": "symbol_id is required",
+ "error": 'get_symbol requires `symbol_id`, e.g. "path/to/file.py::Name".',
"_meta": _build_meta(timing_ms=(time.perf_counter() - t0) * 1000),
}
diff --git a/tests/unit/server/mcp/test_symbol_range_and_recovery.py b/tests/unit/server/mcp/test_symbol_range_and_recovery.py
index 6ee8c48d8..3a57dfd88 100644
--- a/tests/unit/server/mcp/test_symbol_range_and_recovery.py
+++ b/tests/unit/server/mcp/test_symbol_range_and_recovery.py
@@ -205,7 +205,36 @@ async def test_neither_id_nor_symbol_id_returns_shaped_error(setup_mcp, repo_on_
from repowise.server.mcp_server import get_symbol
result = await get_symbol()
- assert "required" in (result.get("error") or "").lower()
+ assert "`symbol_id`" in (result.get("error") or "")
+
+
+async def test_query_alone_is_read_as_symbol_id(setup_mcp, repo_on_disk):
+ # A host that defers tool schemas lets the model guess `query` for the id.
+ from repowise.server.mcp_server import get_symbol
+
+ by_query = await get_symbol(query="pkg/mod.py:5-6")
+ by_id = await get_symbol("pkg/mod.py:5-6")
+
+ assert by_query.get("error") is None
+ assert by_query["source"] == by_id["source"]
+
+
+async def test_symbol_id_wins_over_query(setup_mcp, repo_on_disk):
+ from repowise.server.mcp_server import get_symbol
+
+ result = await get_symbol("pkg/mod.py:5-6", query="pkg/ghost.py:1-2")
+ assert result.get("error") is None
+ assert result["start_line"] == 5
+
+
+async def test_blank_query_still_names_symbol_id(setup_mcp, repo_on_disk):
+ from repowise.server.mcp_server import get_symbol
+
+ result = await get_symbol(query=" ")
+ assert "`symbol_id`" in result["error"]
@pytest.mark.asyncio