172 tokens in your agent's harness. One MCP tool that counts the tool-definition cost of any other MCP server.
Project description
mcptokens
172 tokens in your agent's harness. One tool, inspect, that
counts the tool-definition cost of any other MCP server 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.
How
Add mcptokens to your agent's MCP config (Claude Code, Pi,
OpenCode, Codex, ...). The agent gains one tool:
{
"name": "inspect",
"description": "Count tool-def tokens of any MCP server. Pass argv [...]",
"inputSchema": {
"properties": {
"command": {"type": "array", "items": {"type": "string"}},
"encoding": {"type": "string", "enum": ["cl100k_base","o200k_base"], "default": "cl100k_base"},
"timeout": {"type": "number", "default": 15, "minimum": 1, "maximum": 60}
},
"required": ["command"]
}
}
The agent calls:
inspect(command=["python", "-m", "some_mcp_server"])
The agent decides whether to enable the candidate server based on the answer.
The numbers
| Self-cost on wire | 172 tokens of cl100k_base |
| Tools exposed | 1, named inspect |
| Cross-platform | Linux, macOS, Windows |
| Python | 3.11+ |
| Imports | 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 |
Why it's cheap
One server, one tool, tight description, minimal schema. The shipped tool definition tokenizes to 172 tokens. A small tool list is the product.
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-0.1.5.tar.gz.
File metadata
- Download URL: mcptokens-0.1.5.tar.gz
- Upload date:
- Size: 20.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
984e858d9d8588d7d58c0ee9ca1d5af51ae4c8fe685e3457c20190d91cf65601
|
|
| MD5 |
87db59e3fab15235eff97b02f6697248
|
|
| BLAKE2b-256 |
56e6a5e3110da5038cc766ff72f902ea911bb19c52149945e8bbb7a069d16906
|
File details
Details for the file mcptokens-0.1.5-py3-none-any.whl.
File metadata
- Download URL: mcptokens-0.1.5-py3-none-any.whl
- Upload date:
- Size: 15.1 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 |
72680544776c6df55c1f75343cc5d503d619c4db3d09868b065909101cab41c7
|
|
| MD5 |
dc28c46f861c34614b364c7cb078b620
|
|
| BLAKE2b-256 |
ec7fe9fa0041d11e4a6f8585f54d6e25cb503201caab134d8601c1d05f860e5c
|