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
| Name | Required | Description | Default |
|---|---|---|---|
| invoice | Yes | The lightning invoice to pay | |
| amount | No | Optional amount in millisats to pay a zero-amount invoice | |
| metadata | No | Optional metadata to include with the payment |
Implementation Reference
- src/tools/pay_invoice.ts:24-39 (handler)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), }, ], }; } );
- src/tools/pay_invoice.ts:12-23 (schema)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(), },
- src/tools/pay_invoice.ts:5-40 (registration)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), }, ], }; } ); }
- src/mcp_server.ts:22-22 (registration)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";