An x402-gated MCP server that proxies Anthropic inference over Streamable HTTP. Pay in USDC on Base, get a Claude response.
Live endpoint: https://anthropic.yeetful.com/api/mcp/mcp
- Client calls
POST /api/mcp/mcpwith an MCP JSON-RPC request. - The Next.js proxy (
proxy.ts, Next.js 16's replacement formiddleware.ts) returns HTTP 402 Payment Required with an x402 payment challenge describing the required USDC amount, network, and receiving wallet. - Client signs an EIP-3009
transferWithAuthorizationfor the challenge using an x402 client helper (e.g.x402-fetch/x402-axios) and retries the request with anX-PAYMENTheader. - The x402 facilitator verifies + settles the payment on Base. On success, the request is forwarded to the MCP handler, which invokes the Anthropic SDK using the operator's
ANTHROPIC_API_KEY. - The MCP tool result (Claude's text response) is returned.
| Tool | Purpose |
|---|---|
ask_claude |
Single-prompt text completion. |
claude_chat |
Multi-turn chat with a messages array. |
cd anthropic-mcp
npm install
cp .env.example .env.local # fill in ANTHROPIC_API_KEY
npm run devDefaults:
- Receiving wallet:
0x66268791B55e1F5fA585D990326519F101407257 - Network:
base(mainnet). SetX402_NETWORK=base-sepoliafor test USDC. - Price:
$0.005per inference call. Override withX402_PRICE_USD. - Default model:
claude-sonnet-4-6. Override withANTHROPIC_DEFAULT_MODEL.
- Mainnet (
base): the middleware defaults to Coinbase CDP's hosted facilitator bundled withx402-next. - Testnet (
base-sepolia): setX402_FACILITATOR_URL=https://x402.org/facilitator.
| Path | Gated | Description |
|---|---|---|
/ |
no | Human-readable summary page. |
/api/info |
no | JSON describing pricing + tools. |
/api/mcp/mcp |
yes | MCP Streamable HTTP endpoint. |
npm testThree test suites:
tests/config.test.ts— env parsing, price formatting, default wallet.tests/anthropic.test.ts— the Anthropic SDK wrapper, with a mocked client.tests/payment-gate.test.ts— the proxy returns a valid 402 x402 challenge pointing at the configured wallet, and/api/infopublishes the right payment metadata.
curl -i -X POST https://anthropic.yeetful.com/api/mcp/mcp \
-H 'content-type: application/json' \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'(Swap the host for http://localhost:3000 when running npm run dev locally.)
You should see HTTP/1.1 402 Payment Required and a JSON body containing accepts[].payTo equal to the configured wallet.
import { wrapFetchWithPayment } from "x402-fetch";
import { privateKeyToAccount } from "viem/accounts";
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
const fetchWithPayment = wrapFetchWithPayment(fetch, account);
const res = await fetchWithPayment("https://anthropic.yeetful.com/api/mcp/mcp", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({
jsonrpc: "2.0",
id: 1,
method: "tools/call",
params: {
name: "ask_claude",
arguments: { prompt: "What is the capital of France?" },
},
}),
});
console.log(await res.json());