Skip to main content
Glama
akutishevsky

LunchMoney MCP Server

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
NameRequiredDescriptionDefault
inputYes

Implementation Reference

  • 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),
                },
            ],
        };
    }
  • 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"),
        }),
    },
  • 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),
                    },
                ],
            };
        }
    );

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/akutishevsky/lunchmoney-mcp'

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