paymentsx402mcpmarketplacetool-discovery

Discover pay-per-call API and MCP tools from the Fatstack marketplace and use them as an AI SDK ToolSet. Discovery is free; calls settle in real USDC on Base via x402, with required daily spend guards.

Installation

pnpm add @fatstack/ai-sdk-tools ai viem

Usage

import { generateText, isStepCount } from 'ai';
import { fatstackTools } from '@fatstack/ai-sdk-tools';
import { privateKeyToAccount } from 'viem/accounts';

// Discovery is free and happens once; only calling a tool costs anything.
//
// The public catalogue is on Base mainnet, so calls spend real USDC. The
// required guards bound spending and cannot be raised by the model.
const tools = await fatstackTools({
  wallet: privateKeyToAccount(process.env.AGENT_PRIVATE_KEY as `0x${string}`),
  networks: ['base'],
  guards: { maxPerDay: 0.5, maxPerCall: 0.01 },
});

const { text } = await generateText({
  model: 'openai/gpt-5-mini',
  prompt: 'Convert 20 degrees Celsius to Fahrenheit.',
  tools,
  stopWhen: isStepCount(3),
});

console.log(text);