pr-legislative-x402
MCP server that enables AI agents to search and read Puerto Rico legislative measures with pay-per-call in USDC on Base, using the x402 agent-payment standard.
README
pr-legislative-x402
Pay-per-call access to structured Puerto Rico legislative data, over the x402 agent-payment standard.
▶ Live demo: pr-legislative-x402.vercel.app — try /health, /v1/preview, /v1/bills/search?q=solar. (Sample data, payments off.)
An HTTP API + MCP server that lets AI agents search and read measures of the Puerto Rico Legislative Assembly (Asamblea Legislativa) — and pay per call in USDC on Base, autonomously, no accounts or API keys.
Data originates from OpenStates / SUTRA (public source); the value sold here is
the cleaned, structured, topic-tagged, bilingual layer that CivicaPR built
on top of it — the same corpus behind civicapr.com/legislacion (~4,900 measures).
Status: scaffold. Runs end-to-end on built-in sample data with zero secrets. Wire it to the live Neon DB + a wallet to go paid.
Why this exists (and why it protects the data, not exposes it)
The public site already serves this data free to any scraper. This project adds a separate, controlled, paid channel for machines — which is strictly more control than a public HTML page:
- Read-only.
DATABASE_URLshould point at a role withSELECTonly. The code issues no writes. - Bounded responses. Search returns summary rows capped at 25 (no abstract); full detail is a separate, pricier single-record call. Extracting the whole corpus therefore costs per bill — bulk scraping isn't cheap.
- Neutral naming. Given the live
CIVICAtrademark conflict, this package is deliberately not branded "Civica." - Free tier stays free. The human site is untouched; this is an additive paid API tier for agents.
Architecture
Agent (Claude Code / OpenClaw)
│ calls MCP tools: search_pr_legislation, get_pr_bill
▼
MCP server (src/mcp) ── wraps fetch with wallet auto-pay (x402) ──┐
│ │ 402 → pay USDC on Base → retry
▼ ▼
HTTP API (src/server) ── x402 payment gate ──▶ priced routes ──▶ Neon `bills` (read-only)
free: /health, /v1/preview └─ falls back to sample data
Payment layer is isolated in src/server/x402.ts (seller) and
src/mcp/pay-fetch.ts (buyer) so the young x402 SDK can churn without touching
the rest of the app.
Quickstart (dev — no wallet, no DB)
npm install
npm test # bounds + paywall-config tests, on sample data
npm run dev:server # API on http://localhost:4021, payments OFF
# in another shell:
curl localhost:4021/v1/preview
curl 'localhost:4021/v1/bills/search?q=solar'
curl localhost:4021/v1/bills/PC%20456
Point an agent at the MCP server (payments off):
PR_X402_API_BASE=http://localhost:4021 npm run dev:mcp
Endpoints
| Method | Path | Tier | Price* |
|---|---|---|---|
| GET | /health |
free | — |
| GET | /v1/preview |
free | — (corpus counts only) |
| GET | /v1/bills/search?q=&chamber=&status=&limit= |
paid | $0.01 |
| GET | /v1/bills/:identifier |
paid | $0.03 |
*Prices live in one place: src/server/routes.ts.
Going paid (production)
- Point at real data — create the read-only role with
scripts/neon-readonly-role.sql, then setDATABASE_URLto that role's pooled Neon connection string. - Set your receiving wallet —
RECEIVING_WALLET_ADDRESS= a Base address you control. (This project never handles a seller private key; USDC settles on-chain to that address.) - Enable + configure the facilitator —
PAYMENTS_ENABLED=true, plus the Coinbase CDP keys the facilitator needs (CDP_API_KEY_ID/CDP_API_KEY_SECRET). - Deploy — see "Deploy" below.
✅ The seller wiring (
src/server/x402.ts) is verified against the real@x402/express@2.xAPI — anx402ResourceServer+ExactEvmScheme, CAIP-2 networks,accepts-shaped routes — and the unpaid → 402 challenge is certified on Base Sepolia (npm run test:testnet). The remaining unproven leg is a live paid settlement (402 → pay → 200), which needs a funded testnet key — seeTESTNET.mdto run it, then flip to mainnet.
Deploy
Vercel (recommended for a data API). All routes rewrite to one serverless
function (api/index.ts) that runs the same Express app. vercel.json is
included.
vercel # link + preview deploy
vercel --prod # production
# set env in the dashboard (or `vercel env add`):
# DATABASE_URL, PAYMENTS_ENABLED, RECEIVING_WALLET_ADDRESS,
# X402_NETWORK, CDP_API_KEY_ID, CDP_API_KEY_SECRET
Container / VPS / your own box. A multi-stage Dockerfile is
included:
docker build -t pr-legislative-x402 .
docker run -p 4021:4021 --env-file .env pr-legislative-x402
| Option | Good for | Notes |
|---|---|---|
| Vercel (serverless) | data API like this | Near-zero compute; reuses your existing stack. Recommended. |
| Cheap VPS ($5/mo) / Docker | always-on control | Fine; more ops than Vercel for no real gain here. |
| Closet box | selling compute (GPU/inference/transcription) | Only worth it when your marginal cost beats cloud. For a data API the box adds downtime/ISP risk with no upside — skip it here. |
Use it from an agent (MCP)
Copy examples/claude-mcp-config.json into a
project .mcp.json, point PR_X402_API_BASE at your deployment, and (for a
paid server) set a dedicated low-balance WALLET_PRIVATE_KEY. Tools exposed:
search_pr_legislation, get_pr_bill.
Quality gates
npm run typecheck·npm test(17 tests) ·npm run build— all run in CI (.github/workflows/ci.yml) on push/PR.- HTTP layer: zod-validated inputs (400 on bad query/identifier), JSON 404 +
error handlers, CORS, security headers, and a best-effort rate limit on the
free routes. API described in
openapi.yaml.
Buyer side (agents that pay)
The MCP auto-pays only if WALLET_PRIVATE_KEY is set — use a dedicated,
low-balance Base key, never a treasury wallet. Unset = plain fetch, which
works against an open dev server.
Layout
src/
data/ schema.ts (types + zod inputs + limit clamp) · queries.ts (Neon, read-only) · mock.ts (sample corpus)
server/ routes.ts (price config) · x402.ts (seller gate) · middleware.ts (cors/ratelimit/errors) · app.ts · index.ts
mcp/ index.ts (tools) · pay-fetch.ts (buyer auto-pay)
api/ index.ts (Vercel serverless entry)
scripts/ neon-readonly-role.sql
examples/ claude-mcp-config.json
test/ bounds.test.ts · paywall.test.ts · validation.test.ts
openapi.yaml · vercel.json · Dockerfile · .github/workflows/ci.yml
MIT. Built by R21 Digital.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。