Skip to main content
Glama

pay_invoice

Process Lightning Network payments by submitting a BOLT11 invoice through the Bitcoin MCP Server to complete Bitcoin transactions securely and efficiently.

Instructions

Pay a Lightning invoice

Input Schema

NameRequiredDescriptionDefault
invoiceYesBOLT11 Lightning invoice

Input Schema (JSON Schema)

{ "properties": { "invoice": { "description": "BOLT11 Lightning invoice", "type": "string" } }, "required": [ "invoice" ], "type": "object" }

Implementation Reference

  • The MCP tool handler function that validates input using PayInvoiceSchema, calls the bitcoinService.payInvoice, and returns the payment hash in MCP content format.
    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 for pay_invoice tool input validation and inferred TypeScript type.
    export const PayInvoiceSchema = z.object({ invoice: z.string().min(1, "Invoice cannot be empty"), }); export type PayInvoiceArgs = z.infer<typeof PayInvoiceSchema>;
  • Registration of the 'pay_invoice' tool in the MCP listTools response, including name, description, and inputSchema.
    { name: "pay_invoice", description: "Pay a Lightning invoice", inputSchema: { type: "object", properties: { invoice: { type: "string", description: "BOLT11 Lightning invoice", }, }, required: ["invoice"], }, } as Tool,
  • Dispatch handler in the CallToolRequest switch statement that routes 'pay_invoice' calls to handlePayInvoice.
    case "pay_invoice": { return handlePayInvoice(this.bitcoinService, args); }
  • Core service method that performs the actual invoice payment via LNBits client and returns the 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 ); } }

Other Tools

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

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