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
| Name | Required | Description | Default |
|---|---|---|---|
| filter | No | 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 | No | Page number for pagination | |
| pageSize | No | Number of items per page |
Implementation Reference
- build/index.js:601-626 (handler)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)}` }] }; } });
- build/index.js:598-600 (schema)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)}` }] }; } });
- build/index.js:127-142 (helper)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; }