b24_users_list
Retrieve active Bitrix24 users with name, email, position, department, and online status. Apply filters to narrow results by department or name.
Instructions
Lista usuarios activos con nombre, email, cargo, departamento y estado online.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filter | No | Filtros. Default: { ACTIVE: true }. Otros: { "UF_DEPARTMENT": 5, "NAME": "Brian" } | |
| select | No | Campos a retornar. Default: ID, NAME, LAST_NAME, EMAIL, WORK_POSITION, UF_DEPARTMENT, IS_ONLINE | |
| all_pages | No | ||
| webhook_url | No |
Implementation Reference
- src/tools/users-departments.js:19-29 (handler)The main handler function for b24_users_list. Calls Bitrix24 API 'user.get' with optional filters, selects, and pagination. Returns portal name, total count, and user list.
export async function usersList({ filter = { ACTIVE: true }, select, all_pages = true, webhook_url }) { const client = new Bitrix24Client(resolveWebhook(webhook_url)); const params = { filter, select: select ?? ['ID', 'NAME', 'LAST_NAME', 'EMAIL', 'WORK_POSITION', 'UF_DEPARTMENT', 'IS_ONLINE', 'LAST_ACTIVITY_DATE'], }; const users = all_pages ? await fetchAllPages(client, 'user.get', params) : (await client.call('user.get', params)).result ?? []; return { portal: client.portal, total: users.length, users }; } - src/tools/users-departments.js:8-17 (schema)Zod schema for b24_users_list input. Defines optional parameters: filter (defaults to {ACTIVE: true}), select (fields to return), all_pages (pagination flag), and webhook_url.
export const usersListSchema = z.object({ filter: z.record(z.any()).optional().default({ ACTIVE: true }).describe( 'Filtros. Default: { ACTIVE: true }. Otros: { "UF_DEPARTMENT": 5, "NAME": "Brian" }' ), select: z.array(z.string()).optional().describe( 'Campos a retornar. Default: ID, NAME, LAST_NAME, EMAIL, WORK_POSITION, UF_DEPARTMENT, IS_ONLINE' ), all_pages: z.boolean().optional().default(true), webhook_url: z.string().url().optional(), }); - index.js:196-198 (registration)Registration of the 'b24_users_list' tool on the MCP server with its schema and wrapped handler.
server.tool('b24_users_list', 'Lista usuarios activos con nombre, email, cargo, departamento y estado online.', usersListSchema.shape, wrap(usersList)); - src/utils/pagination.js:1-23 (helper)Helper utility 'fetchAllPages' used by the handler to fetch all pages of results from the Bitrix24 API.
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; } return results; } - src/utils/resolve-webhook.js:1-10 (helper)Helper utility 'resolveWebhook' that resolves the webhook URL from the 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; }