fakestore_get_user_carts
Retrieve all shopping carts for a specific user from the Fake Store API to manage e-commerce data for testing or learning purposes.
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 userId and fetches the user's carts 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 calls the getUserCarts function and formats the response as MCP content.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:152-164 (schema)Tool schema definition including name, description, and inputSchema for validation.{ 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)Registration of all tools including cartTools (which contains fakestore_get_user_carts) in the MCP server's listTools handler.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [...productTools, ...cartTools, ...userTools], }; });