Skip to main content
Glama

x402_call

Automatically pay for and call any x402 API endpoint by handling the full payment flow: request, sign USDC payment via AgentCash, retry with proof, and return data.

Instructions

Call any x402 paid API endpoint with automatic USDC payment via AgentCash.

Accepts a full URL with query parameters. Handles the complete x402 payment flow:

  1. Sends request → receives 402 payment requirement

  2. Signs USDC payment on Base via AgentCash wallet

  3. Retries with payment proof → returns endpoint data

Requires AgentCash wallet to be set up and funded (https://agentcash.dev).

Examples:

  • url: "https://www.alderpost.co/api/domain-shield?domain=stripe.com"

  • url: "https://www.alderpost.co/api/company-xray?domain=hubspot.com"

  • url: "https://www.alderpost.co/api/health-signal?query=ibuprofen"

  • url: "https://www.alderpost.co/api/property-intel?address=123+Main+St+Milwaukee+WI"

  • Works with any x402 endpoint URL discovered via x402_discover.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesFull endpoint URL with query parameters

Implementation Reference

  • cli.js:518-532 (handler)
    Handler function for x402_call. Validates URL, delegates to callX402Endpoint (which wraps agentcash fetch), and returns the endpoint data or error.
    async function handleCall(args) {
      const url = args.url;
      if (!url || !url.startsWith('http')) {
        return { content: [{ type: 'text', text: 'Invalid URL. Provide a full URL like https://www.alderpost.co/api/domain-shield?domain=stripe.com' }], isError: true };
      }
    
      const result = await callX402Endpoint(url);
    
      if (!result.success) {
        return { content: [{ type: 'text', text: `Call failed: ${result.error}` }], isError: true };
      }
    
      const text = typeof result.data === 'string' ? result.data : JSON.stringify(result.data, null, 2);
      return { content: [{ type: 'text', text }] };
    }
  • cli.js:396-423 (registration)
    Tool registration with name 'x402_call', description, and input schema (url parameter only).
      {
        name: 'x402_call',
        description: `Call any x402 paid API endpoint with automatic USDC payment via AgentCash.
    
    Accepts a full URL with query parameters. Handles the complete x402 payment flow:
      1. Sends request → receives 402 payment requirement
      2. Signs USDC payment on Base via AgentCash wallet
      3. Retries with payment proof → returns endpoint data
    
    Requires AgentCash wallet to be set up and funded (https://agentcash.dev).
    
    Examples:
      - url: "https://www.alderpost.co/api/domain-shield?domain=stripe.com"
      - url: "https://www.alderpost.co/api/company-xray?domain=hubspot.com"
      - url: "https://www.alderpost.co/api/health-signal?query=ibuprofen"
      - url: "https://www.alderpost.co/api/property-intel?address=123+Main+St+Milwaukee+WI"
      - Works with any x402 endpoint URL discovered via x402_discover.`,
        inputSchema: {
          type: 'object',
          properties: {
            url: {
              type: 'string',
              description: 'Full endpoint URL with query parameters',
            },
          },
          required: ['url'],
        },
      },
  • cli.js:678-696 (registration)
    MCP server handler registration routing 'x402_call' to handleCall function.
    server.setRequestHandler(CallToolRequestSchema, async (request) => {
      const { name, arguments: args } = request.params;
    
      switch (name) {
        case 'x402_discover':
          return handleDiscover(args);
        case 'x402_call':
          return handleCall(args);
        case 'x402_balance':
          return handleBalance();
        case 'x402_research':
          return handleResearch(args);
        default:
          return {
            content: [{ type: 'text', text: `Unknown tool: ${name}. Available: x402_discover, x402_call, x402_balance, x402_research` }],
            isError: true,
          };
      }
    });
  • Helper that calls agentcashExec to perform the x402 fetch with automatic payment flow.
    async function callX402Endpoint(url) {
      return agentcashExec(`fetch "${url}" -m GET --format json`);
    }
  • Helper that executes the AgentCash CLI command to handle x402 payment and data retrieval.
    async function agentcashExec(args) {
      try {
        const { stdout, stderr } = await execAsync(
          `npx -y agentcash ${args}`,
          { timeout: AGENTCASH_TIMEOUT_MS, maxBuffer: 1024 * 1024 }
        );
        const text = stdout.trim();
        if (!text) return { success: false, error: 'Empty response from AgentCash' };
        try {
          return { success: true, data: JSON.parse(text) };
        } catch {
          const jsonMatch = text.match(/\{[\s\S]*\}/);
          if (jsonMatch) return { success: true, data: JSON.parse(jsonMatch[0]) };
          return { success: true, data: { raw: text } };
        }
      } catch (err) {
        const msg = (err.stderr || err.message || 'Unknown error').toString();
        if (msg.includes('INSUFFICIENT_BALANCE')) {
          return { success: false, error: 'Insufficient USDC balance. Fund your wallet at https://agentcash.dev/deposit' };
        }
        if (msg.includes('ENOENT') || msg.includes('not found') || msg.includes('not recognized')) {
          return { success: false, error: 'AgentCash not found. Set up at https://agentcash.dev then run: npx agentcash install' };
        }
        return { success: false, error: `AgentCash error: ${msg.slice(0, 300)}` };
      }
    }
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Despite no annotations, the description fully discloses the 3-step payment flow, requirements for AgentCash wallet, and retry logic. No contradictions or hidden behaviors.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Well-structured with clear sections, bullet-point steps, and examples. Every sentence adds value; no redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no output schema, the description lacks explicit return value details, but examples imply endpoint data. Overall, it covers purpose, flow, requirements, and usage adequately.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema covers the 'url' parameter with 100% coverage, and description adds examples and explains it accepts full URLs with query parameters, adding value beyond the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Description clearly states it calls x402 paid APIs with automatic USDC payment. It distinguishes from siblings (x402_balance, x402_discover, x402_research) which handle different aspects of the x402 protocol.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Provides when-to-use context with examples and mentions integration with x402_discover. Lacks explicit when-not-to-use or alternative tools, but context is sufficient.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/8randonpickart5/x402-buyer-mcp'

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