fakestore_add_product
Add a new product to the Fake Store API for e-commerce demos and testing by providing title, price, description, image URL, and category.
Instructions
Add a new product to the store (simulation - does not persist)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| title | Yes | Product title | |
| price | Yes | Product price | |
| description | Yes | Product description | |
| image | Yes | Product image URL | |
| category | Yes | Product category |
Implementation Reference
- src/tools/products.ts:60-90 (handler)The `addProduct` function that executes the tool logic: validates input parameters and posts a new product to the FakeStore API.export async function addProduct(args: { title: string; price: number; description: string; image: string; category: string; }): Promise<Product> { const { title, price, description, image, category } = args; if (!title || typeof title !== 'string') { throw new Error('Title must be a non-empty string'); } if (typeof price !== 'number' || price <= 0) { throw new Error('Price must be a positive number'); } if (!description || typeof description !== 'string') { throw new Error('Description must be a non-empty string'); } validateUrl(image, 'Image URL'); if (!category || typeof category !== 'string') { throw new Error('Category must be a non-empty string'); } return post<Product>('/products', { title, price, description, image, category, }); }
- src/tools/products.ts:186-215 (schema)The input schema definition for the 'fakestore_add_product' tool, specifying required properties and types.{ name: 'fakestore_add_product', description: 'Add a new product to the store (simulation - does not persist)', inputSchema: { type: 'object', properties: { title: { type: 'string', description: 'Product title', }, price: { type: 'number', description: 'Product price', }, description: { type: 'string', description: 'Product description', }, image: { type: 'string', description: 'Product image URL', }, category: { type: 'string', description: 'Product category', }, }, required: ['title', 'price', 'description', 'image', 'category'], }, },
- src/index.ts:82-93 (registration)Dispatch logic in the main tool handler that matches the tool name and invokes the `addProduct` handler function.if (name === 'fakestore_add_product') { const result = await addProduct(args as { title: string; price: number; description: string; image: string; category: string; }); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], }; }