x402_register
Register a new x402 service in the discovery index, providing service details, endpoint, price, and capabilities, to make it discoverable by agents.
Instructions
Register a new x402 service with the discovery index. Free. Your service will appear in the catalog and be discoverable by agents.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | ||
| endpoint_url | Yes | ||
| description | Yes | ||
| price_per_call | Yes | ||
| capability_tags | Yes | ||
| wallet_address | Yes | ||
| network | No | base |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- server.py:275-332 (handler)The x402_register function is the core handler for registering a new x402 service. It accepts name, endpoint_url, description, price_per_call, capability_tags, wallet_address, and network, then POSTs to the discovery API's /register endpoint and returns a confirmation with service ID.
def x402_register( name: str, endpoint_url: str, description: str, price_per_call: float, capability_tags: str, wallet_address: str, network: str = "base", ) -> str: """Register an x402 service with the discovery index. Args: name: Service name (e.g. 'My Weather API'). endpoint_url: Your x402-gated endpoint URL. description: One sentence: what input it takes, what it returns. price_per_call: Price in USD per call (e.g. 0.005). capability_tags: Comma-separated tags: research, data, compute, monitoring, etc. wallet_address: Your Base wallet address that receives USDC payments. network: Payment network (default: 'base'). Returns: Registration confirmation with your service ID. """ tags = [t.strip() for t in capability_tags.split(",") if t.strip()] payload = { "name": name, "endpoint_url": endpoint_url, "description": description, "price_per_call": price_per_call, "capability_tags": tags, "provider_wallet": wallet_address, "network": network, "payment_token": "USDC", "pricing_model": "flat", "agent_callable": True, "auth_required": False, } try: with httpx.Client(timeout=15.0) as client: resp = client.post(f"{DISCOVERY_API}/register", json=payload) resp.raise_for_status() data = resp.json() except Exception as e: return f"Registration error: {e}\nTry manually: POST {DISCOVERY_API}/register" service_id = data.get("service_id", "?") return ( f"✅ Service registered successfully!\n" f"Service ID: {service_id}\n" f"Name: {name}\n" f"Endpoint: {endpoint_url}\n" f"Price: ${price_per_call}/call\n" f"Tags: {', '.join(tags)}\n\n" f"Your service is now discoverable at:\n" f"{DISCOVERY_API}/health/{service_id}\n\n" f"Full catalog: {DISCOVERY_API}/catalog" ) - server.py:275-283 (schema)The input parameters (name, endpoint_url, description, price_per_call, capability_tags, wallet_address, network) define the expected schema/type definitions for the tool. The handler also constructs a payload with fixed fields (payment_token='USDC', pricing_model='flat', agent_callable=True, auth_required=False).
def x402_register( name: str, endpoint_url: str, description: str, price_per_call: float, capability_tags: str, wallet_address: str, network: str = "base", ) -> str: - server.py:263-274 (registration)The @mcp.tool decorator registers x402_register as an MCP tool with FastMCP. It sets the description and annotations (readOnlyHint=False, destructiveHint=False, idempotentHint=False, openWorldHint=True).
@mcp.tool( description=( "Register a new x402 service with the discovery index. " "Free. Your service will appear in the catalog and be discoverable by agents." ), annotations=ToolAnnotations( readOnlyHint=False, destructiveHint=False, idempotentHint=False, openWorldHint=True, ), ) - server.py:20-21 (helper)The DISCOVERY_API constant (https://x402-discovery-api.onrender.com) is used as the base URL for the registration POST request in the handler.
DISCOVERY_API = "https://x402-discovery-api.onrender.com" WALLET_ADDRESS = os.getenv("WALLET_ADDRESS", "0xDBBe14C418466Bf5BF0ED7638B4E6849B852aFfA")