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

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


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.4.tar.gz (17.0 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.4-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mcptokens-0.1.4.tar.gz
  • Upload date:
  • Size: 17.0 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.4.tar.gz
Algorithm Hash digest
SHA256 a978d91b2673e8e79c13ca74658ce5f1e416c83c8187ecf27547c3735bf52489
MD5 ff4fbb8ed0422d5f1c9371337e8a57e8
BLAKE2b-256 1d956b316a0778b8811891050ee2432b62cc479340514365509bf6b6b129550f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mcptokens-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 13.2 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1ab9fd0d94a86f8f1a0a030133af6eec089573baa201c997c1d394358a865d6f
MD5 9ce37035ccd562dacf39dab09e47b086
BLAKE2b-256 3f545aa95cb7075915b77c27afae72617361fd1710f5fe2bfe2b9931a0523c60

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