decode_invoice
Decode BOLT11 Lightning invoices to retrieve payment details, enabling clear transaction information extraction from the Bitcoin network.
Instructions
Decode a Lightning invoice
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| invoice | Yes | BOLT11 Lightning invoice |
Implementation Reference
- src/server/tools.ts:199-231 (handler)The MCP tool handler for 'decode_invoice'. Validates the 'invoice' parameter, decodes using BitcoinService, and returns formatted text content with invoice details.export async function handleDecodeInvoice( bitcoinService: BitcoinService, args: unknown ) { if ( !args || typeof args !== "object" || !("invoice" in args) || typeof args.invoice !== "string" ) { throw new McpError( ErrorCode.InvalidParams, "Invalid parameters: invoice is required" ); } try { const invoice = bitcoinService.decodeInvoice(args.invoice); return { content: [ { type: "text", text: `Decoded Lightning invoice:\nNetwork: ${invoice.network}\nAmount: ${invoice.amount} satoshis\nDescription: ${invoice.description}\nExpiry: ${invoice.expiryDate}\nStatus: ${invoice.status}`, }, ] as TextContent[], }; } catch (error: any) { throw new McpError( ErrorCode.InternalError, error.message || "Failed to decode invoice" ); } }
- src/server/base.ts:163-175 (schema)JSON schema definition for the 'decode_invoice' tool input, registered in the ListToolsRequest handler. Requires a single 'invoice' string parameter.name: "decode_invoice", description: "Decode a Lightning invoice", inputSchema: { type: "object", properties: { invoice: { type: "string", description: "BOLT11 Lightning invoice", }, }, required: ["invoice"], }, } as Tool,
- src/server/base.ts:215-217 (registration)Tool dispatch registration in the CallToolRequestSchema switch statement, routing 'decode_invoice' calls to handleDecodeInvoice.case "decode_invoice": { return handleDecodeInvoice(this.bitcoinService, args); }
- src/services/bitcoin.ts:278-295 (helper)Supporting method in BitcoinService that performs the actual invoice decoding by delegating to LNBitsClient.toHumanFriendlyInvoice.decodeInvoice(bolt11: string): HumanFriendlyInvoice { if (!this.lnbitsClient) { throw new LightningError( "LNBits not configured. Please add lnbitsUrl, lnbitsAdminKey, and lnbitsReadKey to configuration.", LightningErrorCode.NOT_CONNECTED ); } try { return this.lnbitsClient.toHumanFriendlyInvoice(bolt11); } catch (error) { logger.error({ error, bolt11 }, "Failed to decode invoice"); throw new LightningError( "Failed to decode Lightning invoice", LightningErrorCode.PAYMENT_ERROR ); } }