Skip to main content
Glama

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
NameRequiredDescriptionDefault
invoiceYesBOLT11 Lightning invoice

Implementation Reference

  • 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" ); } }
  • 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,
  • Tool dispatch registration in the CallToolRequestSchema switch statement, routing 'decode_invoice' calls to handleDecodeInvoice.
    case "decode_invoice": { return handleDecodeInvoice(this.bitcoinService, args); }
  • 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 ); } }

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