Repository navigation
feat: usage-aware tool ranking for LLM agent discovery - #43
Merged
knowsuchagency merged 4 commits intoApr 6, 2026
Merged
knowsuchagency merged 4 commits into
knowsuchagency merged 4 commits into
Conversation
Track tool invocations locally in ~/.cache/mcp2cli/usage.json and use that data to rank --list output. Adds three new CLI flags: - --sort usage|recent|alpha|default: control list ordering - --top N: show only the top N tools (key for LLM agent token savings) - --compact: space-separated names only, no descriptions When usage data exists for a source, the default sort becomes "usage" (most-called first). Otherwise insertion order is preserved. Usage is recorded after successful execution in handle_mcp(), _handle_openapi_mode(), and handle_graphql(). Closes knowsuchagency#31
The sort_commands lookup and record_usage in _handle_openapi_mode used different key derivations, which could cause recorded usage to not match during sorting. Unify on `tool_name or graphql_field_name or name`. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Owner
|
Thanks for the contribution! |
knowsuchagency
added a commit
that referenced
this pull request
Apr 6, 2026
Document the usage-aware tool ranking feature added in #43: new CLI reference entries and a usage examples section showing the LLM agent workflow. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
2 tasks done
knowsuchagency
added a commit
that referenced
this pull request
Apr 6, 2026
…44) Document the usage-aware tool ranking feature added in #43: new CLI reference entries and a usage examples section showing the LLM agent workflow. Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the feature described in #31: track tool invocations locally and use that data to rank
--listoutput, reducing token costs for LLM agents working with large MCP servers.--sort usage|recent|alpha|default-- control list ordering by call frequency, recency, alphabetical, or insertion order--top N-- show only the top N tools (the key feature for agents:--list --top 10 --compactyields ~20 tokens instead of ~1,400)--compact-- space-separated tool names only, no descriptionsUsage data is stored in
~/.cache/mcp2cli/usage.jsonwith the format from the issue. Last-write-wins for file locking per maintainer approval. When usage data exists for a source, the default sort isusage; otherwise insertion order is preserved.Design decisions (per discussion in #31)
__init__.pyas approvedHooks
Usage is recorded after successful execution in:
handle_mcp()-- MCP HTTP and stdio modes_handle_openapi_mode()-- OpenAPI modehandle_graphql()-- GraphQL modeLLM agent workflow
Test plan
tests/test_usage.pycovering:--compactoutput for MCP, OpenAPI, and GraphQL listing--top Ntruncation--sort+--top+--compacttest_helpers.py::TestCachingunrelated to this PR)Closes #31