Skip to main content
Glama
akutishevsky

LunchMoney MCP Server

get_all_categories

Retrieve a comprehensive list of all financial categories from your LunchMoney account, available in flattened alphabetical order or nested hierarchical format for better organization.

Instructions

Get a flattened list of all categories in alphabetical order associated with the user's account.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputYes

Implementation Reference

  • The handler function for the get_all_categories tool. It fetches categories from the Lunchmoney API endpoint `/categories` with optional format parameter, handles errors, and returns JSON stringified categories.
    async ({ input }) => {
        const format = input.format || "flattened";
        const { baseUrl, lunchmoneyApiToken } = getConfig();
        const response = await fetch(`${baseUrl}/categories?format=${format}`, {
            headers: {
                Authorization: `Bearer ${lunchmoneyApiToken}`,
            },
        });
    
        if (!response.ok) {
            return {
                content: [
                    {
                        type: "text",
                        text: `Failed to get all categories: ${response.statusText}`,
                    },
                ],
            };
        }
    
        const categories: Category[] = await response.json();
        
        return {
            content: [
                {
                    type: "text",
                    text: JSON.stringify(categories),
                },
            ],
        };
    }
  • The input schema for the get_all_categories tool, defining an optional 'format' parameter using Zod.
    input: z.object({
        format: z
            .string()
            .optional()
            .describe(
                "Can either flattened or nested. If flattened, returns a singular array of categories, ordered alphabetically. If nested, returns top-level categories (either category groups or categories not part of a category group) in an array. Subcategories are nested within the category group under the property children."
            ),
    }),
  • The registration of the get_all_categories tool within the registerCategoryTools function using server.tool().
    server.tool(
        "get_all_categories",
        "Get a flattened list of all categories in alphabetical order associated with the user's account.",
        {
            input: z.object({
                format: z
                    .string()
                    .optional()
                    .describe(
                        "Can either flattened or nested. If flattened, returns a singular array of categories, ordered alphabetically. If nested, returns top-level categories (either category groups or categories not part of a category group) in an array. Subcategories are nested within the category group under the property children."
                    ),
            }),
        },
        async ({ input }) => {
            const format = input.format || "flattened";
            const { baseUrl, lunchmoneyApiToken } = getConfig();
            const response = await fetch(`${baseUrl}/categories?format=${format}`, {
                headers: {
                    Authorization: `Bearer ${lunchmoneyApiToken}`,
                },
            });
    
            if (!response.ok) {
                return {
                    content: [
                        {
                            type: "text",
                            text: `Failed to get all categories: ${response.statusText}`,
                        },
                    ],
                };
            }
    
            const categories: Category[] = await response.json();
            
            return {
                content: [
                    {
                        type: "text",
                        text: JSON.stringify(categories),
                    },
                ],
            };
        }
    );

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