kanban-zone-mcp-server 0.1.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,447 @@
1
+ const { z } = require('zod');
2
+ const { makeApiRequest, safeRun } = require('../client');
3
+ const { responseFormatField, ResponseFormat, toJsonString, truncateIfNeeded } = require('../format');
4
+ const { objectIdField, boardPublicIdField, pageField, countField, isoDateField } = require('../schemas');
5
+
6
+ const READ = { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true };
7
+ const WRITE = { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true };
8
+ const IDEMPOTENT_WRITE = { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true };
9
+
10
+ const renderCardLine = card => {
11
+ const number = card.number !== undefined ? `#${card.number} ` : '';
12
+ const owner = card.owner && card.owner.email ? ` — owner ${card.owner.email}` : '';
13
+ return `- ${number}**${card.title}** (\`${card._id}\`)${owner}`;
14
+ };
15
+
16
+ const registerCardsTools = server => {
17
+ server.registerTool(
18
+ 'kanbanzone_create_card',
19
+ {
20
+ title: 'Create a card',
21
+ description: [
22
+ 'Create a single card on a board.',
23
+ 'Internally calls the batch POST /cards endpoint with a one-card array.',
24
+ '',
25
+ 'Args:',
26
+ ' - board (string, required): board publicId.',
27
+ ' - title (string, required): card title.',
28
+ ' - description (string, optional): rich-text or plain description.',
29
+ ' - column (string, optional): column ObjectId. If omitted, the card lands in the default backlog.',
30
+ ' - owner (string, optional): account email of the assignee.',
31
+ ' - label (string, optional): label name (e.g. "Enhancement"). Must match a label configured on the board.',
32
+ ' - addToTop (boolean, optional): insert at the top of the column instead of the bottom.',
33
+ '',
34
+ 'Examples:',
35
+ ' - "Create a card titled \'Refactor auth\' on board OeMrbG8g"',
36
+ ' - "Add a card to the To-Do column with description ..."',
37
+ ].join('\n'),
38
+ inputSchema: {
39
+ board: boardPublicIdField,
40
+ title: z.string().min(1).max(500),
41
+ description: z.string().optional(),
42
+ column: objectIdField.optional(),
43
+ owner: z.string().optional(),
44
+ label: z.string().optional(),
45
+ addToTop: z.boolean().optional(),
46
+ },
47
+ annotations: WRITE,
48
+ },
49
+ async ({ board, title, description, column, owner, label, addToTop }) =>
50
+ safeRun(async () => {
51
+ const card = { title };
52
+ if (description !== undefined) card.description = description;
53
+ if (column !== undefined) card.columnId = column;
54
+ if (owner !== undefined) card.owner = owner;
55
+ if (label !== undefined) card.label = label;
56
+
57
+ const body = { board, cards: [card] };
58
+ if (addToTop !== undefined) body.addToTop = addToTop;
59
+
60
+ const data = await makeApiRequest('/cards', { method: 'POST', body });
61
+ const created = Array.isArray(data) ? data[0] : data;
62
+
63
+ return {
64
+ content: [
65
+ {
66
+ type: 'text',
67
+ text: `Created card **${created.title}** (\`${created._id}\`) on board ${board}.`,
68
+ },
69
+ ],
70
+ structuredContent: created,
71
+ };
72
+ })
73
+ );
74
+
75
+ server.registerTool(
76
+ 'kanbanzone_list_cards',
77
+ {
78
+ title: 'List cards on a board',
79
+ description: [
80
+ 'List cards on a board with optional filters and pagination.',
81
+ '',
82
+ 'Args:',
83
+ ' - board (string, required): board publicId.',
84
+ ' - columns (string, optional): comma-separated column ObjectIds to restrict to.',
85
+ ' - owner (string, optional): account ObjectId or email — only cards owned by this person.',
86
+ ' - label (string, optional): label ObjectId or description string.',
87
+ ' - days_since_last_update (number, optional): only cards untouched for N+ days.',
88
+ ' - include_archived (boolean, optional): include archived cards.',
89
+ ' - number (number, optional): fetch a single card by its #N number.',
90
+ ' - page (number, optional, default 1).',
91
+ ' - count (number, optional, default 20, max 100).',
92
+ ' - response_format ("markdown" | "json").',
93
+ '',
94
+ 'Examples:',
95
+ ' - "What cards are in progress on the OeMrbG8g board?"',
96
+ ' - "List my cards owned by alice@example.com"',
97
+ ].join('\n'),
98
+ inputSchema: {
99
+ board: boardPublicIdField,
100
+ columns: z.string().optional(),
101
+ owner: z.string().optional(),
102
+ label: z.string().optional(),
103
+ days_since_last_update: z.number().int().min(0).optional(),
104
+ include_archived: z.boolean().optional(),
105
+ number: z.number().int().min(1).optional(),
106
+ page: pageField,
107
+ count: countField,
108
+ response_format: responseFormatField,
109
+ },
110
+ annotations: READ,
111
+ },
112
+ async ({
113
+ board,
114
+ columns,
115
+ owner,
116
+ label,
117
+ days_since_last_update,
118
+ include_archived,
119
+ number,
120
+ page,
121
+ count,
122
+ response_format,
123
+ }) =>
124
+ safeRun(async () => {
125
+ const data = await makeApiRequest('/cards', {
126
+ query: {
127
+ board,
128
+ columns,
129
+ owner,
130
+ label,
131
+ daysSinceLastUpdate: days_since_last_update,
132
+ includeArchived: include_archived ? 'true' : undefined,
133
+ number,
134
+ page,
135
+ count,
136
+ },
137
+ });
138
+
139
+ // Upstream returns either a bare array or a paginated wrapper depending on filters.
140
+ const items = Array.isArray(data) ? data : data.cards || data.results || [];
141
+ const total = typeof data.total === 'number' ? data.total : items.length;
142
+ const hasMore = total > page * count;
143
+
144
+ if (response_format === ResponseFormat.JSON) {
145
+ return {
146
+ content: [{ type: 'text', text: toJsonString({ total, count: items.length, page, items, has_more: hasMore }) }],
147
+ structuredContent: { total, count: items.length, page, items, has_more: hasMore },
148
+ };
149
+ }
150
+
151
+ const rerender = list =>
152
+ [
153
+ `# Cards on ${board} (page ${page}, ${list.length} of ${total})`,
154
+ '',
155
+ ...list.map(renderCardLine),
156
+ hasMore ? `\n_More results available — call again with \`page: ${page + 1}\`._` : '',
157
+ ]
158
+ .filter(Boolean)
159
+ .join('\n');
160
+
161
+ const { text } = truncateIfNeeded({ items, rendered: rerender(items), rerender });
162
+
163
+ return {
164
+ content: [{ type: 'text', text }],
165
+ structuredContent: { total, count: items.length, page, items, has_more: hasMore },
166
+ };
167
+ })
168
+ );
169
+
170
+ server.registerTool(
171
+ 'kanbanzone_get_card',
172
+ {
173
+ title: 'Get a card',
174
+ description: [
175
+ 'Fetch one card by its ObjectId.',
176
+ '',
177
+ 'Args:',
178
+ ' - id (string, required): card ObjectId.',
179
+ ' - board (string, optional): board publicId — required for mirror cards to disambiguate.',
180
+ ' - response_format ("markdown" | "json").',
181
+ '',
182
+ 'Examples:',
183
+ ' - "Show me card 6700aabbccddeeff00112233"',
184
+ ].join('\n'),
185
+ inputSchema: {
186
+ id: objectIdField,
187
+ board: boardPublicIdField.optional(),
188
+ response_format: responseFormatField,
189
+ },
190
+ annotations: READ,
191
+ },
192
+ async ({ id, board, response_format }) =>
193
+ safeRun(async () => {
194
+ const data = await makeApiRequest(`/cards/${id}`, { query: { board } });
195
+ const text =
196
+ response_format === ResponseFormat.JSON
197
+ ? toJsonString(data)
198
+ : `# ${data.title}\n- **id**: ${data._id}${data.description ? `\n- **description**: ${data.description}` : ''}`;
199
+ return { content: [{ type: 'text', text }], structuredContent: data };
200
+ })
201
+ );
202
+
203
+ server.registerTool(
204
+ 'kanbanzone_update_card',
205
+ {
206
+ title: 'Update a card',
207
+ description: [
208
+ 'Update fields on an existing card. Only included fields are changed.',
209
+ '',
210
+ 'Args:',
211
+ ' - id (string, required): card ObjectId.',
212
+ ' - board (string, optional): board publicId — required for mirror cards to disambiguate.',
213
+ ' - title (string, optional)',
214
+ ' - description (string, optional)',
215
+ ' - owner (string, optional): account email or ObjectId.',
216
+ ' - label (string, optional): label name (e.g. "Enhancement") or ObjectId.',
217
+ ' - dueAt (string, optional): ISO date or datetime.',
218
+ ' - customFields (array, optional): list of { label, value } pairs. `label` matches the custom-field name configured on the board.',
219
+ '',
220
+ 'Examples:',
221
+ ' - "Reassign card 670... to bob@example.com"',
222
+ ' - "Set the due date on card 670... to 2025-06-01"',
223
+ ' - "Set the Project Code custom field on card 670... to ABC-123"',
224
+ ].join('\n'),
225
+ inputSchema: {
226
+ id: objectIdField,
227
+ board: boardPublicIdField.optional(),
228
+ title: z.string().min(1).max(500).optional(),
229
+ description: z.string().optional(),
230
+ owner: z.string().optional(),
231
+ label: z.string().optional(),
232
+ dueAt: isoDateField.optional(),
233
+ customFields: z
234
+ .array(
235
+ z.object({
236
+ label: z.string().min(1),
237
+ value: z.union([z.string(), z.number(), z.boolean()]),
238
+ })
239
+ )
240
+ .optional(),
241
+ },
242
+ annotations: IDEMPOTENT_WRITE,
243
+ },
244
+ async ({ id, ...updates }) =>
245
+ safeRun(async () => {
246
+ const data = await makeApiRequest(`/cards/${id}`, { method: 'PATCH', body: updates });
247
+ return {
248
+ content: [{ type: 'text', text: `Updated card **${data.title || id}**.` }],
249
+ structuredContent: data,
250
+ };
251
+ })
252
+ );
253
+
254
+ server.registerTool(
255
+ 'kanbanzone_move_card',
256
+ {
257
+ title: 'Move a card',
258
+ description: [
259
+ 'Move a card to a different column (and optionally a different board).',
260
+ '',
261
+ 'Args:',
262
+ ' - id (string, required): card ObjectId.',
263
+ ' - board (string, required): destination board publicId.',
264
+ ' - column (string, required): destination column ObjectId.',
265
+ ' - position (number, optional): 0-based position within the destination column.',
266
+ '',
267
+ 'Examples:',
268
+ ' - "Move card 670... to the In Progress column"',
269
+ ].join('\n'),
270
+ inputSchema: {
271
+ id: objectIdField,
272
+ board: boardPublicIdField,
273
+ column: objectIdField,
274
+ position: z.number().int().min(0).optional(),
275
+ },
276
+ annotations: IDEMPOTENT_WRITE,
277
+ },
278
+ async ({ id, board, column, position }) =>
279
+ safeRun(async () => {
280
+ const data = await makeApiRequest(`/cards/${id}/move`, {
281
+ method: 'POST',
282
+ body: { board, columnId: column, position },
283
+ });
284
+ return {
285
+ content: [{ type: 'text', text: `Moved card to column ${column}.` }],
286
+ structuredContent: data,
287
+ };
288
+ })
289
+ );
290
+
291
+ server.registerTool(
292
+ 'kanbanzone_get_card_history',
293
+ {
294
+ title: 'Get card history',
295
+ description: [
296
+ 'Fetch the activity history for a card (column moves, edits, comments, etc.) starting from a date.',
297
+ '',
298
+ 'Args:',
299
+ ' - id (string, required): card ObjectId.',
300
+ ' - start (string, required): ISO date — only events on/after this date are returned.',
301
+ ' - response_format ("markdown" | "json").',
302
+ '',
303
+ 'Examples:',
304
+ ' - "What happened to card 670... since 2025-01-01?"',
305
+ ].join('\n'),
306
+ inputSchema: {
307
+ id: objectIdField,
308
+ start: isoDateField.describe('ISO date — only events on/after this date are returned.'),
309
+ response_format: responseFormatField,
310
+ },
311
+ annotations: READ,
312
+ },
313
+ async ({ id, start, response_format }) =>
314
+ safeRun(async () => {
315
+ const data = await makeApiRequest(`/cards/${id}/history`, { query: { start } });
316
+ const events = Array.isArray(data) ? data : data.history || data.events || [];
317
+
318
+ if (response_format === ResponseFormat.JSON) {
319
+ return {
320
+ content: [{ type: 'text', text: toJsonString(events) }],
321
+ structuredContent: { events },
322
+ };
323
+ }
324
+
325
+ const rerender = list =>
326
+ [
327
+ `# History (${list.length} events since ${start})`,
328
+ '',
329
+ ...list.map(ev => `- ${ev.createdAt || ev.date || '?'} — ${ev.action || ev.type}`),
330
+ ].join('\n');
331
+ const { text } = truncateIfNeeded({ items: events, rendered: rerender(events), rerender });
332
+ return { content: [{ type: 'text', text }], structuredContent: { events } };
333
+ })
334
+ );
335
+
336
+ server.registerTool(
337
+ 'kanbanzone_get_card_metrics',
338
+ {
339
+ title: 'Get card metrics',
340
+ description: [
341
+ 'Fetch time-in-column and cycle/lead-time metrics for a card.',
342
+ '',
343
+ 'Args:',
344
+ ' - id (string, required): card ObjectId.',
345
+ ' - board (string, optional): board publicId — required for mirror cards.',
346
+ ' - response_format ("markdown" | "json").',
347
+ '',
348
+ 'Examples:',
349
+ ' - "How long has card 670... been in each column?"',
350
+ ].join('\n'),
351
+ inputSchema: {
352
+ id: objectIdField,
353
+ board: boardPublicIdField.optional(),
354
+ response_format: responseFormatField,
355
+ },
356
+ annotations: READ,
357
+ },
358
+ async ({ id, board, response_format }) =>
359
+ safeRun(async () => {
360
+ const data = await makeApiRequest(`/cards/${id}/metrics`, { query: { board } });
361
+ const text =
362
+ response_format === ResponseFormat.JSON
363
+ ? toJsonString(data)
364
+ : `# Metrics for card ${id}\n${toJsonString(data)}`;
365
+ return { content: [{ type: 'text', text }], structuredContent: data };
366
+ })
367
+ );
368
+
369
+ server.registerTool(
370
+ 'kanbanzone_search_cards',
371
+ {
372
+ title: 'Search cards by title or number',
373
+ description: [
374
+ 'Full-text search across cards in your organization. Matches card titles and card numbers.',
375
+ 'Task, comment, and attachment text are not searched in this version.',
376
+ 'Results are sorted by relevance (best match first).',
377
+ '',
378
+ 'Mirror cards: results are returned per (card, board) pair — a card mirrored to two',
379
+ 'boards that matches the query appears twice, each with that board\'s bucket, label,',
380
+ 'owner, and watchers. Use the returned `board` field to know which board to act on.',
381
+ '',
382
+ 'Args:',
383
+ ' - q (string, required): search text, minimum 2 characters.',
384
+ ' - board (string, optional): board publicId to narrow the search to one board. Omit to search across every board in the org.',
385
+ ' - include_archived (boolean, optional): include archived cards.',
386
+ ' - page (number, optional, default 1).',
387
+ ' - count (number, optional, default 20, max 100).',
388
+ ' - response_format ("markdown" | "json").',
389
+ '',
390
+ 'Examples:',
391
+ ' - "Search for cards mentioning billing"',
392
+ ' - "Find cards about webhook on the OeMrbG8g board"',
393
+ ].join('\n'),
394
+ inputSchema: {
395
+ q: z.string().min(2).describe('Search text (min 2 characters).'),
396
+ board: boardPublicIdField.optional(),
397
+ include_archived: z.boolean().optional(),
398
+ page: pageField,
399
+ count: countField,
400
+ response_format: responseFormatField,
401
+ },
402
+ annotations: READ,
403
+ },
404
+ async ({ q, board, include_archived, page, count, response_format }) =>
405
+ safeRun(async () => {
406
+ const data = await makeApiRequest('/cards/search', {
407
+ query: {
408
+ q,
409
+ board,
410
+ includeArchived: include_archived ? 'true' : undefined,
411
+ page,
412
+ count,
413
+ },
414
+ });
415
+
416
+ const items = data.items || [];
417
+ const total = typeof data.total === 'number' ? data.total : items.length;
418
+ const hasMore = data.has_more === true;
419
+
420
+ if (response_format === ResponseFormat.JSON) {
421
+ return {
422
+ content: [{ type: 'text', text: toJsonString(data) }],
423
+ structuredContent: data,
424
+ };
425
+ }
426
+
427
+ const rerender = list =>
428
+ [
429
+ `# Search results for "${q}" (page ${page}, ${list.length} of ${total})`,
430
+ '',
431
+ ...list.map(renderCardLine),
432
+ hasMore ? `\n_More results available — call again with \`page: ${page + 1}\`._` : '',
433
+ ]
434
+ .filter(Boolean)
435
+ .join('\n');
436
+
437
+ const { text } = truncateIfNeeded({ items, rendered: rerender(items), rerender });
438
+
439
+ return {
440
+ content: [{ type: 'text', text }],
441
+ structuredContent: data,
442
+ };
443
+ })
444
+ );
445
+ };
446
+
447
+ module.exports = { registerCardsTools };
@@ -0,0 +1,150 @@
1
+ const { z } = require('zod');
2
+ const { makeApiRequest, safeRun } = require('../client');
3
+ const { responseFormatField, ResponseFormat, toJsonString, truncateIfNeeded } = require('../format');
4
+ const { objectIdField } = require('../schemas');
5
+
6
+ const READ = { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true };
7
+ const WRITE = { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true };
8
+ const IDEMPOTENT_WRITE = { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true };
9
+
10
+ const registerChecklistsTools = server => {
11
+ server.registerTool(
12
+ 'kanbanzone_create_checklist',
13
+ {
14
+ title: 'Create a checklist on a card',
15
+ description: [
16
+ 'Create a checklist on a card. Optionally pre-populate it with tasks in one call.',
17
+ '',
18
+ 'Args:',
19
+ ' - card (string, required): card ObjectId.',
20
+ ' - title (string, optional): checklist title.',
21
+ ' - checklistTemplate (string, optional): checklist template ObjectId.',
22
+ ' - tasks (array, optional): list of { description: string }. Task position is taken from array index — any `position` field on a task is ignored.',
23
+ '',
24
+ 'Examples:',
25
+ ' - "Add a checklist to card 670... with tasks: write tests, update docs"',
26
+ ' - "Apply checklist template 660... to card 670..."',
27
+ ].join('\n'),
28
+ inputSchema: {
29
+ card: objectIdField,
30
+ title: z.string().max(200).optional(),
31
+ checklistTemplate: objectIdField.optional(),
32
+ tasks: z
33
+ .array(
34
+ z.object({
35
+ description: z.string().min(1).max(2000),
36
+ })
37
+ )
38
+ .optional(),
39
+ },
40
+ annotations: WRITE,
41
+ },
42
+ async ({ card, title, checklistTemplate, tasks }) =>
43
+ safeRun(async () => {
44
+ const body = { card };
45
+ if (title !== undefined) body.title = title;
46
+ if (checklistTemplate !== undefined) body.checklistTemplate = checklistTemplate;
47
+ if (tasks !== undefined) body.tasks = tasks;
48
+
49
+ const data = await makeApiRequest('/checklists', { method: 'POST', body });
50
+ const taskCount = Array.isArray(data.tasks) ? data.tasks.length : 0;
51
+ return {
52
+ content: [
53
+ {
54
+ type: 'text',
55
+ text: `Created checklist **${data.title || '(untitled)'}** with ${taskCount} task(s).`,
56
+ },
57
+ ],
58
+ structuredContent: data,
59
+ };
60
+ })
61
+ );
62
+
63
+ server.registerTool(
64
+ 'kanbanzone_update_checklist',
65
+ {
66
+ title: 'Update a checklist',
67
+ description: [
68
+ 'Update title or position of a checklist on a card.',
69
+ '',
70
+ 'Args:',
71
+ ' - id (string, required): checklist ObjectId.',
72
+ ' - title (string, optional)',
73
+ ' - position (number, optional, ≥0)',
74
+ '',
75
+ 'Examples:',
76
+ ' - "Rename checklist 670... to \'QA tasks\'"',
77
+ ' - "Move checklist 670... to position 0"',
78
+ ].join('\n'),
79
+ inputSchema: {
80
+ id: objectIdField,
81
+ title: z.string().max(200).optional(),
82
+ position: z.number().int().min(0).optional(),
83
+ },
84
+ annotations: IDEMPOTENT_WRITE,
85
+ },
86
+ async ({ id, title, position }) =>
87
+ safeRun(async () => {
88
+ const updates = {};
89
+ if (title !== undefined) updates.title = title;
90
+ if (position !== undefined) updates.position = position;
91
+ const data = await makeApiRequest(`/checklists/${id}`, { method: 'PATCH', body: updates });
92
+ return {
93
+ content: [{ type: 'text', text: `Updated checklist ${id}.` }],
94
+ structuredContent: data,
95
+ };
96
+ })
97
+ );
98
+
99
+ server.registerTool(
100
+ 'kanbanzone_list_card_checklists',
101
+ {
102
+ title: 'List checklists on a card',
103
+ description: [
104
+ 'List all checklists on a card, including their tasks.',
105
+ '',
106
+ 'Args:',
107
+ ' - id (string, required): card ObjectId.',
108
+ ' - response_format ("markdown" | "json").',
109
+ '',
110
+ 'Examples:',
111
+ ' - "What checklists are on card 670... and what\'s left to do?"',
112
+ ].join('\n'),
113
+ inputSchema: {
114
+ id: objectIdField,
115
+ response_format: responseFormatField,
116
+ },
117
+ annotations: READ,
118
+ },
119
+ async ({ id, response_format }) =>
120
+ safeRun(async () => {
121
+ const data = await makeApiRequest(`/cards/${id}/checklists`);
122
+ const items = Array.isArray(data) ? data : data.checklists || [];
123
+
124
+ if (response_format === ResponseFormat.JSON) {
125
+ return {
126
+ content: [{ type: 'text', text: toJsonString(items) }],
127
+ structuredContent: { items },
128
+ };
129
+ }
130
+
131
+ const renderChecklist = checklist => {
132
+ const tasks = Array.isArray(checklist.tasks) ? checklist.tasks : [];
133
+ const lines = [`## ${checklist.title || '(untitled)'} (\`${checklist._id}\`)`];
134
+ for (const task of tasks) {
135
+ const box = task.completed ? '[x]' : '[ ]';
136
+ lines.push(`- ${box} ${task.description} (\`${task._id}\`)`);
137
+ }
138
+ return lines.join('\n');
139
+ };
140
+
141
+ const rerender = list =>
142
+ [`# Checklists on card ${id} (${list.length})`, '', ...list.map(renderChecklist)].join('\n\n');
143
+ const { text } = truncateIfNeeded({ items, rendered: rerender(items), rerender });
144
+
145
+ return { content: [{ type: 'text', text }], structuredContent: { items } };
146
+ })
147
+ );
148
+ };
149
+
150
+ module.exports = { registerChecklistsTools };
@@ -0,0 +1,87 @@
1
+ const { z } = require('zod');
2
+ const { makeApiRequest, safeRun } = require('../client');
3
+ const { responseFormatField, ResponseFormat, toJsonString, truncateIfNeeded } = require('../format');
4
+ const { objectIdField } = require('../schemas');
5
+
6
+ const READ = { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true };
7
+ const WRITE = { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true };
8
+
9
+ const renderComment = comment => {
10
+ const author = comment.author && (comment.author.email || comment.author._id);
11
+ const when = comment.createdAt ? ` _${comment.createdAt}_` : '';
12
+ const body = comment.text || comment.body || '';
13
+ return `- **${author || 'unknown'}**${when}: ${body}`;
14
+ };
15
+
16
+ const registerCommentsTools = server => {
17
+ server.registerTool(
18
+ 'kanbanzone_create_comment',
19
+ {
20
+ title: 'Create a comment on a card',
21
+ description: [
22
+ 'Add a comment to a card.',
23
+ '',
24
+ 'Args:',
25
+ ' - card (string, required): card ObjectId.',
26
+ ' - text (string, required): the comment body.',
27
+ '',
28
+ 'Examples:',
29
+ ' - "Add a comment to card 670... saying: blocked on design review"',
30
+ ].join('\n'),
31
+ inputSchema: {
32
+ card: objectIdField,
33
+ text: z.string().min(1).max(10000),
34
+ },
35
+ annotations: WRITE,
36
+ },
37
+ async ({ card, text }) =>
38
+ safeRun(async () => {
39
+ const data = await makeApiRequest('/comments', { method: 'POST', body: { card, text } });
40
+ return {
41
+ content: [{ type: 'text', text: `Comment added to card ${card}.` }],
42
+ structuredContent: data,
43
+ };
44
+ })
45
+ );
46
+
47
+ server.registerTool(
48
+ 'kanbanzone_list_card_comments',
49
+ {
50
+ title: 'List comments on a card',
51
+ description: [
52
+ 'List all comments on a card, oldest first.',
53
+ '',
54
+ 'Args:',
55
+ ' - id (string, required): card ObjectId.',
56
+ ' - response_format ("markdown" | "json").',
57
+ '',
58
+ 'Examples:',
59
+ ' - "What have people said on card 670...?"',
60
+ ].join('\n'),
61
+ inputSchema: {
62
+ id: objectIdField,
63
+ response_format: responseFormatField,
64
+ },
65
+ annotations: READ,
66
+ },
67
+ async ({ id, response_format }) =>
68
+ safeRun(async () => {
69
+ const data = await makeApiRequest(`/cards/${id}/comments`);
70
+ const items = Array.isArray(data) ? data : data.comments || [];
71
+
72
+ if (response_format === ResponseFormat.JSON) {
73
+ return {
74
+ content: [{ type: 'text', text: toJsonString(items) }],
75
+ structuredContent: { items },
76
+ };
77
+ }
78
+
79
+ const rerender = list =>
80
+ [`# Comments on card ${id} (${list.length})`, '', ...list.map(renderComment)].join('\n');
81
+ const { text } = truncateIfNeeded({ items, rendered: rerender(items), rerender });
82
+ return { content: [{ type: 'text', text }], structuredContent: { items } };
83
+ })
84
+ );
85
+ };
86
+
87
+ module.exports = { registerCommentsTools };