Skip to main content
Glama
op-enny
by op-enny

fakestore_add_cart

Add a cart with user ID, date, and products to simulate e-commerce transactions for testing and demos.

Instructions

Add a new cart (simulation - does not persist)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
userIdYesUser ID who owns the cart
dateYesCart date in ISO format (e.g., 2024-01-01)
productsYesArray of products in the cart

Implementation Reference

  • The addCart function implements the core logic for the fakestore_add_cart tool: validates inputs (userId, date, products), checks each product's productId and quantity, then posts to the FakeStore API to simulate adding a cart.
    export async function addCart(args: { userId: number; date: string; products: CartProduct[]; }): Promise<Cart> { const { userId, date, products } = args; validatePositiveInteger(userId, 'User ID'); validateISODate(date, 'Date'); validateNonEmptyArray<CartProduct>(products, 'Products'); // Validate each product in the cart products.forEach((product, index) => { if (typeof product.productId !== 'number' || product.productId <= 0) { throw new Error(`Product ${index + 1}: productId must be a positive number`); } if (typeof product.quantity !== 'number' || product.quantity <= 0) { throw new Error(`Product ${index + 1}: quantity must be a positive number`); } }); return post<Cart>('/carts', { userId, date, products, }); }
  • Input schema definition for fakestore_add_cart tool within the cartTools array, specifying required properties: userId (number), date (ISO string), products (array of {productId, quantity}).
    { name: 'fakestore_add_cart', description: 'Add a new cart (simulation - does not persist)', inputSchema: { type: 'object', properties: { userId: { type: 'number', description: 'User ID who owns the cart', }, date: { type: 'string', description: 'Cart date in ISO format (e.g., 2024-01-01)', }, products: { type: 'array', description: 'Array of products in the cart', items: { type: 'object', properties: { productId: { type: 'number', description: 'Product ID', }, quantity: { type: 'number', description: 'Product quantity', }, }, required: ['productId', 'quantity'], }, }, }, required: ['userId', 'date', 'products'], }, },
  • src/index.ts:138-147 (registration)
    MCP server registration: In the CallToolRequestSchema handler, checks if name === 'fakestore_add_cart' and invokes addCart with cast arguments, returning JSON-stringified result.
    if (name === 'fakestore_add_cart') { const result = await addCart(args as { userId: number; date: string; products: Array<{ productId: number; quantity: number }>; }); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], }; }
  • src/index.ts:42-42 (registration)
    Tool list registration: In ListToolsRequestSchema handler, includes cartTools (containing fakestore_add_cart schema) in the returned tools list.
    tools: [...productTools, ...cartTools, ...userTools],
  • src/index.ts:19-19 (registration)
    Imports the addCart handler function and cartTools (with schema) from carts.ts into the main MCP server index.
    import { cartTools, getAllCarts, getCartById, getUserCarts, addCart, updateCart, deleteCart } from './tools/carts.js';

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/op-enny/mcp-server-fakestore'

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