@mdlog/agentgate
v0.2.1
Published
Wrap any HTTP API into a paid x402 service on Casper — HTTP 402 micropayments in native CSPR with on-chain discovery and reputation.
Maintainers
Readme
@mdlog/agentgate
Wrap any HTTP API into a paid x402 service on Casper — HTTP 402 micropayments in native CSPR, with on-chain discovery and reputation. One command turns your endpoint into a machine-payable service that AI agents can discover, pay, and rate autonomously.
Services carry an on-chain accepts[] price list (registry v2): native CSPR, or a CEP-18 token like WCSPR settled through the official Casper x402 facilitator (gas sponsored — true sub-CSPR micropayments). buy auto-detects the rail from the 402.
Read the live catalog — zero setup
The read commands run against Casper Testnet with no configuration and no keys:
npx @mdlog/agentgate list # on-chain service catalog with scores + trust tiers
npx @mdlog/agentgate status 1 # one service: record, price, trust, attestationsWrap your API (writes)
wrap registers your service on Casper Testnet and drops a 402 paywall in front of it — one line, the only thing besides the args is your funded wallet key:
npx @mdlog/agentgate wrap https://api.example.com/gold --price 2.5 --name "Gold Spot Feed" --pem ./key.pemIt signs the on-chain registration with --pem, then maps your upstream on the gateway by signing an ownership challenge with the same key — no shared admin token. --gateway defaults to the hosted gateway; pass it to target a local or self-hosted one. (--pem is irreducible: registering on-chain is a signed, gas-paying transaction.)
Buy a call (writes)
buy runs the whole x402 exchange for you: fetch the 402 invoice, pay it with a native CSPR transfer carrying the invoice nonce as transfer_id, retry with the X-PAYMENT proof, and print the result — response body on stdout (pipeable), payment receipt on stderr:
npx @mdlog/agentgate buy 2 --pem ./buyer.pem --max 5--max is a budget cap: any invoice priced above it is refused (PRICE_EXCEEDED) before a single mote moves. Unknown or paused services fail fast before any payment.
Use from any MCP agent
mcp serves AgentGate as a Model Context Protocol stdio server, so any MCP-capable agent (Claude Desktop, a custom client, an MCP-aware framework) gets AgentGate as native tools — discover, inspect, and pay services:
npx @mdlog/agentgate mcpTools: agentgate_list_services, agentgate_get_service, agentgate_get_invoice (read-only, no key) and agentgate_buy (pays a 402 invoice in native CSPR from the buyer key, capped by maxCspr). Wire it into Claude Desktop's claude_desktop_config.json:
{ "mcpServers": { "agentgate": { "command": "npx", "args": ["-y", "@mdlog/agentgate", "mcp"] } } }Flags & environment
Every config value can be given as a flag or an env var; precedence is flag > env var > built-in default.
| Flag | Env var | Needed for |
|---|---|---|
| --mode <mock\|live> | AGENTGATE_MODE | all (CLI defaults to live) |
| --node-url <url> | CASPER_NODE_URL | all (defaults to Testnet) |
| --registry <hash> | REGISTRY_CONTRACT_PACKAGE_HASH | all (defaults to the deployed registry) |
| --gateway <url> | — | wrap (defaults to the hosted gateway in live) · buy (defaults to the service's on-chain endpoint) |
| --pem <path> | SELLER_SIGNER_PEM_PATH (wrap/pause/resume) · BUYER_SIGNER_PEM_PATH (buy) | live writes — your wallet key |
| --max <cspr> | — | buy: refuse invoices priced above this many CSPR |
| --api-key <key> | CSPR_CLOUD_API_KEY | status attestation history only |
| --admin-token <token> | AGENTGATE_ADMIN_TOKEN | mock / self-hosted-admin mapping only |
Live
wrapuses owner-signature auth, so no admin token is needed.--pemis a path, not a secret — safe in shell history.--api-key/--admin-tokenare secrets (visible in history andps); prefer their env vars.
On an invalid value the CLI fails fast with a clear one-line message (e.g. error: SIGNER_MISSING: live mode needs a seller key — pass --pem <path> or set SELLER_SIGNER_PEM_PATH) — never a stack trace.
Commands
list— list on-chain services (zero-config)status <id>— service detail + reputation (zero-config;--api-keyadds attestation history)wrap <url> --price <CSPR> --name <name>— register + put a 402 paywall in front of an APIbuy <id> --pem <key>— pay a service's 402 invoice and print the response (--maxcaps the price)mcp— serve AgentGate as an MCP stdio server (agent tools: list / inspect / buy)pause <id>/resume <id>— toggle a service you owndemo-accounts— mint faucet-funded buyer/seller accounts on the mock devnet (mock mode only)
Notes
- Node ≥ 22 required.
- Source: https://github.com/mdlog/AgentGate
