Skip to main content
Glama
Kishore-MK

AI42-MCP X402 Payment Server

by Kishore-MK

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
NameRequiredDescriptionDefault
limitYesMaximum payment amount in SOL (0 to remove limit)

Implementation Reference

  • 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
        };
      }
    }
  • 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
          };
        }
      }
    );
  • Global variable used to store the current payment limit by the handler.
    let paymentLimit: number | null = null;

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Kishore-MK/ai42-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server