pay_invoice
Process a Bitcoin Lightning invoice payment via the NWC MCP Server, enabling fast and secure transactions directly within supported platforms.
Instructions
Pay a lightning invoice
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| amount | No | Optional amount in millisats to pay a zero-amount invoice | |
| invoice | Yes | The lightning invoice to pay | |
| metadata | No | Optional metadata to include with the payment |
Implementation Reference
- src/tools/pay_invoice.ts:24-39 (handler)The handler function that executes the pay_invoice tool logic: calls client.payInvoice with invoice, optional amount and metadata, then returns the result as formatted JSON text content.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 input schema for pay_invoice tool parameters: invoice (required string), amount (optional number in millisats), metadata (optional 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 that registers the pay_invoice tool on the MCP server via server.tool(), including name, description, input 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)Top-level call to registerPayInvoiceTool during MCP server initialization.registerPayInvoiceTool(server, client);