Skip to main content
Glama

list-categories

Retrieve a paginated list of categories with support for multiple filters using field, operator, and value combinations.

Instructions

List all categories with filtering support

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filterNoFilter criteria in the format 'fieldName(operator)=value'. Multiple filters can be combined with & (e.g., 'description(like)=dashboard&orgId(eq)=1'). Available operators: eq, ne, gt, lt, ge, le, like, nlike. Use get-filterable-attributes tool to see available fields.
pageNoPage number for pagination
pageSizeNoNumber of items per page

Implementation Reference

  • The async handler function for the 'list-categories' tool. It builds query params with pagination (page, pageSize), optionally parses filter strings via parseFilters(), makes a GET request to /categories, and returns the result.
    }, async ({ filter, page, pageSize }) => {
        try {
            let queryParams = {
                page: page.toString(),
                pageSize: pageSize.toString()
            };
            // Parse and add filter parameters
            if (filter) {
                const filterParams = parseFilters(filter);
                queryParams = { ...queryParams, ...filterParams };
            }
            const categories = await authenticatedRequest("/categories", "GET", null, queryParams);
            return {
                content: [{
                        type: "text",
                        text: `Categories retrieved successfully:\n${JSON.stringify(categories, null, 2)}`
                    }]
            };
        }
        catch (error) {
            return {
                isError: true,
                content: [{ type: "text", text: `Error fetching categories: ${getErrorMessage(error)}` }]
            };
        }
  • build/index.js:597-626 (registration)
    Registration of the 'list-categories' tool on the MCP server using server.tool() with name 'list-categories', description, Zod schema for inputs (filter, page, pageSize), and the handler function.
    server.tool("list-categories", "List all categories with filtering support", {
        filter: z.string().optional().describe("Filter criteria in the format 'fieldName(operator)=value'. Multiple filters can be combined with & (e.g., 'description(like)=dashboard&orgId(eq)=1'). Available operators: eq, ne, gt, lt, ge, le, like, nlike. Use get-filterable-attributes tool to see available fields."),
        page: z.number().optional().default(1).describe("Page number for pagination"),
        pageSize: z.number().optional().default(20).describe("Number of items per page")
    }, async ({ filter, page, pageSize }) => {
        try {
            let queryParams = {
                page: page.toString(),
                pageSize: pageSize.toString()
            };
            // Parse and add filter parameters
            if (filter) {
                const filterParams = parseFilters(filter);
                queryParams = { ...queryParams, ...filterParams };
            }
            const categories = await authenticatedRequest("/categories", "GET", null, queryParams);
            return {
                content: [{
                        type: "text",
                        text: `Categories retrieved successfully:\n${JSON.stringify(categories, null, 2)}`
                    }]
            };
        }
        catch (error) {
            return {
                isError: true,
                content: [{ type: "text", text: `Error fetching categories: ${getErrorMessage(error)}` }]
            };
        }
    });
  • Input schema for the 'list-categories' tool: filter (optional string), page (optional number, default 1), pageSize (optional number, default 20).
    filter: z.string().optional().describe("Filter criteria in the format 'fieldName(operator)=value'. Multiple filters can be combined with & (e.g., 'description(like)=dashboard&orgId(eq)=1'). Available operators: eq, ne, gt, lt, ge, le, like, nlike. Use get-filterable-attributes tool to see available fields."),
    page: z.number().optional().default(1).describe("Page number for pagination"),
    pageSize: z.number().optional().default(20).describe("Number of items per page")
  • The parseFilters() helper function that converts a filter string like 'field(op)=value&field2(op2)=val2' into query parameters.
    function parseFilters(filterString) {
        const queryParams = {};
        if (!filterString)
            return queryParams;
        // Split by & to handle multiple filters
        const filters = filterString.split('&');
        for (const filter of filters) {
            // Match the pattern fieldName(operator)=value
            const match = filter.match(/([a-zA-Z]+)\(([a-zA-Z]+)\)=(.+)/);
            if (match) {
                const [_, field, operator, value] = match;
                queryParams[`${field}(${operator})`] = value;
            }
        }
        return queryParams;
    }
  • The authenticatedRequest() helper that makes HTTP requests with the auth token, adds orgId, handles JSON/binary/text responses.
    async function authenticatedRequest(endpoint, method = "GET", body = null, queryParams = {}) {
        if (!apiUrlSet) {
            throw new Error("API URL not set. Please set the API URL using the set-api-url tool.");
        }
        if (!authToken) {
            throw new Error("Not authenticated. Please authenticate first.");
        }
        // Build URL with query parameters
        let url = `${API_BASE_URL}${endpoint}`;
        // Add orgId if available
        if (orgId !== null) {
            queryParams.orgId = orgId.toString();
        }
        // Add query parameters if any
        if (Object.keys(queryParams).length > 0) {
            const queryString = Object.entries(queryParams)
                .map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
                .join("&");
            url = `${url}?${queryString}`;
        }
        logInfo(`Making ${method} request to ${url}`);
        const headers = {
            "Authorization": `bearer ${authToken}`,
            "Content-Type": "application/json"
        };
        const options = {
            method,
            headers
        };
        if (body !== null && ["POST", "PUT"].includes(method)) {
            options.body = JSON.stringify(body);
            logInfo(`Request body: ${JSON.stringify(body)}`);
        }
        try {
            const response = await fetch(url, options);
            if (!response.ok) {
                const errorText = await response.text();
                logError(`API request failed with status ${response.status}: ${errorText}`);
                throw new Error(`API request failed with status ${response.status}: ${response.statusText}`);
            }
            // Check if the response is JSON or binary
            const contentType = response.headers.get("content-type") || "";
            if (contentType.includes("application/json")) {
                const jsonData = await response.json();
                logInfo(`Received JSON response: ${JSON.stringify(jsonData).substring(0, 200)}...`);
                return jsonData;
            }
            else if (contentType.includes("text/csv")) {
                // For binary/file responses, return a base64 encoded string
                const buffer = await response.arrayBuffer();
                const base64 = Buffer.from(buffer).toString("base64");
                logInfo(`Received binary response of type ${contentType}, length: ${base64.length}`);
                return {
                    contentType,
                    data: base64
                };
            }
            else {
                // Otherwise, return as text
                const text = await response.text();
                logInfo(`Received text response: ${text.substring(0, 200)}...`);
                return text;
            }
        }
        catch (error) {
            logError(`API request error: ${getErrorMessage(error)}`);
            throw error;
        }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden but only states 'list all categories with filtering support'. It does not disclose pagination behavior (though schema has page/pageSize), the format of the result list, or any side effects. Returns are not described.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single concise sentence with no fluff. It front-loads the action and resource. However, it could be slightly expanded to include key behavioral notes without losing conciseness.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The tool has no output schema, no annotations, and 3 parameters. The description is minimal and does not explain return format, pagination behavior, or how filtering affects results. For a list tool, more context (e.g., 'returns paginated list of category objects sorted by...') is needed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the schema already documents all parameters. The description adds value by explicitly mentioning 'filtering support', which hints at the filter parameter. For a complete schema coverage, a baseline of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'list' and the resource 'categories', and mentions filtering support. It distinguishes from siblings like 'get-category' (single item) and 'create-category' (creation). However, it could be more specific about the scope (e.g., 'all categories with optional filtering') to avoid ambiguity.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives such as 'get-category' for a single category or 'list-charts' for a different resource. The description does not mention exclusions or prerequisites.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/mingzilla/pi-api-mcp-server'

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