Skip to content
16 changes: 11 additions & 5 deletions code_review_graph/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
get_suggested_questions_func,
get_surprising_connections_func,
get_wiki_page_func,
traverse_graph_func,
list_communities_func,
list_flows,
list_graph_stats,
Expand All @@ -52,6 +51,7 @@
refactor_func,
run_postprocess,
semantic_search_nodes,
traverse_graph_func,
)

# NOTE: Thread-safe for stdio MCP (single-threaded). If adding HTTP/SSE
Expand Down Expand Up @@ -155,7 +155,7 @@ async def run_postprocess_tool(


@mcp.tool()
def get_minimal_context_tool(
async def get_minimal_context_tool(
task: str = "",
changed_files: Optional[list[str]] = None,
repo_root: Optional[str] = None,
Expand All @@ -167,15 +167,21 @@ def get_minimal_context_tool(
next tools in a single compact response. Use this as the entry point
before any other graph tool to minimize token usage.

Offloaded to a thread via ``asyncio.to_thread`` so git diff / analyze_changes
don't block the stdio event loop. See: #46, #136.

Args:
task: What you are doing (e.g. "review PR #42", "debug login timeout").
changed_files: Explicit list of changed files. Auto-detected if omitted.
repo_root: Repository root path. Auto-detected if omitted.
base: Git ref for diff comparison. Default: HEAD~1.
"""
return get_minimal_context(
task=task, changed_files=changed_files,
repo_root=_resolve_repo_root(repo_root), base=base,
return await asyncio.to_thread(
get_minimal_context,
task=task,
changed_files=changed_files,
repo_root=_resolve_repo_root(repo_root),
base=base,
)


Expand Down
3 changes: 2 additions & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def fake_run(**kwargs):

monkeypatch.setattr(crg_main.mcp, "run", fake_run)
crg_main.main(repo_root=None)
assert calls == [{"transport": "stdio"}]
assert calls == [{"transport": "stdio", "show_banner": False}]

def test_http_calls_mcp_run_with_host_port(self, monkeypatch):
calls: list[dict] = []
Expand Down Expand Up @@ -103,6 +103,7 @@ class TestLongRunningToolsAreAsync:
"embed_graph_tool",
"detect_changes_tool",
"generate_wiki_tool",
"get_minimal_context_tool",
}

def test_heavy_tools_are_coroutines(self):
Expand Down
Loading