add_item
Add products to a shopping cart using public key identification. Specify cart ID and item details to manage your order.
Instructions
Add an item to an existing shopping cart. Uses W3SHIP_PUBLIC_KEY as cartId if not provided.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cartId | Yes | Public key ID of the cart. Optional if W3SHIP_PUBLIC_KEY is set. | |
| item | Yes |
Implementation Reference
- src/index.ts:440-455 (handler)The handler logic for the 'add_item' tool. It retrieves the cart from valkeyService, adds the item to the cart's item list, and saves the updated cart back.
case 'add_item': { const cartId = (args?.cartId as string) || CONFIGURED_KEY; if (!cartId) { return { content: [{ type: 'text', text: 'Error: No cart ID. Set W3SHIP_PUBLIC_KEY or provide a cartId.' }], isError: true }; } const itemArg = args?.item as any; const cart = await valkeyService.getCart(cartId); if (!cart) { return { content: [{ type: 'text', text: `Error: Cart not found: ${cartId}` }], isError: true }; } const cartItem = { id: Math.random().toString(36).substring(7), ...itemArg }; cart.cartItem = cart.cartItem || []; cart.cartItem.push(cartItem); await valkeyService.saveCart(cart); return { content: [{ type: 'text', text: `Item added successfully to cart ${cartId}` }] }; } - src/index.ts:92-122 (schema)The input schema definition for the 'add_item' tool, defining the required cartId and item structure.
name: 'add_item', description: 'Add an item to an existing shopping cart. Uses W3SHIP_PUBLIC_KEY as cartId if not provided.', inputSchema: { type: 'object', properties: { cartId: { type: 'string', description: 'Public key ID of the cart. Optional if W3SHIP_PUBLIC_KEY is set.' }, item: { type: 'object', properties: { productOffering: { type: 'object', properties: { id: { type: 'string' }, name: { type: 'string' }, }, required: ['id'], }, quantity: { type: 'object', properties: { amount: { type: 'number' }, }, required: ['amount'], }, }, required: ['productOffering'], }, }, required: ['cartId', 'item'], }, },