fakestore_update_cart
Modify cart details like user ID, date, or 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 |
|---|---|---|---|
| id | Yes | Cart ID to update | |
| userId | No | New user ID | |
| date | No | New cart date | |
| products | No | New products array |
Implementation Reference
- src/tools/carts.ts:81-105 (handler)Core handler function that validates the input arguments and performs the PUT request to update the cart on the FakeStore API.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/index.ts:149-159 (handler)Top-level dispatch handler in the MCP server that matches the tool name and invokes the updateCart function with typed arguments, returning the 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/tools/carts.ts:202-241 (schema)Tool schema definition including name, description, and inputSchema for validation in the MCP tool list.{ 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:40-44 (registration)Registration of all tools including cartTools (which contains fakestore_update_cart) in the MCP listTools handler.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [...productTools, ...cartTools, ...userTools], }; });