@opsee/mcp-server 0.6.1 → 0.6.4

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.
@@ -4,7 +4,14 @@ import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
4
4
  import type { ApiClients } from "../client/api.js";
5
5
  import { defaultPagination } from "../client/api.js";
6
6
  import { authManager } from "../auth/manager.js";
7
- import { formatTaskList, formatTask, formatError } from "../utils/format.js";
7
+ import {
8
+ formatTaskList,
9
+ formatTask,
10
+ formatTaskDependencyList,
11
+ formatCommentList,
12
+ formatTaskLabelList,
13
+ formatError,
14
+ } from "../utils/format.js";
8
15
  import {
9
16
  FilterOptionsSchema,
10
17
  FilterSchema,
@@ -16,18 +23,35 @@ export function registerTaskTools(
16
23
  ): void {
17
24
  server.tool(
18
25
  "opsee_list_tasks",
19
- "List tasks in an Opsee project. Supports filtering by status, assignee, board column, cycle, and labels.",
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).",
20
27
  {
21
28
  projectId: z.number().describe("The project ID"),
22
29
  columnId: z.number().optional().describe("Filter by board column ID (status)"),
23
30
  assigneeId: z.number().optional().describe("Filter by assigned user ID"),
24
31
  cycleId: z.number().optional().describe("Filter by cycle/sprint ID"),
25
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)"),
26
45
  page: z.number().optional().describe("Page number (default: 1)"),
27
46
  pageSize: z.number().optional().describe("Items per page (default: 50)"),
28
47
  },
29
48
  { readOnlyHint: true, destructiveHint: false },
30
- async ({ projectId, columnId, assigneeId, cycleId, labelIds, page, pageSize }) => {
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
+ }) => {
31
55
  try {
32
56
  const clients = getClients();
33
57
 
@@ -35,6 +59,16 @@ export function registerTaskTools(
35
59
  if (columnId) filters.push({ key: "BoardColumnId", value: String(columnId) });
36
60
  if (assigneeId) filters.push({ key: "AssignedUserId", value: String(assigneeId) });
37
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 });
38
72
 
39
73
  const filterOptions = filters.length > 0
40
74
  ? create(FilterOptionsSchema, {
@@ -47,6 +81,8 @@ export function registerTaskTools(
47
81
  pagination: defaultPagination(page || 1, pageSize || 50),
48
82
  filterOptions,
49
83
  labelIds: labelIds ?? [],
84
+ sortBy,
85
+ sortDir,
50
86
  });
51
87
 
52
88
  return { content: [{ type: "text", text: formatTaskList(res.tasks) }] };
@@ -73,23 +109,88 @@ export function registerTaskTools(
73
109
  },
74
110
  );
75
111
 
112
+ server.tool(
113
+ "opsee_get_task_with_context",
114
+ "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.",
115
+ { taskId: z.number().describe("The task ID") },
116
+ { readOnlyHint: true, destructiveHint: false },
117
+ async ({ taskId }) => {
118
+ try {
119
+ const clients = getClients();
120
+
121
+ const taskRes = await clients.tasks.getTask({ id: taskId });
122
+ const task = taskRes.task;
123
+ if (!task) {
124
+ return { content: [{ type: "text", text: "Task not found. Use opsee_list_tasks to see available tasks." }] };
125
+ }
126
+
127
+ const [labelsRes, depsRes, commentsRes, subtasksRes, parentRes] = await Promise.all([
128
+ clients.taskLabels.getTaskLabels({
129
+ taskId,
130
+ pagination: defaultPagination(1, 50),
131
+ }),
132
+ clients.taskDependencies.getTaskDependencies({
133
+ taskId,
134
+ pagination: defaultPagination(1, 50),
135
+ }),
136
+ clients.comments.getComments({
137
+ taskId,
138
+ pagination: defaultPagination(1, 50),
139
+ }),
140
+ clients.tasks.getTasks({
141
+ projectId: task.project?.id ?? 0,
142
+ pagination: defaultPagination(1, 50),
143
+ filterOptions: create(FilterOptionsSchema, {
144
+ filters: [
145
+ create(FilterSchema, { key: "ParentTaskId", value: String(task.id) }),
146
+ ],
147
+ }),
148
+ }),
149
+ task.parentTaskId
150
+ ? clients.tasks.getTask({ id: task.parentTaskId })
151
+ : Promise.resolve(null),
152
+ ]);
153
+
154
+ const sections: string[] = [];
155
+ sections.push(formatTask(task));
156
+
157
+ const parentTask = parentRes?.task;
158
+ if (parentTask) {
159
+ sections.push(`\n--- Parent Task ---\n[${parentTask.identifier}] ${parentTask.title} (ID: ${parentTask.id})`);
160
+ }
161
+
162
+ sections.push(`\n--- Labels ---\n${formatTaskLabelList(labelsRes.taskLabels)}`);
163
+ sections.push(`\n--- Dependencies ---\n${formatTaskDependencyList(depsRes.taskDependencies)}`);
164
+ sections.push(`\n--- Subtasks ---\n${formatTaskList(subtasksRes.tasks)}`);
165
+ sections.push(`\n--- Comments ---\n${formatCommentList(commentsRes.comments)}`);
166
+
167
+ return { content: [{ type: "text", text: sections.join("\n") }] };
168
+ } catch (error) {
169
+ return { content: [{ type: "text", text: formatError(error) }], isError: true };
170
+ }
171
+ },
172
+ );
173
+
76
174
  server.tool(
77
175
  "opsee_create_task",
78
176
  "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.",
79
177
  {
80
178
  projectId: z.number().describe("The project ID"),
81
179
  title: z.string().describe("Task title"),
82
- description: z.string().optional().describe("Task description. Backend may transform plain text or markdown into BlockNote JSON on write; check returned task to see exact stored form. See README \"Task description format\" for details."),
180
+ 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."),
83
181
  taskTypeId: z.number().optional().describe("Task type ID (from opsee_list_task_types)"),
84
182
  priorityId: z.number().optional().describe("Priority ID (from opsee_list_task_priorities)"),
85
183
  boardColumnId: z.number().optional().describe("Board column ID (from opsee_list_board_columns)"),
86
184
  assigneeId: z.number().optional().describe("Assigned user ID"),
87
185
  cycleId: z.number().optional().describe("Cycle/sprint ID"),
186
+ milestoneId: z.number().int().min(1).optional().describe("Milestone ID — attaches this task to the milestone."),
187
+ parentTaskId: z.number().int().min(1).optional().describe("Parent task ID — makes this task a subtask of the given task."),
88
188
  storyPoints: z.number().int().min(1).optional().describe("Story points estimate (positive integer)"),
89
189
  estimatedHours: z.number().min(0).optional().describe("Estimated effort in hours"),
190
+ 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."),
90
191
  },
91
192
  { readOnlyHint: false, destructiveHint: false },
92
- async ({ projectId, title, description, taskTypeId, priorityId, boardColumnId, assigneeId, cycleId, storyPoints, estimatedHours }) => {
193
+ async ({ projectId, title, description, taskTypeId, priorityId, boardColumnId, assigneeId, cycleId, milestoneId, parentTaskId, storyPoints, estimatedHours, labelIds }) => {
93
194
  try {
94
195
  const clients = getClients();
95
196
 
@@ -152,16 +253,19 @@ export function registerTaskTools(
152
253
  taskPriorityId: resolvedPriorityId,
153
254
  reporterUserId,
154
255
  assignedUserId: assigneeId,
256
+ parentTaskId,
155
257
  displayOrder: 0,
156
258
  aiModeEnabled: false,
157
259
  cycleId,
260
+ milestoneId,
158
261
  storyPoints,
159
262
  estimatedHours,
160
263
  repositoryIds: [],
264
+ labelIds: labelIds ?? [],
161
265
  });
162
266
 
163
267
  if (!res.task)
164
- return { content: [{ type: "text", text: "Failed to create task." }] };
268
+ 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 };
165
269
 
166
270
  return {
167
271
  content: [
@@ -180,17 +284,20 @@ export function registerTaskTools(
180
284
  {
181
285
  taskId: z.number().describe("The task ID to update"),
182
286
  title: z.string().optional().describe("New title"),
183
- description: z.string().optional().describe("New description. Backend may transform plain text or markdown into BlockNote JSON on write; check returned task to see exact stored form. See README \"Task description format\" for details."),
287
+ 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."),
184
288
  taskTypeId: z.number().optional().describe("New task type ID"),
185
289
  priorityId: z.number().optional().describe("New priority ID"),
186
290
  boardColumnId: z.number().optional().describe("New board column ID (status)"),
187
291
  assigneeId: z.number().optional().describe("New assigned user ID"),
188
292
  cycleId: z.number().optional().describe("New cycle/sprint ID"),
293
+ milestoneId: z.number().int().min(0).optional().describe("New milestone ID (0 detaches from the current milestone)."),
294
+ parentTaskId: z.number().int().min(0).optional().describe("New parent task ID (0 clears the parent and promotes to a top-level task)."),
189
295
  storyPoints: z.number().int().min(1).optional().describe("Story points estimate (positive integer)"),
190
296
  estimatedHours: z.number().min(0).optional().describe("Estimated effort in hours"),
297
+ 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."),
191
298
  },
192
299
  { readOnlyHint: false, destructiveHint: false },
193
- async ({ taskId, title, description, taskTypeId, priorityId, boardColumnId, assigneeId, cycleId, storyPoints, estimatedHours }) => {
300
+ async ({ taskId, title, description, taskTypeId, priorityId, boardColumnId, assigneeId, cycleId, milestoneId, parentTaskId, storyPoints, estimatedHours, labelIds }) => {
194
301
  try {
195
302
  const clients = getClients();
196
303
 
@@ -221,11 +328,14 @@ export function registerTaskTools(
221
328
  reporterUserId: task.reporterUser?.id ?? 0,
222
329
  assignedUserId: assigneeId ?? task.assignedUser?.id,
223
330
  cycleId: cycleId ?? task.cycle?.id,
331
+ milestoneId: milestoneId ?? task.milestoneId,
332
+ parentTaskId: parentTaskId ?? task.parentTaskId,
224
333
  repositoryIds: task.taskRepositories?.map((r: { id: number }) => r.id) ?? [],
334
+ labelIds,
225
335
  });
226
336
 
227
337
  if (!res.task)
228
- return { content: [{ type: "text", text: "Failed to update task." }] };
338
+ 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 };
229
339
 
230
340
  return {
231
341
  content: [
@@ -240,7 +350,7 @@ export function registerTaskTools(
240
350
 
241
351
  server.tool(
242
352
  "opsee_bulk_update_tasks",
243
- "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.",
353
+ "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.",
244
354
  {
245
355
  projectId: z.number().describe("Project ID - all tasks must belong to this project"),
246
356
  taskIds: z.array(z.number()).min(1).describe("Task IDs to update (at least one)"),
@@ -249,9 +359,14 @@ export function registerTaskTools(
249
359
  taskTypeId: z.number().optional().describe("New task type ID"),
250
360
  assignedUserId: z.number().optional().describe("New assigned user ID"),
251
361
  cycleId: z.number().optional().describe("New cycle/sprint ID"),
362
+ 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."),
363
+ storyPoints: z.number().int().min(1).optional().describe("Story points to set on every task"),
364
+ estimatedHours: z.number().min(0).optional().describe("Estimated hours to set on every task"),
365
+ parentTaskId: z.number().int().min(0).optional().describe("Parent task ID for every task (pass 0 to clear)"),
366
+ labelIds: z.array(z.number().int().min(1)).optional().describe("Replace label attachments on every task with this set. Empty / omitted leaves labels untouched."),
252
367
  },
253
368
  { readOnlyHint: false, destructiveHint: false },
254
- async ({ projectId, taskIds, boardColumnId, taskPriorityId, taskTypeId, assignedUserId, cycleId }) => {
369
+ async ({ projectId, taskIds, boardColumnId, taskPriorityId, taskTypeId, assignedUserId, cycleId, milestoneId, storyPoints, estimatedHours, parentTaskId, labelIds }) => {
255
370
  try {
256
371
  const clients = getClients();
257
372
  const res = await clients.tasks.bulkEditTasks({
@@ -262,7 +377,12 @@ export function registerTaskTools(
262
377
  taskTypeId,
263
378
  assignedUserId,
264
379
  cycleId,
380
+ milestoneId,
381
+ storyPoints,
382
+ estimatedHours,
383
+ parentTaskId,
265
384
  repositoryIds: [],
385
+ labelIds: labelIds ?? [],
266
386
  });
267
387
 
268
388
  const requested = taskIds.length;
@@ -277,4 +397,203 @@ export function registerTaskTools(
277
397
  }
278
398
  },
279
399
  );
400
+
401
+ server.tool(
402
+ "opsee_bulk_move_to_cycle",
403
+ "Convenience wrapper: move many tasks to the same cycle in one call. Equivalent to opsee_bulk_update_tasks with only cycleId set.",
404
+ {
405
+ projectId: z.number().describe("Project ID - all tasks must belong to this project"),
406
+ taskIds: z.array(z.number()).min(1).describe("Task IDs to move"),
407
+ cycleId: z.number().describe("Target cycle/sprint ID"),
408
+ },
409
+ { readOnlyHint: false, destructiveHint: false },
410
+ async ({ projectId, taskIds, cycleId }) => {
411
+ try {
412
+ const clients = getClients();
413
+ const res = await clients.tasks.bulkEditTasks({
414
+ projectId,
415
+ taskIds,
416
+ cycleId,
417
+ repositoryIds: [],
418
+ labelIds: [],
419
+ });
420
+ const text = `Moved ${res.updatedCount} of ${taskIds.length} task(s) to cycle ${cycleId}.`;
421
+ return { content: [{ type: "text", text }] };
422
+ } catch (error) {
423
+ return { content: [{ type: "text", text: formatError(error) }], isError: true };
424
+ }
425
+ },
426
+ );
427
+
428
+ server.tool(
429
+ "opsee_bulk_move_to_column",
430
+ "Convenience wrapper: move many tasks to the same board column (status) in one call.",
431
+ {
432
+ projectId: z.number().describe("Project ID - all tasks must belong to this project"),
433
+ taskIds: z.array(z.number()).min(1).describe("Task IDs to move"),
434
+ boardColumnId: z.number().describe("Target board column ID (status)"),
435
+ },
436
+ { readOnlyHint: false, destructiveHint: false },
437
+ async ({ projectId, taskIds, boardColumnId }) => {
438
+ try {
439
+ const clients = getClients();
440
+ const res = await clients.tasks.bulkEditTasks({
441
+ projectId,
442
+ taskIds,
443
+ boardColumnId,
444
+ repositoryIds: [],
445
+ labelIds: [],
446
+ });
447
+ const text = `Moved ${res.updatedCount} of ${taskIds.length} task(s) to column ${boardColumnId}.`;
448
+ return { content: [{ type: "text", text }] };
449
+ } catch (error) {
450
+ return { content: [{ type: "text", text: formatError(error) }], isError: true };
451
+ }
452
+ },
453
+ );
454
+
455
+ server.tool(
456
+ "opsee_bulk_assign",
457
+ "Convenience wrapper: assign many tasks to the same user in one call.",
458
+ {
459
+ projectId: z.number().describe("Project ID - all tasks must belong to this project"),
460
+ taskIds: z.array(z.number()).min(1).describe("Task IDs to reassign"),
461
+ assigneeId: z.number().describe("Target user ID"),
462
+ },
463
+ { readOnlyHint: false, destructiveHint: false },
464
+ async ({ projectId, taskIds, assigneeId }) => {
465
+ try {
466
+ const clients = getClients();
467
+ const res = await clients.tasks.bulkEditTasks({
468
+ projectId,
469
+ taskIds,
470
+ assignedUserId: assigneeId,
471
+ repositoryIds: [],
472
+ labelIds: [],
473
+ });
474
+ const text = `Assigned ${res.updatedCount} of ${taskIds.length} task(s) to user ${assigneeId}.`;
475
+ return { content: [{ type: "text", text }] };
476
+ } catch (error) {
477
+ return { content: [{ type: "text", text: formatError(error) }], isError: true };
478
+ }
479
+ },
480
+ );
481
+
482
+ server.tool(
483
+ "opsee_bulk_set_priority",
484
+ "Convenience wrapper: set the same priority on many tasks in one call.",
485
+ {
486
+ projectId: z.number().describe("Project ID - all tasks must belong to this project"),
487
+ taskIds: z.array(z.number()).min(1).describe("Task IDs to reprioritize"),
488
+ priorityId: z.number().describe("Target priority ID (from opsee_list_task_priorities)"),
489
+ },
490
+ { readOnlyHint: false, destructiveHint: false },
491
+ async ({ projectId, taskIds, priorityId }) => {
492
+ try {
493
+ const clients = getClients();
494
+ const res = await clients.tasks.bulkEditTasks({
495
+ projectId,
496
+ taskIds,
497
+ taskPriorityId: priorityId,
498
+ repositoryIds: [],
499
+ labelIds: [],
500
+ });
501
+ const text = `Set priority ${priorityId} on ${res.updatedCount} of ${taskIds.length} task(s).`;
502
+ return { content: [{ type: "text", text }] };
503
+ } catch (error) {
504
+ return { content: [{ type: "text", text: formatError(error) }], isError: true };
505
+ }
506
+ },
507
+ );
508
+
509
+ server.tool(
510
+ "opsee_replace_task_labels",
511
+ "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.",
512
+ {
513
+ taskId: z.number().describe("The task ID"),
514
+ labelIds: z.array(z.number().int().min(1)).describe("Label IDs to set (empty array clears all labels)"),
515
+ },
516
+ { readOnlyHint: false, destructiveHint: false },
517
+ async ({ taskId, labelIds }) => {
518
+ try {
519
+ const clients = getClients();
520
+ const getRes = await clients.tasks.getTask({ id: taskId });
521
+ const task = getRes.task;
522
+ if (!task) {
523
+ return { content: [{ type: "text", text: "Task not found." }] };
524
+ }
525
+ const res = await clients.tasks.editTask({
526
+ id: task.id,
527
+ identifier: task.identifier,
528
+ title: task.title,
529
+ description: task.description,
530
+ displayOrder: task.displayOrder,
531
+ storyPoints: task.storyPoints,
532
+ estimatedHours: task.estimatedHours,
533
+ actualHours: task.actualHours,
534
+ dueDate: task.dueDate,
535
+ aiModeEnabled: task.aiModeEnabled,
536
+ metadataJson: task.metadataJson,
537
+ boardId: task.board?.id ?? 0,
538
+ boardColumnId: task.boardColumn?.id ?? 0,
539
+ projectId: task.project?.id ?? 0,
540
+ taskTypeId: task.taskType?.id ?? 0,
541
+ taskPriorityId: task.taskPriority?.id ?? 0,
542
+ reporterUserId: task.reporterUser?.id ?? 0,
543
+ assignedUserId: task.assignedUser?.id,
544
+ cycleId: task.cycle?.id,
545
+ repositoryIds: task.taskRepositories?.map((r: { id: number }) => r.id) ?? [],
546
+ labelIds,
547
+ });
548
+ if (!res.task) {
549
+ 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 };
550
+ }
551
+ const verb = labelIds.length === 0 ? "Cleared all labels on" : `Set ${labelIds.length} label(s) on`;
552
+ return { content: [{ type: "text", text: `${verb} ${res.task.identifier}.` }] };
553
+ } catch (error) {
554
+ return { content: [{ type: "text", text: formatError(error) }], isError: true };
555
+ }
556
+ },
557
+ );
558
+
559
+ server.tool(
560
+ "opsee_delete_task",
561
+ "Delete a task by ID. This is permanent.",
562
+ { taskId: z.number().describe("The task ID to delete") },
563
+ { readOnlyHint: false, destructiveHint: true },
564
+ async ({ taskId }) => {
565
+ try {
566
+ const clients = getClients();
567
+ await clients.tasks.deleteTask({ id: taskId });
568
+ return { content: [{ type: "text", text: "Task deleted." }] };
569
+ } catch (error) {
570
+ return { content: [{ type: "text", text: formatError(error) }], isError: true };
571
+ }
572
+ },
573
+ );
574
+
575
+ server.tool(
576
+ "opsee_bulk_delete_tasks",
577
+ "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.",
578
+ {
579
+ projectId: z.number().describe("Project ID - all tasks must belong to this project"),
580
+ taskIds: z.array(z.number()).min(1).describe("Task IDs to delete (at least one)"),
581
+ },
582
+ { readOnlyHint: false, destructiveHint: true },
583
+ async ({ projectId, taskIds }) => {
584
+ try {
585
+ const clients = getClients();
586
+ const res = await clients.tasks.bulkDeleteTasks({ projectId, taskIds });
587
+ const requested = taskIds.length;
588
+ const deleted = res.deletedCount;
589
+ let text = `Deleted ${deleted} of ${requested} task(s).`;
590
+ if (deleted < requested) {
591
+ text += " (Tasks not visible to your company or not found were skipped.)";
592
+ }
593
+ return { content: [{ type: "text", text }] };
594
+ } catch (error) {
595
+ return { content: [{ type: "text", text: formatError(error) }], isError: true };
596
+ }
597
+ },
598
+ );
280
599
  }
@@ -0,0 +1,123 @@
1
+ import { z } from "zod";
2
+ import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
+ import type { ApiClients } from "../client/api.js";
4
+ import { formatError } from "../utils/format.js";
5
+
6
+ // Work log RPCs live on TaskService (AddWorkLog / DeleteWorkLog). There is
7
+ // no list endpoint — work logs are preloaded onto the Task by GetTask, so
8
+ // we surface them by hitting GetTask and projecting the embedded work_logs.
9
+
10
+ export function registerWorkLogTools(
11
+ server: McpServer,
12
+ getClients: () => ApiClients,
13
+ ): void {
14
+ server.tool(
15
+ "opsee_list_work_logs",
16
+ "List all work-log entries for a task, oldest first. Includes the user who logged each entry, hours, and optional description.",
17
+ { taskId: z.number().describe("The task ID") },
18
+ { readOnlyHint: true, destructiveHint: false },
19
+ async ({ taskId }) => {
20
+ try {
21
+ const clients = getClients();
22
+ const res = await clients.tasks.getTask({ id: taskId });
23
+ const task = res.task;
24
+ if (!task) {
25
+ return { content: [{ type: "text", text: "Task not found." }] };
26
+ }
27
+ const logs = task.workLogs ?? [];
28
+ if (logs.length === 0) {
29
+ return { content: [{ type: "text", text: `No work logs on ${task.identifier}.` }] };
30
+ }
31
+ const lines = logs.map((wl: { id: number; userId: number; user?: { fullName?: string }; hours: number; description?: string; createdAt?: { seconds: bigint | number } }) => {
32
+ const who = wl.user?.fullName || `User #${wl.userId}`;
33
+ const when = wl.createdAt
34
+ ? new Date((typeof wl.createdAt.seconds === "bigint" ? Number(wl.createdAt.seconds) : wl.createdAt.seconds) * 1000).toISOString().split("T")[0]
35
+ : "—";
36
+ const desc = wl.description ? ` — ${wl.description}` : "";
37
+ return `${who} @ ${when}: ${wl.hours}h${desc} (ID: ${wl.id})`;
38
+ });
39
+ const total = logs.reduce((sum: number, wl: { hours: number }) => sum + wl.hours, 0);
40
+ return {
41
+ content: [
42
+ { type: "text", text: `Work logs for ${task.identifier} (total ${total}h):\n` + lines.join("\n") },
43
+ ],
44
+ };
45
+ } catch (error) {
46
+ return { content: [{ type: "text", text: formatError(error) }], isError: true };
47
+ }
48
+ },
49
+ );
50
+
51
+ server.tool(
52
+ "opsee_log_work",
53
+ "Log time against a task. Posts as the authenticated user. Hours must be > 0.",
54
+ {
55
+ taskId: z.number().describe("The task ID"),
56
+ hours: z.number().min(0.1).describe("Hours worked (>= 0.1)"),
57
+ description: z.string().optional().describe("Optional note describing what was done"),
58
+ },
59
+ { readOnlyHint: false, destructiveHint: false },
60
+ async ({ taskId, hours, description }) => {
61
+ try {
62
+ const clients = getClients();
63
+ const res = await clients.tasks.addWorkLog({ taskId, hours, description });
64
+ if (!res.workLog) {
65
+ return { content: [{ type: "text", text: "Failed to log work. The backend returned an empty response (no error). Retry; if it persists, surface the call to the Opsee team." }], isError: true };
66
+ }
67
+ return {
68
+ content: [
69
+ { type: "text", text: `Logged ${res.workLog.hours}h on task ${taskId} (work_log ID ${res.workLog.id}).` },
70
+ ],
71
+ };
72
+ } catch (error) {
73
+ return { content: [{ type: "text", text: formatError(error) }], isError: true };
74
+ }
75
+ },
76
+ );
77
+
78
+ server.tool(
79
+ "opsee_delete_work_log",
80
+ "Delete a work-log entry by ID. This is permanent.",
81
+ {
82
+ taskId: z.number().describe("The task ID the work log belongs to"),
83
+ workLogId: z.number().describe("The work log ID to delete"),
84
+ },
85
+ { readOnlyHint: false, destructiveHint: true },
86
+ async ({ taskId, workLogId }) => {
87
+ try {
88
+ const clients = getClients();
89
+ await clients.tasks.deleteWorkLog({ taskId, id: workLogId });
90
+ return { content: [{ type: "text", text: "Work log deleted." }] };
91
+ } catch (error) {
92
+ return { content: [{ type: "text", text: formatError(error) }], isError: true };
93
+ }
94
+ },
95
+ );
96
+
97
+ server.tool(
98
+ "opsee_get_task_actual_hours",
99
+ "Sum of all work_log hours on a task. Use this to compare against opsee_get_task's estimatedHours when assessing whether a task is over budget.",
100
+ { taskId: z.number().describe("The task ID") },
101
+ { readOnlyHint: true, destructiveHint: false },
102
+ async ({ taskId }) => {
103
+ try {
104
+ const clients = getClients();
105
+ const res = await clients.tasks.getTask({ id: taskId });
106
+ const task = res.task;
107
+ if (!task) {
108
+ return { content: [{ type: "text", text: "Task not found." }] };
109
+ }
110
+ const total = (task.workLogs ?? []).reduce((sum: number, wl: { hours: number }) => sum + wl.hours, 0);
111
+ const estimated = task.estimatedHours ?? 0;
112
+ const delta = estimated > 0 ? ` (estimated ${estimated}h, ${total > estimated ? "over by " + (total - estimated) : "under by " + (estimated - total)} h)` : "";
113
+ return {
114
+ content: [
115
+ { type: "text", text: `${task.identifier}: ${total}h logged${delta}.` },
116
+ ],
117
+ };
118
+ } catch (error) {
119
+ return { content: [{ type: "text", text: formatError(error) }], isError: true };
120
+ }
121
+ },
122
+ );
123
+ }
@@ -33,6 +33,9 @@ export function formatTask(t: Task): string {
33
33
  const cycle = t.cycle?.name || "None";
34
34
  lines.push(` Assignee: ${assignee} | Cycle: ${cycle}`);
35
35
 
36
+ if (t.storyPoints) lines.push(` Story Points: ${t.storyPoints}`);
37
+ if (t.estimatedHours) lines.push(` Estimated Hours: ${t.estimatedHours}`);
38
+
36
39
  if (t.description) {
37
40
  const desc =
38
41
  t.description.length > 200