Framework recipes: x402 tools for agent frameworks
Wrap the paid fetch in a tool for Vercel AI SDK, LangChain, LangGraph, OpenAI Agents SDK and Coinbase AgentKit, or connect the MCP server from Claude Desktop, Cursor and Codex.
Each recipe assumes fetchWithPayment (TypeScript) or an x402HttpxClient (Python) from /docs/quickstart. The tool only builds the URL; payment happens in the wrapped client.
Vercel AI SDK
import { tool } from "ai";
import { z } from "zod";
export const webSearch = tool({
description: "Live Google results as JSON (paid per call via x402).",
inputSchema: z.object({ q: z.string() }),
execute: async ({ q }) => {
const res = await fetchWithPayment(`https://marketplaceforaiagents.com/api/public/v1/google-search?q=${encodeURIComponent(q)}`);
return res.json();
},
});LangChain JS
import { tool } from "@langchain/core/tools";
import { z } from "zod";
export const webSearch = tool(
async ({ q }) => {
const res = await fetchWithPayment(`https://marketplaceforaiagents.com/api/public/v1/google-search?q=${encodeURIComponent(q)}`);
return JSON.stringify(await res.json());
},
{ name: "web_search", description: "Live Google results (x402-paid).", schema: z.object({ q: z.string() }) },
);LangGraph / LangChain Python
from langchain_core.tools import tool
@tool
async def web_search(q: str) -> str:
"""Live Google results as JSON (paid per call via x402)."""
async with x402HttpxClient(client) as http:
r = await http.get("https://marketplaceforaiagents.com/api/public/v1/google-search", params={"q": q})
await r.aread()
return r.textOpenAI Agents SDK
import { tool } from "@openai/agents";
import { z } from "zod";
export const webSearch = tool({
name: "web_search",
description: "Live Google results (x402-paid).",
parameters: z.object({ q: z.string() }),
execute: async ({ q }) => {
const res = await fetchWithPayment(`https://marketplaceforaiagents.com/api/public/v1/google-search?q=${encodeURIComponent(q)}`);
return JSON.stringify(await res.json());
},
});from agents import function_tool
@function_tool
async def web_search(q: str) -> str:
"""Live Google results (x402-paid)."""
async with x402HttpxClient(client) as http:
r = await http.get("https://marketplaceforaiagents.com/api/public/v1/google-search", params={"q": q})
await r.aread()
return r.textCoinbase AgentKit
Use the account from AgentKit's wallet provider as the signer for the x402 client above (it plays the role of privateKeyToAccount), then expose the paid fetch as an action or tool in your agent. Alternatively, connect the agent to the MCP server below. Check the AgentKit documentation for the exact wallet-provider API of your version.
MCP clients (Claude Desktop, Cursor, Codex)
MCP endpoint: https://marketplaceforaiagents.com/mcp (streamable HTTP, no auth).
{"mcpServers":{"marketplace-for-ai-agents":{"url":"https://marketplaceforaiagents.com/mcp"}}}Claude Desktop with the mcp-remote bridge:
{"mcpServers":{"marketplace-for-ai-agents":{"command":"npx","args":["-y","mcp-remote","https://marketplaceforaiagents.com/mcp"]}}}Codex (~/.codex/config.toml):
[mcp_servers.marketplace]
command = "npx"
args = ["-y", "mcp-remote", "https://marketplaceforaiagents.com/mcp"]Paying over MCP: when a tool result has isError: true with x402 accepts[], retry the same tools/call with params._meta["x402/payment"] set to an x402 v2 PaymentPayload. The receipt comes back in result._meta["x402/payment-response"].
{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"call_api","arguments":{"slug":"google-search","params":{"q":"x402"}},"_meta":{"x402/payment":{"x402Version":2,"accepted":{"...":"one entry of accepts[]"},"payload":{"...":"signed authorization"}}}}}