add-to-cart
Add products to your shopping cart on Terminal.shop by specifying the product variant ID and desired quantity, enabling streamlined order management through API integration.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| productVariantID | Yes | ||
| quantity | Yes |
Implementation Reference
- server.js:571-615 (handler)The asynchronous handler function that implements the core logic of the 'add-to-cart' tool. It sends a PUT request to the Terminal.shop API to add the specified product variant ID and quantity to the user's shopping cart, then returns a formatted summary of the updated cart.try { const response = await terminalApi.put("/cart/item", { productVariantID, quantity, }); const cart = response.data.data; let formattedText = "# Item Added to Cart\n\n"; formattedText += `Successfully added item to your cart.\n\n`; formattedText += "## Updated Cart\n"; formattedText += `Items: ${cart.items.length}\n`; formattedText += `Subtotal: $${cart.subtotal / 100}\n`; if (cart.amount && cart.amount.shipping) { formattedText += `Shipping: $${cart.amount.shipping / 100}\n`; if (cart.amount.total) { formattedText += `Total: $${cart.amount.total / 100}\n`; } else { formattedText += `Total: $${(cart.amount.subtotal + cart.amount.shipping) / 100}\n`; } } return { content: [ { type: "text", text: formattedText, }, ], }; } catch (error) { console.error("Error adding item to cart:", error); return { content: [ { type: "text", text: `Error adding item to cart: ${error.message}`, }, ], isError: true, }; } },
- server.js:567-570 (schema)Zod schema defining the input parameters for the 'add-to-cart' tool: productVariantID as a required string and quantity as a positive integer.productVariantID: z.string(), quantity: z.number().int().positive(), }, async ({ productVariantID, quantity }) => {
- server.js:565-616 (registration)The server.tool() call that registers the 'add-to-cart' tool on the MCP server, specifying its name, input schema, and inline handler function."add-to-cart", { productVariantID: z.string(), quantity: z.number().int().positive(), }, async ({ productVariantID, quantity }) => { try { const response = await terminalApi.put("/cart/item", { productVariantID, quantity, }); const cart = response.data.data; let formattedText = "# Item Added to Cart\n\n"; formattedText += `Successfully added item to your cart.\n\n`; formattedText += "## Updated Cart\n"; formattedText += `Items: ${cart.items.length}\n`; formattedText += `Subtotal: $${cart.subtotal / 100}\n`; if (cart.amount && cart.amount.shipping) { formattedText += `Shipping: $${cart.amount.shipping / 100}\n`; if (cart.amount.total) { formattedText += `Total: $${cart.amount.total / 100}\n`; } else { formattedText += `Total: $${(cart.amount.subtotal + cart.amount.shipping) / 100}\n`; } } return { content: [ { type: "text", text: formattedText, }, ], }; } catch (error) { console.error("Error adding item to cart:", error); return { content: [ { type: "text", text: `Error adding item to cart: ${error.message}`, }, ], isError: true, }; } }, );