get_single_transaction
Retrieve detailed information about a specific transaction from LunchMoney using its unique ID, including amount, date, and category data.
Instructions
Get details of a specific transaction
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| input | Yes |
Implementation Reference
- src/tools/transactions.ts:138-179 (handler)Handler function that retrieves a single transaction by ID from the LunchMoney API, handles optional debit_as_negative parameter, and returns the transaction as JSON text.const { baseUrl, lunchmoneyApiToken } = getConfig(); const params = new URLSearchParams(); if (input.debit_as_negative !== undefined) { params.append( "debit_as_negative", input.debit_as_negative.toString() ); } const url = params.toString() ? `${baseUrl}/transactions/${input.transaction_id}?${params}` : `${baseUrl}/transactions/${input.transaction_id}`; const response = await fetch(url, { headers: { Authorization: `Bearer ${lunchmoneyApiToken}`, }, }); if (!response.ok) { return { content: [ { type: "text", text: `Failed to get transaction: ${response.statusText}`, }, ], }; } const transaction: Transaction = await response.json(); return { content: [ { type: "text", text: JSON.stringify(transaction), }, ], }; }
- src/tools/transactions.ts:126-136 (schema)Input schema using Zod for validating transaction_id (required number) and optional debit_as_negative (boolean). Defines the tool's input parameters.{ input: z.object({ transaction_id: z .number() .describe("ID of the transaction to retrieve"), debit_as_negative: z .boolean() .optional() .describe("Pass true to return debit amounts as negative"), }), },
- src/tools/transactions.ts:123-180 (registration)Registration of the 'get_single_transaction' tool on the MCP server within the registerTransactionTools function, including name, description, schema, and handler.server.tool( "get_single_transaction", "Get details of a specific transaction", { input: z.object({ transaction_id: z .number() .describe("ID of the transaction to retrieve"), debit_as_negative: z .boolean() .optional() .describe("Pass true to return debit amounts as negative"), }), }, async ({ input }) => { const { baseUrl, lunchmoneyApiToken } = getConfig(); const params = new URLSearchParams(); if (input.debit_as_negative !== undefined) { params.append( "debit_as_negative", input.debit_as_negative.toString() ); } const url = params.toString() ? `${baseUrl}/transactions/${input.transaction_id}?${params}` : `${baseUrl}/transactions/${input.transaction_id}`; const response = await fetch(url, { headers: { Authorization: `Bearer ${lunchmoneyApiToken}`, }, }); if (!response.ok) { return { content: [ { type: "text", text: `Failed to get transaction: ${response.statusText}`, }, ], }; } const transaction: Transaction = await response.json(); return { content: [ { type: "text", text: JSON.stringify(transaction), }, ], }; } );