Spending guard for AI agents — wraps any MCP server with budget limits and loop detection
Project description
mcp-budget
A spending guard for AI agents. Wraps any MCP server with hard call limits and loop detection — your AI won't spend more than you allow.
The problem
AI agents calling tools can run up costs fast. A coding agent in a loop can burn through hundreds of API calls in minutes. Existing dashboards show you the damage after it happens. mcp-budget is the circuit breaker that trips before the next call.
How it works
mcp-budget sits between your AI client (Claude Desktop, Claude Code, Cursor, etc.) and your MCP servers as a transparent proxy. It counts every tool call and blocks the agent when a limit is hit — no changes needed to the MCP server itself.
Client (Claude/Cursor) → mcp-budget → your MCP server
↓
budget tracker
loop detector
circuit breaker
Install
pip install mcp-budget
Quick start
# Create a config with sensible defaults
mcp-budget init
# See your limits and current usage
mcp-budget status
Setting budgets
Set limits on any timeframe — mix and match as many as you want:
mcp-budget set 60 per minute # burst protection
mcp-budget set 500 per hour # hourly cap
mcp-budget set 2000 per day # daily cap
mcp-budget set 10000 per week # weekly cap
mcp-budget set 50000 per month # monthly cap
mcp-budget set 200 per session # per-session cap
Friendly aliases work too — daily, weekly, monthly, mins, hrs, etc.
mcp-budget set 2000 daily # same as "per day"
mcp-budget remove hour # drop a limit
mcp-budget warn 90 # warn at 90% usage (default: 80%)
mcp-budget reset daily # reset today's counter
Wiring it up
Add mcp-budget in front of any MCP server command in your client config. The -- separates mcp-budget options from the server command.
Claude Desktop / Claude Code / Cursor:
{
"mcpServers": {
"my-server": {
"command": "mcp-budget",
"args": ["--", "npx", "-y", "@modelcontextprotocol/server-filesystem", "/path/to/dir"]
}
}
}
With a custom config path:
{
"mcpServers": {
"my-server": {
"command": "mcp-budget",
"args": ["--config", "/path/to/config.json", "--", "npx", "-y", "your-mcp-server"]
}
}
}
What gets enforced
- Budget limits — hard caps on tool calls per minute, hour, day, week, month, or session. When a limit is hit, the agent gets a clear error and stops.
- Loop detection — catches agents stuck in a loop calling the same tool repeatedly. Two modes: exact match (same tool + same arguments) and name-only match (same tool, any arguments).
- Near-limit warnings — logged when usage crosses a configurable threshold (default 80%), so you can see it coming.
Security
- Counter files are HMAC-signed — an agent with filesystem access can't edit its own budget counters without detection. Tampered files fail closed (treated as if the limit is already hit).
- Error messages to agents are deliberately vague — no exact counts or limits are leaked.
- All substantive MCP methods are metered:
tools/call,resources/read, andprompts/get.
Status check
$ mcp-budget status
Budget usage:
Minute [#####--------------------] 12 / 60
Session [############-------------] 98 / 200
Day [################---------] 812 / 1,000 << NEAR LIMIT
Week [######-------------------] 1,203 / 5,000
Month [##-----------------------] 3,891 / 20,000
Warning: day budget is at 81% — 188 calls remaining
Loop breaker: 10 identical / 20 same-tool
Warn at: 80%
Config file
Stored at ~/.mcp-budget/config.json. You can edit it directly or use the CLI commands above.
{
"budgets": [
{"limit": 60, "window": "minute"},
{"limit": 200, "window": "session"},
{"limit": 1000, "window": "day"},
{"limit": 5000, "window": "week"},
{"limit": 20000, "window": "month"}
],
"loop_threshold": 10,
"name_only_loop_threshold": 20,
"warn_at_percent": 80,
"log_file": "",
"enabled": true
}
Requirements
- Python 3.10+
- Works on Windows, macOS, and Linux
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcp_budget-0.1.0.tar.gz.
File metadata
- Download URL: mcp_budget-0.1.0.tar.gz
- Upload date:
- Size: 14.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8adf5d0f96f3f1c6220d0737380ba6b64cb43fc1bbfd6fb971306da5a8b03123
|
|
| MD5 |
e1638b8af1a8e121cf53dd6ebb986f8c
|
|
| BLAKE2b-256 |
d0439a70c632c8b642e4b70454683197738b832570e49316759b72a2a6b1177c
|
Provenance
The following attestation bundles were made for mcp_budget-0.1.0.tar.gz:
Publisher:
publish.yml on thedunc101/mcp-budget
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mcp_budget-0.1.0.tar.gz -
Subject digest:
8adf5d0f96f3f1c6220d0737380ba6b64cb43fc1bbfd6fb971306da5a8b03123 - Sigstore transparency entry: 1755299841
- Sigstore integration time:
-
Permalink:
thedunc101/mcp-budget@1b8be80beca97059689eb09e66562edeb3d90e2f -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/thedunc101
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1b8be80beca97059689eb09e66562edeb3d90e2f -
Trigger Event:
release
-
Statement type:
File details
Details for the file mcp_budget-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mcp_budget-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29610b38aada949be187393fd70321179e282e21b5d5837168f297ffe3283980
|
|
| MD5 |
ffb75a37d2740e096a4de3f7883de2d5
|
|
| BLAKE2b-256 |
52de0abec0bd7aeaed845e00be4dec81a32a3cff1818d0aa4d3ed7fc650f7479
|
Provenance
The following attestation bundles were made for mcp_budget-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on thedunc101/mcp-budget
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mcp_budget-0.1.0-py3-none-any.whl -
Subject digest:
29610b38aada949be187393fd70321179e282e21b5d5837168f297ffe3283980 - Sigstore transparency entry: 1755299918
- Sigstore integration time:
-
Permalink:
thedunc101/mcp-budget@1b8be80beca97059689eb09e66562edeb3d90e2f -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/thedunc101
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1b8be80beca97059689eb09e66562edeb3d90e2f -
Trigger Event:
release
-
Statement type: