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
| Name | Required | Description | Default |
|---|---|---|---|
| userId | Yes | User ID |
Implementation Reference
- src/tools/carts.ts:41-45 (handler)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}`); }
- src/index.ts:131-136 (handler)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) }], }; }
- src/tools/carts.ts:153-164 (schema)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';