From 0d3e20cca48b72a99cf497fc264c12d37db29f70 Mon Sep 17 00:00:00 2001 From: sam00101011 <239554522+sam00101011@users.noreply.github.com> Date: Sun, 15 Mar 2026 20:06:35 +0900 Subject: [PATCH] Add x402 monetization (/.well-known/x402.json + middleware) --- .well-known/x402.json | 12 ++++++++++++ x402-middleware-example.ts | 25 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 .well-known/x402.json create mode 100644 x402-middleware-example.ts diff --git a/.well-known/x402.json b/.well-known/x402.json new file mode 100644 index 0000000..b743ce3 --- /dev/null +++ b/.well-known/x402.json @@ -0,0 +1,12 @@ +{ + "name": "microsoft/DebugMCP", + "description": "Gift your VS Code agent a real debugger: breakpoints, stepping, inspection.", + "accepts": [ + { + "network": "eip155:8453", + "asset": "USDC", + "address": "YOUR_WALLET_ADDRESS" + } + ], + "resources": [] +} diff --git a/x402-middleware-example.ts b/x402-middleware-example.ts new file mode 100644 index 0000000..ab52dda --- /dev/null +++ b/x402-middleware-example.ts @@ -0,0 +1,25 @@ +// x402 payment middleware - add before your protected routes +import { createPaymentMiddleware } from 'x402-express'; // or implement manually + +// Option A: use the x402-express package +app.use('/api', createPaymentMiddleware({ + walletAddress: process.env.X402_WALLET_ADDRESS, + network: 'eip155:8453', // Base mainnet + facilitatorUrl: 'https://facilitator.402.bot/verify', +})); + +// Option B: manual (just check the payment header) +app.use('/api', (req, res, next) => { + const payment = req.headers['x-payment']; + if (!payment) { + // Return 402 with payment requirements + res.status(402).json({ + accepts: [{ network: 'eip155:8453', asset: 'USDC', address: process.env.X402_WALLET_ADDRESS }], + price: '0.01', + }); + return; + } + // Verify payment with facilitator + // See: https://api.402.bot/mcp/setup + next(); +});