Skip to main content

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

PyPI License: MIT Python 3.11+ Repo


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"]
  }
}

Then the agent calls:

inspect(command=["hound"])                      # 1023 wire tokens, 8 tools
inspect(command=["python", "-m", "my_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
Source 5 files, ~700 LOC
Tests 31 passing in under 10 seconds

Install

pip install mcptokens

Add mcptokens to your agent's mcpServers / mcp_servers. Done.

CLI (debug surface)

mcptokens hound                       # human table
mcptokens --json hound                # pipeline-friendly JSON
mcptokens --timeout 30 python -m srv  # custom spawn
mcptokens serve                       # run as an MCP server
mcptokens --version                   # 0.1.0
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.

Tests

python -m pytest tests/  # 31 passing in under 10 seconds

Engine tests cover JSON-RPC id-matching, null-safe shape coercion, timeouts, and end-to-end via mcp.ClientSession.

License

MIT. pip install mcptokens from the canonical PyPI index.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcptokens-0.1.2.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcptokens-0.1.2-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file mcptokens-0.1.2.tar.gz.

File metadata

  • Download URL: mcptokens-0.1.2.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for mcptokens-0.1.2.tar.gz
Algorithm Hash digest
SHA256 3f77c3d864bafa322544ff256bd56f226c8a27ac9e50fe3a50c548bfa61688d7
MD5 f93ca3cbf80c10f2a2bfdec2a4ff5513
BLAKE2b-256 5dd873bf0724440a979976523766d97181b8c56869a3d02a64022e541521289c

See more details on using hashes here.

File details

Details for the file mcptokens-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: mcptokens-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 13.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for mcptokens-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ebced0c46de2357d3fef6855f4e479319e399a26db18804223f3da86550dd08f
MD5 2fde2defa80368d3b0341d77de599333
BLAKE2b-256 5b496f959e498d44992c8eac210fb88a42755d6ed61c8b6c8622c5bca21d360f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page