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 get_risk(changed_files=[...]) without targets (#2761)

Raghav Chamadiya5be76bfbbb8a
diff --git a/README.md b/README.md
index fa9f9e953..e634b5265 100644
--- a/README.md
+++ b/README.md
@@ -718,7 +718,7 @@ so your agent always knows how much to trust what it just read.
| `get_context(targets, include?)` | Triage card for files, modules or symbols: summary, signatures, `hotspot` bit, governing decisions, `symbol_id`s. `include` opens callers, callees, ownership and metrics. Batch many targets in one call. |
| `get_symbol("file.py::Name")` | Source for one indexed symbol with exact line bounds. Cheaper and safer than `Read` plus offset math. |
| `search_codebase(query, kind?)` | Semantic search over the wiki, filterable by kind (implementation / test / config / doc), tagging each result's `search_method`. |
-| `get_risk(targets, changed_files?)` | Hotspots, dependents, co-change partners, ownership, test gaps, bug history. Pass `changed_files` for PR mode and get a `directive` block back. |
+| `get_risk(targets?, changed_files?)` | Hotspots, dependents, co-change partners, ownership, test gaps, bug history. Pass `changed_files` for PR mode and get a `directive` block back. |
| `get_change_risk(revspec)` | What a commit, range or uncommitted change newly made worse across defect, maintainability and performance, why each finding is attributable to it, the tests coverage proves it touches, and how the diff's shape ranks against recent commits. |
| `get_why(query?, targets?)` | Architectural decisions and their verbatim evidence spans, stamped exact / fuzzy / unverified. Falls back to git archaeology when no decisions exist. |
| `get_dead_code(...)` | Unreachable code by confidence tier with cleanup-impact estimates, and cross-repo consumer detection in workspace mode. |
diff --git a/packages/core/src/repowise/core/generation/editor_files/tool_table.py b/packages/core/src/repowise/core/generation/editor_files/tool_table.py
index 0df1ead07..6b38e6f16 100644
--- a/packages/core/src/repowise/core/generation/editor_files/tool_table.py
+++ b/packages/core/src/repowise/core/generation/editor_files/tool_table.py
@@ -86,7 +86,7 @@ TOOL_TABLE_ROWS: dict[str, tuple[str, str]] = {
"rationale comments. Call before a refactor or a pattern divergence.",
),
"get_risk": (
- "get_risk(targets, changed_files?, include?)",
+ "get_risk(targets?, changed_files?, include?)",
"File history and structural reach. PR mode leads with `directive`; its "
"0-10 structural heuristic is uncalibrated, not a probability. Read typed "
"test recommendations and coverage state first.",
diff --git a/packages/server/README.md b/packages/server/README.md
index ce64a96ab..85dfe853f 100644
--- a/packages/server/README.md
+++ b/packages/server/README.md
@@ -251,7 +251,7 @@ repowise mcp --transport sse # legacy SSE transport on port 7338
| `get_context(targets)` | Docs, ownership, history, decisions, freshness for files/modules/symbols | When you need to understand specific code before reading or modifying it |
| `get_symbol(symbol_id)` | Source body, signature, docstring for a qualified symbol | When the question names a specific function or class |
| `search_codebase(query, mode?)` | Hybrid symbol / path / concept search (auto-routes by query shape) | When locating a symbol, a file, or code by topic |
-| `get_risk(targets)` | Hotspot score, dependents, co-change partners, risk summary | Before modifying files — assess what could break |
+| `get_risk(targets?, changed_files?)` | Hotspot score, dependents, co-change partners, risk summary | Before modifying files — assess what could break |
| `get_change_risk(revspec?)` | What the change newly made worse, with attribution, plus a supporting diff-shape percentile | Before merging a commit or PR range |
| `get_why(query?)` | Architectural decisions, rationale, constraints | Before making architectural changes — understand existing intent |
| `get_dead_code` | Unused/unreachable code sorted by cleanup impact | Before cleanup tasks |
diff --git a/packages/server/src/repowise/server/mcp_server/tool_risk/get_risk.py b/packages/server/src/repowise/server/mcp_server/tool_risk/get_risk.py
index adb29c4f3..bc993a38a 100644
--- a/packages/server/src/repowise/server/mcp_server/tool_risk/get_risk.py
+++ b/packages/server/src/repowise/server/mcp_server/tool_risk/get_risk.py
@@ -294,7 +294,7 @@ async def _lead_with_pr_directive(
),
)
async def get_risk(
- targets: list[str],
+ targets: list[str] | None = None,
repo: str | None = None,
changed_files: list[str] | None = None,
include: list[str] | None = None,
@@ -323,7 +323,7 @@ async def get_risk(
Include-gated blocks are projections, not omissions.
Args:
- targets: file paths to assess.
+ targets: file paths to assess; defaults to changed_files.
repo: usually omitted.
changed_files: PR-changed files for blast-radius mode.
include: opt-in blocks - "graph", "churn", "scales" (units and
@@ -331,6 +331,8 @@ async def get_risk(
"""
if repo == "all":
return _unsupported_repo_all("get_risk")
+ if not targets and not changed_files:
+ return {"error": "targets or changed_files is required", "_meta": _build_meta()}
ignored: list[dict] = []
include_set = {
block
@@ -340,7 +342,7 @@ async def get_risk(
ctx = await _resolve_repo_context(repo)
collector = OmissionCollector("get_risk", repo_root=ctx.path)
exclude_spec = _get_exclude_spec(ctx.path)
- targets = filter_path_list(targets, exclude_spec)
+ targets = filter_path_list(targets or changed_files, exclude_spec)
changed_files = filter_path_list(changed_files, exclude_spec)
include_graph = "graph" in include_set
evidence = await _gather_evidence(
diff --git a/tests/unit/server/mcp/test_risk.py b/tests/unit/server/mcp/test_risk.py
index 12da7c405..ec3e20e20 100644
--- a/tests/unit/server/mcp/test_risk.py
+++ b/tests/unit/server/mcp/test_risk.py
@@ -177,6 +177,29 @@ async def test_get_risk_pr_directive_splits_test_breakage(setup_mcp):
assert set(RISK_RELATED_FILE_KEYS) <= set(directive)
+async def test_get_risk_changed_files_alone_is_pr_mode(setup_mcp):
+ """The documented get_risk(changed_files=[...]) call assesses the changed set."""
+ from repowise.server.mcp_server import get_risk
+
+ alone = await get_risk(changed_files=["src/auth/service.py"])
+ explicit = await get_risk(["src/auth/service.py"], changed_files=["src/auth/service.py"])
+
+ assert next(iter(alone)) == "directive"
+ assert alone["directive"] == explicit["directive"]
+ assert list(alone["targets"]) == ["src/auth/service.py"]
+
+
+async def test_get_risk_without_targets_or_changed_files_is_an_error(setup_mcp):
+ from repowise.server.mcp_server import get_risk
+
+ result = await get_risk()
+
+ assert result["error"] == "targets or changed_files is required"
+ assert "targets" not in result
+
+
@pytest.mark.asyncio
async def test_get_risk_pr_directive_surfaces_coverage_backed_tests_to_run(setup_mcp, session):
"""PR directive carries coverage-backed tests_to_run from the per-test map."""