Skip to main content
Glama
getAlby

Alby Bitcoin Payments MCP Server

Official

Pay Invoice

pay_invoice

Pay Lightning Network invoices to send Bitcoin payments instantly using the Alby Bitcoin Payments MCP Server.

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

  • The execution handler for the 'pay_invoice' tool. It calls client.payInvoice with the provided invoice, optional amount and metadata, processes the result (converting millisats to sats), and returns formatted content.
    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,
      };
    }
  • Input schema (invoice: string, amount_in_sats: number optional, metadata: object optional) and output schema (preimage: string, fees_paid_in_sats: number optional) using Zod.
    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
    },
  • The registerPayInvoiceTool function that registers the 'pay_invoice' tool on the MCP server using server.registerTool, including title, description, schema, and handler.
    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,
          };
        }
      );
    }
  • Call to registerPayInvoiceTool(server, client) within the createMCPServer function, which registers all tools on the server.
    registerPayInvoiceTool(server, client);

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