Skip to main content
Glama
AbdelStark
by AbdelStark

decode_invoice

Decode BOLT11 Lightning invoices to extract payment details and verify transaction information for Bitcoin network interactions.

Instructions

Decode a Lightning invoice

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
invoiceYesBOLT11 Lightning invoice

Implementation Reference

  • The primary MCP tool handler for 'decode_invoice'. Validates the input args for a required 'invoice' string, delegates decoding to BitcoinService.decodeInvoice, formats the result into MCP TextContent response, and handles errors appropriately.
    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"
        );
      }
    }
  • Registration of the 'decode_invoice' tool in the ListToolsRequestHandler. Defines the tool name, description, and input schema requiring a '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,
  • Dispatching logic in the CallToolRequestHandler switch statement that routes 'decode_invoice' calls to the handleDecodeInvoice function with BitcoinService instance.
    case "decode_invoice": {
      return handleDecodeInvoice(this.bitcoinService, args);
    }
  • BitcoinService.decodeInvoice method: Checks if LNBitsClient is configured, then delegates the actual BOLT11 decoding to LNBitsClient.toHumanFriendlyInvoice, with error handling and logging.
    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
        );
      }
    }
  • LNBitsClient helper methods for decoding BOLT11 invoices. 'toHumanFriendlyInvoice' uses the 'bolt11-decoder' library to parse the invoice string, then 'humanFriendlyInvoice' extracts and formats key fields like network, amount, description, expiry, and status into HumanFriendlyInvoice.
    humanFriendlyInvoice(decoded: DecodedInvoice): HumanFriendlyInvoice {
      const network = decoded.prefix.startsWith("lnbc") ? "mainnet" : "testnet";
      const descriptionTag = decoded.tags.find(
        (t) => t.tagName === "description"
      );
      const description = descriptionTag
        ? String(descriptionTag.data)
        : "No description provided";
      return {
        network: network,
        amount: decoded.satoshis,
        description: description,
        expiryDate: new Date(decoded.timestamp * 1000).toLocaleString(),
        status: "VALID",
      };
    }
    
    toHumanFriendlyInvoice(bolt11Invoice: string): HumanFriendlyInvoice {
      const decoded = bolt11.decode(bolt11Invoice) as DecodedInvoice;
      return this.humanFriendlyInvoice(decoded);
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the action 'decode' but doesn't explain what decoding entails (e.g., extracting payment details, checking validity, or returning structured data). For a tool with zero annotation coverage, this leaves significant gaps in understanding its behavior and output.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero waste. It's front-loaded with the core action and resource, making it easy to parse quickly. No unnecessary words or redundant information are included.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the lack of annotations and output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., decoded fields like amount, timestamp, or destination) or potential errors (e.g., invalid invoice format). For a decoding tool with no structured output documentation, this leaves the agent guessing about results.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with the parameter 'invoice' documented as a 'BOLT11 Lightning invoice'. The description doesn't add any meaning beyond this, such as format examples or validation rules. Since the schema already provides adequate coverage, the baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'decode' and the resource 'Lightning invoice', making the purpose immediately understandable. It doesn't differentiate from siblings like 'decode_tx' or 'pay_invoice', but the core action is specific enough to understand what the tool does.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'decode_tx' or 'validate_address'. It doesn't mention prerequisites, such as needing a valid BOLT11 invoice, or clarify that this is for decoding rather than processing payments (which 'pay_invoice' handles).

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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