x402_fetch
Fetch URLs with automatic cryptocurrency payments when encountering HTTP 402 responses, returning both content and payment details.
Instructions
Fetch a URL with automatic x402 payment. If the server responds with HTTP 402, automatically sign a cryptocurrency payment and retry. Returns the response along with payment details if payment was made.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | Target URL to fetch (HTTPS required) | |
| method | No | HTTP method (default: GET) | |
| headers | No | Additional HTTP headers | |
| body | No | Request body string | |
| wallet_id | No | Target wallet ID. Required for multi-wallet sessions; auto-resolved when session has a single wallet. |
Implementation Reference
- The handler function that processes the x402_fetch tool request by calling the apiClient.
async (args) => { const requestBody: Record<string, unknown> = { url: args.url }; if (args.method) requestBody['method'] = args.method; if (args.headers) requestBody['headers'] = args.headers; if (args.body) requestBody['body'] = args.body; if (args.wallet_id) requestBody['walletId'] = args.wallet_id; const result = await apiClient.post('/v1/x402/fetch', requestBody); return toToolResult(result); }, - The schema definition for the x402_fetch tool arguments using Zod.
{ url: z.string().url().describe('Target URL to fetch (HTTPS required)'), method: z.enum(['GET', 'POST', 'PUT', 'DELETE', 'PATCH']).optional() .describe('HTTP method (default: GET)'), headers: z.record(z.string()).optional() .describe('Additional HTTP headers'), body: z.string().optional() .describe('Request body string'), wallet_id: z.string().optional().describe('Target wallet ID. Required for multi-wallet sessions; auto-resolved when session has a single wallet.'), }, - packages/mcp/src/tools/x402-fetch.ts:14-45 (registration)The registration function that registers the x402_fetch tool with the McpServer.
export function registerX402Fetch( server: McpServer, apiClient: ApiClient, walletContext?: WalletContext, ): void { server.tool( 'x402_fetch', withWalletPrefix( 'Fetch a URL with automatic x402 payment. If the server responds with HTTP 402, automatically sign a cryptocurrency payment and retry. Returns the response along with payment details if payment was made.', walletContext?.walletName, ), { url: z.string().url().describe('Target URL to fetch (HTTPS required)'), method: z.enum(['GET', 'POST', 'PUT', 'DELETE', 'PATCH']).optional() .describe('HTTP method (default: GET)'), headers: z.record(z.string()).optional() .describe('Additional HTTP headers'), body: z.string().optional() .describe('Request body string'), wallet_id: z.string().optional().describe('Target wallet ID. Required for multi-wallet sessions; auto-resolved when session has a single wallet.'), }, async (args) => { const requestBody: Record<string, unknown> = { url: args.url }; if (args.method) requestBody['method'] = args.method; if (args.headers) requestBody['headers'] = args.headers; if (args.body) requestBody['body'] = args.body; if (args.wallet_id) requestBody['walletId'] = args.wallet_id; const result = await apiClient.post('/v1/x402/fetch', requestBody); return toToolResult(result); }, ); }