Tokenomics MCP
Counts LLM prompt tokens and estimates API costs across OpenAI and Anthropic models directly inside MCP-compatible chat clients. Supports exact tokenization for OpenAI models and fallback approximation for Claude when no API key is present.
README
Tokenomics MCP
An MCP server for counting LLM prompt tokens and estimating API costs across OpenAI and Anthropic models — right inside your chat client, no browser-based token counter needed.
Tools
| Tool | What it does |
|---|---|
count_tokens(text, model) |
Exact/approximate token count for a piece of text |
estimate_cost(text, model, expected_output_tokens) |
$ cost estimate for input + optional expected output |
compare_models_cost(text, models, expected_output_tokens) |
Side-by-side cost table across several models |
list_supported_models() |
See every model this server has pricing data for |
How token counting works
- OpenAI models (
gpt-4o,gpt-4.1,gpt-5,o3, etc.): exact, via tiktoken. - Claude models: exact via Anthropic's
count_tokensAPI ifANTHROPIC_API_KEYis set; otherwise falls back to atiktoken-based approximation, and says so explicitly in the output.
Pricing data lives in src/tokenomics_mcp/pricing.py as a plain dict —
PRICING_LAST_VERIFIED marks the date it was checked. LLM pricing changes
often; update that dict directly when it does.
Project layout
tokenomics-mcp/
├── src/tokenomics_mcp/
│ ├── server.py # MCP tool wiring (thin layer)
│ ├── pricing.py # pricing table + token-counting logic (unit-tested)
│ └── __init__.py
├── tests/
│ └── test_pricing.py # pure-logic tests, no network/API calls needed
├── Dockerfile # multi-stage build, non-root runtime user
├── docker-compose.yml
├── .github/workflows/
│ ├── ci.yml # lint + test on every PR/push to main
│ └── docker-publish.yml # build + push image to GHCR on version tags
├── pyproject.toml
└── .env.example
Local development
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
cp .env.example .env # optional: add ANTHROPIC_API_KEY for exact Claude counts
ruff check . # lint
pytest -v # test
python -m tokenomics_mcp.server # run the server standalone (stdio)
Running with Docker
docker build -t tokenomics-mcp .
docker run -i --rm --env-file .env tokenomics-mcp
MCP servers communicate over stdio, not a network port — that's why the
Dockerfile has no EXPOSE and the run command uses -i (keep stdin open)
rather than -p (publish a port). docker-compose.yml wraps the same
invocation if you prefer docker compose run tokenomics-mcp.
Connect it to Claude Desktop
Local (no Docker):
{
"mcpServers": {
"tokenomics": {
"command": "python",
"args": ["-m", "tokenomics_mcp.server"],
"env": { "ANTHROPIC_API_KEY": "your_key_here" }
}
}
}
Via Docker:
{
"mcpServers": {
"tokenomics": {
"command": "docker",
"args": ["run", "-i", "--rm", "--env-file", "/absolute/path/to/.env", "tokenomics-mcp"]
}
}
}
Restart Claude Desktop, then try: "How many tokens is this prompt for gpt-4o?" or "Compare the cost of this prompt across all supported models."
CI/CD
ci.ymlruns on every PR and push tomain: installs the package, lints withruff, runs thepytestsuite. All logic inpricing.pyis unit-tested with stubbed tokenizers, so tests run fast with no network calls or API keys required.docker-publish.ymlruns when you push a version tag (git tag v0.1.0 && git push origin v0.1.0): builds the Docker image and pushes it to GitHub Container Registry (ghcr.io/<your-username>/tokenomics-mcp), tagged both with the version andlatest. No registry account setup needed — it authenticates with theGITHUB_TOKENGitHub Actions already provides.
Releasing a new version
- Bump
versioninpyproject.tomland__version__in__init__.py. - Commit, merge to
main. - Tag and push:
git tag v0.2.0 && git push origin v0.2.0. - Watch the Publish Docker image workflow run in the Actions tab —
once green, the image is live at
ghcr.io/<your-username>/tokenomics-mcp:v0.2.0.
Notes
- The pricing table needs periodic manual updates; there's no live pricing feed to scrape reliably, so this is intentionally a plain, editable dict rather than something auto-fetched.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.