576 tokens in your agent's harness. One MCP tool that counts the tool-definition cost of any other MCP server.
Project description
mcptokens
505 tokens in your agent's harness. One tool, inspect, that
counts the tool-definition cost of any other MCP server (stdio or
Streamable HTTP) before you enable it.
pip install mcptokens
Why
When your agent enables a new MCP server, its tools enter the
agent's context on every turn. The cost compounds fast. mcptokens
lets the agent ask is this server cheap enough? before flipping
the switch.
Transports
Same tool, same response shape:
- stdio (default): spawn a local process and speak JSON-RPC on its stdin/stdout.
- streamable_http: POST
initializeandtools/listto a remote MCP endpoint per MCP 2025-03-26. Server may reply viaapplication/json(one message) ortext/event-stream.
How
Add mcptokens to your agent's MCP config (Claude Code, Pi,
OpenCode, Codex, ...). The agent gains one tool:
inspect(command=["python", "-m", "some_mcp_server"])
# stdio spawn argv, same as your MCP config
inspect(command=["hound"])
# pre-installed binary
inspect(
transport="streamable_http",
url="http://localhost:8080/mcp",
headers={"Authorization": "Bearer ..."}, # optional
)
# remote MCP server
# Returns the same JSON shape every call:
# {ok, server, tool_count, wire_total_tokens,
# tools: [{name, total}], encoding, elapsed_ms, version}
wire_total_tokens is the number to report. Use it BEFORE
enabling a candidate server: a large value means don't enable.
The numbers
| Self-cost on wire | 505 tokens of cl100k_base |
| Tools exposed | 1, named inspect |
| Transports | stdio, streamable_http |
| Cross-platform | Linux, macOS, Windows |
| Python | 3.11+ |
| Imports | stdlib, tiktoken, mcp |
Install
pip install mcptokens
Add mcptokens to your agent's mcpServers / mcp_servers. Done.
CLI (debug surface)
mcptokens python -m some_mcp_server # human table
mcptokens --json python -m some_mcp_server # pipeline-friendly JSON
mcptokens --timeout 30 python -m srv # custom spawn, custom timeout
mcptokens serve # run as an MCP server
| Flag | Default | Purpose |
|---|---|---|
--encoding |
cl100k_base |
cl100k_base or o200k_base |
--timeout |
15 |
Per-server timeout in seconds (1 to 60) |
--json |
false |
Output JSON instead of the table |
License
MIT. pip install mcptokens from the canonical PyPI index.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcptokens-1.1.0.tar.gz.
File metadata
- Download URL: mcptokens-1.1.0.tar.gz
- Upload date:
- Size: 30.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c33086ba677d72290a08b23616120039944d9df3afdf0ac92761dde3ad337728
|
|
| MD5 |
1b586e11ff8c16045c64e0d605efbc3f
|
|
| BLAKE2b-256 |
9d2774e279dac50cc862e874b4f059b85627f1d3b400cffa1418cbe91c6a8823
|
File details
Details for the file mcptokens-1.1.0-py3-none-any.whl.
File metadata
- Download URL: mcptokens-1.1.0-py3-none-any.whl
- Upload date:
- Size: 21.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d3579c73433e018e4a805898d16f52e729c3f89ef9518679e1116700d2db4d9
|
|
| MD5 |
96854802a5072c57eac3a7bc37e7bfc7
|
|
| BLAKE2b-256 |
85c41c90d171a5614a92c2d37a9bc1c067a08f09182d72163647f310302cdfdc
|