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

Uploaded Python 3

File details

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

File metadata

  • Download URL: mcptokens-0.1.3.tar.gz
  • Upload date:
  • Size: 17.5 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.3.tar.gz
Algorithm Hash digest
SHA256 611823d5851ac2351ff30996965356b7be3aaeb0b5df0324cd0e7d02a87fc182
MD5 5492d1a0fc87aeae022306dcb80c1074
BLAKE2b-256 bddc51c4af35228f27aeea423c07381558ee5afda68ffc9dba79c9f50969c029

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mcptokens-0.1.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1de3e3b91a0c9f3a2ad54d8fa0cf942252e197bf856ec60d2421229ed2915cbb
MD5 bb1cfd1e557847e2d693ff2f9bdb448c
BLAKE2b-256 a723a6ead591a2ff58a99511847b7f02d297cb7cc56443d63a6725af7baef57b

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