fakestore_get_carts
Retrieve shopping carts from the Fake Store API with options to limit results and sort by date for e-commerce testing and data management.
Instructions
Get all carts from the store. Optionally limit results and sort.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Limit the number of carts returned | |
| sort | No | Sort carts (asc or desc) |
Implementation Reference
- src/tools/carts.ts:12-27 (handler)Core handler function that fetches all carts from the FakeStore API endpoint '/carts' with optional limit and sort parameters, including input validation.export async function getAllCarts(args: { limit?: number; sort?: SortOrder }): Promise<Cart[]> { const { limit, sort } = args; if (limit !== undefined) { validateLimit(limit); } if (sort !== undefined) { validateSortOrder(sort); } const params: Record<string, unknown> = {}; if (limit) params.limit = limit; if (sort) params.sort = sort; return get<Cart[]>('/carts', params); }
- src/tools/carts.ts:121-137 (schema)Input schema definition for the fakestore_get_carts tool, specifying optional limit (number) and sort (enum: 'asc'|'desc') parameters.name: 'fakestore_get_carts', description: 'Get all carts from the store. Optionally limit results and sort.', inputSchema: { type: 'object', properties: { limit: { type: 'number', description: 'Limit the number of carts returned', }, sort: { type: 'string', enum: ['asc', 'desc'], description: 'Sort carts (asc or desc)', }, }, }, },
- src/index.ts:117-122 (registration)Tool dispatching logic in the MCP CallToolRequest handler that maps 'fakestore_get_carts' to the getAllCarts function and formats the JSON response.if (name === 'fakestore_get_carts') { const result = await getAllCarts(args as { limit?: number; sort?: 'asc' | 'desc' }); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], }; }
- src/index.ts:40-44 (registration)Registration of available tools list handler, which includes cartTools containing the fakestore_get_carts schema.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [...productTools, ...cartTools, ...userTools], }; });
- src/index.ts:19-19 (registration)Import statement bringing in cartTools (schemas) and getAllCarts (handler) from carts module.import { cartTools, getAllCarts, getCartById, getUserCarts, addCart, updateCart, deleteCart } from './tools/carts.js';