fakestore_get_carts
Retrieve shopping carts from the Fake Store API with options to limit results and sort them in ascending or descending order.
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, validates input parameters, constructs query params, and calls the API.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:120-137 (schema)Tool schema definition including name, description, and input schema for validation.{ 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:116-122 (registration)Registers and dispatches the fakestore_get_carts tool call to the handler function within the MCP CallToolRequest handler.// Cart tools 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)Registers the tool schemas (including fakestore_get_carts from cartTools) for the ListToolsRequest.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [...productTools, ...cartTools, ...userTools], }; });