store-routing-credentials
Store L402 macaroon and preimage after paying the Lightning invoice to enable automatic authentication for subsequent routing requests.
Instructions
Store L402 payment credentials (macaroon + preimage) after paying a routing invoice. Call this after the user has paid the Lightning invoice returned by a payment_required response. Once stored, all subsequent routing calls (score-venues, get-isochrone, get-directions) will authenticate automatically.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| macaroon | Yes | The macaroon from the payment_required response | |
| preimage | Yes | The payment preimage obtained after paying the invoice |
Implementation Reference
- src/tools/store-credentials.ts:10-30 (handler)Handler function that stores L402 payment credentials (macaroon + preimage) on the RoutingClient instance after a user pays a Lightning invoice.
export async function handleStoreRoutingCredentials( args: { macaroon: string preimage: string }, routingClient: RoutingClient, ) { console.error('Storing L402 routing credentials') routingClient.storeL402Credentials(args.macaroon, args.preimage) return { content: [{ type: 'text' as const, text: JSON.stringify({ success: true, message: 'L402 credentials stored. Subsequent routing calls will authenticate automatically.', }), }], } } - src/tools/store-credentials.ts:45-51 (schema)Input schema using Zod validation: 'macaroon' (base64 string, 1-4096 chars) and 'preimage' (hex string, 1-128 chars), with idempotent annotation.
inputSchema: { macaroon: z.string().min(1).max(4096).regex(/^[A-Za-z0-9+/=]+$/, 'Must be valid base64') .describe('The macaroon from the payment_required response'), preimage: z.string().min(1).max(128).regex(/^[0-9a-fA-F]+$/, 'Must be valid hex') .describe('The payment preimage obtained after paying the invoice'), }, annotations: { readOnlyHint: false, idempotentHint: true }, - src/tools/store-credentials.ts:36-55 (registration)Registers the 'store-routing-credentials' tool with the MCP server, wiring the Zod schema and handler.
export function registerStoreCredentialsTool(server: McpServer, routingClient: RoutingClient): void { server.registerTool( 'store-routing-credentials', { description: 'Store L402 payment credentials (macaroon + preimage) after paying a routing invoice. ' + 'Call this after the user has paid the Lightning invoice returned by a payment_required response. ' + 'Once stored, all subsequent routing calls (score-venues, get-isochrone, get-directions) ' + 'will authenticate automatically.', inputSchema: { macaroon: z.string().min(1).max(4096).regex(/^[A-Za-z0-9+/=]+$/, 'Must be valid base64') .describe('The macaroon from the payment_required response'), preimage: z.string().min(1).max(128).regex(/^[0-9a-fA-F]+$/, 'Must be valid hex') .describe('The payment preimage obtained after paying the invoice'), }, annotations: { readOnlyHint: false, idempotentHint: true }, }, async (args) => handleStoreRoutingCredentials(args, routingClient), ) } - src/index.ts:44-44 (registration)Main entry point where the store-credentials tool is registered via registerStoreCredentialsTool.
registerStoreCredentialsTool(server, routingClient) - src/routing.ts:32-34 (helper)RoutingClient method that delegates to L402State.store() to persist the macaroon and preimage in memory.
storeL402Credentials(macaroon: string, preimage: string): void { this.l402.store(macaroon, preimage) }