What MCP Cost Optimizer does
MCP Cost Optimizer MCP server provides local cost analysis for AI agents, developers, and teams. It accepts normalized usage data and a rate table rather than connecting directly to model providers. The calculations can identify costs by model, models without prices, repeated requests that may be candidates for conditional response caching, and estimated savings from switching models.
The project is intended for the 💻 Developer Tools category and runs as an MCP server over stdio. Local operation does not require provider credentials, an account, telemetry, or network access. It does not observe other MCP or API calls automatically, so the agent or calling application must supply the relevant records.
How it works
Usage records contain an exact model name, input-token count, output-token count, and optional cached-input tokens and request hash. Rates provide a currency, optional effective date, and per-million-token prices for each exact model name. Input data must be normalized before submission; provider-specific fields such as OpenAI or Anthropic usage shapes are not accepted directly.
The MCP Cost Optimizer MCP server exposes three operations:
estimate_llm_cost calculates the cost of one request.
analyze_llm_usage groups costs by model and reports unpriced models and duplicate opportunities.
compare_llm_models evaluates a target-model scenario using the observed token counts.
Unknown model prices make a report incomplete, and incomplete baselines cannot be used for comparisons. Comparisons clear cached-token counts and do not combine scenarios. They also do not evaluate quality, latency, tokenizer differences, tool support, or context-window fit; those checks remain with the developer.
A request hash must represent the full effective request, including relevant context and model settings. Matching hashes indicate a possible reusable response, not provider prompt caching. The resulting savings estimate is an upper bound and excludes cache infrastructure costs.
Setup and configuration
Use Node.js 20 or newer. An MCP client can launch the package with npx -y mcp-cost-optimizer, or a local checkout can be started with an absolute path to src/index.js. The repository documents configuration for Claude Code, Codex CLI, Claude Desktop, Cursor, Windsurf, Cline, Gemini CLI, VS Code, and Zed.
From source, install with npm install --ignore-scripts, then run the project checks and tests. The CLI accepts JSON or JSONL usage files and a rates file. Local CLI and MCP operation require no environment variables. A separate hosted HTTP process uses CONTROL_PLANE_URL for quota reservations and requires a bearer token; local analysis remains offline.
Tools and capabilities
The core calculations and CLI are tested in the repository, while the MCP SDK integration test requires validation in an environment with npm registry access. The MCP Cost Optimizer MCP server uses the official TypeScript SDK and Zod for its MCP integration.
The CLI can process up to 100,000 records and 20 MiB per input file. It reads files below its current directory, checks file type and size, and parses JSONL incrementally. Aggregated token totals must remain safe integers. Raw prompts are not needed for duplicate analysis.
Limitations and notes
Rates are supplied by the caller; provider prices and currency conversion are not bundled, and example rates are fictional. Missing cached-input prices fall back to the normal input price. Cache-write pricing is unsupported in this MVP.
The project does not reconcile invoices, calculate taxes, set budgets, send alerts, route requests automatically, or store usage. Hosted quotas, history, budgets, and alerts are separate from the free local path. The package is an MVP and is not yet published to npm according to the provided project status.