Agent Financial Advisor
The compliance officer, risk manager, tax advisor and performance auditor for AI agents that trade and advise. Agents call it before they act; it answers with sourced, deterministic checks and charges a small fee per call.
Tools
Drop-in code (Alpaca order guard, MCP client configs, x402 paying client): examples/.
Run locally (Node 20+, no dependencies)
npm test
npm start # http://localhost:8787 (payments off until PAY_TO is set)
Try it:
curl localhost:8787/llms.txt
curl -X POST localhost:8787/v1/tools/position_size -H "content-type: application/json" \
-d '{"equity":50000,"entry_price":100,"stop_price":95,"method":"fixed_fractional"}'
MCP clients: point a streamable-HTTP MCP connection at http://localhost:8787/mcp.
For the keyed free tier and credits, send Authorization: Bearer <key>, use /mcp?key=<key>, or have the agent call
the free get_api_key tool, which binds a new key to the MCP session. Add ?src=<name> to any URL to attribute usage in /stats.
Endpoints
Configuration (env vars)
Deploy (free)
Cloudflare Workers: npx wrangler kv namespace create AFA_KV, put the id in wrangler.toml, then npx wrangler deploy.
Real USDC: npx wrangler secret put CDP_API_KEY_JSON < secrets/cdp_api_key.json, set X402_NETWORK = "base" in wrangler.toml, deploy.
Payments (x402)
Speaks x402 v2: a 402 carries a base64 PAYMENT-REQUIRED header (CAIP-2 network, e.g. eip155:8453), clients pay with
PAYMENT-SIGNATURE, and the settlement comes back in PAYMENT-RESPONSE. v1 clients (X-PAYMENT, body accepts) still work.
End-to-end test on the test network: npm i --no-save viem && node scripts/e2e-payment.mjs <server url> --fund.
Layout
src/app.js fetch-style router: REST, MCP, billing hooks
src/server.js Node entry
src/worker.js Cloudflare Workers entry (KV store)
src/billing/ free tier, API keys, credits, x402, ledger
src/tools/ the advisory tools
src/lib/regs.js rule table with sources (reviewed weekly)
src/lib/calendar.js NYSE calendar
test/ node --test suites