fakestore_get_products
Retrieve product listings from a fake store API with options to limit results and sort by price for e-commerce testing and development.
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 implementation of the fakestore_get_products tool logic: validates inputs, constructs API params, and fetches products from /products endpoint.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/index.ts:54-59 (handler)Dispatch handler in the MCP callToolRequestHandler that matches the tool name and invokes the getAllProducts function with parsed arguments.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/tools/products.ts:132-149 (schema)Input schema and metadata definition for the fakestore_get_products tool, used for tool listing and argument 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:40-44 (registration)Registers the fakestore_get_products tool (via productTools) in the MCP server's listTools response.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [...productTools, ...cartTools, ...userTools], }; });