mcptokens
375 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 | 375 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.
Metadata
Release files for mcptokens 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| mcptokens-1.2.0.tar.gz | 31.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mcptokens-1.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 52.6 kB
Release files / mcptokens-1.2.0.tar.gz
| Download URL | mcptokens-1.2.0.tar.gz |
|---|---|
| Size | 31.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
854c325db36013e772ae961a4216538e8a795d0e9c018fbb4adaafa3eafec31f
|
|
BLAKE2b-256 checksum How to use checksums |
3f59252d1dfd706c7516e197585a97e50811dee03c1d76442d547385deebb2ee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.9
|
Release files / mcptokens-1.2.0-py3-none-any.whl
| Download URL | mcptokens-1.2.0-py3-none-any.whl |
|---|---|
| Size | 21.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6144d27b4798b28874dca0dbc6699457e9267baf71c15220b42c59c91ef28f49
|
|
BLAKE2b-256 checksum How to use checksums |
a14d9c61b05ce1fb170492512b2167f46d2f8b805da5c917a326214d3dc1c478
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.9
|
Security for mcptokens 1.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.