When a charge fails, the SDK returns an error to the agent instead of executing the tool. You can customize these messages to help agents resolve issues.
Payment required. WeatherAPI has enabled Payo micropayments for 'get_weather' ($0.01).To use this tool:1. Get your agent token at https://payo.dev/agent/api-keys2. Add the token to your MCP client's Authorization header3. Documentation: https://docs.payo.dev/quickstart-agentQuestions? Contact [email protected]
The SDK handles payment errors before your tool runs. But if your tool itself throws an error, it passes through normally:
Copy
paidServer.tool('my_tool', schema, async (args) => { // Payment already succeeded if we get here try { const result = await doSomething(args); return result; } catch (error) { // Your error, not a payment error throw new Error('Tool failed: ' + error.message); }});
For advanced use cases, catch PaymentError in your server:
Copy
import { PaymentError, PaymentErrorCode } from '@payo/mcp';// The SDK throws PaymentError for payment failures// These are returned to the agent, not your tool// You can use PaymentError for type checking:if (error instanceof PaymentError) { console.log('Payment failed:', error.code, error.message);}