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.

feat(mcp): tell agents when to reach for repowise instead of a text search (#3134)

Raghav Chamadiya1d24f0f24d06
diff --git a/packages/server/src/repowise/server/mcp_server/_server.py b/packages/server/src/repowise/server/mcp_server/_server.py
index 2fd692736..04580fb20 100644
--- a/packages/server/src/repowise/server/mcp_server/_server.py
+++ b/packages/server/src/repowise/server/mcp_server/_server.py
@@ -719,12 +719,28 @@ async def _lifespan(server: FastMCP):
mcp = FastMCP(
"repowise",
+ # Hosts that defer tool schemas show the model only tool names and this
+ # string, so it says when to call; tests pin the key lines and a length cap.
instructions=(
- "repowise is a codebase documentation engine. Use these tools to query "
- "the wiki for architecture overviews, contextual docs on files/modules/"
- "symbols, modification and change-risk assessment, architectural decision "
- "rationale, semantic search, dead code, and code health. In workspace mode, "
- "get_architecture and get_blast_radius are also available. If the tools "
+ "repowise indexes this repository's code graph, git history and "
+ "decisions. One call here often replaces several text searches and "
+ "file reads.\n"
+ "- Use search_codebase(query) to find an identifier or literal: it "
+ "returns `lines` (path, line, kind, text; definitions first) read from "
+ "live files, and `complete: true` means that is every match. Path-like "
+ "and concept queries rank files.\n"
+ '- Use get_context(targets=[symbol], include=["references"]) before a '
+ "rename or an update-all-callers change: it lists the definition, "
+ "imports and calls, and a `complete` list is the whole edit set.\n"
+ "- Use get_answer(question) for a how/where/why question: one cited "
+ "answer.\n"
+ "- Use get_risk before a non-trivial edit to a widely imported file, "
+ "get_change_risk before committing a multi-file change, and get_why "
+ "before changing an established pattern. Skip them for one-line fixes.\n"
+ "- Targets with uncommitted edits are flagged; the index is stale for "
+ "them until `repowise update --working-tree` runs.\n"
+ "In workspace mode, get_architecture and get_blast_radius are also "
+ "available. If the tools "
"report that the repo has no index, tell the user to run "
"'repowise init --yes' in the repo root; it needs no API key. Suggest it, "
"do not run it yourself."
diff --git a/tests/unit/server/mcp/test_server_instructions.py b/tests/unit/server/mcp/test_server_instructions.py
new file mode 100644
index 000000000..ceb2c22a3
--- /dev/null
+++ b/tests/unit/server/mcp/test_server_instructions.py
@@ -0,0 +1,32 @@
+"""The server ``instructions`` string decides whether an agent reaches for the tools.
+
+Hosts that defer tool schemas show only tool names plus this string, and some
+truncate long instructions, so the guidance that matters is pinned here.
+"""
+
+from __future__ import annotations
+
+from repowise.server.mcp_server import mcp
+
+# Well under the 2,000 chars some hosts keep.
+_MAX_INSTRUCTIONS_CHARS = 1500
+
+
+def test_instructions_fit_the_length_cap() -> None:
+ assert len(mcp.instructions) < _MAX_INSTRUCTIONS_CHARS
+
+
+def test_instructions_say_when_each_tool_replaces_a_text_search() -> None:
+ text = mcp.instructions
+ assert "search_codebase" in text and "`lines`" in text
+ assert 'include=["references"]' in text
+ assert "get_answer" in text
+ assert "get_risk" in text and "get_change_risk" in text and "get_why" in text
+ assert "repowise update --working-tree" in text
+
+
+def test_instructions_keep_the_no_index_and_workspace_guidance() -> None:
+ text = mcp.instructions
+ assert "repowise init --yes" in text
+ assert "do not run it yourself" in text
+ assert "get_architecture" in text and "get_blast_radius" in text