Skip to main content
Glama
pashaydev

Terminal.shop MCP Server

by pashaydev

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
NameRequiredDescriptionDefault
productVariantIDYes
quantityYes

Implementation Reference

  • 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, }; } },
  • 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, }; } }, );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/pashaydev/terminal.shop.mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server