Skip to main content
Glama

pay_invoice

Process Bitcoin Lightning payments by submitting BOLT11 invoices to settle transactions on the network.

Instructions

Pay a Lightning invoice

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
invoiceYesBOLT11 Lightning invoice

Implementation Reference

  • MCP tool handler for 'pay_invoice'. Validates input schema, calls bitcoinService.payInvoice(bolt11), and returns success response with payment hash or throws MCP error.
    export async function handlePayInvoice( bitcoinService: BitcoinService, args: unknown ) { const result = PayInvoiceSchema.safeParse(args); if (!result.success) { throw new McpError( ErrorCode.InvalidParams, `Invalid parameters: ${result.error.message}` ); } try { const paymentHash = await bitcoinService.payInvoice(result.data.invoice); return { content: [ { type: "text", text: `Payment successful!\nPayment hash: ${paymentHash}`, }, ] as TextContent[], }; } catch (error: any) { throw new McpError( ErrorCode.InternalError, error.message || "Failed to pay invoice" ); } }
  • Zod schema defining input for pay_invoice tool: requires 'invoice' string.
    export const PayInvoiceSchema = z.object({ invoice: z.string().min(1, "Invoice cannot be empty"), }); export type PayInvoiceArgs = z.infer<typeof PayInvoiceSchema>;
  • Tool registration in listToolsRequestHandler: defines name, description, and inputSchema for 'pay_invoice'.
    name: "pay_invoice", description: "Pay a Lightning invoice", inputSchema: { type: "object", properties: { invoice: { type: "string", description: "BOLT11 Lightning invoice", }, }, required: ["invoice"], }, } as Tool,
  • Dispatch/handling registration in callToolRequestHandler switch statement: routes 'pay_invoice' calls to handlePayInvoice.
    case "pay_invoice": { return handlePayInvoice(this.bitcoinService, args); }
  • Core helper method in BitcoinService that performs the actual invoice payment via LNBits client and returns payment_hash.
    async payInvoice(bolt11: string): Promise<string> { if (!this.lnbitsClient) { throw new LightningError( "LNBits not configured. Please add lnbitsUrl, lnbitsAdminKey, and lnbitsReadKey to configuration.", LightningErrorCode.NOT_CONNECTED ); } try { const response = await this.lnbitsClient.sendPayment(bolt11); return response.payment_hash; } catch (error) { logger.error({ error, bolt11 }, "Failed to pay invoice"); throw new LightningError( "Failed to pay Lightning invoice", LightningErrorCode.PAYMENT_ERROR ); } }

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/AbdelStark/bitcoin-mcp'

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