get_categories
Retrieve a list of product categories from CS-Cart stores. Filter by parent category ID or status (Active, Disabled, Hidden) to organize and manage e-commerce product structures effectively.
Instructions
Get list of product categories
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| parent_id | No | Parent category ID (0 for root categories) | |
| status | No | Category status filter (A=Active, D=Disabled, H=Hidden) |
Implementation Reference
- src/index.js:487-498 (handler)The core handler function for the 'get_categories' tool. It constructs query parameters from input args (parent_id and status), makes a GET request to the CS-Cart /categories endpoint via the makeRequest helper, and returns the JSON response formatted as text content.async getCategories(args) { const params = new URLSearchParams(); if (args.parent_id !== undefined) params.append('parent_id', args.parent_id.toString()); if (args.status) params.append('status', args.status); const queryString = params.toString(); const endpoint = `/categories${queryString ? `?${queryString}` : ''}`; const result = await this.makeRequest('GET', endpoint); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] }; }
- src/index.js:228-242 (schema)Input schema definition for the 'get_categories' tool, specifying optional parent_id (number, default 0) and status (string enum ['A','D','H']) properties.inputSchema: { type: 'object', properties: { parent_id: { type: 'number', description: 'Parent category ID (0 for root categories)', default: 0, }, status: { type: 'string', description: 'Category status filter (A=Active, D=Disabled, H=Hidden)', enum: ['A', 'D', 'H'], }, }, },
- src/index.js:225-243 (registration)Registration of the 'get_categories' tool in the ListToolsRequestSchema response, defining its name, description, and input schema.{ name: 'get_categories', description: 'Get list of product categories', inputSchema: { type: 'object', properties: { parent_id: { type: 'number', description: 'Parent category ID (0 for root categories)', default: 0, }, status: { type: 'string', description: 'Category status filter (A=Active, D=Disabled, H=Hidden)', enum: ['A', 'D', 'H'], }, }, }, },
- src/index.js:402-403 (handler)Dispatch case in the CallToolRequestSchema handler that invokes the getCategories method for the 'get_categories' tool.case 'get_categories': return await this.getCategories(args);
- src/index.js:424-440 (helper)Shared helper method used by getCategories (and other tools) to perform 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; }