create_product
Add a new product to your subscription catalog. Required fields: name and category. Optionally include description, internal ID, or SKU.
Instructions
Create a product. POST /products. Required: name, category. Optional: description, internalProductId, sku.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Product name (required) | |
| category | Yes | Category (required) | |
| description | No | Description | |
| internalProductId | No | Internal product ID | |
| sku | No | SKU |
Implementation Reference
- Handler function that validates args via Zod schema, then calls productService.createProduct with the parsed data. Returns error result if validation fails.
async function handler(client: Client, args: Record<string, unknown> | undefined) { const parsed = schema.safeParse(args); if (!parsed.success) { return errorResult(parsed.error.errors.map((e) => `${e.path.join(".")}: ${e.message}`).join("; ")); } return handleToolCall(() => productService.createProduct(client, parsed.data)); - Zod schema for input validation: required name and category, optional description, internalProductId, sku.
const schema = z.object({ name: z.string().min(1, "name is required"), category: z.string().min(1, "category is required"), description: z.string().optional(), internalProductId: z.string().optional(), sku: z.string().optional(), }); - MCP tool definition (name: 'create_product', description, inputSchema with properties and required fields).
const definition = { name: "create_product", description: "Create a product. POST /products. Required: name, category. Optional: description, internalProductId, sku.", inputSchema: { type: "object" as const, properties: { name: { type: "string", description: "Product name (required)" }, category: { type: "string", description: "Category (required)" }, description: { type: "string", description: "Description" }, internalProductId: { type: "string", description: "Internal product ID" }, sku: { type: "string", description: "SKU" }, }, required: ["name", "category"], }, }; - src/tools/products/index.ts:16-27 (registration)Product tools registration function includes createProductTool in the list of product tools.
export function registerProductTools(): Tool[] { return [ listProductsTool, getProductTool, createProductTool, updateProductTool, deleteProductTool, updateProductStatusTool, linkExternalProductTool, unlinkExternalProductTool, ]; } - Service function that constructs the payload and calls client.post('/products', payload) to create a product via the API.
export async function createProduct( client: Client, body: CreateProductBody ): Promise<unknown> { const payload = { name: body.name, category: body.category, description: body.description, internalProductId: body.internalProductId, sku: body.sku, effectiveStartDate: body.effectiveStartDate, effectiveEndDate: body.effectiveEndDate, productRatePlan: body.productRatePlan ?? [], }; return client.post<unknown>("/products", payload); }