Skip to content

fix(github-mcp): rank the requested tool first in pi's tool_search - #16

Merged
Martin Bens (SpiGAndromeda) merged 1 commit into
mainfrom
fix/pi-tool-search-ranking
Oct 3, 2026
Merged

Martin Bens (SpiGAndromeda) merged 1 commit into
mainfrom
fix/pi-tool-search-ranking

Conversation

@SpiGAndromeda

@SpiGAndromeda Martin Bens (SpiGAndromeda) commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #15.

pi's tool_search ranks deferred tools with BM25. Each tool's search text includes its server's description and instructions, so every word in those texts appears in every tool of that server. The old texts listed the nouns the tools are named after (issues, pull requests, runs, …). Those words stopped telling tools apart, and issue_view ranked 5th for the query issue_view.

Changes

  • Server descriptions (pi/index.ts): Remote GitHub data through the gh CLI, not local git. and Changes to remote GitHub data through the gh CLI, not local git. Empty unless enable_write_server is true. They share no word with any tool name. "Not local git" keeps some scope in pi's mcp_servers summary without naming tool categories, because every category word is also a tool name.
  • Server instructions (config-read.json, config-write.json): rewritten under the same rule. The vendored SDK (v5.2.0) does not send instructions yet; once a later SDK does, the old texts would have put issue_view back at 5th. The read instructions no longer name repo_tree/repo_file; the tool directive names every tool for every host.
  • pi directive (hooks/prompts/host-pi.md): while the tools are deferred, call a tool that is already loaded directly; otherwise search by exact name with limit: 1, and search again if a different tool loads. tool_search only ranks tools that are not loaded yet, so the default limit of 8 loaded up to eight tools per lookup.
  • Shared tool directive (mcp-tool-directives.md): lists release_list, which was missing for every host. The root README's category list now includes releases.

Remaining misses

Five names share terms with another tool through their own catalog descriptions, so no server text can fix them: search (up to 3rd), repo_file (3rd), and with the write server pr_comments (5th), pr_reviews (3rd) and pr_comment (3rd). Under limit: 1 each takes one more search per place it ranks below first. limit: 1 is still the cheaper choice: all other tools rank first, so most lookups load one tool. The real fix is in pi's ranker (exact-name matches first, or server text kept out of per-tool documents).

pi's tool_search ranks deferred tools with BM25 and adds each MCP server's description and instructions to every one of its tools' search text. The old texts listed the nouns the tools are named after (issues, pull requests, runs), so those terms stopped telling tools apart and an exact-name query such as issue_view ranked 5th. The server descriptions in pi/index.ts and the instructions in config-read.json and config-write.json now share no word with any tool name. The vendored SDK does not send the instructions yet, but a later version would otherwise undo the fix.

host-pi.md now tells the model to call a loaded tool directly and otherwise search by exact name with limit: 1, searching again when a different tool loads, because tool_search skips loaded tools and the default limit loads up to eight tools per search. search, repo_file, and with the write server pr_comments, pr_reviews and pr_comment still rank 2nd to 5th, since their own descriptions share terms with another tool.

tool-search-ranking.test.ts runs pi's own ranker over both tool catalogs, with and without the instructions, and requires every tool to rank first except those five, each with a worst allowed rank. A second test fails when a server text shares a word with a tool name. pi_e2e.bats checks that the real tool_search with limit: 1 loads exactly pr_view and, in a new case, issue_view. The two pi unit test files now share one fake pi in fake-pi.ts.

The shared tool directive now lists release_list and the root README lists releases. Both were missing.

Closes #15

Co-Authored-By: Claude <noreply@anthropic.com>
@SpiGAndromeda
Martin Bens (SpiGAndromeda) merged commit 870bc21 into main Oct 3, 2026
1 check passed
@SpiGAndromeda
Martin Bens (SpiGAndromeda) deleted the fix/pi-tool-search-ranking branch October 3, 2026 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pi: use generic MCP server descriptions so tool_search ranks the right tool

1 participant