Skip to main content
Glama

fakestore_add_cart

Simulate adding a shopping cart with user ID, date, and products for testing e-commerce workflows in development environments.

Instructions

Add a new cart (simulation - does not persist)

Input Schema

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

Implementation Reference

  • Handler function that implements the core logic for adding a new cart: validates inputs, checks products, and simulates POST to /carts endpoint.
    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 the fakestore_add_cart tool, defining parameters userId, date, and products array with validation.
    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)
    Registration in the main CallToolRequestSchema handler: dispatches 'fakestore_add_cart' calls to the addCart function.
    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:40-42 (registration)
    Tool list registration: includes cartTools (containing fakestore_add_cart schema) in the list of available tools.
    server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [...productTools, ...cartTools, ...userTools],

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