k402-mcp is an MCP (Model Context Protocol) server that provides AI agents with a catalog of APIs callable on a pay-per-call basis, with all payment settlement completed on Kaspa L1. Its core idea is to bring x402's pay-per-call model to the Kaspa network, allowing agents to autonomously discover, pay for, and use services without accounts, bank cards, or API keys.
Purpose
This server is aimed at any MCP-capable agent environment, including Claude Code, Claude Desktop, and various agent SDKs. It solves the payment and identity verification problem when agents call external services: traditional APIs require registering accounts, binding payment methods, and managing keys, whereas k402-mcp achieves accountless, keyless pay-per-call billing through Kaspa on-chain payments.
Main capabilities
The server provides the following categories of APIs:
- Text tools: summarize, schema-guaranteed extract, classify, rewrite.
- Web reading: read_url.
- Embeddings and semantic search: embed_text, search_index, search_query.
- Kaspa on-chain data: kaspa_balance, kaspa_utxos, kaspa_tx_status, kaspa_fee_estimate, kaspa_network.
- GPU model inference: generate, offering multiple tiers (chat, llama, reason, think, code, kaspa-expert).
- Covenant as a service: covenant_compile, covenant_address, covenant_utxos, covenant_build, covenant_check, covenant_broadcast, used for compiling, deriving, checking, building, and broadcasting Silverscript covenants.
- RISC Zero proof as a service: prove_guest_upload, prove_preflight, prove_submit, job_status, job_result, attest_verify, supporting uploading guests, obtaining exact cycle quotes, generating proofs, and verifying.
- Session and payment management: catalog (view all services and real-time KAS/USD prices, free), open_session (obtain a session and a dedicated Kaspa mainnet deposit address, free), session_status (view balance consumption, free), payment_options, pay_per_call.
Usage
Hosted endpoint (zero installation)
The same server runs hosted on a public gateway in streamable HTTP mode. Hosted sessions are isolated per connection: open_session binds the payment session to your MCP connection and returns a key, which you can save and later reattach on reconnect via use_session(<key>). Nothing is shared between connections.
Local installation (stdio)
Suitable for Claude Desktop or generic MCP configuration. All environment variables are optional: K402_GATEWAY (defaults to the public gateway), K402_SESSION (pin a funded session key), K402_STATE (persistence location for automatically opening a session, default ~/.k402/session.json).
Payment loop
The payment flow is agent-native: an unfunded call returns operational guidance ("send KAS to this address, the cost of this call is X"), based on which the agent can autonomously discover services, learn how to pay, and use them. The basic steps are: call open_session to obtain a session and a dedicated Kaspa mainnet deposit address (free), fund it from any wallet (minimum 0.25 KAS, confirmed within seconds), and then you can call the various services.
Trustless payment channel (kaspa-channel)
Where the gateway supports it, channel_config and channel_status can expose covenant payment channels: your KAS is held in a Kaspa L1 covenant (rather than a merchant wallet), and each call is paid via a signed credential—the merchant can only claim the amount you signed, and you can reclaim the rest. Opening and funding a channel requires your Kaspa keys, so this part runs in the k402 Python client (k402.channel); the MCP tools only cover discovery and status queries.
Example
In CAfter adding it in Claude Code via claude mcp add, you can enter: "Use the k402 tools to check the current Kaspa network status and summarize https://kaspa.org”。首次调用会返回付款指引;为提供的充值地址充值后重试即可。
Use Cases
- Agents need to call capabilities such as text processing, web reading, and embedding search, but want to avoid account registration and key management.
- Agent applications that need real-time Kaspa on-chain data queries.
- Scenarios that need GPU inference capabilities but do not want to deploy models themselves.
- Developers who need to compile, build, or broadcast Silverscript contracts.
- Scenarios that need RISC Zero zero-knowledge proof generation and verification.
- Agent workflows that want to use APIs with pay-as-you-go pricing at extremely low cost (a fraction of a cent per call).
Limitations and Notes
- The project is a prototype. There are two payment settlement methods: custodial prepaid (session) or a trustless method via the kaspa-channel contract payment channel (already running on mainnet, but the contract has not been audited, and channel size has an upper limit).
- It is recommended to keep a small balance: a few KAS is enough to cover thousands of calls.
- Paid tools return payment_required and operating instructions when unpaid, rather than an ambiguous failure.
- The gateway rate-limits by IP; prices fluctuate with KAS/USD, and the catalog shows the current price.
- When KAS is needed, any exchange or wallet will do; topping up is just an ordinary mainnet transfer.
- Supported payment currencies include KAS, BTC, LTC, DOGE, BCH, DASH, ETH, and USDC.
- The project uses the MIT license, with copyright owned by Kaspa Lab.