@opsee/mcp-server 0.9.31 → 0.9.33

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.
@@ -1,712 +1,18 @@
1
- import { z } from "zod";
2
- import { create } from "@bufbuild/protobuf";
3
1
  import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
4
2
  import type { ApiClients } from "../client/api.js";
5
- import { defaultPagination } from "../client/api.js";
6
- import { authManager } from "../auth/manager.js";
7
- import {
8
- formatTaskList,
9
- formatTask,
10
- formatTaskDependencyList,
11
- formatCommentList,
12
- formatTaskLabelList,
13
- formatError,
14
- } from "../utils/format.js";
15
- import {
16
- FilterOptionsSchema,
17
- FilterSchema,
18
- } from "../../gen/api/v1/filter_pb.js";
3
+ import { registerTaskReadWriteTools } from "./tasks-read-write.js";
4
+ import { registerTaskBulkTools } from "./tasks-bulk.js";
5
+ import { registerTaskRelationTools } from "./tasks-relations.js";
6
+ import { registerTaskDeleteTools } from "./tasks-delete.js";
19
7
 
8
+ // Registration order is the order tools/list reports, so keep the groups in
9
+ // the sequence clients have been seeing.
20
10
  export function registerTaskTools(
21
11
  server: McpServer,
22
12
  getClients: () => ApiClients,
23
13
  ): void {
24
- server.tool(
25
- "opsee_list_tasks",
26
- "List tasks in an Opsee project. Supports filtering by status, assignee, board column, cycle, labels, priority, type, milestone, parent, due date, and update/create recency. labelIds uses AND semantics; multi-id filters (priorityIds/taskTypeIds/milestoneIds) use OR semantics. Supports sorting via sortBy (created_at|updated_at|due_date|priority|title|id|display_order) and sortDir (asc|desc).",
27
- {
28
- projectId: z.number().int().min(1).describe("The project ID"),
29
- columnId: z.number().int().min(1).optional().describe("Filter by board column ID (status)"),
30
- assigneeId: z.number().int().min(1).optional().describe("Filter by assigned user ID"),
31
- cycleId: z.number().int().min(1).optional().describe("Filter by cycle/sprint ID"),
32
- labelIds: z.array(z.number().int().min(1)).optional().describe("Filter by label IDs (AND semantics — task must have all listed labels)"),
33
- priorityIds: z.array(z.number().int().min(1)).optional().describe("Filter by one or more priority IDs (OR semantics)"),
34
- taskTypeIds: z.array(z.number().int().min(1)).optional().describe("Filter by one or more task type IDs (OR semantics)"),
35
- milestoneIds: z.array(z.number().int().min(1)).optional().describe("Filter by one or more milestone IDs (OR semantics)"),
36
- parentTaskId: z.number().int().min(1).optional().describe("Filter to subtasks of this task ID"),
37
- hasParent: z.boolean().optional().describe("true = only subtasks, false = only top-level tasks"),
38
- unassigned: z.boolean().optional().describe("true = only unassigned tasks (triage queue)"),
39
- updatedSince: z.string().optional().describe("Only tasks updated at or after this timestamp (RFC3339 or YYYY-MM-DD)"),
40
- createdSince: z.string().optional().describe("Only tasks created at or after this timestamp (RFC3339 or YYYY-MM-DD)"),
41
- dueBefore: z.string().optional().describe("Only tasks due at or before this date (RFC3339 or YYYY-MM-DD)"),
42
- dueAfter: z.string().optional().describe("Only tasks due at or after this date (RFC3339 or YYYY-MM-DD)"),
43
- sortBy: z.enum(["created_at", "updated_at", "due_date", "priority", "title", "id", "display_order"]).optional().describe("Sort column. NULLs sort last."),
44
- sortDir: z.enum(["asc", "desc"]).optional().describe("Sort direction (default: desc)"),
45
- page: z.number().int().min(1).optional().describe("Page number (default: 1)"),
46
- pageSize: z.number().int().min(1).optional().describe("Items per page (default: 50)"),
47
- },
48
- { readOnlyHint: true, destructiveHint: false },
49
- async ({
50
- projectId, columnId, assigneeId, cycleId, labelIds,
51
- priorityIds, taskTypeIds, milestoneIds, parentTaskId, hasParent,
52
- unassigned, updatedSince, createdSince, dueBefore, dueAfter,
53
- sortBy, sortDir, page, pageSize,
54
- }) => {
55
- try {
56
- const clients = getClients();
57
-
58
- const filters: Array<{ key: string; value: string }> = [];
59
- if (columnId) filters.push({ key: "BoardColumnId", value: String(columnId) });
60
- if (assigneeId) filters.push({ key: "AssignedUserId", value: String(assigneeId) });
61
- if (cycleId) filters.push({ key: "CycleId", value: String(cycleId) });
62
- if (priorityIds?.length) filters.push({ key: "TaskPriorityId", value: priorityIds.join(",") });
63
- if (taskTypeIds?.length) filters.push({ key: "TaskTypeId", value: taskTypeIds.join(",") });
64
- if (milestoneIds?.length) filters.push({ key: "MilestoneId", value: milestoneIds.join(",") });
65
- if (parentTaskId) filters.push({ key: "ParentTaskId", value: String(parentTaskId) });
66
- if (hasParent !== undefined) filters.push({ key: "HasParent", value: hasParent ? "true" : "false" });
67
- if (unassigned) filters.push({ key: "Unassigned", value: "true" });
68
- if (updatedSince) filters.push({ key: "UpdatedSince", value: updatedSince });
69
- if (createdSince) filters.push({ key: "CreatedSince", value: createdSince });
70
- if (dueBefore) filters.push({ key: "DueBefore", value: dueBefore });
71
- if (dueAfter) filters.push({ key: "DueAfter", value: dueAfter });
72
-
73
- const filterOptions = filters.length > 0
74
- ? create(FilterOptionsSchema, {
75
- filters: filters.map((f) => create(FilterSchema, f)),
76
- })
77
- : undefined;
78
-
79
- const res = await clients.tasks.getTasks({
80
- projectId,
81
- pagination: defaultPagination(page || 1, pageSize || 50),
82
- filterOptions,
83
- labelIds: labelIds ?? [],
84
- sortBy,
85
- sortDir,
86
- });
87
-
88
- const pagination = res.pagination;
89
- const currentPage = page || 1;
90
- const hasMore = (pagination?.nextPage ?? 0) > 0;
91
-
92
- return {
93
- content: [{
94
- type: "text",
95
- text: formatTaskList(res.tasks, {
96
- totalCount: pagination?.total,
97
- page: currentPage,
98
- hasMore,
99
- nextPage: hasMore ? currentPage + 1 : undefined,
100
- }),
101
- }],
102
- };
103
- } catch (error) {
104
- return { content: [{ type: "text", text: formatError(error) }], isError: true };
105
- }
106
- },
107
- );
108
-
109
- server.tool(
110
- "opsee_get_task",
111
- "Get full details of a specific task by ID.",
112
- { taskId: z.number().int().min(1).describe("The task ID") },
113
- { readOnlyHint: true, destructiveHint: false },
114
- async ({ taskId }) => {
115
- try {
116
- const clients = getClients();
117
- const res = await clients.tasks.getTask({ id: taskId });
118
- if (!res.task) return { content: [{ type: "text", text: "Task not found. Use opsee_list_tasks to see available tasks." }] };
119
- return { content: [{ type: "text", text: formatTask(res.task, { full: true }) }] };
120
- } catch (error) {
121
- return { content: [{ type: "text", text: formatError(error) }], isError: true };
122
- }
123
- },
124
- );
125
-
126
- server.tool(
127
- "opsee_get_task_with_context",
128
- "One-shot composer that returns a task plus all its related context: labels, comments, dependencies (both directions), parent task, and subtasks. Use this when picking up a ticket — saves ~5 round-trips compared to calling each tool separately.",
129
- { taskId: z.number().int().min(1).describe("The task ID") },
130
- { readOnlyHint: true, destructiveHint: false },
131
- async ({ taskId }) => {
132
- try {
133
- const clients = getClients();
134
-
135
- const taskRes = await clients.tasks.getTask({ id: taskId });
136
- const task = taskRes.task;
137
- if (!task) {
138
- return { content: [{ type: "text", text: "Task not found. Use opsee_list_tasks to see available tasks." }] };
139
- }
140
-
141
- const [labelsRes, depsRes, commentsRes, subtasksRes, parentRes] = await Promise.all([
142
- clients.taskLabels.getTaskLabels({
143
- taskId,
144
- pagination: defaultPagination(1, 50),
145
- }),
146
- clients.taskDependencies.getTaskDependencies({
147
- taskId,
148
- pagination: defaultPagination(1, 50),
149
- }),
150
- clients.comments.getComments({
151
- taskId,
152
- pagination: defaultPagination(1, 50),
153
- }),
154
- clients.tasks.getTasks({
155
- projectId: task.project?.id ?? 0,
156
- pagination: defaultPagination(1, 50),
157
- filterOptions: create(FilterOptionsSchema, {
158
- filters: [
159
- create(FilterSchema, { key: "ParentTaskId", value: String(task.id) }),
160
- ],
161
- }),
162
- }),
163
- task.parentTaskId
164
- ? clients.tasks.getTask({ id: task.parentTaskId })
165
- : Promise.resolve(null),
166
- ]);
167
-
168
- const sections: string[] = [];
169
- sections.push(formatTask(task, { full: true }));
170
-
171
- const parentTask = parentRes?.task;
172
- if (parentTask) {
173
- sections.push(`\n--- Parent Task ---\n[${parentTask.identifier}] ${parentTask.title} (ID: ${parentTask.id})`);
174
- }
175
-
176
- sections.push(`\n--- Labels ---\n${formatTaskLabelList(labelsRes.taskLabels)}`);
177
- sections.push(`\n--- Dependencies ---\n${formatTaskDependencyList(depsRes.taskDependencies)}`);
178
- sections.push(`\n--- Subtasks ---\n${formatTaskList(subtasksRes.tasks)}`);
179
- sections.push(`\n--- Comments ---\n${formatCommentList(commentsRes.comments)}`);
180
-
181
- return { content: [{ type: "text", text: sections.join("\n") }] };
182
- } catch (error) {
183
- return { content: [{ type: "text", text: formatError(error) }], isError: true };
184
- }
185
- },
186
- );
187
-
188
- server.tool(
189
- "opsee_create_task",
190
- "Create a new task in an Opsee project. Use opsee_list_task_types, opsee_list_task_priorities, and opsee_list_board_columns first to get valid values for optional fields.",
191
- {
192
- projectId: z.number().int().min(1).describe("The project ID"),
193
- title: z.string().describe("Task title"),
194
- description: z.string().optional().describe("Task description. Markdown is supported — headings (##), bullets (-), code fences, inline **bold** / *italic* / `code` / links all render as proper formatted blocks in the UI. For ACCEPTANCE CRITERIA, write them inline in this description as a `## Acceptance criteria` heading followed by markdown checkbox lines: `- [ ] criterion text` and `- [x] done item`. The UI renders those as clickable checkboxes (BlockNote checkListItem) and users can toggle them. Do NOT use the structured opsee_add_acceptance_criterion tool for typical AC — it writes to a separate DB table that does not surface in the task detail UI; it's reserved for automation paths (PR-to-criterion mapping etc.). Written as-is to the backend; the frontend BlockEditor parses markdown on read and saves the parsed BlockNote JSON on the next edit, so the round-trip preserves structure."),
195
- taskTypeId: z.number().int().min(1).optional().describe("Task type ID (from opsee_list_task_types)"),
196
- priorityId: z.number().int().min(1).optional().describe("Priority ID (from opsee_list_task_priorities)"),
197
- boardColumnId: z.number().int().min(1).optional().describe("Board column ID (from opsee_list_board_columns)"),
198
- assigneeId: z.number().int().min(1).optional().describe("Assigned user ID"),
199
- cycleId: z.number().int().min(1).optional().describe("Cycle/sprint ID"),
200
- milestoneId: z.number().int().min(1).optional().describe("Milestone ID — attaches this task to the milestone."),
201
- parentTaskId: z.number().int().min(1).optional().describe("Parent task ID — makes this task a subtask of the given task."),
202
- storyPoints: z.number().int().min(1).optional().describe("Story points estimate (positive integer)"),
203
- estimatedHours: z.number().min(0).optional().describe("Estimated effort in hours"),
204
- labelIds: z.array(z.number().int().min(1)).optional().describe("Label IDs to attach to the new task. Saves a follow-up opsee_attach_label_to_task call per label."),
205
- },
206
- { readOnlyHint: false, destructiveHint: false },
207
- async ({ projectId, title, description, taskTypeId, priorityId, boardColumnId, assigneeId, cycleId, milestoneId, parentTaskId, storyPoints, estimatedHours, labelIds }) => {
208
- try {
209
- const clients = getClients();
210
-
211
- // Auto-resolve defaults
212
- let resolvedBoardId = 0;
213
- let resolvedColumnId = boardColumnId || 0;
214
- let resolvedTaskTypeId = taskTypeId || 0;
215
- let resolvedPriorityId = priorityId || 0;
216
-
217
- // Get default board
218
- const boardsRes = await clients.boards.getBoards({ projectId });
219
- if (boardsRes.boards?.length) {
220
- resolvedBoardId = boardsRes.boards[0].id;
221
-
222
- // Get first column if not specified
223
- if (!boardColumnId) {
224
- const colsRes = await clients.boardColumns.getBoardColumns({
225
- boardId: resolvedBoardId,
226
- });
227
- if (colsRes.boardColumns?.length) {
228
- resolvedColumnId = colsRes.boardColumns[0].id;
229
- }
230
- }
231
- }
232
-
233
- // Get first task type if not specified
234
- if (!taskTypeId) {
235
- const typesRes = await clients.taskTypes.getTaskTypes({ projectId });
236
- if (typesRes.taskTypes?.length) {
237
- resolvedTaskTypeId = typesRes.taskTypes[0].id;
238
- }
239
- }
240
-
241
- // Get first priority if not specified
242
- if (!priorityId) {
243
- const priRes = await clients.taskPriorities.getTaskPriorities({ projectId });
244
- if (priRes.taskPriorities?.length) {
245
- resolvedPriorityId = priRes.taskPriorities[0].id;
246
- }
247
- }
248
-
249
- // Get reporter (current user)
250
- let reporterUserId = 0;
251
- const userId = authManager.getUserId();
252
- if (userId) {
253
- reporterUserId = Number(userId);
254
- }
255
- if (!reporterUserId) {
256
- const meRes = await clients.users.getMe({});
257
- if (meRes.user) reporterUserId = meRes.user.id;
258
- }
259
-
260
- const res = await clients.tasks.addTask({
261
- projectId,
262
- title,
263
- description,
264
- boardId: resolvedBoardId,
265
- boardColumnId: resolvedColumnId,
266
- taskTypeId: resolvedTaskTypeId,
267
- taskPriorityId: resolvedPriorityId,
268
- reporterUserId,
269
- assignedUserId: assigneeId,
270
- parentTaskId,
271
- displayOrder: "",
272
- aiModeEnabled: false,
273
- cycleId,
274
- milestoneId,
275
- storyPoints,
276
- estimatedHours,
277
- repositoryIds: [],
278
- labelIds: labelIds ?? [],
279
- });
280
-
281
- if (!res.task)
282
- return { content: [{ type: "text", text: "Failed to create task. The backend returned an empty response (no error). Retry; if it persists, surface the call to the Opsee team." }], isError: true };
283
-
284
- return {
285
- content: [
286
- { type: "text", text: `Task created:\n${formatTask(res.task, { full: true })}` },
287
- ],
288
- };
289
- } catch (error) {
290
- return { content: [{ type: "text", text: formatError(error) }], isError: true };
291
- }
292
- },
293
- );
294
-
295
- server.tool(
296
- "opsee_update_task",
297
- "Update a task's fields (patch semantics - only provided fields are changed). Fetches the current task first, merges your changes, and sends the full update.",
298
- {
299
- taskId: z.number().int().min(1).describe("The task ID to update"),
300
- title: z.string().optional().describe("New title"),
301
- description: z.string().optional().describe("New description. Markdown is supported — headings (##), bullets (-), code fences, inline **bold** / *italic* / `code` / links all render as proper formatted blocks in the UI. For ACCEPTANCE CRITERIA, write them inline in this description as a `## Acceptance criteria` heading followed by markdown checkbox lines: `- [ ] criterion text` and `- [x] done item`. The UI renders those as clickable checkboxes (BlockNote checkListItem) and users can toggle them. Do NOT use the structured opsee_add_acceptance_criterion tool for typical AC — it writes to a separate DB table that does not surface in the task detail UI; it's reserved for automation paths (PR-to-criterion mapping etc.). Written as-is to the backend; the frontend BlockEditor parses markdown on read and saves the parsed BlockNote JSON on the next edit, so the round-trip preserves structure."),
302
- taskTypeId: z.number().int().min(1).optional().describe("New task type ID"),
303
- priorityId: z.number().int().min(1).optional().describe("New priority ID"),
304
- boardColumnId: z.number().int().min(1).optional().describe("New board column ID (status)"),
305
- assigneeId: z.number().int().min(1).optional().describe("New assigned user ID"),
306
- cycleId: z.number().int().min(1).optional().describe("New cycle/sprint ID"),
307
- milestoneId: z.number().int().min(0).optional().describe("New milestone ID (0 detaches from the current milestone)."),
308
- parentTaskId: z.number().int().min(0).optional().describe("New parent task ID (0 clears the parent and promotes to a top-level task)."),
309
- storyPoints: z.number().int().min(1).optional().describe("Story points estimate (positive integer)"),
310
- estimatedHours: z.number().min(0).optional().describe("Estimated effort in hours"),
311
- labelIds: z.array(z.number().int().min(0)).optional().describe("Replace this task's labels with this set. Omit to leave labels unchanged. Empty array clears all labels."),
312
- initiativeId: z.number().int().min(0).optional().describe("Initiative ID to link this task to. >0 links the task to that Initiative, 0 detaches."),
313
- },
314
- { readOnlyHint: false, destructiveHint: false },
315
- async ({ taskId, title, description, taskTypeId, priorityId, boardColumnId, assigneeId, cycleId, milestoneId, parentTaskId, storyPoints, estimatedHours, labelIds, initiativeId }) => {
316
- try {
317
- const clients = getClients();
318
-
319
- // Read current task
320
- const getRes = await clients.tasks.getTask({ id: taskId });
321
- const task = getRes.task;
322
- if (!task)
323
- return { content: [{ type: "text", text: "Task not found. Use opsee_list_tasks to see available tasks." }] };
324
-
325
- // Merge changes into full EditTaskRequest
326
- const res = await clients.tasks.editTask({
327
- id: task.id,
328
- identifier: task.identifier,
329
- title: title ?? task.title,
330
- description: description ?? task.description,
331
- displayOrder: task.displayOrder,
332
- storyPoints: storyPoints ?? task.storyPoints,
333
- estimatedHours: estimatedHours ?? task.estimatedHours,
334
- actualHours: task.actualHours,
335
- dueDate: task.dueDate,
336
- aiModeEnabled: task.aiModeEnabled,
337
- metadataJson: task.metadataJson,
338
- boardId: task.board?.id ?? 0,
339
- boardColumnId: boardColumnId ?? task.boardColumn?.id ?? 0,
340
- projectId: task.project?.id ?? 0,
341
- taskTypeId: taskTypeId ?? task.taskType?.id ?? 0,
342
- taskPriorityId: priorityId ?? task.taskPriority?.id ?? 0,
343
- reporterUserId: task.reporterUser?.id ?? 0,
344
- assignedUserId: assigneeId ?? task.assignedUser?.id,
345
- cycleId: cycleId ?? task.cycle?.id,
346
- milestoneId: milestoneId ?? task.milestoneId,
347
- parentTaskId: parentTaskId ?? task.parentTaskId,
348
- repositoryIds: task.taskRepositories?.map((r: { id: number }) => r.id) ?? [],
349
- labelIds,
350
- initiativeId: initiativeId !== undefined ? initiativeId : task.initiativeId,
351
- });
352
-
353
- if (!res.task)
354
- return { content: [{ type: "text", text: "Failed to update task. The backend returned an empty response (no error). Retry; if it persists, surface the call to the Opsee team." }], isError: true };
355
-
356
- return {
357
- content: [
358
- { type: "text", text: `Task updated:\n${formatTask(res.task, { full: true })}` },
359
- ],
360
- };
361
- } catch (error) {
362
- return { content: [{ type: "text", text: formatError(error) }], isError: true };
363
- }
364
- },
365
- );
366
-
367
- server.tool(
368
- "opsee_bulk_update_tasks",
369
- "Atomicity: backend wraps all updates in one DB transaction. Per-task lookup failures (task not visible to your company, or unknown ID) are silently skipped — compare updated_count against taskIds.length to detect partial application. Omitted fields are not touched. labelIds with a non-empty list replaces each task's labels; empty/omitted leaves them alone.",
370
- {
371
- projectId: z.number().int().min(1).describe("Project ID - all tasks must belong to this project"),
372
- taskIds: z.array(z.number().int().min(1)).min(1).describe("Task IDs to update (at least one)"),
373
- boardColumnId: z.number().int().min(1).optional().describe("New board column ID (status)"),
374
- taskPriorityId: z.number().int().min(1).optional().describe("New priority ID"),
375
- taskTypeId: z.number().int().min(1).optional().describe("New task type ID"),
376
- assignedUserId: z.number().int().min(1).optional().describe("New assigned user ID"),
377
- cycleId: z.number().int().min(1).optional().describe("New cycle/sprint ID"),
378
- milestoneId: z.number().int().min(1).optional().describe("Milestone ID to attach every task to. Bulk only supports set, not clear — use opsee_update_task for detaching a single task."),
379
- storyPoints: z.number().int().min(1).optional().describe("Story points to set on every task"),
380
- estimatedHours: z.number().min(0).optional().describe("Estimated hours to set on every task"),
381
- parentTaskId: z.number().int().min(0).optional().describe("Parent task ID for every task (pass 0 to clear)"),
382
- labelIds: z.array(z.number().int().min(1)).optional().describe("Replace label attachments on every task with this set. Empty / omitted leaves labels untouched."),
383
- },
384
- { readOnlyHint: false, destructiveHint: false },
385
- async ({ projectId, taskIds, boardColumnId, taskPriorityId, taskTypeId, assignedUserId, cycleId, milestoneId, storyPoints, estimatedHours, parentTaskId, labelIds }) => {
386
- try {
387
- const clients = getClients();
388
- const res = await clients.tasks.bulkEditTasks({
389
- projectId,
390
- taskIds,
391
- boardColumnId,
392
- taskPriorityId,
393
- taskTypeId,
394
- assignedUserId,
395
- cycleId,
396
- milestoneId,
397
- storyPoints,
398
- estimatedHours,
399
- parentTaskId,
400
- repositoryIds: [],
401
- labelIds: labelIds ?? [],
402
- });
403
-
404
- const requested = taskIds.length;
405
- const updated = res.updatedCount;
406
- let text = `Updated ${updated} of ${requested} task(s).`;
407
- if (updated < requested) {
408
- text += " (Tasks not visible to your company or not found were skipped.)";
409
- }
410
- return { content: [{ type: "text", text }] };
411
- } catch (error) {
412
- return { content: [{ type: "text", text: formatError(error) }], isError: true };
413
- }
414
- },
415
- );
416
-
417
- server.tool(
418
- "opsee_bulk_move_to_cycle",
419
- "Convenience wrapper: move many tasks to the same cycle in one call. Equivalent to opsee_bulk_update_tasks with only cycleId set.",
420
- {
421
- projectId: z.number().int().min(1).describe("Project ID - all tasks must belong to this project"),
422
- taskIds: z.array(z.number().int().min(1)).min(1).describe("Task IDs to move"),
423
- cycleId: z.number().int().min(1).describe("Target cycle/sprint ID"),
424
- },
425
- { readOnlyHint: false, destructiveHint: false },
426
- async ({ projectId, taskIds, cycleId }) => {
427
- try {
428
- const clients = getClients();
429
- const res = await clients.tasks.bulkEditTasks({
430
- projectId,
431
- taskIds,
432
- cycleId,
433
- repositoryIds: [],
434
- labelIds: [],
435
- });
436
- const text = `Moved ${res.updatedCount} of ${taskIds.length} task(s) to cycle ${cycleId}.`;
437
- return { content: [{ type: "text", text }] };
438
- } catch (error) {
439
- return { content: [{ type: "text", text: formatError(error) }], isError: true };
440
- }
441
- },
442
- );
443
-
444
- server.tool(
445
- "opsee_bulk_move_to_column",
446
- "Convenience wrapper: move many tasks to the same board column (status) in one call.",
447
- {
448
- projectId: z.number().int().min(1).describe("Project ID - all tasks must belong to this project"),
449
- taskIds: z.array(z.number().int().min(1)).min(1).describe("Task IDs to move"),
450
- boardColumnId: z.number().int().min(1).describe("Target board column ID (status)"),
451
- },
452
- { readOnlyHint: false, destructiveHint: false },
453
- async ({ projectId, taskIds, boardColumnId }) => {
454
- try {
455
- const clients = getClients();
456
- const res = await clients.tasks.bulkEditTasks({
457
- projectId,
458
- taskIds,
459
- boardColumnId,
460
- repositoryIds: [],
461
- labelIds: [],
462
- });
463
- const text = `Moved ${res.updatedCount} of ${taskIds.length} task(s) to column ${boardColumnId}.`;
464
- return { content: [{ type: "text", text }] };
465
- } catch (error) {
466
- return { content: [{ type: "text", text: formatError(error) }], isError: true };
467
- }
468
- },
469
- );
470
-
471
- server.tool(
472
- "opsee_bulk_assign",
473
- "Convenience wrapper: assign many tasks to the same user in one call.",
474
- {
475
- projectId: z.number().int().min(1).describe("Project ID - all tasks must belong to this project"),
476
- taskIds: z.array(z.number().int().min(1)).min(1).describe("Task IDs to reassign"),
477
- assigneeId: z.number().int().min(1).describe("Target user ID"),
478
- },
479
- { readOnlyHint: false, destructiveHint: false },
480
- async ({ projectId, taskIds, assigneeId }) => {
481
- try {
482
- const clients = getClients();
483
- const res = await clients.tasks.bulkEditTasks({
484
- projectId,
485
- taskIds,
486
- assignedUserId: assigneeId,
487
- repositoryIds: [],
488
- labelIds: [],
489
- });
490
- const text = `Assigned ${res.updatedCount} of ${taskIds.length} task(s) to user ${assigneeId}.`;
491
- return { content: [{ type: "text", text }] };
492
- } catch (error) {
493
- return { content: [{ type: "text", text: formatError(error) }], isError: true };
494
- }
495
- },
496
- );
497
-
498
- server.tool(
499
- "opsee_bulk_set_priority",
500
- "Convenience wrapper: set the same priority on many tasks in one call.",
501
- {
502
- projectId: z.number().int().min(1).describe("Project ID - all tasks must belong to this project"),
503
- taskIds: z.array(z.number().int().min(1)).min(1).describe("Task IDs to reprioritize"),
504
- priorityId: z.number().int().min(1).describe("Target priority ID (from opsee_list_task_priorities)"),
505
- },
506
- { readOnlyHint: false, destructiveHint: false },
507
- async ({ projectId, taskIds, priorityId }) => {
508
- try {
509
- const clients = getClients();
510
- const res = await clients.tasks.bulkEditTasks({
511
- projectId,
512
- taskIds,
513
- taskPriorityId: priorityId,
514
- repositoryIds: [],
515
- labelIds: [],
516
- });
517
- const text = `Set priority ${priorityId} on ${res.updatedCount} of ${taskIds.length} task(s).`;
518
- return { content: [{ type: "text", text }] };
519
- } catch (error) {
520
- return { content: [{ type: "text", text: formatError(error) }], isError: true };
521
- }
522
- },
523
- );
524
-
525
- server.tool(
526
- "opsee_replace_task_labels",
527
- "Replace the entire set of labels on a single task. Use opsee_update_task with labelIds for the same effect, but this tool is more discoverable for the common 'set my labels to [...]' flow.",
528
- {
529
- taskId: z.number().int().min(1).describe("The task ID"),
530
- labelIds: z.array(z.number().int().min(1)).describe("Label IDs to set (empty array clears all labels)"),
531
- },
532
- { readOnlyHint: false, destructiveHint: false },
533
- async ({ taskId, labelIds }) => {
534
- try {
535
- const clients = getClients();
536
- const getRes = await clients.tasks.getTask({ id: taskId });
537
- const task = getRes.task;
538
- if (!task) {
539
- return { content: [{ type: "text", text: "Task not found." }] };
540
- }
541
- const res = await clients.tasks.editTask({
542
- id: task.id,
543
- identifier: task.identifier,
544
- title: task.title,
545
- description: task.description,
546
- displayOrder: task.displayOrder,
547
- storyPoints: task.storyPoints,
548
- estimatedHours: task.estimatedHours,
549
- actualHours: task.actualHours,
550
- dueDate: task.dueDate,
551
- aiModeEnabled: task.aiModeEnabled,
552
- metadataJson: task.metadataJson,
553
- boardId: task.board?.id ?? 0,
554
- boardColumnId: task.boardColumn?.id ?? 0,
555
- projectId: task.project?.id ?? 0,
556
- taskTypeId: task.taskType?.id ?? 0,
557
- taskPriorityId: task.taskPriority?.id ?? 0,
558
- reporterUserId: task.reporterUser?.id ?? 0,
559
- assignedUserId: task.assignedUser?.id,
560
- cycleId: task.cycle?.id,
561
- repositoryIds: task.taskRepositories?.map((r: { id: number }) => r.id) ?? [],
562
- labelIds,
563
- });
564
- if (!res.task) {
565
- return { content: [{ type: "text", text: "Failed to update task labels. The backend returned an empty response (no error). Retry; if it persists, surface the call to the Opsee team." }], isError: true };
566
- }
567
- const verb = labelIds.length === 0 ? "Cleared all labels on" : `Set ${labelIds.length} label(s) on`;
568
- return { content: [{ type: "text", text: `${verb} ${res.task.identifier}.` }] };
569
- } catch (error) {
570
- return { content: [{ type: "text", text: formatError(error) }], isError: true };
571
- }
572
- },
573
- );
574
-
575
- server.tool(
576
- "opsee_link_task_to_initiative",
577
- "Link an existing task to an Initiative — use this to bring an already-existing task into an initiative's scope. To create NEW tasks under an initiative, use opsee_decompose_initiative (first time) or opsee_reconcile_initiative (re-planning) instead. Fetches the task first so no other fields are blanked.",
578
- {
579
- taskId: z.number().int().min(1).describe("The task ID to link"),
580
- initiativeId: z.number().int().min(1).describe("The initiative ID to link the task to"),
581
- },
582
- { readOnlyHint: false, destructiveHint: false },
583
- async ({ taskId, initiativeId }) => {
584
- try {
585
- const clients = getClients();
586
- const getRes = await clients.tasks.getTask({ id: taskId });
587
- const task = getRes.task;
588
- if (!task)
589
- return { content: [{ type: "text", text: "Task not found. Use opsee_list_tasks to see available tasks." }] };
590
- const res = await clients.tasks.editTask({
591
- id: task.id,
592
- identifier: task.identifier,
593
- title: task.title,
594
- description: task.description,
595
- displayOrder: task.displayOrder,
596
- storyPoints: task.storyPoints,
597
- estimatedHours: task.estimatedHours,
598
- actualHours: task.actualHours,
599
- dueDate: task.dueDate,
600
- aiModeEnabled: task.aiModeEnabled,
601
- metadataJson: task.metadataJson,
602
- boardId: task.board?.id ?? 0,
603
- boardColumnId: task.boardColumn?.id ?? 0,
604
- projectId: task.project?.id ?? 0,
605
- taskTypeId: task.taskType?.id ?? 0,
606
- taskPriorityId: task.taskPriority?.id ?? 0,
607
- reporterUserId: task.reporterUser?.id ?? 0,
608
- assignedUserId: task.assignedUser?.id,
609
- cycleId: task.cycle?.id,
610
- milestoneId: task.milestoneId,
611
- parentTaskId: task.parentTaskId,
612
- repositoryIds: task.taskRepositories?.map((r: { id: number }) => r.id) ?? [],
613
- initiativeId,
614
- });
615
- if (!res.task)
616
- return { content: [{ type: "text", text: "Failed to link task. The backend returned an empty response (no error). Retry; if it persists, surface the call to the Opsee team." }], isError: true };
617
- return { content: [{ type: "text", text: `Task ${res.task.identifier} linked to initiative ${initiativeId}.` }] };
618
- } catch (error) {
619
- return { content: [{ type: "text", text: formatError(error) }], isError: true };
620
- }
621
- },
622
- );
623
-
624
- server.tool(
625
- "opsee_unlink_task_from_initiative",
626
- "Detach a task from its current Initiative. Fetches the task first so no other fields are blanked.",
627
- {
628
- taskId: z.number().int().min(1).describe("The task ID to unlink"),
629
- },
630
- { readOnlyHint: false, destructiveHint: false },
631
- async ({ taskId }) => {
632
- try {
633
- const clients = getClients();
634
- const getRes = await clients.tasks.getTask({ id: taskId });
635
- const task = getRes.task;
636
- if (!task)
637
- return { content: [{ type: "text", text: "Task not found. Use opsee_list_tasks to see available tasks." }] };
638
- const res = await clients.tasks.editTask({
639
- id: task.id,
640
- identifier: task.identifier,
641
- title: task.title,
642
- description: task.description,
643
- displayOrder: task.displayOrder,
644
- storyPoints: task.storyPoints,
645
- estimatedHours: task.estimatedHours,
646
- actualHours: task.actualHours,
647
- dueDate: task.dueDate,
648
- aiModeEnabled: task.aiModeEnabled,
649
- metadataJson: task.metadataJson,
650
- boardId: task.board?.id ?? 0,
651
- boardColumnId: task.boardColumn?.id ?? 0,
652
- projectId: task.project?.id ?? 0,
653
- taskTypeId: task.taskType?.id ?? 0,
654
- taskPriorityId: task.taskPriority?.id ?? 0,
655
- reporterUserId: task.reporterUser?.id ?? 0,
656
- assignedUserId: task.assignedUser?.id,
657
- cycleId: task.cycle?.id,
658
- milestoneId: task.milestoneId,
659
- parentTaskId: task.parentTaskId,
660
- repositoryIds: task.taskRepositories?.map((r: { id: number }) => r.id) ?? [],
661
- initiativeId: 0,
662
- });
663
- if (!res.task)
664
- return { content: [{ type: "text", text: "Failed to unlink task. The backend returned an empty response (no error). Retry; if it persists, surface the call to the Opsee team." }], isError: true };
665
- return { content: [{ type: "text", text: `Task ${res.task.identifier} unlinked from initiative.` }] };
666
- } catch (error) {
667
- return { content: [{ type: "text", text: formatError(error) }], isError: true };
668
- }
669
- },
670
- );
671
-
672
- server.tool(
673
- "opsee_delete_task",
674
- "Delete a task by ID. This is permanent.",
675
- { taskId: z.number().int().min(1).describe("The task ID to delete") },
676
- { readOnlyHint: false, destructiveHint: true },
677
- async ({ taskId }) => {
678
- try {
679
- const clients = getClients();
680
- await clients.tasks.deleteTask({ id: taskId });
681
- return { content: [{ type: "text", text: "Task deleted." }] };
682
- } catch (error) {
683
- return { content: [{ type: "text", text: formatError(error) }], isError: true };
684
- }
685
- },
686
- );
687
-
688
- server.tool(
689
- "opsee_bulk_delete_tasks",
690
- "Delete multiple tasks in one call. Tasks not visible to your company or not found are silently skipped — compare deletedCount against taskIds.length to detect partial application. This is permanent.",
691
- {
692
- projectId: z.number().int().min(1).describe("Project ID - all tasks must belong to this project"),
693
- taskIds: z.array(z.number().int().min(1)).min(1).describe("Task IDs to delete (at least one)"),
694
- },
695
- { readOnlyHint: false, destructiveHint: true },
696
- async ({ projectId, taskIds }) => {
697
- try {
698
- const clients = getClients();
699
- const res = await clients.tasks.bulkDeleteTasks({ projectId, taskIds });
700
- const requested = taskIds.length;
701
- const deleted = res.deletedCount;
702
- let text = `Deleted ${deleted} of ${requested} task(s).`;
703
- if (deleted < requested) {
704
- text += " (Tasks not visible to your company or not found were skipped.)";
705
- }
706
- return { content: [{ type: "text", text }] };
707
- } catch (error) {
708
- return { content: [{ type: "text", text: formatError(error) }], isError: true };
709
- }
710
- },
711
- );
14
+ registerTaskReadWriteTools(server, getClients);
15
+ registerTaskBulkTools(server, getClients);
16
+ registerTaskRelationTools(server, getClients);
17
+ registerTaskDeleteTools(server, getClients);
712
18
  }