Skip to main content
Glama
README.md
# cf-x402-mcp — Paid MCP tools on Cloudflare Workers (x402, Base USDC)

Stateless Streamable-HTTP MCP server (`POST /mcp`). Paid tool calls without payment get an HTTP `402` with a `PAYMENT-REQUIRED` header (x402 v2, scheme `exact`, USDC on Base `eip155:8453`). Payments are verified and settled through a configurable x402 facilitator.

- **Live Endpoint**: `https://cf-x402-mcp.yan8925298.workers.dev/mcp`
- **Discovery Manifest**: `https://cf-x402-mcp.yan8925298.workers.dev/.well-known/x402`

> Note: `agents@0.35` ships only the x402 *client* (`agents/x402`); there is no server-side `withX402`/`paidTool`, so this project implements a small paywall in `src/x402.ts` (no extra deps) in front of the `@modelcontextprotocol/sdk` `WebStandardStreamableHTTPServerTransport`.

## Tools & pricing

| Tool | Price (USDC) | Purpose |
|---|---|---|
| `ci_log_sieve` | 0.01 | Compress CI/build logs → root cause, failing steps/tests, deduped stack traces, fixes |
| `repo_sec_triage` | 0.02 | Static triage of pasted code/diff/manifest → severity-ranked findings (secrets redacted) |
| `market_edge_feed` | 0.01 | Edge signals in `signals_public.json` schema (`SIGNALS_JSON` / `SIGNALS_URL`, demo fallback) |
| `sample_tools` | free | Lists tools/prices and free preview calls |

**Free at $0:** pass `"sample": true` to any paid tool (built-in input, no payment), or set `FREE_DRY_RUN=true` to disable the paywall entirely (testing).

## Setup

```
npm install
npm test            # vitest
npx tsc --noEmit
npx wrangler dev    # local
npx wrangler deploy
```

Config (`wrangler.jsonc` vars / `.env.example`): `PAY_TO` (public 0x address — ships with a placeholder; never put private keys anywhere), `NETWORK`, `FACILITATOR_URL` (default `https://x402.org/facilitator`; use a Base-mainnet-capable facilitator for production), `FREE_DRY_RUN`, `SIGNALS_URL` (https only) or `SIGNALS_JSON`.

## Layout

`src/core/*` pure logic · `src/x402.ts` paywall · `src/tools.ts` MCP tools · `src/index.ts` Worker handler · `test/*` Vitest.