safe4 — Claude Code MCP server: payment checks for agents
A hosted MCP server that decides whether an agent's proposed payment should go through, by testing the purchase against the task it was given.
claude mcp add --transport http safe4 https://api.safe4.ai/mcp/What safe4 does
Safe4 covers the gap budget limits leave open. A payment can sit inside every cap, fall into a permitted category and go to an approved payee, yet still be the wrong buy because it does not serve the task. The server compares the purchase with the task and answers ALLOW or DENY, with a reason code and the concepts it matched.
Nothing gets installed. The service runs at api.safe4.ai and connects over Streamable HTTP. Connecting and listing tools cost nothing; only safe4_authorize is paid, settled per call in USDC over x402. The free safe4_price tool reports the current price and the networks the endpoint accepts, so an agent sees the cost before committing. Call safe4_authorize without a payment payload and you get the x402 challenge back; an x402-aware client pays, then calls again with the result in the payment argument.
The task and the two allow-lists belong to the principal, not the agent. An agent that fills in task itself is grading its own homework, so the server marks the task context as request-supplied and a swapped constraint shows up in the audit entry. Every decision lands in a hash-chained log: each entry carries the previous one's hash, which keeps the record continuous across restarts and redeploys. The demo examples/mcp_buyer_demo.py walks the whole free surface and stops before signing anything; it needs only httpx.
What it helps with
- refuse a payment that does not serve the assigned task
- catch a swapped payee when task text and category look identical
- read the call price before paying for a decision
- keep a decision log that cannot be quietly rewritten
- block a purchase outside the categories the principal permits
Example prompts for the agent
- Check with safe4 whether this purchase is allowed for the task
- What does a safe4_authorize call cost and which networks are accepted?
- Send the payment to safe4 for authorisation and show me the reason code
How to install safe4
Platform CLI: remote server
claude mcp add --transport http safe4 https://api.safe4.ai/mcp/Platform CLI: remote server
codex mcp add safe4 --url https://api.safe4.ai/mcp/Config file
{
"mcpServers": {
"safe4": {
"url": "https://api.safe4.ai/mcp/"
}
}
}Config file
{
"servers": {
"safe4": {
"type": "http",
"url": "https://api.safe4.ai/mcp/"
}
}
}Platform CLI: remote server
gemini mcp add -t http safe4 https://api.safe4.ai/mcp/Step by step, with commands for each platform: How to add an MCP server to Claude Code, Codex, Cursor, VS Code, Gemini CLI and more
Questions about safe4
How do I install safe4 in Claude Code?
There is nothing to install — the server is hosted. Run claude mcp add --transport http safe4 https://api.safe4.ai/mcp/ and it is connected.
What does safe4 do?
It tests an agent's proposed payment against the task it was given and returns ALLOW or DENY, along with a reason code and an audit entry.
What do I need for a paid decision?
An x402 payment signature in USDC. The demo with --dry-run needs no key and no funded wallet; a real call requires SAFE4_BUYER_PRIVATE_KEY.