Skip to main content
Glama

pay_invoice

Process Bitcoin Lightning payments by submitting invoice details to complete transactions through the NWC MCP Server.

Instructions

Pay a lightning invoice

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
invoiceYesThe lightning invoice to pay
amountNoOptional amount in millisats to pay a zero-amount invoice
metadataNoOptional metadata to include with the payment

Implementation Reference

  • The asynchronous handler function that executes the pay_invoice tool logic: calls client.payInvoice with the input parameters and returns the result as a text content block with JSON stringified response.
    async (params) => { const result = await client.payInvoice({ invoice: params.invoice, amount: params.amount || undefined, metadata: params.metadata || undefined, }); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], }; } );
  • Zod schema for input parameters of the pay_invoice tool: required 'invoice' string, optional 'amount' number in millisats, optional 'metadata' passthrough object.
    { invoice: z.string().describe("The lightning invoice to pay"), amount: z .number() .describe("Optional amount in millisats to pay a zero-amount invoice") .nullish(), metadata: z .object({}) .passthrough() .describe("Optional metadata to include with the payment") .nullish(), },
  • The registerPayInvoiceTool function exports the registration logic, calling server.tool to register the 'pay_invoice' tool with its schema and handler.
    export function registerPayInvoiceTool( server: McpServer, client: nwc.NWCClient ) { server.tool( "pay_invoice", "Pay a lightning invoice", { invoice: z.string().describe("The lightning invoice to pay"), amount: z .number() .describe("Optional amount in millisats to pay a zero-amount invoice") .nullish(), metadata: z .object({}) .passthrough() .describe("Optional metadata to include with the payment") .nullish(), }, async (params) => { const result = await client.payInvoice({ invoice: params.invoice, amount: params.amount || undefined, metadata: params.metadata || undefined, }); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], }; } ); }
  • Invocation of registerPayInvoiceTool within createMCPServer to register the pay_invoice tool on the MCP server instance.
    registerPayInvoiceTool(server, client);
  • src/mcp_server.ts:7-7 (registration)
    Import of the registerPayInvoiceTool function from the pay_invoice module.
    import { registerPayInvoiceTool } from "./tools/pay_invoice.js";

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/nwc-mcp-server'

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