DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk4 min

How to Build an x402-Native MCP Server on Cloudflare Workers

Cloudflare’s Agents SDK provides an x402 pattern for paid MCP tools. Learn the server setup, MCP payment and retry fields, and production decisions the Base Sepolia example leaves open.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Build the server with Cloudflare’s Agents SDK: wrap an MCP server in withX402 and register chargeable tools with paidTool. The official example is a Base Sepolia testnet demonstration, not a production deployment recipe. For production, choose a facilitator and network deliberately, and implement the MCP payment-required and settlement fields specified for x402 transport v2.

What the integration does

x402 lets an MCP server require payment for a tool call. In Cloudflare’s documented pattern, the Agents SDK handles the server integration through withX402 and paidTool. An MCP client receives a payment requirement, prepares a payment payload, and retries the call; after verification, execution, and settlement, the server returns payment-response metadata.

As an Amazon Associate I earn from qualifying purchases.

This is distinct from x402’s HTTP resource-request flow. HTTP integrations use payment headers, while the MCP transport communicates payment requirements and settlement through tool results and MCP _meta fields. See Cloudflare’s x402 documentation and the x402 Foundation’s MCP transport v2 specification.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Build the server with the Agents SDK

The Cloudflare example shows a server wrapped with withX402(server, config). It registers paid tools using paidTool(name, description, priceUSD, inputShape, outputShape, handler). The example also keeps a free echo tool alongside a paid square tool, illustrating that not every tool has to require payment.

  1. Create an MCP server using the MCP server implementation used by the Agents SDK.

  2. Wrap it with withX402(server, config). Configure the payment network, recipient address, and facilitator URL.

  3. Register each chargeable tool with paidTool, providing its name, description, price, input and output shapes, and handler.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  4. Use raw Zod shapes for the tool schemas as in the example. Its API does not accept flexible AI SDK schema adapters.

    Rank #2
    Forvencer Server Book, 2 Zipper Pocket, Server Books for Waitress
    • Upgraded Two Zipper Pockets: Forvencer server books feature two secure zipper pockets for better organization of coins, cash, and receipts, ensuring that everything you collect has a safe and secure place
    • Smart Storage & Quick Access: Designed with 8 multi-functional compartments, the right side includes a guest receipt pad, while the left has a money pocket, ticket pocket, and credit card slot. Two small clear pockets store bills, receipts, and other visible items. A stitched pen loop ensures you always have your favorite pen ready
    • High-quality & Easy to Clean: Crafted from high-quality PU leather with heavy-duty stitching, this server book is built to last. It resists tears, scratches, and its waterproof surface makes cleaning easy with just a damp cloth or a non-chlorine sanitizer
    • Perfect Fit for Your Apron: Measuring 5” x 8”, this compact organizer is slightly smaller than other models, making it ideal for bending or sitting while carrying in your server apron. It holds everything a waitress needs—a place for everything
    • What's Included: This server organizer comes with multiple open and zippered pockets to store money, receipts, tips, etc. Clear sleeves are perfect for keeping menus or special lists while serving. Available in a variety of colors, allowing you to express yourself even when in uniform
  5. Add free tools separately where they suit the service.

The sample configuration uses network: "eip155:84532", a placeholder recipient address, and facilitator: { url: "https://x402.org/facilitator" }. The network identifier is for Base Sepolia. The example labels CLIENT_TEST_PK as test-only, and its $0.01 tool price is illustrative—not a production price recommendation.

Implement the MCP payment and retry flow

For MCP, a payment challenge is a tool result, not merely an HTTP 402 response or header. The transport specification defines the fields and retry behavior:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. The client calls a paid tool without payment.

  2. The server returns a tool result with isError: true and PaymentRequired information. It must include the same information in both structuredContent and content[0].text; the latter contains the JSON encoding of that object.

  3. The client reads structuredContent when available, with content[0].text as the fallback, creates the payment payload, and retries with that payload in request _meta["x402/payment"].

  4. The server verifies the payment, executes the tool, and settles the transaction.

  5. On success, the tool result includes settlement information in _meta["x402/payment-response"]. If settlement fails after the tool has executed, return an error rather than the tool’s result.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

These matching response formats matter for interoperability: clients may rely on structured output or need to parse the text fallback. The specification’s server requirement is explicit: “Servers MUST provide the PaymentRequired in both formats.”

