Skip to main content
Glama

list-categories

Retrieve and filter all categories stored in the PI API MCP Server. Use criteria like field names, operators, and pagination to refine and organize results effectively.

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 handler function for the 'list-categories' tool. It constructs query parameters for pagination and filters (using parseFilters helper), performs an authenticated GET request to /categories, and returns the response as formatted text or error.
    }, 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)}` }] }; } });
  • Zod schema defining the input parameters for the 'list-categories' tool: optional filter string, page (default 1), pageSize (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")
  • build/index.js:597-626 (registration)
    The server.tool registration call that defines and registers the 'list-categories' tool, including description, input schema, and inline 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)}` }] }; } });
  • Helper function parseFilters used by the handler to convert the filter string (e.g., 'description(like)=dashboard') into query parameters for the API request.
    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; }

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