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

691 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

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.

Transports

Same tool, same response shape:

  • stdio (default): spawn a local process and speak JSON-RPC on its stdin/stdout.
  • streamable_http: POST initialize and tools/list to a remote MCP endpoint per MCP 2025-03-26. Server may reply via application/json (one message) or text/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 691 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


Download files

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

Source Distribution

mcptokens-1.0.0.tar.gz (27.8 kB view details)

Uploaded Source

Built Distribution

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

mcptokens-1.0.0-py3-none-any.whl (21.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for mcptokens-1.0.0.tar.gz
Algorithm Hash digest
SHA256 aefe72661b3852a4d378f6e005e9b868dc69c283a97cca5e0edae65f24b64709
MD5 3168c97c0f9ea0589997dae6301c4267
BLAKE2b-256 bb9f034f6804f4fdf62728a2f1fad50f45df9e391aaf91073a56e4bdba609bb1

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for mcptokens-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 675d56979809362d89e6f38edb85bfc29b4f75d4f5132ea5856cb1643f9a0749
MD5 98d200e7d99fab981f05aeb1f49f2a9e
BLAKE2b-256 a42979c49ed1caaba25221a0ed49e4f2c21708f44d31a674657b65e0d3fcd894

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