fakestore_update_cart
Update cart details including user ID, date, and products in a simulated e-commerce environment for testing and development purposes.
Instructions
Update an existing cart (simulation - does not persist)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| date | No | New cart date | |
| id | Yes | Cart ID to update | |
| products | No | New products array | |
| userId | No | New user ID |
Implementation Reference
- src/tools/carts.ts:81-105 (handler)Core handler function that destructures arguments, performs validation using imported validators, constructs update data, and executes a PUT request to the FakeStore API to update the cart.export async function updateCart(args: { id: number; userId?: number; date?: string; products?: CartProduct[]; }): Promise<Cart> { const { id, userId, date, products } = args; validatePositiveInteger(id, 'Cart ID'); const updateData: Record<string, unknown> = {}; if (userId !== undefined) { validatePositiveInteger(userId, 'User ID'); updateData.userId = userId; } if (date !== undefined) { validateISODate(date, 'Date'); updateData.date = date; } if (products !== undefined) { validateNonEmptyArray<CartProduct>(products, 'Products'); updateData.products = products; } return put<Cart>(`/carts/${id}`, updateData); }
- src/tools/carts.ts:202-241 (schema)Input schema definition for the fakestore_update_cart tool, defining properties for id (required), userId, date, products array with productId and quantity.{ name: 'fakestore_update_cart', description: 'Update an existing cart (simulation - does not persist)', inputSchema: { type: 'object', properties: { id: { type: 'number', description: 'Cart ID to update', }, userId: { type: 'number', description: 'New user ID', }, date: { type: 'string', description: 'New cart date', }, products: { type: 'array', description: 'New products array', items: { type: 'object', properties: { productId: { type: 'number', description: 'Product ID', }, quantity: { type: 'number', description: 'Product quantity', }, }, required: ['productId', 'quantity'], }, }, }, required: ['id'], }, },
- src/index.ts:149-159 (registration)Tool dispatch logic in the CallToolRequestSchema handler that matches the tool name and invokes the updateCart function with typed arguments, returning JSON stringified result.if (name === 'fakestore_update_cart') { const result = await updateCart(args as { id: number; userId?: number; date?: string; products?: Array<{ productId: number; quantity: number }>; }); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], }; }
- src/index.ts:40-44 (registration)Registers all tools including fakestore_update_cart (via cartTools) by returning the combined tools list in response to ListTools requests.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [...productTools, ...cartTools, ...userTools], }; });