@x0333/bitrix24-mcp-server 2.3.3 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,327 @@
1
+ #!/usr/bin/env node
2
+ import axios from "axios";
3
+ import { FastMCP } from "fastmcp";
4
+ import { createRequire } from "node:module";
5
+ import { z } from "zod";
6
+ const B24_BASE = process.env.B24_BASE;
7
+ const require = createRequire(import.meta.url);
8
+ const packageJson = require("../package.json");
9
+ if (!B24_BASE) {
10
+ console.error("Error: B24_BASE environment variable is not set.");
11
+ console.error("Please set it to your Bitrix24 webhook URL (e.g., https://domain.bitrix24.ru/rest/1/abcde/).");
12
+ process.exit(1);
13
+ }
14
+ function bitrixPortalUrlFromBase(base) {
15
+ try {
16
+ const u = new URL(base.trim());
17
+ if (!u.host)
18
+ return null;
19
+ return `${u.protocol}//${u.host}`;
20
+ }
21
+ catch {
22
+ return null;
23
+ }
24
+ }
25
+ const B24_PORTAL_URL = bitrixPortalUrlFromBase(B24_BASE);
26
+ if (!B24_PORTAL_URL) {
27
+ console.error("Error: B24_BASE must be a valid absolute URL with a host (e.g., https://domain.bitrix24.ru/rest/1/abcde/).");
28
+ process.exit(1);
29
+ }
30
+ const taskViewUrlPrefix = `${B24_PORTAL_URL}/company/personal/user/0/tasks/task/view/`;
31
+ const taskPortalLinkHowto = `When the user needs a link to a task (or to paste one), use ${taskViewUrlPrefix}<task-id>/ — substitute only <task-id> with the numeric task ID from the API. Example: ${taskViewUrlPrefix}9483/`;
32
+ const mcpInstructions = `Bitrix24 address: ${B24_PORTAL_URL}. ${taskPortalLinkHowto}`;
33
+ const bitrixBaseUrl = B24_BASE.replace(/\/$/, "");
34
+ const IM_MESSAGES_LIMIT_MAX = 50;
35
+ const stderrLogger = {
36
+ debug: (...args) => console.error(...args),
37
+ error: (...args) => console.error(...args),
38
+ info: (...args) => console.error(...args),
39
+ log: (...args) => console.error(...args),
40
+ warn: (...args) => console.error(...args),
41
+ };
42
+ function asObject(value) {
43
+ return value !== null && typeof value === "object" && !Array.isArray(value)
44
+ ? value
45
+ : null;
46
+ }
47
+ function optionalNumber(value) {
48
+ if (value === undefined || value === null || value === "")
49
+ return null;
50
+ const numberValue = Number(value);
51
+ return Number.isFinite(numberValue) ? numberValue : null;
52
+ }
53
+ function positiveNumber(value, fieldName) {
54
+ const numberValue = optionalNumber(value);
55
+ if (numberValue === null || numberValue <= 0) {
56
+ throw new Error(`${fieldName} must be a positive number`);
57
+ }
58
+ return numberValue;
59
+ }
60
+ function jsonText(data) {
61
+ return {
62
+ content: [{ type: "text", text: JSON.stringify(data, null, 2) }],
63
+ };
64
+ }
65
+ function bitrixRestApiBaseFromLegacy() {
66
+ const b = bitrixBaseUrl;
67
+ if (/\/rest\/api\//.test(b))
68
+ return null;
69
+ if (/\/rest\/\d+\//.test(b))
70
+ return b.replace("/rest/", "/rest/api/");
71
+ return null;
72
+ }
73
+ async function callBitrix(method, body, baseUrl = bitrixBaseUrl) {
74
+ const url = `${baseUrl.replace(/\/$/, "")}/${method}`;
75
+ try {
76
+ const response = await axios.post(url, body, {
77
+ headers: { "Content-Type": "application/json" },
78
+ });
79
+ return asObject(response.data) ?? { result: response.data };
80
+ }
81
+ catch (error) {
82
+ const msg = axios.isAxiosError(error) && error.response
83
+ ? `HTTP ${error.response.status}: ${JSON.stringify(error.response.data)}`
84
+ : error instanceof Error
85
+ ? error.message
86
+ : String(error);
87
+ throw new Error(msg);
88
+ }
89
+ }
90
+ function pickTaskItem(taskGetResult) {
91
+ const result = asObject(taskGetResult.result);
92
+ if (!result)
93
+ return null;
94
+ return asObject(result.item) ?? asObject(result.task) ?? null;
95
+ }
96
+ function resolveTaskChatId(item) {
97
+ if (!item)
98
+ return null;
99
+ return optionalNumber(item.chatId ?? item.CHAT_ID ?? item.chat?.id ?? item.chat?.ID);
100
+ }
101
+ function slimTaskChatMessages(messages) {
102
+ const list = Array.isArray(messages) ? messages : [];
103
+ return list.map((message) => {
104
+ const m = asObject(message) ?? {};
105
+ return {
106
+ id: m.id,
107
+ author_id: m.author_id,
108
+ text: m.text,
109
+ date: m.date,
110
+ };
111
+ });
112
+ }
113
+ function slimImUsers(users) {
114
+ const list = Array.isArray(users) ? users : [];
115
+ return list.map((user) => {
116
+ const u = asObject(user) ?? {};
117
+ return {
118
+ id: u.id,
119
+ name: u.name,
120
+ work_position: u.work_position ?? null,
121
+ email: u.email ?? null,
122
+ };
123
+ });
124
+ }
125
+ function throwIfBitrixError(data, context) {
126
+ if (!Object.prototype.hasOwnProperty.call(data, "error") || data.error == null)
127
+ return;
128
+ const code = typeof data.error === "object" ? JSON.stringify(data.error) : String(data.error);
129
+ const desc = data.error_description != null ? String(data.error_description) : "";
130
+ throw new Error(`${context}: ${code}${desc ? ` — ${desc}` : ""}`);
131
+ }
132
+ const server = new FastMCP({
133
+ instructions: mcpInstructions,
134
+ logger: stderrLogger,
135
+ name: "bitrix24-mcp-server",
136
+ version: packageJson.version,
137
+ });
138
+ server.addTool({
139
+ annotations: { readOnlyHint: true, openWorldHint: true },
140
+ description: "Fetch current user profile information from Bitrix24",
141
+ name: "get_profile",
142
+ parameters: z.object({}),
143
+ execute: async () => {
144
+ const data = await callBitrix("profile", {});
145
+ throwIfBitrixError(data, "profile");
146
+ return jsonText(data);
147
+ },
148
+ });
149
+ server.addTool({
150
+ annotations: { readOnlyHint: true, openWorldHint: true },
151
+ description: "Retrieve task details by ID from Bitrix24. " +
152
+ taskPortalLinkHowto +
153
+ " The tool response JSON includes agent_instructions with the same rule plus a direct link for the requested task id.",
154
+ name: "get_task",
155
+ parameters: z.object({
156
+ id: z.number().positive().describe("The unique ID of the task"),
157
+ select: z.array(z.string()).optional().describe("Fields to return (default: ['*'])"),
158
+ }),
159
+ execute: async ({ id, select }) => {
160
+ const taskId = positiveNumber(id, "get_task: id");
161
+ const data = await callBitrix("tasks.task.get", {
162
+ taskId,
163
+ select: select ?? ["*"],
164
+ });
165
+ throwIfBitrixError(data, "tasks.task.get");
166
+ return jsonText({
167
+ ...data,
168
+ agent_instructions: `${taskPortalLinkHowto} For this task: ${taskViewUrlPrefix}${taskId}/`,
169
+ });
170
+ },
171
+ });
172
+ server.addTool({
173
+ annotations: { readOnlyHint: true, openWorldHint: true },
174
+ description: "Search tasks in Bitrix24: by title substring (%TITLE), by Kanban stage id (filter STAGE_ID), or both.",
175
+ name: "search_tasks",
176
+ parameters: z.object({
177
+ title: z.string().trim().min(1).optional().describe("Substring of the task title to search for"),
178
+ stage_id: z.number().optional().describe("Kanban stage ID (tasks.task.list filter STAGE_ID)"),
179
+ order: z.string().trim().min(1).default("ID").describe("Field to sort by (default: 'ID')"),
180
+ dir: z.enum(["asc", "desc"]).default("desc").describe("Sort direction (default: 'desc')"),
181
+ start: z.number().nonnegative().default(0).describe("Pagination offset (default: 0)"),
182
+ }),
183
+ execute: async ({ title, stage_id, order, dir, start }) => {
184
+ if (!title && stage_id === undefined) {
185
+ throw new Error("search_tasks requires at least one of: title, stage_id");
186
+ }
187
+ const filter = {};
188
+ if (title)
189
+ filter["%TITLE"] = title;
190
+ if (stage_id !== undefined)
191
+ filter.STAGE_ID = stage_id;
192
+ const data = await callBitrix("tasks.task.list", {
193
+ order: { [order]: dir.toUpperCase() },
194
+ filter,
195
+ select: ["ID", "TITLE", "STATUS", "RESPONSIBLE_ID", "GROUP_ID", "STAGE_ID"],
196
+ start,
197
+ });
198
+ throwIfBitrixError(data, "tasks.task.list");
199
+ return jsonText(data);
200
+ },
201
+ });
202
+ server.addTool({
203
+ annotations: { readOnlyHint: true, openWorldHint: true },
204
+ description: "Search for workgroups or projects by name in Bitrix24",
205
+ name: "search_groups",
206
+ parameters: z.object({
207
+ name: z.string().trim().min(1).describe("Substring of the group name to search for"),
208
+ }),
209
+ execute: async ({ name }) => {
210
+ const data = await callBitrix("sonet_group.get.json", {
211
+ FILTER: { "%NAME": name },
212
+ });
213
+ throwIfBitrixError(data, "sonet_group.get.json");
214
+ return jsonText(data);
215
+ },
216
+ });
217
+ server.addTool({
218
+ annotations: { readOnlyHint: true, openWorldHint: true },
219
+ description: "Retrieve detailed information about a workgroup or project by ID",
220
+ name: "get_group",
221
+ parameters: z.object({
222
+ id: z.number().positive().describe("The unique ID of the group"),
223
+ }),
224
+ execute: async ({ id }) => {
225
+ const data = await callBitrix("sonet_group.get.json", {
226
+ FILTER: { ID: positiveNumber(id, "get_group: id") },
227
+ });
228
+ throwIfBitrixError(data, "sonet_group.get.json");
229
+ return jsonText(data);
230
+ },
231
+ });
232
+ server.addTool({
233
+ annotations: { readOnlyHint: true, openWorldHint: true },
234
+ description: "Get task Kanban stages for a workgroup or project (task.stages.get). entityId is the group ID.",
235
+ name: "get_kanban_stages_by_group",
236
+ parameters: z.object({
237
+ id: z.number().positive().describe("The unique ID of the group (entityId for task kanban)"),
238
+ }),
239
+ execute: async ({ id }) => {
240
+ const data = await callBitrix("task.stages.get", {
241
+ entityId: positiveNumber(id, "get_kanban_stages_by_group: id"),
242
+ });
243
+ throwIfBitrixError(data, "task.stages.get");
244
+ return jsonText(data);
245
+ },
246
+ });
247
+ server.addTool({
248
+ annotations: { readOnlyHint: true, openWorldHint: true },
249
+ description: "Comments for a task on the new task card (module tasks 25.700.0+): messages come from the task chat via im.dialog.messages.get, newest first when no cursors are passed. " +
250
+ "Arrays are trimmed: messages only id, author_id, text, date; users only id, name, work_position, email. " +
251
+ "author_id 0 means system/service chat messages (stage changes, time tracking, joins, etc.) — not a user comment; do not expect a matching row in users. " +
252
+ "For author_id > 0, match message.author_id to users[].id to resolve author name. " +
253
+ "ИИ: author_id 0 = системные сообщения чата (не комментарий человека), в users не сопоставлять; для author_id > 0 сопоставляй с users[].id. В теле ответа см. agent_instructions. " +
254
+ "Pagination: limit 1–50 (default 20). first_id = Bitrix FIRST_ID (next page of older messages). last_id = Bitrix LAST_ID (messages newer than id). Do not send both first_id and last_id.",
255
+ name: "get_task_comments",
256
+ parameters: z.object({
257
+ task_id: z.number().positive().describe("Task ID"),
258
+ limit: z.number().int().min(1).max(IM_MESSAGES_LIMIT_MAX).default(20)
259
+ .describe(`Page size (1–${IM_MESSAGES_LIMIT_MAX}, default 20). Bitrix im.dialog.messages.get LIMIT`),
260
+ first_id: z.number().positive().optional()
261
+ .describe("Optional. Bitrix FIRST_ID: load messages older than this id (next page toward history). Typically set to the smallest message id from the previous response."),
262
+ last_id: z.number().positive().optional()
263
+ .describe("Optional. Bitrix LAST_ID: load messages newer than this id. Do not combine with first_id."),
264
+ }),
265
+ execute: async ({ task_id, limit, first_id, last_id }) => {
266
+ if (first_id !== undefined && last_id !== undefined) {
267
+ throw new Error("get_task_comments: pass only one of first_id or last_id, not both");
268
+ }
269
+ const taskId = positiveNumber(task_id, "get_task_comments: task_id");
270
+ const taskSelect = ["id", "chatId", "chat.id"];
271
+ let taskRaw = await callBitrix("tasks.task.get", {
272
+ id: taskId,
273
+ select: taskSelect,
274
+ });
275
+ throwIfBitrixError(taskRaw, "tasks.task.get");
276
+ let item = pickTaskItem(taskRaw);
277
+ let chatId = resolveTaskChatId(item);
278
+ const apiBase = bitrixRestApiBaseFromLegacy();
279
+ if (!chatId && apiBase) {
280
+ taskRaw = await callBitrix("tasks.task.get", { id: taskId, select: taskSelect }, apiBase);
281
+ throwIfBitrixError(taskRaw, "tasks.task.get (rest/api)");
282
+ item = pickTaskItem(taskRaw);
283
+ chatId = resolveTaskChatId(item);
284
+ }
285
+ if (!chatId) {
286
+ throw new Error("get_task_comments: task has no chatId (new-card comments unavailable, no access, or set B24_BASE to .../rest/api/...)");
287
+ }
288
+ const imBody = {
289
+ DIALOG_ID: `chat${chatId}`,
290
+ LIMIT: limit,
291
+ };
292
+ if (first_id !== undefined)
293
+ imBody.FIRST_ID = first_id;
294
+ if (last_id !== undefined)
295
+ imBody.LAST_ID = last_id;
296
+ const imRaw = await callBitrix("im.dialog.messages.get", imBody);
297
+ throwIfBitrixError(imRaw, "im.dialog.messages.get");
298
+ const imResult = asObject(imRaw.result) ?? {};
299
+ const slimMessages = slimTaskChatMessages(imResult.messages);
300
+ const ids = slimMessages
301
+ .map((message) => optionalNumber(message.id))
302
+ .filter((id) => id !== null);
303
+ const minId = ids.length ? Math.min(...ids) : null;
304
+ const maxId = ids.length ? Math.max(...ids) : null;
305
+ return jsonText({
306
+ task_id: taskId,
307
+ chat_id: imResult.chat_id ?? chatId,
308
+ messages: slimMessages,
309
+ users: slimImUsers(imResult.users),
310
+ pagination: {
311
+ limit,
312
+ first_id_sent: first_id ?? null,
313
+ last_id_sent: last_id ?? null,
314
+ suggested_next_first_id: last_id === undefined && slimMessages.length > 0 ? minId : null,
315
+ suggested_next_last_id: first_id === undefined && slimMessages.length > 0 ? maxId : null,
316
+ note: "If suggested_next_first_id is set and you need older messages, call again with first_id equal to that value. If suggested_next_last_id is set and you need newer messages, call again with last_id equal to that value. Empty page or short page means no more in that direction (heuristic).",
317
+ },
318
+ agent_instructions: "author_id 0 — это системные сообщения чата Битрикс24 (смена стадии, учёт времени, приглашения и т.п.), а не пользовательский комментарий; не ищи для них запись в users. " +
319
+ "Для author_id > 0 сопоставь author_id с users[].id и бери имя/должность из найденного user. Текст сообщения в messages[].text.",
320
+ });
321
+ },
322
+ });
323
+ server.start({ transportType: "stdio" }).catch((error) => {
324
+ console.error("Fatal error in main():", error);
325
+ process.exit(1);
326
+ });
327
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAmC,MAAM,SAAS,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;AACtC,MAAM,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AAE,aAAa,EAAE,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;IAChE,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAC;IAC/C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,16 +1,29 @@
1
1
  {
2
2
  "name": "@x0333/bitrix24-mcp-server",
3
- "version": "2.3.3",
3
+ "version": "2.5.0",
4
4
  "description": "Bitrix24 MCP Server for AI Agent Integration.",
5
- "main": "index.js",
5
+ "main": "dist/index.js",
6
+ "type": "module",
7
+ "engines": {
8
+ "node": ">=20"
9
+ },
6
10
  "bin": {
7
- "bitrix24-mcp": "index.js"
11
+ "bitrix24-mcp": "dist/index.js"
8
12
  },
9
- "type": "commonjs",
13
+ "files": [
14
+ "dist",
15
+ "README.md",
16
+ "package.json"
17
+ ],
10
18
  "license": "MIT",
11
19
  "dependencies": {
12
- "@modelcontextprotocol/sdk": "^1.29.0",
13
- "axios": "^1.5.0"
20
+ "axios": "^1.5.0",
21
+ "fastmcp": "^4.0.1",
22
+ "zod": "^4.4.3"
23
+ },
24
+ "devDependencies": {
25
+ "@types/node": "^20.0.0",
26
+ "typescript": "^5.0.0"
14
27
  },
15
28
  "keywords": [
16
29
  "mcp",
@@ -22,5 +35,11 @@
22
35
  "author": "Lukentui",
23
36
  "publishConfig": {
24
37
  "access": "public"
38
+ },
39
+ "scripts": {
40
+ "build": "tsc",
41
+ "typecheck": "tsc --noEmit",
42
+ "start": "node dist/index.js",
43
+ "dev": "tsc --watch"
25
44
  }
26
- }
45
+ }
@@ -1,50 +0,0 @@
1
- name: Publish to npm
2
-
3
- on:
4
- push:
5
- branches: [main, master]
6
- paths:
7
- - "package.json"
8
- workflow_dispatch:
9
-
10
- concurrency:
11
- group: npm-publish-${{ github.repository }}
12
- cancel-in-progress: false
13
-
14
- jobs:
15
- publish:
16
- runs-on: ubuntu-latest
17
- permissions:
18
- contents: read
19
- steps:
20
- - uses: actions/checkout@v4
21
-
22
- - uses: actions/setup-node@v4
23
- with:
24
- node-version: "20"
25
- registry-url: "https://registry.npmjs.org"
26
-
27
- - name: Compare local version with npm latest
28
- id: version
29
- run: |
30
- set -euo pipefail
31
- LOCAL=$(node -p "require('./package.json').version")
32
- NAME=$(node -p "require('./package.json').name")
33
- NPM_VER=$(npm view "$NAME" version 2>/dev/null || echo "0.0.0")
34
- echo "Package: $NAME"
35
- echo "Local version: $LOCAL"
36
- echo "npm latest: $NPM_VER"
37
- MATCH=$(npx -y semver@7 -r ">$NPM_VER" "$LOCAL" 2>/dev/null || true)
38
- if [ "$MATCH" = "$LOCAL" ]; then
39
- echo "should_publish=true" >> "$GITHUB_OUTPUT"
40
- echo "Will publish: $LOCAL is newer than $NPM_VER"
41
- else
42
- echo "should_publish=false" >> "$GITHUB_OUTPUT"
43
- echo "Skip publish: $LOCAL is not newer than $NPM_VER"
44
- fi
45
-
46
- - name: npm publish
47
- if: steps.version.outputs.should_publish == 'true'
48
- run: npm publish --access public
49
- env:
50
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
package/index.js DELETED
@@ -1,424 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
-
4
- const { Server } = require("@modelcontextprotocol/sdk/server/index.js");
5
- const { StdioServerTransport } = require("@modelcontextprotocol/sdk/server/stdio.js");
6
- const {
7
- CallToolRequestSchema,
8
- ListToolsRequestSchema,
9
- } = require("@modelcontextprotocol/sdk/types.js");
10
- const axios = require("axios");
11
-
12
- /**
13
- * Bitrix24 MCP Server
14
- *
15
- * This server implements the Model Context Protocol (MCP) to provide
16
- * Bitrix24 integration for AI agents.
17
- */
18
-
19
- const B24_BASE = process.env.B24_BASE;
20
-
21
- if (!B24_BASE) {
22
- console.error("Error: B24_BASE environment variable is not set.");
23
- console.error("Please set it to your Bitrix24 webhook URL (e.g., https://domain.bitrix24.ru/rest/1/abcde/).");
24
- process.exit(1);
25
- }
26
-
27
- function bitrixPortalUrlFromBase(base) {
28
- try {
29
- const u = new URL(String(base).trim());
30
- if (!u.host) return null;
31
- return `${u.protocol}//${u.host}`;
32
- } catch {
33
- return null;
34
- }
35
- }
36
-
37
- const B24_PORTAL_URL = bitrixPortalUrlFromBase(B24_BASE);
38
- if (!B24_PORTAL_URL) {
39
- console.error("Error: B24_BASE must be a valid absolute URL with a host (e.g., https://domain.bitrix24.ru/rest/1/abcde/).");
40
- process.exit(1);
41
- }
42
-
43
- const taskViewUrlPrefix = `${B24_PORTAL_URL}/company/personal/user/0/tasks/task/view/`;
44
- const taskPortalLinkHowto =
45
- `When the user needs a link to a task (or to paste one), use ${taskViewUrlPrefix}<task-id>/ — substitute only <task-id> with the numeric task ID from the API. Example: ${taskViewUrlPrefix}9483/`;
46
- const mcpInstructions = `Bitrix24 address: ${B24_PORTAL_URL}. ${taskPortalLinkHowto}`;
47
-
48
- const server = new Server(
49
- {
50
- name: "bitrix24-mcp-server",
51
- version: "2.3.3",
52
- },
53
- {
54
- capabilities: {
55
- tools: {},
56
- },
57
- instructions: mcpInstructions,
58
- }
59
- );
60
-
61
- /**
62
- * If B24_BASE is legacy .../rest/{user}/{webhook}/ (without /api/), new task fields
63
- * like chatId are returned from .../rest/api/{user}/{webhook}/ only.
64
- */
65
- function bitrixRestApiBaseFromLegacy() {
66
- const b = B24_BASE.replace(/\/$/, "");
67
- if (/\/rest\/api\//.test(b)) return null;
68
- if (/\/rest\/\d+\//.test(b)) return b.replace("/rest/", "/rest/api/");
69
- return null;
70
- }
71
-
72
- /**
73
- * Helper to call Bitrix24 REST API
74
- * @param {string} [baseUrl] — override base (e.g. rest/api for tasks.task.get)
75
- */
76
- async function callBitrix(method, body, baseUrl) {
77
- const url = `${(baseUrl || B24_BASE).replace(/\/$/, "")}/${method}`;
78
- try {
79
- const response = await axios.post(url, body, {
80
- headers: { "Content-Type": "application/json" },
81
- });
82
- return response.data;
83
- } catch (err) {
84
- const msg = err.response
85
- ? `HTTP ${err.response.status}: ${JSON.stringify(err.response.data)}`
86
- : err.message;
87
- throw new Error(msg);
88
- }
89
- }
90
-
91
- const IM_MESSAGES_LIMIT_MAX = 50;
92
-
93
- function pickTaskItem(taskGetResult) {
94
- const r = taskGetResult?.result;
95
- if (!r) return null;
96
- return r.item ?? r.task ?? null;
97
- }
98
-
99
- function resolveTaskChatId(item) {
100
- if (!item || typeof item !== "object") return null;
101
- const cid = item.chatId ?? item.CHAT_ID ?? item.chat?.id ?? item.chat?.ID;
102
- return cid != null && cid !== "" ? Number(cid) : null;
103
- }
104
-
105
- function slimTaskChatMessages(messages) {
106
- const list = Array.isArray(messages) ? messages : [];
107
- return list.map((m) => ({
108
- id: m.id,
109
- author_id: m.author_id,
110
- text: m.text,
111
- date: m.date,
112
- }));
113
- }
114
-
115
- function slimImUsers(users) {
116
- const list = Array.isArray(users) ? users : [];
117
- return list.map((u) => ({
118
- id: u.id,
119
- name: u.name,
120
- work_position: u.work_position ?? null,
121
- email: u.email ?? null,
122
- }));
123
- }
124
-
125
- function throwIfBitrixError(data, context) {
126
- if (!data || typeof data !== "object") return;
127
- if (!Object.prototype.hasOwnProperty.call(data, "error") || data.error == null) return;
128
- const code = typeof data.error === "object" ? JSON.stringify(data.error) : String(data.error);
129
- const desc = data.error_description != null ? String(data.error_description) : "";
130
- throw new Error(`${context}: ${code}${desc ? ` — ${desc}` : ""}`);
131
- }
132
-
133
- /**
134
- * Define available tools
135
- */
136
- server.setRequestHandler(ListToolsRequestSchema, async () => {
137
- return {
138
- tools: [
139
- {
140
- name: "get_profile",
141
- description: "Fetch current user profile information from Bitrix24",
142
- inputSchema: {
143
- type: "object",
144
- properties: {},
145
- },
146
- },
147
- {
148
- name: "get_task",
149
- description:
150
- "Retrieve task details by ID from Bitrix24. " +
151
- taskPortalLinkHowto +
152
- " The tool response JSON includes agent_instructions with the same rule plus a direct link for the requested task id.",
153
- inputSchema: {
154
- type: "object",
155
- properties: {
156
- id: { type: "number", description: "The unique ID of the task" },
157
- select: {
158
- type: "array",
159
- items: { type: "string" },
160
- description: "Fields to return (default: ['*'])"
161
- },
162
- },
163
- required: ["id"],
164
- },
165
- },
166
- {
167
- name: "search_tasks",
168
- description:
169
- "Search tasks in Bitrix24: by title substring (%TITLE), by Kanban stage id (filter STAGE_ID), or both.",
170
- inputSchema: {
171
- type: "object",
172
- properties: {
173
- title: { type: "string", description: "Substring of the task title to search for" },
174
- stage_id: {
175
- type: "number",
176
- description: "Kanban stage ID (tasks.task.list filter STAGE_ID)",
177
- },
178
- order: { type: "string", description: "Field to sort by (default: 'ID')" },
179
- dir: { type: "string", enum: ["asc", "desc"], description: "Sort direction (default: 'desc')" },
180
- start: { type: "number", description: "Pagination offset (default: 0)" },
181
- },
182
- },
183
- },
184
- {
185
- name: "search_groups",
186
- description: "Search for workgroups or projects by name in Bitrix24",
187
- inputSchema: {
188
- type: "object",
189
- properties: {
190
- name: { type: "string", description: "Substring of the group name to search for" },
191
- },
192
- required: ["name"],
193
- },
194
- },
195
- {
196
- name: "get_group",
197
- description: "Retrieve detailed information about a workgroup or project by ID",
198
- inputSchema: {
199
- type: "object",
200
- properties: {
201
- id: { type: "number", description: "The unique ID of the group" },
202
- },
203
- required: ["id"],
204
- },
205
- },
206
- {
207
- name: "get_kanban_stages_by_group",
208
- description:
209
- "Get task Kanban stages for a workgroup or project (task.stages.get). entityId is the group ID.",
210
- inputSchema: {
211
- type: "object",
212
- properties: {
213
- id: { type: "number", description: "The unique ID of the group (entityId for task kanban)" },
214
- },
215
- required: ["id"],
216
- },
217
- },
218
- {
219
- name: "get_task_comments",
220
- description:
221
- "Comments for a task on the new task card (module tasks 25.700.0+): messages come from the task chat via im.dialog.messages.get, newest first when no cursors are passed. " +
222
- "Arrays are trimmed: messages only id, author_id, text, date; users only id, name, work_position, email. " +
223
- "author_id 0 means system/service chat messages (stage changes, time tracking, joins, etc.) — not a user comment; do not expect a matching row in users. " +
224
- "For author_id > 0, match message.author_id to users[].id to resolve author name. " +
225
- "ИИ: author_id 0 = системные сообщения чата (не комментарий человека), в users не сопоставлять; для author_id > 0 сопоставляй с users[].id. В теле ответа см. agent_instructions. " +
226
- "Pagination: limit 1–50 (default 20). first_id = Bitrix FIRST_ID (next page of older messages). last_id = Bitrix LAST_ID (messages newer than id). Do not send both first_id and last_id.",
227
- inputSchema: {
228
- type: "object",
229
- properties: {
230
- task_id: { type: "number", description: "Task ID" },
231
- limit: {
232
- type: "number",
233
- description: `Page size (1–${IM_MESSAGES_LIMIT_MAX}, default 20). Bitrix im.dialog.messages.get LIMIT`,
234
- },
235
- first_id: {
236
- type: "number",
237
- description:
238
- "Optional. Bitrix FIRST_ID: load messages older than this id (next page toward history). Typically set to the smallest message id from the previous response.",
239
- },
240
- last_id: {
241
- type: "number",
242
- description:
243
- "Optional. Bitrix LAST_ID: load messages newer than this id. Do not combine with first_id.",
244
- },
245
- },
246
- required: ["task_id"],
247
- },
248
- },
249
- ],
250
- };
251
- });
252
-
253
- /**
254
- * Handle tool calls
255
- */
256
- server.setRequestHandler(CallToolRequestSchema, async (request) => {
257
- const { name, arguments: args } = request.params;
258
-
259
- try {
260
- switch (name) {
261
- case "get_profile": {
262
- const data = await callBitrix("profile", {});
263
- return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
264
- }
265
-
266
- case "get_task": {
267
- const taskId = Number(args.id);
268
- const body = { taskId: args.id, select: args.select || ["*"] };
269
- const data = await callBitrix("tasks.task.get", body);
270
- throwIfBitrixError(data, "tasks.task.get");
271
- const payload = {
272
- ...data,
273
- agent_instructions: `${taskPortalLinkHowto} For this task: ${taskViewUrlPrefix}${taskId}/`,
274
- };
275
- return { content: [{ type: "text", text: JSON.stringify(payload, null, 2) }] };
276
- }
277
-
278
- case "search_tasks": {
279
- const hasTitle = args.title != null && String(args.title).trim() !== "";
280
- const hasStage =
281
- args.stage_id !== undefined && args.stage_id !== null && !Number.isNaN(Number(args.stage_id));
282
- if (!hasTitle && !hasStage) {
283
- throw new Error("search_tasks requires at least one of: title, stage_id");
284
- }
285
- const filter = {};
286
- if (hasTitle) {
287
- filter["%TITLE"] = args.title;
288
- }
289
- if (hasStage) {
290
- filter.STAGE_ID = Number(args.stage_id);
291
- }
292
- const body = {
293
- order: { [args.order || "ID"]: (args.dir || "desc").toUpperCase() },
294
- filter,
295
- select: ["ID", "TITLE", "STATUS", "RESPONSIBLE_ID", "GROUP_ID", "STAGE_ID"],
296
- start: args.start || 0,
297
- };
298
- const data = await callBitrix("tasks.task.list", body);
299
- return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
300
- }
301
-
302
- case "search_groups": {
303
- const body = {
304
- FILTER: { "%NAME": args.name },
305
- };
306
- const data = await callBitrix("sonet_group.get.json", body);
307
- return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
308
- }
309
-
310
- case "get_group": {
311
- const body = { FILTER: { ID: args.id } };
312
- const data = await callBitrix("sonet_group.get.json", body);
313
- return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
314
- }
315
-
316
- case "get_kanban_stages_by_group": {
317
- const body = { entityId: args.id };
318
- const data = await callBitrix("task.stages.get", body);
319
- return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
320
- }
321
-
322
- case "get_task_comments": {
323
- const taskId = Number(args.task_id);
324
- if (!Number.isFinite(taskId) || taskId <= 0) {
325
- throw new Error("get_task_comments: task_id must be a positive number");
326
- }
327
- const hasFirst = args.first_id !== undefined && args.first_id !== null;
328
- const hasLast = args.last_id !== undefined && args.last_id !== null;
329
- if (hasFirst && hasLast) {
330
- throw new Error("get_task_comments: pass only one of first_id or last_id, not both");
331
- }
332
- let limit = args.limit === undefined || args.limit === null ? 20 : Number(args.limit);
333
- if (!Number.isFinite(limit)) limit = 20;
334
- limit = Math.min(IM_MESSAGES_LIMIT_MAX, Math.max(1, Math.floor(limit)));
335
-
336
- const taskSelect = ["id", "chatId", "chat.id"];
337
- let taskRaw = await callBitrix("tasks.task.get", {
338
- id: taskId,
339
- select: taskSelect,
340
- });
341
- throwIfBitrixError(taskRaw, "tasks.task.get");
342
- let item = pickTaskItem(taskRaw);
343
- let chatId = resolveTaskChatId(item);
344
- const apiBase = bitrixRestApiBaseFromLegacy();
345
- if (!chatId && apiBase) {
346
- taskRaw = await callBitrix(
347
- "tasks.task.get",
348
- { id: taskId, select: taskSelect },
349
- apiBase
350
- );
351
- throwIfBitrixError(taskRaw, "tasks.task.get (rest/api)");
352
- item = pickTaskItem(taskRaw);
353
- chatId = resolveTaskChatId(item);
354
- }
355
- if (!chatId) {
356
- throw new Error(
357
- "get_task_comments: task has no chatId (new-card comments unavailable, no access, or set B24_BASE to .../rest/api/...)"
358
- );
359
- }
360
-
361
- const imBody = {
362
- DIALOG_ID: `chat${chatId}`,
363
- LIMIT: limit,
364
- };
365
- if (hasFirst) imBody.FIRST_ID = Number(args.first_id);
366
- if (hasLast) imBody.LAST_ID = Number(args.last_id);
367
-
368
- const imRaw = await callBitrix("im.dialog.messages.get", imBody);
369
- throwIfBitrixError(imRaw, "im.dialog.messages.get");
370
- const imResult = imRaw.result || {};
371
- const rawMessages = Array.isArray(imResult.messages) ? imResult.messages : [];
372
- const slimMessages = slimTaskChatMessages(rawMessages);
373
- const ids = slimMessages.map((m) => m.id).filter((id) => typeof id === "number");
374
- const minId = ids.length ? Math.min(...ids) : null;
375
- const maxId = ids.length ? Math.max(...ids) : null;
376
-
377
- const payload = {
378
- task_id: taskId,
379
- chat_id: imResult.chat_id ?? chatId,
380
- messages: slimMessages,
381
- users: slimImUsers(imResult.users),
382
- pagination: {
383
- limit,
384
- first_id_sent: hasFirst ? Number(args.first_id) : null,
385
- last_id_sent: hasLast ? Number(args.last_id) : null,
386
- suggested_next_first_id:
387
- !hasLast && slimMessages.length > 0 ? minId : null,
388
- suggested_next_last_id:
389
- !hasFirst && slimMessages.length > 0 ? maxId : null,
390
- note:
391
- "If suggested_next_first_id is set and you need older messages, call again with first_id equal to that value. If suggested_next_last_id is set and you need newer messages, call again with last_id equal to that value. Empty page or short page means no more in that direction (heuristic).",
392
- },
393
- agent_instructions:
394
- "author_id 0 — это системные сообщения чата Битрикс24 (смена стадии, учёт времени, приглашения и т.п.), а не пользовательский комментарий; не ищи для них запись в users. " +
395
- "Для author_id > 0 сопоставь author_id с users[].id и бери имя/должность из найденного user. Текст сообщения в messages[].text.",
396
- };
397
-
398
- return { content: [{ type: "text", text: JSON.stringify(payload, null, 2) }] };
399
- }
400
-
401
- default:
402
- throw new Error(`Unknown tool: ${name}`);
403
- }
404
- } catch (error) {
405
- return {
406
- content: [{ type: "text", text: `Error: ${error.message}` }],
407
- isError: true,
408
- };
409
- }
410
- });
411
-
412
- /**
413
- * Start the server
414
- */
415
- async function main() {
416
- const transport = new StdioServerTransport();
417
- await server.connect(transport);
418
- console.error("Bitrix24 MCP Server running on stdio");
419
- }
420
-
421
- main().catch((error) => {
422
- console.error("Fatal error in main():", error);
423
- process.exit(1);
424
- });