Add mcp-tokens command to measure tool token costs#300
Merged
Conversation
Reports tiktoken-based token counts for every MCP tool exposed by the
codebase, sorted by cost. Useful for tracking tool-description token
budgets across revisions and spotting heavy tools when trimming.
- Snapshot mode prints a per-tool table with totals.
- `-json` emits the full export-tools-shaped JSON for downstream tools.
- `-base=<ref>` materialises the ref in a throwaway git worktree and
diffs token counts; supports text/markdown/json output.
rafaeljusto
reviewed
May 5, 2026
Swap github.com/pkoukk/tiktoken-go (stale since Sept 2025) for github.com/localit-io/tiktoken-go v0.2.1 (active fork) per PR review. Drop-in API; output and tests unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
rafaeljusto
approved these changes
May 6, 2026
Contributor
rafaeljusto
left a comment
There was a problem hiding this comment.
Nice one! Only an optional comment that can be addressed in a future iteration (if required).
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
cmd/mcp-tokensdev tool: tiktoken-based token counts for every MCP tool, sorted by cost.-jsonemits the same shape asmcp-http-cli export-tools.-base=<ref>materialises the ref in a throwawaygit worktreeand prints a diff (text/markdown/json).Test plan
go run ./cmd/mcp-tokens— snapshot table renders, total matches expectation.go run ./cmd/mcp-tokens -base=main— diff renders, working tree untouched.go test ./cmd/mcp-tokens/— smoke test passes.