How to Connect PayAgents to Claude Desktop & Other LLMs (Cursor, Custom Agents on OpenAI, Gemini) Using MCP
By Suchi•August 22, 2026•5 min read
Until now, when an AI model needed access to a premium research database, real-time financial stream, or gated web scraping tool, it hit an immediate brick wall: HTTP 402 Payment Required.
With the release of the official payagents-mcp package, you can now connect PayAgents to any Model Context Protocol (MCP) client or custom agent runtime. Whether you are using desktop apps like Claude Desktop and Cursor, or building custom autonomous agents on OpenAI (GPT-4o) or Google Gemini (Gemini 2.0/1.5), your AI can autonomously evaluate 402 micro-payment challenges, pay fraction-of-a-cent fees across Bitcoin Lightning (L402) and Base USDC (x402), and fetch live data directly.
1. Connecting to Desktop Assistants (Claude Desktop, Cursor, Windsurf)
2. Connecting Custom Agents on OpenAI & Google Gemini
If you are building custom agents with OpenAI or Gemini SDKs, you can connect payagents-mcp directly using the MCP client SDK or standard tool calling:
B. Custom Google Gemini Agent (Gemini 2.0 / 1.5 Pro)
gemini-agent.ts
import { GoogleGenAI } from'@google/genai';
import { PayAgents } from'payagents';
const ai = newGoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const payagents = newPayAgents({ apiKey: process.env.PAYAGENTS_API_KEY });
// Define the PayAgents function declaration for Geminiconst payUrlTool = {
functionDeclarations: [{
name: 'payagents_pay_url',
description: 'Autonomous payment for any HTTP 402 agent-gated URL (Lightning/Base USDC)',
parameters: {
type: 'OBJECT',
properties: { url: { type: 'STRING', description: 'Target 402 URL to pay and unlock' } },
required: ['url']
}
}]
};
// Generate content with automated function callingconst response = await ai.models.generateContent({
model: 'gemini-2.0-flash',
contents: 'Analyze market data at https://api.signals.ai/realtime',
config: { tools: [payUrlTool] }
});
3. What Tools Does Your Agent Get?
⚡ 1. payagents_pay_url
Takes a target URL, probes the HTTP 402 payment challenge, auto-selects the fastest/cheapest rail (Lightning or Base USDC), pays the micro-fee, and returns the unlocked response data to your agent.
💳 2. payagents_get_balance
Allows your agent to check its current available USD budget and active enterprise spending policy limits before making high-frequency tool calls.
🧾 3. payagents_get_transaction
Queries transaction status, payment rails, cryptographic proof (preimage/on-chain hash), and settlement method (Direct vs Managed).
4. Enterprise Guardrails & Policy Protection
Giving an LLM an autonomous wallet might sound risky, but PayAgents was built with strict safety guardrails from day one:
Per-Transaction Limit: Your agent cannot spend more than your set ceiling on any single tool call (e.g. max $0.02).
Daily Budget Caps: Prevents runaway recursive loops from draining funds (e.g. max $5.00/day).
Domain Allowlists: You control which hostnames your agent is permitted to transact with.
Human Approval Workflow: Any payment exceeding your policy threshold is automatically paused in your dashboard until you approve it.
5. Monetizing Your Own MCP Tools with PayAgents
If you are building an MCP server and want external agents to pay you micro-fees when calling your tools: