b24_products_sections
Retrieves product catalog sections or categories from Bitrix24. Optionally filter by catalog ID using a webhook URL.
Instructions
Lista las secciones/categorías del catálogo de productos.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| catalog_id | No | ID del catálogo (opcional) | |
| webhook_url | No |
Implementation Reference
- src/tools/catalog-products.js:82-87 (handler)Main handler for the b24_products_sections tool. Calls catalog.section.list Bitrix24 API with optional catalog_id filter, fetching all pages via pagination helper.
export async function productsSections({ catalog_id, webhook_url }) { const client = new Bitrix24Client(resolveWebhook(webhook_url)); const params = catalog_id ? { filter: { CATALOG_ID: catalog_id } } : {}; const sections = await fetchAllPages(client, 'catalog.section.list', params); return { portal: client.portal, total: sections.length, sections }; } - src/tools/catalog-products.js:77-80 (schema)Zod schema defining input parameters: optional catalog_id and optional webhook_url.
export const productsSectionsSchema = z.object({ catalog_id: z.union([z.string(), z.number()]).optional().describe('ID del catálogo (opcional)'), webhook_url: z.string().url().optional(), }); - index.js:279-281 (registration)Registration of the tool on the MCP server with name 'b24_products_sections', description, schema, and wrapped handler.
server.tool('b24_products_sections', 'Lista las secciones/categorías del catálogo de productos.', productsSectionsSchema.shape, wrap(productsSections)); - src/utils/resolve-webhook.js:1-10 (helper)Helper used to resolve the webhook URL from parameter or environment variable.
export function resolveWebhook(webhookParam) { const url = webhookParam || process.env.B24_DEFAULT_WEBHOOK; if (!url) { throw new Error( 'No se especificó webhook_url y no hay B24_DEFAULT_WEBHOOK configurado. ' + 'Indicá el webhook en el parámetro webhook_url o configuralo en el servidor MCP.' ); } return url; } - src/utils/pagination.js:1-20 (helper)Helper for paginated API calls, used by the handler to fetch all section pages.
export async function fetchAllPages(client, method, params = {}) { const results = []; let start = 0; while (true) { const response = await client.call(method, { ...params, start }); const items = response.result; if (!items || (Array.isArray(items) && items.length === 0)) break; if (Array.isArray(items)) { results.push(...items); } else { results.push(items); } const total = response.total ?? 0; start += 50; if (start >= total || items.length < 50) break; }