Skip to main content
Glama

pay_invoice

Process BOLT11 Lightning invoices from agent balance and return payment proof. Requires agent authorization and supports fee limits.

Instructions

Pay a BOLT11 Lightning invoice from the agent balance. Returns preimage as proof of payment. REQUIRES AGENT KEY.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
bolt11YesBOLT11 invoice string to pay (starts with lnbc...)
max_fee_satsNoMaximum routing fee in satoshis

Implementation Reference

  • Handler for 'pay_invoice' tool in MCP server, which parses input and calls the client method.
    case 'pay_invoice': {
      const parsed = PayInvoiceSchema.parse(args);
      const result = await session.requireClient().payInvoice(parsed.bolt11, parsed.max_fee_sats);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify({
              success: true,
              message: 'Invoice paid successfully',
              preimage: result.preimage,
              amount_sats: result.amountSats,
              routing_fee_sats: result.routingFeeSats,
              platform_fee_sats: result.platformFeeSats,
              total_cost: result.totalCost,
              payment_hash: result.paymentHash,
              new_balance: result.newBalance,
            }, null, 2),
          },
        ],
      };
    }
  • The implementation method 'payInvoice' in LightningFaucetClient that performs the actual API request.
    async payInvoice(
      bolt11: string,
      maxFeeSats?: number
    ): Promise<{
      preimage: string;
      amountSats: number;
      routingFeeSats: number;
      platformFeeSats: number;
      totalCost: number;
      paymentHash: string;
      newBalance: number;
      rawResponse: PayInvoiceResponse;
    }> {
      const data: Record<string, unknown> = {
        invoice: bolt11,
      };
    
      if (maxFeeSats !== undefined) {
        data.max_fee_sats = maxFeeSats;
      }
    
      const result = await this.request<PayInvoiceResponse>('pay_invoice', data);
    
      const amountSats = result.amount_sats || result.amount_paid || 0;
      const routingFeeSats = (result as any).routing_fee_sats || 0;
      const platformFeeSats = (result as any).platform_fee_sats || 0;
    
      return {
        preimage: result.preimage || result.payment_preimage || '',
        amountSats,
        routingFeeSats,
        platformFeeSats,
        totalCost: (result as any).total_cost || (amountSats + routingFeeSats + platformFeeSats),
        paymentHash: result.payment_hash || '',
        newBalance: result.new_balance || 0,
        rawResponse: result,
      };
    }
  • Validation schema for the 'pay_invoice' tool inputs.
    const PayInvoiceSchema = z.object({
      bolt11: z.string().regex(/^ln(bc|tb|bcrt)1[a-z0-9]+$/i, 'Invalid BOLT11 invoice format')
        .describe('BOLT11 invoice string to pay (starts with lnbc...)'),
      max_fee_sats: z.number().min(0).optional()
        .describe('Maximum routing fee in satoshis (default: 10% of invoice amount)'),
    });
  • src/index.ts:340-354 (registration)
    Registration definition of the 'pay_invoice' tool.
      name: 'pay_invoice',
      description: 'Pay a BOLT11 Lightning invoice from the agent balance. Returns preimage as proof of payment. REQUIRES AGENT KEY.',
      inputSchema: {
        type: 'object',
        properties: {
          bolt11: { type: 'string', description: 'BOLT11 invoice string to pay (starts with lnbc...)' },
          max_fee_sats: {
            type: 'integer',
            minimum: 0,
            description: 'Maximum routing fee in satoshis',
          },
        },
        required: ['bolt11'],
      },
    },
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden and does well by disclosing key behavioral traits: it's a payment operation (implies mutation), requires specific authentication ('AGENT KEY'), and describes the return value ('preimage as proof of payment'). It could improve by mentioning rate limits or error conditions.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with the core purpose in the first sentence, followed by return value and prerequisite in subsequent clauses. Every sentence adds essential information with zero waste, making it highly efficient.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a payment tool with no annotations and no output schema, the description is fairly complete: it covers purpose, prerequisites, and return value. It could be more complete by detailing error cases or confirmation behavior, but it provides sufficient context for basic use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents both parameters thoroughly. The description adds no additional parameter semantics beyond what's in the schema, meeting the baseline score of 3 for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Pay'), the resource ('BOLT11 Lightning invoice'), and the source ('from the agent balance'), distinguishing it from sibling tools like 'pay_lightning_address' or 'keysend' that handle different payment methods.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It provides clear context by specifying 'REQUIRES AGENT KEY' as a prerequisite, which helps determine when to use this tool. However, it does not explicitly mention when not to use it or name alternatives like 'pay_lightning_address' for different invoice types.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/lightningfaucet/lightning-wallet-mcp'

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