Skip to main content
Glama

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
NameRequiredDescriptionDefault
urlYesTarget URL to fetch (HTTPS required)
methodNoHTTP method (default: GET)
headersNoAdditional HTTP headers
bodyNoRequest body string
wallet_idNoTarget 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.'),
    },
  • 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);
        },
      );
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/minhoyoo-iotrust/WAIaaS'

If you have feedback or need assistance with the MCP directory API, please join our Discord server