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

fakestore_update_cart

Modify cart details like user ID, date, or products in a simulated e-commerce environment for testing and development purposes.

Instructions

Update an existing cart (simulation - does not persist)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesCart ID to update
userIdNoNew user ID
dateNoNew cart date
productsNoNew products array

Implementation Reference

  • Core handler function that validates the input arguments and performs the PUT request to update the cart on the FakeStore API.
    export async function updateCart(args: {
      id: number;
      userId?: number;
      date?: string;
      products?: CartProduct[];
    }): Promise<Cart> {
      const { id, userId, date, products } = args;
      validatePositiveInteger(id, 'Cart ID');
    
      const updateData: Record<string, unknown> = {};
      if (userId !== undefined) {
        validatePositiveInteger(userId, 'User ID');
        updateData.userId = userId;
      }
      if (date !== undefined) {
        validateISODate(date, 'Date');
        updateData.date = date;
      }
      if (products !== undefined) {
        validateNonEmptyArray<CartProduct>(products, 'Products');
        updateData.products = products;
      }
    
      return put<Cart>(`/carts/${id}`, updateData);
    }
  • Top-level dispatch handler in the MCP server that matches the tool name and invokes the updateCart function with typed arguments, returning the JSON stringified result.
    if (name === 'fakestore_update_cart') {
      const result = await updateCart(args as {
        id: number;
        userId?: number;
        date?: string;
        products?: Array<{ productId: number; quantity: number }>;
      });
      return {
        content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
      };
    }
  • Tool schema definition including name, description, and inputSchema for validation in the MCP tool list.
    {
      name: 'fakestore_update_cart',
      description: 'Update an existing cart (simulation - does not persist)',
      inputSchema: {
        type: 'object',
        properties: {
          id: {
            type: 'number',
            description: 'Cart ID to update',
          },
          userId: {
            type: 'number',
            description: 'New user ID',
          },
          date: {
            type: 'string',
            description: 'New cart date',
          },
          products: {
            type: 'array',
            description: 'New products array',
            items: {
              type: 'object',
              properties: {
                productId: {
                  type: 'number',
                  description: 'Product ID',
                },
                quantity: {
                  type: 'number',
                  description: 'Product quantity',
                },
              },
              required: ['productId', 'quantity'],
            },
          },
        },
        required: ['id'],
      },
    },
  • src/index.ts:40-44 (registration)
    Registration of all tools including cartTools (which contains fakestore_update_cart) in the MCP listTools handler.
    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