Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(mcp): gate bare symbol names defined only in excluded files (#4084)
Yunus Ozen1b51b62827a9
diff --git a/packages/server/src/repowise/server/mcp_server/tool_context/resolution.py b/packages/server/src/repowise/server/mcp_server/tool_context/resolution.pyindex 95ef249f2..353ff4f2c 100644--- a/packages/server/src/repowise/server/mcp_server/tool_context/resolution.py+++ b/packages/server/src/repowise/server/mcp_server/tool_context/resolution.py@@ -29,6 +29,7 @@ from repowise.server.mcp_server._helpers import (LIKE_ESCAPE,escape_like,filter_path_list,+ filter_rows_by_attr,is_excluded,)from repowise.server.mcp_server._references import symbol_identity@@ -152,13 +153,17 @@ async def _excluded(q: TargetQuery) -> Resolution | None:aren't path-matchable here and fall through to neighbor filtering)."""gate_path = q.target.split("::", 1)[0] if "::" in q.target else q.targetif is_excluded(gate_path, q.exclude_spec):- return {- "target": q.target,- "error": f"'{q.target}' is excluded by exclude_patterns configuration",- }+ return _excluded_error(q)return None+def _excluded_error(q: TargetQuery) -> Resolution:+ return {+ "target": q.target,+ "error": f"'{q.target}' is excluded by exclude_patterns configuration",+ }++async def _file_page_by_id(q: TargetQuery) -> Resolution | None:"""A file page, the most common target."""page = await q.session.get(Page, f"file_page:{q.target}")@@ -253,6 +258,11 @@ async def _symbol(q: TargetQuery) -> Resolution | None:sym_matches = await _symbol_rows(q)if not sym_matches:return None+ # A bare name isn't path-matchable in ``_excluded``, so drop the rows in+ # excluded files here; if none is left, answer as a ``path::Name`` would.+ sym_matches = filter_rows_by_attr(sym_matches, "file_path", q.exclude_spec)+ if not sym_matches:+ return _excluded_error(q)return ResolvedTarget("symbol",file_path=sym_matches[0].file_path,diff --git a/tests/unit/server/mcp/test_mcp_exclude_filter_context_answer.py b/tests/unit/server/mcp/test_mcp_exclude_filter_context_answer.pyindex 4de1ff5a7..256c8347c 100644--- a/tests/unit/server/mcp/test_mcp_exclude_filter_context_answer.py+++ b/tests/unit/server/mcp/test_mcp_exclude_filter_context_answer.py@@ -51,6 +51,44 @@ async def test_get_context_gates_excluded_symbol_id_target(setup_mcp, monkeypatcassert "error" in t[email protected]("target", ["User", "db.models.User"])+async def test_get_context_gates_excluded_bare_symbol_target(setup_mcp, monkeypatch, target):+ """A bare or qualified name defined only in an excluded file is gated like ``path::Name``."""+ import repowise.server.mcp_server.tool_context.context as context_mod+ from repowise.server.mcp_server import get_context++ monkeypatch.setattr(context_mod, "_get_exclude_spec", lambda _p: SPEC)++ result = await get_context([target], include=["docs"])+ t = result["targets"][target]+ assert "exclude" in t["error"].lower()+ assert "docs" not in t+++async def test_get_context_bare_symbol_outside_exclusion_still_resolves(setup_mcp, monkeypatch):+ import repowise.server.mcp_server.tool_context.context as context_mod+ from repowise.server.mcp_server import get_context++ monkeypatch.setattr(context_mod, "_get_exclude_spec", lambda _p: SPEC)++ result = await get_context(["AuthService"], include=["docs"])+ t = result["targets"]["AuthService"]+ assert t["type"] == "symbol"+ assert t["docs"]["file_path"] == "src/auth/service.py"+++async def test_get_context_bare_symbol_unfiltered_without_spec(setup_mcp):+ from repowise.server.mcp_server import get_context++ result = await get_context(["User"], include=["docs"])+ t = result["targets"]["User"]+ assert t["type"] == "symbol"+ assert t["docs"]["file_path"] == "src/db/models.py"++@pytest.mark.asyncioasync def test_get_context_filters_excluded_imported_by(setup_mcp, monkeypatch):"""An excluded importer must not appear in a non-excluded file's imported_by."""