> ## Documentation Index
> Fetch the complete documentation index at: https://docs.civic.com/llms.txt
> Use this file to discover all available pages before exploring further.

# X402 MCP

> Enable micropayments for MCP tool invocations with X402 payment protocol

**Flask Status: Distilling** 🧪

<Frame caption="X402 MCP Direct Integration">
  <img src="https://mintcdn.com/civic/O4L8MDyrwt6gcvaS/images/labs/projects/x402-mcp/direct.png?fit=max&auto=format&n=O4L8MDyrwt6gcvaS&q=85&s=65fa19df9263617a4e881c3ef25ee3b4" align="center" className="image-60 image-rounded" width="666" height="1176" data-path="images/labs/projects/x402-mcp/direct.png" />
</Frame>

## Overview

X402 MCP bridges the [Model Context Protocol](https://modelcontextprotocol.io/) with the [X402 payment protocol](https://www.x402.org/), enabling micropayments for AI tool invocations.
This integration allows developers to monetize their MCP tools with instant, automatic stablecoin payments directly over HTTP.

The system enables programmatic machine-to-machine transactions without accounts or complex authentication,
making it ideal for AI agents that need to pay for premium tools and services.

## Key Features

### Instant Micropayments

* Pay-per-use model for MCP tools
* Automatic USDC payments on Base network
* No accounts or authentication required
* Settlement happens transparently during tool invocation

### Flexible Architecture

The library supports multiple deployment patterns:

<Frame caption="Client Proxy Architecture - Bridge non-payment-aware clients to payment-required servers">
  <img src="https://mintcdn.com/civic/O4L8MDyrwt6gcvaS/images/labs/projects/x402-mcp/client-proxy.png?fit=max&auto=format&n=O4L8MDyrwt6gcvaS&q=85&s=c782422e9e0663a34224219d501575ff" align="center" className="image-60 image-rounded" width="588" height="1290" data-path="images/labs/projects/x402-mcp/client-proxy.png" />
</Frame>

<Frame caption="Server Proxy Architecture - Monetize existing API-key-protected services">
  <img src="https://mintcdn.com/civic/O4L8MDyrwt6gcvaS/images/labs/projects/x402-mcp/server-proxy.png?fit=max&auto=format&n=O4L8MDyrwt6gcvaS&q=85&s=4a6feed98b1309bf6f6c97587a63e86c" align="center" className="image-60 image-rounded" width="528" height="1276" data-path="images/labs/projects/x402-mcp/server-proxy.png" />
</Frame>

## Use Cases

### For Tool Developers

* Monetize your MCP tools with minimal setup
* Set custom pricing per tool invocation
* Receive instant payments in USDC
* No payment infrastructure needed

### For AI Applications

* Access premium tools programmatically
* Pay only for what you use
* Automatic payment handling
* Works with Claude Desktop and other MCP clients

### For Service Providers

* Wrap existing APIs with micropayment layer
* Convert API-key services to pay-per-use
* Create new revenue streams
* Maintain full MCP protocol compatibility

## How It Works

1. **Client requests a tool invocation** - Standard MCP request flow
2. **Server responds with payment requirement** - HTTP 402 status with payment details
3. **Client constructs payment** - Automatic USDC transaction on Base
4. **Server verifies and executes** - Tool runs after payment confirmation
5. **Results returned to client** - Standard MCP response with settlement info

Learn more about the [technical implementation](https://github.com/civicteam/x402-mcp#what-is-x402)

## Quick Demo

Try it with your LLM by adding this MCP server configuration:

```json theme={null}
{
  "mcpServers": {
    "x402": {
      "command": "npx",
      "args": [ "@civic/x402-mcp" ],
      "env": {
        "PRIVATE_KEY": "Your wallet private key",
        "TARGET_URL": "https://x402-mcp.fly.dev/mcp"
      }
    }
  }
}
```

The demo uses Base Sepolia testnet. Get test ETH and USDC from the [Coinbase developer platform faucet](https://portal.cdp.coinbase.com/products/faucet).

## Technical Details

### X402 Protocol

[X402](https://www.x402.org/) revives the HTTP 402 Payment Required status code to enable programmatic payments. Developed by [Coinbase](https://www.coinbase.com/en-de/developer-platform/products/x402), it creates a simple flow for instant, on-chain stablecoin payments. Learn more at the [X402 documentation](https://www.x402.org/).

### MCP Integration

The library wraps [MCP's streaming HTTP transport](https://github.com/civicteam/x402-mcp#how-mcp-works-with-streaming-http) to intercept tool calls and handle payment flows transparently, maintaining full protocol compatibility while adding monetization capabilities. See the [integration architecture](https://github.com/civicteam/x402-mcp#integrating-mcp-and-x402) for implementation details.

## Open Source

X402 MCP is open source and available on [GitHub](https://github.com/civicteam/x402-mcp). Contributions and feedback are welcome!

## Getting Started

Ready to monetize your MCP tools or access payment-required services? Check out our [implementation guide](/labs/private/x402-mcp) or [contact us](https://civickey.typeform.com/to/uVH7CWJ5) for support.
