get_products
Retrieve and filter a list of products from a CS-Cart store using pagination, status, category, or search queries for efficient product management and inventory tracking.
Instructions
Retrieve a list of products from the CS-Cart store
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| category_id | No | Filter by category ID | |
| items_per_page | No | Number of items per page | |
| page | No | Page number for pagination | |
| q | No | Search query for product name | |
| status | No | Product status filter (A=Active, D=Disabled, H=Hidden) |
Implementation Reference
- src/index.js:443-457 (handler)The core handler function that implements the get_products tool logic. It constructs URL query parameters from input arguments and fetches products from the CS-Cart API endpoint `/products`, returning the JSON response as tool content.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:46-73 (schema)Defines the input schema for the get_products tool, specifying optional parameters for pagination, status filtering, category filtering, and search query.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:43-74 (registration)Registers the get_products tool in the ListTools response, including its name, description, and input schema.{ 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)Dispatches calls to the get_products tool handler in the CallToolRequestHandler switch statement.case 'get_products': return await this.getProducts(args);
- src/index.js:424-440 (helper)Shared helper method used by getProducts (and other tools) to make authenticated HTTP requests to the CS-Cart API.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; }