Skip to main content
MCP (Model Context Protocol) is an open standard for connecting AI agents to external tools and services. Semantic supports MCP as a transport for x402, meaning AI agents can discover, call, and pay for tools through a standard MCP server.

How it works

A normal MCP flow: an agent connects to an MCP server, discovers available tools via listTools(), and calls them via callTool(). With x402, the server can require payment for specific tools. The @x402/mcp package handles the payment flow transparently:
  1. Agent calls a tool via MCP
  2. Server responds with a 402 Payment Required challenge (embedded in the MCP response)
  3. The x402 MCP client automatically signs a payment authorization
  4. Client retries the tool call with the payment header
  5. The facilitator settles on-chain, and the tool returns its result
From the agent’s perspective, it just calls a tool. Payment happens in the background.

Install

Client setup

Use createx402MCPClient to create an MCP client with built-in x402 payment handling.

Discovering and calling tools

Once connected, use standard MCP methods. Payment is handled automatically when a tool requires it.

Payment control

The onPaymentRequested callback gives you control over which payments to approve. Return true to pay, false to reject.

Using with LLMs

The standard pattern is: connect to MCP, convert tools to your LLM’s format, let the LLM decide when to call tools, execute via MCP.

OpenAI

Anthropic

Multi-network support

Register multiple chains so the client can pay on whichever network the server requires:

Cleanup

Always close the client when done:

Next steps

Last modified on February 13, 2026