listCategories
Retrieve paginated product categories from the Omnisend catalog to manage and organize e-commerce inventory.
Instructions
Retrieve a list of product categories from the Omnisend catalog with pagination support. The response includes pagination information (next/previous cursor, limit, offset).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/categories/index.ts:18-42 (handler)The handler function for the "listCategories" MCP tool. It calls the underlying API function, filters the categories using filterCategoryFields, formats the response as JSON, and handles errors by returning error text content.async (args) => { try { const response = await listCategories(args); // Filter categories data to include only defined fields const filteredCategories = response.categories.map(filterCategoryFields); return { content: [ { type: "text", text: JSON.stringify({ categories: filteredCategories, paging: response.paging }, null, 2) } ] }; } catch (error) { if (error instanceof Error) { return { content: [{ type: "text", text: `Error: ${error.message}` }] }; } return { content: [{ type: "text", text: "An unknown error occurred" }] }; } }
- src/tools/categories/index.ts:10-17 (schema)The JSON schema defining the input parameters for the listCategories tool: optional limit and offset for pagination.{ additionalProperties: false, properties: { limit: { description: "Maximum number of categories to return", type: "number" }, offset: { description: "Skip first N results", type: "number" } }, type: "object" },
- src/tools/categories/index.ts:7-43 (registration)The registration of the "listCategories" tool using McpServer.tool(), including name, description, input schema, and handler function.server.tool( "listCategories", "Retrieve a list of product categories from the Omnisend catalog with pagination support. The response includes pagination information (next/previous cursor, limit, offset).", { additionalProperties: false, properties: { limit: { description: "Maximum number of categories to return", type: "number" }, offset: { description: "Skip first N results", type: "number" } }, type: "object" }, async (args) => { try { const response = await listCategories(args); // Filter categories data to include only defined fields const filteredCategories = response.categories.map(filterCategoryFields); return { content: [ { type: "text", text: JSON.stringify({ categories: filteredCategories, paging: response.paging }, null, 2) } ] }; } catch (error) { if (error instanceof Error) { return { content: [{ type: "text", text: `Error: ${error.message}` }] }; } return { content: [{ type: "text", text: "An unknown error occurred" }] }; } } );
- Helper function that performs the actual API call to Omnisend's /product-categories endpoint, used by the tool handler.export const listCategories = async (params: ListCategoriesParams = {}): Promise<CategoriesResponse> => { try { const response = await omnisendApi.get<CategoriesResponse>('/product-categories', { params }); return response.data; } catch (error) { if (error instanceof Error) { throw new Error(`Error getting categories list: ${error.message}`); } else { throw new Error('Unknown error occurred when getting categories list'); } } };