Skip to main content
Glama
getAlby

Alby Bitcoin Payments MCP Server

Official

Pay Invoice

pay_invoice

Pay a Lightning Network invoice by supplying the invoice string. For zero-amount invoices, you can set the amount and attach metadata.

Instructions

Pay a lightning invoice

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
invoiceYesThe lightning invoice to pay
amount_in_satsNo
metadataNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
preimageYesPayment preimage
fees_paid_in_satsNoFees paid in sats

Implementation Reference

  • Main handler function `registerPayInvoiceTool` that registers and implements the 'pay_invoice' tool. It wraps `client.payInvoice()`, converts sats to millisats for NWC, converts millisats back to sats in response, and returns structured content with preimage and fees_paid_in_sats.
    import { nwc } from "@getalby/sdk";
    import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
    import { z } from "zod";
    
    export function registerPayInvoiceTool(
      server: McpServer,
      client: nwc.NWCClient
    ) {
      server.registerTool(
        "pay_invoice",
        {
          title: "Pay Invoice",
          description: "Pay a lightning invoice",
          inputSchema: {
            invoice: z.string().describe("The lightning invoice to pay"),
            amount_in_sats: z
              .number()
              .describe(
                "Optional amount in sats, only provide if paying a zero-amount invoice"
              )
              .nullish(),
            metadata: z
              .object({})
              .passthrough()
              .describe("Optional metadata to include with the payment")
              .nullish(),
          },
          outputSchema: {
            preimage: z.string().describe("Payment preimage"),
            fees_paid_in_sats: z.number().nullish().describe("Fees paid in sats"), // TODO: remove nullish once Primal supports it
          },
        },
        async (params) => {
          const { fees_paid, preimage, ...result } = await client.payInvoice({
            invoice: params.invoice,
            amount: params.amount_in_sats
              ? params.amount_in_sats * 1000
              : undefined, // Convert sats to millisats for NWC
            metadata: params.metadata || undefined,
          });
    
          // Convert millisats back to sats in the response
          const convertedResult = {
            ...result,
            preimage: preimage || "", // TODO: once Primal supports preimage, remove this
            fees_paid_in_sats:
              typeof fees_paid === "number"
                ? Math.ceil(fees_paid / 1000) // Round up fees when converting millisats to sats
                : undefined,
          };
    
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify(convertedResult, null, 2),
              },
            ],
            structuredContent: convertedResult,
          };
        }
      );
    }
  • Registration of the 'pay_invoice' tool on the MCP server, including input schema (invoice, amount_in_sats, metadata) and output schema (preimage, fees_paid_in_sats).
    server.registerTool(
      "pay_invoice",
      {
        title: "Pay Invoice",
        description: "Pay a lightning invoice",
        inputSchema: {
          invoice: z.string().describe("The lightning invoice to pay"),
          amount_in_sats: z
            .number()
            .describe(
              "Optional amount in sats, only provide if paying a zero-amount invoice"
            )
            .nullish(),
          metadata: z
            .object({})
            .passthrough()
            .describe("Optional metadata to include with the payment")
            .nullish(),
        },
        outputSchema: {
          preimage: z.string().describe("Payment preimage"),
          fees_paid_in_sats: z.number().nullish().describe("Fees paid in sats"), // TODO: remove nullish once Primal supports it
        },
      },
  • src/mcp_server.ts:7-7 (registration)
    Import of `registerPayInvoiceTool` from the pay_invoice module.
    import { registerPayInvoiceTool } from "./tools/nwc/pay_invoice.js";
  • Registration call: `registerPayInvoiceTool(server, client)` inside `createMCPServer`.
    registerPayInvoiceTool(server, client);
Behavior2/5

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

With no annotations, the description only says 'pay', implying a mutation but failing to disclose side effects like balance deduction, failure modes, or irreversible nature.

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

Conciseness3/5

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

The description is a single sentence with no wasted words, but it is too sparse for the tool's complexity (3 parameters, no annotations), sacrificing completeness for brevity.

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 number of parameters, lack of annotations, and presence of an output schema, the description omits essential context such as success/error behavior, amount handling, and result structure.

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

Parameters1/5

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

The description adds no information about parameters; schema coverage is only 33% (one parameter described), so the tool's behavior on parameters is largely opaque.

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

Purpose5/5

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

The description clearly states the action ('Pay') and the resource ('lightning invoice'), which is specific and distinct from sibling tools like make_invoice or lookup_invoice.

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?

No guidance is provided on when to use this tool versus alternatives (e.g., request_invoice, make_invoice), nor are there any prerequisites or contextual cues.

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/getAlby/mcp'

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