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.1.tar.gz (16.7 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.1-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mcptokens-0.1.1.tar.gz
  • Upload date:
  • Size: 16.7 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.1.tar.gz
Algorithm Hash digest
SHA256 9cfdea6d64f67bc32118528934d5f78cc0ac939eb4a4acabbeebcfdb307eabaa
MD5 867b0c879c598e0ab27d5b31777f5dc3
BLAKE2b-256 ecaa6add18fb8bc938840cc1f051a64fc0c8f06de95aa50ec05c651acdb17cb4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mcptokens-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c426655250acc84511548b97952ddca3184e1705f9eb48831a23b28c8a717ffd
MD5 88f393037e18d668f24fc3005670fcc2
BLAKE2b-256 70e7efcb1a851bae0b851336e5cead14e503db3959a627288876ab5247b22ddb

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