fakestore_get_products
Retrieve product listings from a mock e-commerce store with options to limit results and sort by price for testing or demonstration purposes.
Instructions
Get all products from the store. Optionally limit results and sort by price.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Limit the number of products returned | |
| sort | No | Sort products by price (asc or desc) |
Implementation Reference
- src/tools/products.ts:12-27 (handler)Core handler function that fetches all products with optional limit and sort parameters using the FakeStore API.export async function getAllProducts(args: { limit?: number; sort?: SortOrder }): Promise<Product[]> { 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<Product[]>('/products', params); }
- src/tools/products.ts:132-149 (schema)Tool schema definition including name, description, and input schema for validation.{ name: 'fakestore_get_products', description: 'Get all products from the store. Optionally limit results and sort by price.', inputSchema: { type: 'object', properties: { limit: { type: 'number', description: 'Limit the number of products returned', }, sort: { type: 'string', enum: ['asc', 'desc'], description: 'Sort products by price (asc or desc)', }, }, }, },
- src/index.ts:54-59 (registration)MCP server dispatch registration that executes the tool handler and formats the response.if (name === 'fakestore_get_products') { const result = await getAllProducts(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 the list tools handler that advertises the fakestore_get_products tool.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [...productTools, ...cartTools, ...userTools], }; });