set-payment-limit
Configure maximum spending per request in SOL for the X402 Payment Server. Set a limit to control costs or use 0 to remove restrictions.
Instructions
Set maximum amount willing to pay per request (in SOL). Set to 0 to remove limit.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | Yes | Maximum payment amount in SOL (0 to remove limit) |
Implementation Reference
- src/index.ts:120-148 (handler)Handler function that sets the global paymentLimit based on input, validates non-negative, and returns confirmation or error.async ({ limit }) => { try { if (limit < 0) { throw new Error("Limit must be non-negative"); } paymentLimit = limit === 0 ? null : limit; return { content: [{ type: "text", text: JSON.stringify({ message: paymentLimit === null ? "Payment limit removed" : `Payment limit set to ${paymentLimit} SOL`, current_limit: paymentLimit }, null, 2) }] }; } catch (err: any) { return { content: [{ type: "text", text: `Error: ${err.message || "Failed to set payment limit"}` }], isError: true }; } }
- src/index.ts:116-118 (schema)Input schema defining the 'limit' parameter as a number with description.inputSchema: { limit: z.number().describe("Maximum payment amount in SOL (0 to remove limit)") },
- src/index.ts:111-149 (registration)Registers the 'set-payment-limit' tool with MCP server, including title, description, input schema, and handler reference.server.registerTool( "set-payment-limit", { title: "Set Payment Limit", description: "Set maximum amount willing to pay per request (in SOL). Set to 0 to remove limit.", inputSchema: { limit: z.number().describe("Maximum payment amount in SOL (0 to remove limit)") }, }, async ({ limit }) => { try { if (limit < 0) { throw new Error("Limit must be non-negative"); } paymentLimit = limit === 0 ? null : limit; return { content: [{ type: "text", text: JSON.stringify({ message: paymentLimit === null ? "Payment limit removed" : `Payment limit set to ${paymentLimit} SOL`, current_limit: paymentLimit }, null, 2) }] }; } catch (err: any) { return { content: [{ type: "text", text: `Error: ${err.message || "Failed to set payment limit"}` }], isError: true }; } } );
- src/index.ts:21-21 (helper)Global variable used to store the current payment limit by the handler.let paymentLimit: number | null = null;