Skip to main content
Glama

fakestore_get_user_carts

Retrieve all shopping carts associated with a specific user ID to manage and analyze user purchase data in e-commerce systems.

Instructions

Get all carts belonging to a specific user

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
userIdYesUser ID

Implementation Reference

  • Core handler function that validates the input userId and retrieves the carts for that user from the FakeStore API endpoint `/carts/user/${userId}`.
    export async function getUserCarts(args: { userId: number }): Promise<Cart[]> { const { userId } = args; validatePositiveInteger(userId, 'User ID'); return get<Cart[]>(`/carts/user/${userId}`); }
  • MCP server dispatch handler that maps the tool name to the getUserCarts function and formats the response.
    if (name === 'fakestore_get_user_carts') { const result = await getUserCarts(args as { userId: number }); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], }; }
  • Tool definition including name, description, and input schema requiring a numeric userId.
    name: 'fakestore_get_user_carts', description: 'Get all carts belonging to a specific user', inputSchema: { type: 'object', properties: { userId: { type: 'number', description: 'User ID', }, }, required: ['userId'], },
  • src/index.ts:40-44 (registration)
    Registers the listTools handler which returns all tool definitions, including fakestore_get_user_carts from cartTools.
    server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [...productTools, ...cartTools, ...userTools], }; });
  • src/index.ts:19-19 (registration)
    Imports the getUserCarts handler function and cartTools definitions from carts.ts for use in the MCP server.
    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