About llm-cost-estimator
llm-cost-estimator is a local token-counting and LLM cost-estimation server for MCP clients such as Claude and Cursor, with no API key required. It shares its calculation core with a VS Code extension and distinguishes exact OpenAI counts from estimates for other models.
Key features
- 01Estimate costs across models
- 02Count tokens for one model
- 03List model prices and context windows
- 04Return Markdown tables and JSON
- 05No API key required
Use cases
- 01Compare text costs across models
- 02Count prompt tokens
- 03Review model prices and context windows
MCP support
It exposes cost estimation, token counting, and model-listing tools to MCP clients over stdio.
Configuration
Local server config is the same for every client. Copy it into your client’s MCP config file.
Tools
3Saved tool list · updated 3w ago
| Parameter | Type | Required | Description |
|---|---|---|---|
| text | string | Yes | The prompt or text to measure. |
| models | array | No | Model keys to compare (e.g. gpt-4o, claude-sonnet, gemini-2.5-pro). Omit for a sensible default set. Call list_models to see all keys. |
| currency | string | No | Currency label (default USD; display only). |
| outputTokens | integer | No | Assumed output/completion tokens used for the total cost (default 500). |
Details
From the project READMEllm-cost-estimator-mcp
An MCP (Model Context Protocol) server that gives Claude, Cursor, or any MCP client the ability to count tokens and estimate LLM costs across GPT-4o, Claude, Gemini, DeepSeek, Mistral, Llama, Grok, and 25+ models — locally, with no API key.
It reuses the exact same tokenizer + pricing + estimator core as the LLM Cost & Token Estimator VS Code extension in this repo.
Tools
| Tool | Description |
|---|---|
estimate_cost | Token count + cost across multiple models for a piece of text. Returns a Markdown table and structured JSON. Args: text, models?, outputTokens?, currency?. |
count_tokens | Token count for one model. Args: text, model?. OpenAI is exact (tiktoken); others are flagged estimates. |
list_models | All model keys with provider, prices (USD/1M), and context window. |
⚠️ Prices are representative placeholders — verify against each provider's official pricing page. OpenAI counts are exact; all other providers are approximated via an OpenAI encoding and flagged as estimates.
Build (from source)
The server reuses the extension's core in ../src (whose files import
js-tiktoken), so install the repo-root dependencies first:
npm install # at the repo ROOT, once (provides the reused core's deps)
cd mcp-server
npm install
npm run build # -> dist/index.js
npm test # builds, then runs a real stdio MCP handshake
End users don't need this — they just npx -y llm-cost-estimator-mcp once it's
published (the published dist/index.js is fully self-contained).
Connect it
The server speaks MCP over stdio, so any client launches it as a subprocess.
Use the absolute path to mcp-server/dist/index.js.
Claude Desktop
Edit claude_desktop_config.json
(Windows: %APPDATA%\Claude\claude_desktop_config.json,
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json):
{
"mcpServers": {
"llm-cost-estimator": {
"command": "node",
"args": ["C:/path/to/llm-cost-estimator/mcp-server/dist/index.js"]
}
}
}
Restart Claude Desktop, then ask: "Estimate the cost of this prompt on GPT-4o vs Claude Sonnet vs Gemini."
Claude Code (CLI)
claude mcp add llm-cost-estimator -- node /abs/path/to/mcp-server/dist/index.js
Cursor
Add to ~/.cursor/mcp.json (global) or .cursor/mcp.json (per-project):
{
"mcpServers": {
"llm-cost-estimator": {
"command": "node",
"args": ["/abs/path/to/mcp-server/dist/index.js"]
}
}
}
After publishing to npm (optional)
Once this package is published, clients can launch it without a local build:
{
"mcpServers": {
"llm-cost-estimator": { "command": "npx", "args": ["-y", "llm-cost-estimator-mcp"] }
}
}
License
MIT — see ../LICENSE.
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.