Rank #4
Forvencer Server Book High Volume, Expandable Waitress Book with 2 Zipper
  • Upgraded Magnetic Closure Pocket and Two Zipper Pockets: Unlike other brands, Forvencer server books are designed with two secure zipper pockets and two expandable magnetic pockets. These allow you to easily store and organize a large number of coins, cash, and receipts.
  • Smart Storage & Quick Lookup: 10 multi-functional compartments. On the right side has a check pad, and on the other has a Money Pocket, Tickets Pocket and Credit Card Slot. Two small clear pockets can store bills, receipts and other items to be viewed. A stitched pen loop to store your favorite pen.
  • Long-Lasting and Easy to Clean: Serving book features high-quality PU leather and heavy-duty stitching. PU is extremely strong with high tensile strength and good resistance to tearing, abrasion and scratching. Waterproof leather makes it simple to wipe down your server book with warm water or non-chlorine sanitizer solution to remove any dirt, soil, grime, or soda residue to keep it clean.
  • Fit Perfectly in your Apron: Our 5" x 9" server book is designed to accommodate regular checks and fit easily in your apron pocket.
  • What You Get: Forvencer server book in strict quality control, our worry-free 1-Year warranty, and friendly customer service.

Choose a network, payment scheme, and facilitator

The sample is configured for Base Sepolia and uses the public x402.org facilitator. Treat that as a test setup, not a default mainnet configuration. Cloudflare describes a facilitator as optional but recommended: it can verify payment payloads and submit transactions for settlement, reducing the blockchain work the resource server must handle. For production, the x402 Foundation advises selecting a production facilitator that supports the intended network, operating one, or self-facilitating. Confirm the provider’s availability, supported scheme/network pair, operational behavior, and credential requirements before launch. See the Foundation’s x402 repository and production guidance.

Cloudflare’s overview describes two payment schemes: exact, a fixed token amount, and upto, authorization up to a maximum with the actual charge set at settlement based on resource consumption. The overview lists Base, Ethereum, Polygon, Optimism, Arbitrum, Avalanche, Solana, Aptos, Stellar, and Sui. That list does not guarantee every scheme works with every network, SDK, or facilitator; verify the specific combination you plan to use in the Cloudflare overview and the selected facilitator’s documentation.

For a test configuration, Cloudflare calls out Base Sepolia and test USDC from the Circle Faucet. Keep test credentials and test funds separate from production payment handling.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Decide how the client handles payment approval

Cloudflare’s example demonstrates withX402Client and an optional human payment-confirmation flow. Decide what approval policy your product requires before enabling client-side signing: a client should not silently authorize a user’s payment unless that behavior is intentional and clearly governed by the product’s consent model. See the Agents SDK example.

Best Value
Server Book with Zipper Pocket and Magnetic Closure Server Booklet Waitress Book Serving Book with Money Pocket Waitstaff Organizer Fit Server Apron Waiter Book Wallet High Volume Pocket
  • [Large Capacity & Apron-Friendly] Measuring an oversized 4.7 x 9 inches, this larger server book provides extra room for taller receipts, guest checks, and menus while still fitting perfectly into standard restaurant aprons. (Note: apron and guest check pads are not included.)
  • [Secure Magnetic & Zipper Pockets] Features a powerful magnetic closure pocket to securely hold large amounts of cash flat, alongside a heavy-duty zippered pocket to keep coins from falling out. Perfect for keeping your bills, receipts, change, and credit cards safely locked away during a hectic shift.
  • [Classic Black & White Polka Dot Design] Crafted from high-quality, soft PU faux leather, this server book features a timeless black background accented by retro-chic white polka dots. It brings a touch of modern fashion to your workday, brightening your uniform while matching any restaurant dress code.
  • [Professional Craftsmanship & Durability] Built to withstand the grueling, fast-paced demands of the food service industry. Engineered with reinforced seams and meticulous stitching that won't fray, this lightweight organizer offers a polished, high-end look that stands up to daily wear and tear.
  • [The Ultimate Shift Organizer] The perfect shift companion for busy waitstaff, servers, and bartenders. Whether you are holding cash, writing down orders, or tracking daily food and wine specials, this stylish book keeps you organized, fast, and efficient under pressure.

What to verify before production

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.