mcp-cost-guard
Estimates token counts and USD costs for prompts targeting OpenAI models such as gpt-4o and detects leaked OpenAI API keys prior to sending requests.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
mcp-cost-guard 🛡️
Zero-dependency CLI and Model Context Protocol (MCP) server for auditing LLM token costs, enforcing CI/CD prompt budgets, compressing context windows, and scrubbing leaked API keys before sending requests to Claude, OpenAI, or Gemini.
Features
Instant Cost & Token Estimation: Supports
claude-opus-4,claude-sonnet-4,claude-3-5-haiku,gpt-4o, andgemini-2.5-pro.CI/CD Budget Gatekeeper: Fail builds automatically (
--max-budget 0.05) when oversized context files or system prompts exceed budget thresholds.Credential & Secret Scanner: Detects leaked Anthropic (
sk-ant-...), OpenAI, GitHub, AWS, and private keys before prompts leave your machine.Native MCP Server: Plugs directly into Claude Code and Claude Desktop over stdio with zero third-party dependencies.
Related MCP server: ctxbleach
Quick Start
git clone https://github.com/Git-AnshGrover/mcp-cost-guard.git
cd mcp-cost-guard
pip install -e .CLI Usage
# Audit a prompt file against Claude Sonnet 4
mcp-cost-guard --file system_prompt.md --model claude-sonnet-4
# Enforce a strict USD budget and secret scan in CI/CD
mcp-cost-guard --file context.txt --max-budget 0.10 --fail-on-secrets --json
# List all supported models and pricing per 1M tokens
mcp-cost-guard --list-modelsClaude Code / Claude Desktop MCP Configuration
Add the following to your claude_desktop_config.json or .mcp.json:
{
"mcpServers": {
"cost-guard": {
"command": "mcp-cost-guard",
"args": ["--mcp-stdio"]
}
}
}Contributing
We actively welcome first-time and experienced open-source contributors! Check our open Good First Issues and read CONTRIBUTING.md to get started in under 5 minutes.
This server cannot be deployed
Maintenance
Related MCP Connectors
Exact Claude API cost calc with real cache economics, plus a tiktoken-misuse scanner.
Token guard and rate limiter preventing runaway API cost spikes for OpenAI and Anthropic.
Scan prompts for injection attacks, redact PII, and audit LLM SDK usage from any MCP client
LLM cost optimization gateway, repo token-waste auditor & model arbitrage MCP server.
Related MCP Servers
- AlicenseBqualityDmaintenanceTrack LLM token costs across Claude, GPT and Gemini. MCP server + CLI with optimization hints and $ savings estimates.89 npm1MIT
- AlicenseNot gradedqualityCmaintenanceLocal CLI and MCP server that redacts secrets from logs, files, and diffs before sending them to AI agents, with stable placeholders and token-budgeted truncation.MIT
- AlicenseNot gradedqualityCmaintenanceEnables local, offline prompt compression, smart asking when needed, and routing to the cheapest capable model to save tokens and costs for terminal AI agents.17 npm1MIT
- AlicenseAqualityBmaintenanceEnables AI agents to transcribe audio, detect ASR hallucinations deterministically, repair flagged segments with guarded LLM calls, score transcript quality, and estimate pipeline costs over stdio.5MIT