get_products
Retrieve product listings from CS-Cart stores with pagination, filtering by status, category, or search query to manage inventory and display items.
Instructions
Retrieve a list of products from the CS-Cart store
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page | No | Page number for pagination | |
| items_per_page | No | Number of items per page | |
| status | No | Product status filter (A=Active, D=Disabled, H=Hidden) | |
| category_id | No | Filter by category ID | |
| q | No | Search query for product name |
Implementation Reference
- src/index.js:443-457 (handler)The handler function that executes the get_products tool. It constructs URL query parameters based on input arguments and makes a GET request to the CS-Cart /products API endpoint using the shared makeRequest helper.async getProducts(args) { const params = new URLSearchParams(); if (args.page) params.append('page', args.page.toString()); if (args.items_per_page) params.append('items_per_page', args.items_per_page.toString()); if (args.status) params.append('status', args.status); if (args.category_id) params.append('cid', args.category_id.toString()); if (args.q) params.append('q', args.q); const queryString = params.toString(); const endpoint = `/products${queryString ? `?${queryString}` : ''}`; const result = await this.makeRequest('GET', endpoint); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] }; }
- src/index.js:44-74 (registration)Registration of the get_products tool in the ListToolsRequestHandler, including its metadata and input schema definition.name: 'get_products', description: 'Retrieve a list of products from the CS-Cart store', inputSchema: { type: 'object', properties: { page: { type: 'number', description: 'Page number for pagination', default: 1, }, items_per_page: { type: 'number', description: 'Number of items per page', default: 10, }, status: { type: 'string', description: 'Product status filter (A=Active, D=Disabled, H=Hidden)', enum: ['A', 'D', 'H'], }, category_id: { type: 'number', description: 'Filter by category ID', }, q: { type: 'string', description: 'Search query for product name', }, }, }, },
- src/index.js:390-391 (registration)Dispatch/registration logic in the CallToolRequestHandler switch statement that routes calls to the getProducts handler.case 'get_products': return await this.getProducts(args);
- src/index.js:46-73 (schema)Input schema definition for the get_products tool, specifying parameters for pagination, filtering, and search.inputSchema: { type: 'object', properties: { page: { type: 'number', description: 'Page number for pagination', default: 1, }, items_per_page: { type: 'number', description: 'Number of items per page', default: 10, }, status: { type: 'string', description: 'Product status filter (A=Active, D=Disabled, H=Hidden)', enum: ['A', 'D', 'H'], }, category_id: { type: 'number', description: 'Filter by category ID', }, q: { type: 'string', description: 'Search query for product name', }, }, },
- src/index.js:424-440 (helper)Shared helper method used by getProducts (and other tools) to make authenticated API requests to the CS-Cart server.async makeRequest(method, endpoint, data = null) { const config = { method, url: `${process.env.CSCART_API_URL}${endpoint}`, headers: { 'Content-Type': 'application/json', 'Authorization': `Basic ${Buffer.from(`${process.env.CSCART_API_EMAIL}:${process.env.CSCART_API_KEY}`).toString('base64')}`, }, }; if (data) { config.data = data; } const response = await axios(config); return response.data; }