fakestore_add_product
Add new products to a simulated e-commerce store for testing and demonstration purposes. Specify product title, price, description, image URL, and category to create temporary product entries.
Instructions
Add a new product to the store (simulation - does not persist)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| category | Yes | Product category | |
| description | Yes | Product description | |
| image | Yes | Product image URL | |
| price | Yes | Product price | |
| title | Yes | Product title |
Implementation Reference
- src/tools/products.ts:58-90 (handler)Core handler function that validates the input parameters and performs a POST request to add a new product to the FakeStore API.* Add a new product (simulation - returns the product with an ID) */ 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:187-215 (schema)Tool schema definition including input schema with properties, descriptions, and required fields for fakestore_add_product.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)Registration and dispatch logic in the main CallToolRequest handler that matches the tool name and invokes the addProduct handler.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) }], }; }
- src/index.ts:40-44 (registration)Registration of available tools list handler, which includes the fakestore_add_product tool from productTools.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [...productTools, ...cartTools, ...userTools], }; });