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
| Name | Required | Description | Default |
|---|---|---|---|
| invoice | Yes | BOLT11 Lightning invoice |
Input Schema (JSON Schema)
{
"properties": {
"invoice": {
"description": "BOLT11 Lightning invoice",
"type": "string"
}
},
"required": [
"invoice"
],
"type": "object"
}
Implementation Reference
- src/server/tools.ts:242-270 (handler)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" ); } }
- src/types.ts:130-134 (schema)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>;
- src/server/base.ts:176-189 (registration)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,
- src/server/base.ts:218-220 (registration)Dispatch handler in the CallToolRequest switch statement that routes 'pay_invoice' calls to handlePayInvoice.case "pay_invoice": { return handlePayInvoice(this.bitcoinService, args); }
- src/services/bitcoin.ts:306-324 (helper)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 ); } }