b24_read_pipelines
Retrieve CRM pipelines and their stages, including colors, semantics, and ordering. Use entity type ID to filter results.
Instructions
Lee pipelines (funnels) y sus etapas con colores, semántica y orden.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| webhook_url | No | URL del webhook (opcional si está configurado por defecto) | |
| entity_type_id | No | ID del tipo de entidad (opcional, default: todos) |
Implementation Reference
- src/tools/read-pipelines.js:11-24 (handler)The main handler function for the 'b24_read_pipelines' tool. It instantiates a Bitrix24Client and Bitrix24Reader, calls reader.readPipelines(entity_type_id), and returns a result with the portal URL, pipelines data, and a summary string.
export async function readPipelines({ webhook_url, entity_type_id }) { const client = new Bitrix24Client(resolveWebhook(webhook_url)); const reader = new Bitrix24Reader(client); const pipelines = await reader.readPipelines(entity_type_id); const count = Object.keys(pipelines).length; const stageCount = Object.values(pipelines).reduce((acc, p) => acc + (p.stages?.length ?? 0), 0); return { portal: client.portal, pipelines, summary: `${count} pipelines con ${stageCount} etapas en total`, }; } - src/tools/read-pipelines.js:6-9 (schema)Zod schema defining the input parameters: webhook_url (optional URL string) and entity_type_id (optional integer for filtering by entity type).
export const readPipelinesSchema = z.object({ webhook_url: z.string().url().optional().describe('URL del webhook (opcional si está configurado por defecto)'), entity_type_id: z.number().int().optional().describe('ID del tipo de entidad (opcional, default: todos)'), }); - index.js:146-148 (registration)Registration of the 'b24_read_pipelines' tool with the MCP server, binding its schema and handler.
server.tool('b24_read_pipelines', 'Lee pipelines (funnels) y sus etapas con colores, semántica y orden.', readPipelinesSchema.shape, wrap(readPipelines)); - src/bitrix24/reader.js:30-63 (helper)The reader.readPipelines() method that performs the actual Bitrix24 API calls. Fetches categories (pipelines) using crm.category.list or crm.lead.status.list for leads, then fetches stages per category using crm.stage.list. Returns a dictionary keyed by 'entityTypeId_categoryId'.
async readPipelines(entityTypeId = null) { const pipelines = {}; const entityTypes = entityTypeId ? [{ ENTITY_TYPE_ID: entityTypeId }] : [{ ENTITY_TYPE_ID: 2 }, { ENTITY_TYPE_ID: 1 }]; for (const et of entityTypes) { const id = et.ENTITY_TYPE_ID; try { let categories; if (id === 2) { categories = await fetchAllPages(this.client, 'crm.category.list', { entityTypeId: id }); } else if (id === 1) { const res = await this.client.call('crm.lead.status.list'); categories = [{ ID: 'lead', NAME: 'Lead Pipeline', stages: res.result }]; } else { categories = await fetchAllPages(this.client, 'crm.category.list', { entityTypeId: id }); } for (const cat of categories) { const stages = await fetchAllPages(this.client, 'crm.stage.list', { entityTypeId: id, categoryId: cat.ID, }); pipelines[`${id}_${cat.ID}`] = { ...cat, stages }; } } catch { // Entity type may not support pipelines } } return pipelines; }