createCategory
Add new product categories to the Omnisend catalog with details like title, description, image, and URL for organized product management.
Instructions
Create a new product category in the Omnisend catalog. Category data can include title, description, image, and URL.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/categories/index.ts:62-82 (handler)The handler function for the createCategory MCP tool. It invokes the underlying API createCategory function, applies field filtering, formats the response as JSON text content, and handles errors appropriately.async (args) => { try { const response = await createCategory(args.categoryData); // Filter category data to include only defined fields const filteredCategory = filterCategoryFields(response); return { content: [ { type: "text", text: JSON.stringify(filteredCategory, 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:49-61 (schema)Input schema (JSON Schema) for the createCategory tool, specifying that categoryData is a required object with additional properties allowed.{ additionalProperties: false, properties: { categoryData: { additionalProperties: true, description: "Product category data", properties: {}, type: "object" } }, required: ["categoryData"], type: "object" },
- src/tools/categories/index.ts:46-84 (registration)MCP tool registration call using server.tool() for the createCategory tool, including name, description, schema, and handler.server.tool( "createCategory", "Create a new product category in the Omnisend catalog. Category data can include title, description, image, and URL.", { additionalProperties: false, properties: { categoryData: { additionalProperties: true, description: "Product category data", properties: {}, type: "object" } }, required: ["categoryData"], type: "object" }, async (args) => { try { const response = await createCategory(args.categoryData); // Filter category data to include only defined fields const filteredCategory = filterCategoryFields(response); return { content: [ { type: "text", text: JSON.stringify(filteredCategory, 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 HTTP POST request to the Omnisend API to create a product category.export const createCategory = async (categoryData: Partial<ProductCategory>): Promise<ProductCategory> => { try { const response = await omnisendApi.post<ProductCategory>('/product-categories', categoryData); return response.data; } catch (error) { if (error instanceof Error) { throw new Error(`Error creating category: ${error.message}`); } else { throw new Error('Unknown error occurred when creating category'); } } };
- src/index.ts:33-33 (registration)Invocation of registerCategoriesTools which registers the createCategory tool (among others) on the MCP server.registerCategoriesTools(server);