mcpField
L
llm-cost-estimator

llm-cost-estimator

Local
github.com/waqarulwahabAI & Agents1Updated 19w ago

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

  1. 01Estimate costs across models
  2. 02Count tokens for one model
  3. 03List model prices and context windows
  4. 04Return Markdown tables and JSON
  5. 05No API key required

Use cases

  1. 01Compare text costs across models
  2. 02Count prompt tokens
  3. 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.

mcp.json · Universal config
{
"mcpServers": {
"waqarulwahab-llm-cost-estimator": {
"command": "npx",
"args": [
"-y",
"llm-cost-estimator-mcp"
]
}
}
}
Run commandnpx -y llm-cost-estimator-mcp

Local servers need a runtime on your machine (e.g. Node.js 18+). Config file locations differ by client; see your client’s docs.

Packages
npmllm-cost-estimator-mcp0.3.1

Tools

3

Saved tool list · updated 3w ago

ParameterTypeRequiredDescription
textstringYesThe prompt or text to measure.
modelsarrayNoModel 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.
currencystringNoCurrency label (default USD; display only).
outputTokensintegerNoAssumed output/completion tokens used for the total cost (default 500).

Details

From the project README

llm-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

ToolDescription
estimate_costToken count + cost across multiple models for a piece of text. Returns a Markdown table and structured JSON. Args: text, models?, outputTokens?, currency?.
count_tokensToken count for one model. Args: text, model?. OpenAI is exact (tiktoken); others are flagged estimates.
list_modelsAll 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

Markdown supported

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.