create_x402_payment_header
Generates a payment header for the X402 protocol required in HTTP requests, specifying payment details such as asset, amount, and network for processing on the Fewsats MCP Server.
Instructions
Creates a payment header for the X402 protocol.
The chain is base-sepolia or base
The x402 payload must be a dict with this structure:
{
"accepts": [
{
"asset": "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
"description": "Payment for GET https://proxy402.com/7Yhuf2O3zs",
"extra": {
"name": "USDC",
"version": "2"
},
"maxAmountRequired": "10",
"maxTimeoutSeconds": 300,
"mimeType": "",
"network": "base-sepolia",
"payTo": "0xbA5Ae80f48E0C74878c1a362D69c27c2135Aa594",
"resource": "https://proxy402.com/7Yhuf2O3zs",
"scheme": "exact"
}
],
"error": "X-PAYMENT header is required",
"x402Version": 1
}
Returns a dict with the payment_header field that must be set in X-PAYMENT header in a x402 http request.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chain | Yes | ||
| x402_payload | Yes |
Implementation Reference
- src/fewsats_mcp/server.py:66-98 (handler)The main handler function for the 'create_x402_payment_header' tool, decorated with @mcp.tool() for automatic registration in FastMCP. It takes chain and x402_payload as inputs, describes the expected payload structure in the docstring (serving as schema), and delegates to Fewsats.pay_x402_offer, wrapping the response with handle_response.@mcp.tool() async def create_x402_payment_header(chain: str, x402_payload: dict) -> dict: """ Creates a payment header for the X402 protocol. The chain is base-sepolia or base The x402 payload must be a dict with this structure: { "accepts": [ { "asset": "0x036CbD53842c5426634e7929541eC2318f3dCF7e", "description": "Payment for GET https://proxy402.com/7Yhuf2O3zs", "extra": { "name": "USDC", "version": "2" }, "maxAmountRequired": "10", "maxTimeoutSeconds": 300, "mimeType": "", "network": "base-sepolia", "payTo": "0xbA5Ae80f48E0C74878c1a362D69c27c2135Aa594", "resource": "https://proxy402.com/7Yhuf2O3zs", "scheme": "exact" } ], "error": "X-PAYMENT header is required", "x402Version": 1 } Returns a dict with the payment_header field that must be set in X-PAYMENT header in a x402 http request. """ return handle_response(Fewsats().pay_x402_offer(x402_payload, chain))
- src/fewsats_mcp/server.py:66-66 (registration)The @mcp.tool() decorator registers the create_x402_payment_header function as an MCP tool.@mcp.tool()
- src/fewsats_mcp/server.py:67-97 (schema)Type hints (chain: str, x402_payload: dict -> dict) and detailed docstring describing the input payload structure and output.async def create_x402_payment_header(chain: str, x402_payload: dict) -> dict: """ Creates a payment header for the X402 protocol. The chain is base-sepolia or base The x402 payload must be a dict with this structure: { "accepts": [ { "asset": "0x036CbD53842c5426634e7929541eC2318f3dCF7e", "description": "Payment for GET https://proxy402.com/7Yhuf2O3zs", "extra": { "name": "USDC", "version": "2" }, "maxAmountRequired": "10", "maxTimeoutSeconds": 300, "mimeType": "", "network": "base-sepolia", "payTo": "0xbA5Ae80f48E0C74878c1a362D69c27c2135Aa594", "resource": "https://proxy402.com/7Yhuf2O3zs", "scheme": "exact" } ], "error": "X-PAYMENT header is required", "x402Version": 1 } Returns a dict with the payment_header field that must be set in X-PAYMENT header in a x402 http request. """ return handle_response(Fewsats().pay_x402_offer(x402_payload, chain))