@opsee/mcp-server 0.5.7 → 0.6.3

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,17 +23,33 @@ 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, and cycle.",
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.",
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"),
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)"),
25
43
  page: z.number().optional().describe("Page number (default: 1)"),
26
44
  pageSize: z.number().optional().describe("Items per page (default: 50)"),
27
45
  },
28
46
  { readOnlyHint: true, destructiveHint: false },
29
- async ({ projectId, columnId, assigneeId, cycleId, page, pageSize }) => {
47
+ async ({
48
+ projectId, columnId, assigneeId, cycleId, labelIds,
49
+ priorityIds, taskTypeIds, milestoneIds, parentTaskId, hasParent,
50
+ unassigned, updatedSince, createdSince, dueBefore, dueAfter,
51
+ page, pageSize,
52
+ }) => {
30
53
  try {
31
54
  const clients = getClients();
32
55
 
@@ -34,6 +57,16 @@ export function registerTaskTools(
34
57
  if (columnId) filters.push({ key: "BoardColumnId", value: String(columnId) });
35
58
  if (assigneeId) filters.push({ key: "AssignedUserId", value: String(assigneeId) });
36
59
  if (cycleId) filters.push({ key: "CycleId", value: String(cycleId) });
60
+ if (priorityIds?.length) filters.push({ key: "TaskPriorityId", value: priorityIds.join(",") });
61
+ if (taskTypeIds?.length) filters.push({ key: "TaskTypeId", value: taskTypeIds.join(",") });
62
+ if (milestoneIds?.length) filters.push({ key: "MilestoneId", value: milestoneIds.join(",") });
63
+ if (parentTaskId) filters.push({ key: "ParentTaskId", value: String(parentTaskId) });
64
+ if (hasParent !== undefined) filters.push({ key: "HasParent", value: hasParent ? "true" : "false" });
65
+ if (unassigned) filters.push({ key: "Unassigned", value: "true" });
66
+ if (updatedSince) filters.push({ key: "UpdatedSince", value: updatedSince });
67
+ if (createdSince) filters.push({ key: "CreatedSince", value: createdSince });
68
+ if (dueBefore) filters.push({ key: "DueBefore", value: dueBefore });
69
+ if (dueAfter) filters.push({ key: "DueAfter", value: dueAfter });
37
70
 
38
71
  const filterOptions = filters.length > 0
39
72
  ? create(FilterOptionsSchema, {
@@ -45,6 +78,7 @@ export function registerTaskTools(
45
78
  projectId,
46
79
  pagination: defaultPagination(page || 1, pageSize || 50),
47
80
  filterOptions,
81
+ labelIds: labelIds ?? [],
48
82
  });
49
83
 
50
84
  return { content: [{ type: "text", text: formatTaskList(res.tasks) }] };
@@ -71,21 +105,86 @@ export function registerTaskTools(
71
105
  },
72
106
  );
73
107
 
108
+ server.tool(
109
+ "opsee_get_task_with_context",
110
+ "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.",
111
+ { taskId: z.number().describe("The task ID") },
112
+ { readOnlyHint: true, destructiveHint: false },
113
+ async ({ taskId }) => {
114
+ try {
115
+ const clients = getClients();
116
+
117
+ const taskRes = await clients.tasks.getTask({ id: taskId });
118
+ const task = taskRes.task;
119
+ if (!task) {
120
+ return { content: [{ type: "text", text: "Task not found. Use opsee_list_tasks to see available tasks." }] };
121
+ }
122
+
123
+ const [labelsRes, depsRes, commentsRes, subtasksRes, parentRes] = await Promise.all([
124
+ clients.taskLabels.getTaskLabels({
125
+ taskId,
126
+ pagination: defaultPagination(1, 50),
127
+ }),
128
+ clients.taskDependencies.getTaskDependencies({
129
+ taskId,
130
+ pagination: defaultPagination(1, 50),
131
+ }),
132
+ clients.comments.getComments({
133
+ taskId,
134
+ pagination: defaultPagination(1, 50),
135
+ }),
136
+ clients.tasks.getTasks({
137
+ projectId: task.project?.id ?? 0,
138
+ pagination: defaultPagination(1, 50),
139
+ filterOptions: create(FilterOptionsSchema, {
140
+ filters: [
141
+ create(FilterSchema, { key: "ParentTaskId", value: String(task.id) }),
142
+ ],
143
+ }),
144
+ }),
145
+ task.parentTaskId
146
+ ? clients.tasks.getTask({ id: task.parentTaskId })
147
+ : Promise.resolve(null),
148
+ ]);
149
+
150
+ const sections: string[] = [];
151
+ sections.push(formatTask(task));
152
+
153
+ const parentTask = parentRes?.task;
154
+ if (parentTask) {
155
+ sections.push(`\n--- Parent Task ---\n[${parentTask.identifier}] ${parentTask.title} (ID: ${parentTask.id})`);
156
+ }
157
+
158
+ sections.push(`\n--- Labels ---\n${formatTaskLabelList(labelsRes.taskLabels)}`);
159
+ sections.push(`\n--- Dependencies ---\n${formatTaskDependencyList(depsRes.taskDependencies)}`);
160
+ sections.push(`\n--- Subtasks ---\n${formatTaskList(subtasksRes.tasks)}`);
161
+ sections.push(`\n--- Comments ---\n${formatCommentList(commentsRes.comments)}`);
162
+
163
+ return { content: [{ type: "text", text: sections.join("\n") }] };
164
+ } catch (error) {
165
+ return { content: [{ type: "text", text: formatError(error) }], isError: true };
166
+ }
167
+ },
168
+ );
169
+
74
170
  server.tool(
75
171
  "opsee_create_task",
76
172
  "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.",
77
173
  {
78
174
  projectId: z.number().describe("The project ID"),
79
175
  title: z.string().describe("Task title"),
80
- description: z.string().optional().describe("Task description"),
176
+ 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."),
81
177
  taskTypeId: z.number().optional().describe("Task type ID (from opsee_list_task_types)"),
82
178
  priorityId: z.number().optional().describe("Priority ID (from opsee_list_task_priorities)"),
83
179
  boardColumnId: z.number().optional().describe("Board column ID (from opsee_list_board_columns)"),
84
180
  assigneeId: z.number().optional().describe("Assigned user ID"),
85
181
  cycleId: z.number().optional().describe("Cycle/sprint ID"),
182
+ storyPoints: z.number().int().min(1).optional().describe("Story points estimate (positive integer)"),
183
+ estimatedHours: z.number().min(0).optional().describe("Estimated effort in hours"),
184
+ 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."),
86
185
  },
87
186
  { readOnlyHint: false, destructiveHint: false },
88
- async ({ projectId, title, description, taskTypeId, priorityId, boardColumnId, assigneeId, cycleId }) => {
187
+ async ({ projectId, title, description, taskTypeId, priorityId, boardColumnId, assigneeId, cycleId, storyPoints, estimatedHours, labelIds }) => {
89
188
  try {
90
189
  const clients = getClients();
91
190
 
@@ -151,11 +250,14 @@ export function registerTaskTools(
151
250
  displayOrder: 0,
152
251
  aiModeEnabled: false,
153
252
  cycleId,
253
+ storyPoints,
254
+ estimatedHours,
154
255
  repositoryIds: [],
256
+ labelIds: labelIds ?? [],
155
257
  });
156
258
 
157
259
  if (!res.task)
158
- return { content: [{ type: "text", text: "Failed to create task." }] };
260
+ 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 };
159
261
 
160
262
  return {
161
263
  content: [
@@ -174,15 +276,18 @@ export function registerTaskTools(
174
276
  {
175
277
  taskId: z.number().describe("The task ID to update"),
176
278
  title: z.string().optional().describe("New title"),
177
- description: z.string().optional().describe("New description"),
279
+ 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."),
178
280
  taskTypeId: z.number().optional().describe("New task type ID"),
179
281
  priorityId: z.number().optional().describe("New priority ID"),
180
282
  boardColumnId: z.number().optional().describe("New board column ID (status)"),
181
283
  assigneeId: z.number().optional().describe("New assigned user ID"),
182
284
  cycleId: z.number().optional().describe("New cycle/sprint ID"),
285
+ storyPoints: z.number().int().min(1).optional().describe("Story points estimate (positive integer)"),
286
+ estimatedHours: z.number().min(0).optional().describe("Estimated effort in hours"),
287
+ 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."),
183
288
  },
184
289
  { readOnlyHint: false, destructiveHint: false },
185
- async ({ taskId, title, description, taskTypeId, priorityId, boardColumnId, assigneeId, cycleId }) => {
290
+ async ({ taskId, title, description, taskTypeId, priorityId, boardColumnId, assigneeId, cycleId, storyPoints, estimatedHours, labelIds }) => {
186
291
  try {
187
292
  const clients = getClients();
188
293
 
@@ -199,8 +304,8 @@ export function registerTaskTools(
199
304
  title: title ?? task.title,
200
305
  description: description ?? task.description,
201
306
  displayOrder: task.displayOrder,
202
- storyPoints: task.storyPoints,
203
- estimatedHours: task.estimatedHours,
307
+ storyPoints: storyPoints ?? task.storyPoints,
308
+ estimatedHours: estimatedHours ?? task.estimatedHours,
204
309
  actualHours: task.actualHours,
205
310
  dueDate: task.dueDate,
206
311
  aiModeEnabled: task.aiModeEnabled,
@@ -214,10 +319,11 @@ export function registerTaskTools(
214
319
  assignedUserId: assigneeId ?? task.assignedUser?.id,
215
320
  cycleId: cycleId ?? task.cycle?.id,
216
321
  repositoryIds: task.taskRepositories?.map((r: { id: number }) => r.id) ?? [],
322
+ labelIds,
217
323
  });
218
324
 
219
325
  if (!res.task)
220
- return { content: [{ type: "text", text: "Failed to update task." }] };
326
+ 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 };
221
327
 
222
328
  return {
223
329
  content: [
@@ -229,4 +335,251 @@ export function registerTaskTools(
229
335
  }
230
336
  },
231
337
  );
338
+
339
+ server.tool(
340
+ "opsee_bulk_update_tasks",
341
+ "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.",
342
+ {
343
+ projectId: z.number().describe("Project ID - all tasks must belong to this project"),
344
+ taskIds: z.array(z.number()).min(1).describe("Task IDs to update (at least one)"),
345
+ boardColumnId: z.number().optional().describe("New board column ID (status)"),
346
+ taskPriorityId: z.number().optional().describe("New priority ID"),
347
+ taskTypeId: z.number().optional().describe("New task type ID"),
348
+ assignedUserId: z.number().optional().describe("New assigned user ID"),
349
+ cycleId: z.number().optional().describe("New cycle/sprint ID"),
350
+ storyPoints: z.number().int().min(1).optional().describe("Story points to set on every task"),
351
+ estimatedHours: z.number().min(0).optional().describe("Estimated hours to set on every task"),
352
+ parentTaskId: z.number().int().min(0).optional().describe("Parent task ID for every task (pass 0 to clear)"),
353
+ labelIds: z.array(z.number().int().min(1)).optional().describe("Replace label attachments on every task with this set. Empty / omitted leaves labels untouched."),
354
+ },
355
+ { readOnlyHint: false, destructiveHint: false },
356
+ async ({ projectId, taskIds, boardColumnId, taskPriorityId, taskTypeId, assignedUserId, cycleId, storyPoints, estimatedHours, parentTaskId, labelIds }) => {
357
+ try {
358
+ const clients = getClients();
359
+ const res = await clients.tasks.bulkEditTasks({
360
+ projectId,
361
+ taskIds,
362
+ boardColumnId,
363
+ taskPriorityId,
364
+ taskTypeId,
365
+ assignedUserId,
366
+ cycleId,
367
+ storyPoints,
368
+ estimatedHours,
369
+ parentTaskId,
370
+ repositoryIds: [],
371
+ labelIds: labelIds ?? [],
372
+ });
373
+
374
+ const requested = taskIds.length;
375
+ const updated = res.updatedCount;
376
+ let text = `Updated ${updated} of ${requested} task(s).`;
377
+ if (updated < requested) {
378
+ text += " (Tasks not visible to your company or not found were skipped.)";
379
+ }
380
+ return { content: [{ type: "text", text }] };
381
+ } catch (error) {
382
+ return { content: [{ type: "text", text: formatError(error) }], isError: true };
383
+ }
384
+ },
385
+ );
386
+
387
+ server.tool(
388
+ "opsee_bulk_move_to_cycle",
389
+ "Convenience wrapper: move many tasks to the same cycle in one call. Equivalent to opsee_bulk_update_tasks with only cycleId set.",
390
+ {
391
+ projectId: z.number().describe("Project ID - all tasks must belong to this project"),
392
+ taskIds: z.array(z.number()).min(1).describe("Task IDs to move"),
393
+ cycleId: z.number().describe("Target cycle/sprint ID"),
394
+ },
395
+ { readOnlyHint: false, destructiveHint: false },
396
+ async ({ projectId, taskIds, cycleId }) => {
397
+ try {
398
+ const clients = getClients();
399
+ const res = await clients.tasks.bulkEditTasks({
400
+ projectId,
401
+ taskIds,
402
+ cycleId,
403
+ repositoryIds: [],
404
+ labelIds: [],
405
+ });
406
+ const text = `Moved ${res.updatedCount} of ${taskIds.length} task(s) to cycle ${cycleId}.`;
407
+ return { content: [{ type: "text", text }] };
408
+ } catch (error) {
409
+ return { content: [{ type: "text", text: formatError(error) }], isError: true };
410
+ }
411
+ },
412
+ );
413
+
414
+ server.tool(
415
+ "opsee_bulk_move_to_column",
416
+ "Convenience wrapper: move many tasks to the same board column (status) in one call.",
417
+ {
418
+ projectId: z.number().describe("Project ID - all tasks must belong to this project"),
419
+ taskIds: z.array(z.number()).min(1).describe("Task IDs to move"),
420
+ boardColumnId: z.number().describe("Target board column ID (status)"),
421
+ },
422
+ { readOnlyHint: false, destructiveHint: false },
423
+ async ({ projectId, taskIds, boardColumnId }) => {
424
+ try {
425
+ const clients = getClients();
426
+ const res = await clients.tasks.bulkEditTasks({
427
+ projectId,
428
+ taskIds,
429
+ boardColumnId,
430
+ repositoryIds: [],
431
+ labelIds: [],
432
+ });
433
+ const text = `Moved ${res.updatedCount} of ${taskIds.length} task(s) to column ${boardColumnId}.`;
434
+ return { content: [{ type: "text", text }] };
435
+ } catch (error) {
436
+ return { content: [{ type: "text", text: formatError(error) }], isError: true };
437
+ }
438
+ },
439
+ );
440
+
441
+ server.tool(
442
+ "opsee_bulk_assign",
443
+ "Convenience wrapper: assign many tasks to the same user in one call.",
444
+ {
445
+ projectId: z.number().describe("Project ID - all tasks must belong to this project"),
446
+ taskIds: z.array(z.number()).min(1).describe("Task IDs to reassign"),
447
+ assigneeId: z.number().describe("Target user ID"),
448
+ },
449
+ { readOnlyHint: false, destructiveHint: false },
450
+ async ({ projectId, taskIds, assigneeId }) => {
451
+ try {
452
+ const clients = getClients();
453
+ const res = await clients.tasks.bulkEditTasks({
454
+ projectId,
455
+ taskIds,
456
+ assignedUserId: assigneeId,
457
+ repositoryIds: [],
458
+ labelIds: [],
459
+ });
460
+ const text = `Assigned ${res.updatedCount} of ${taskIds.length} task(s) to user ${assigneeId}.`;
461
+ return { content: [{ type: "text", text }] };
462
+ } catch (error) {
463
+ return { content: [{ type: "text", text: formatError(error) }], isError: true };
464
+ }
465
+ },
466
+ );
467
+
468
+ server.tool(
469
+ "opsee_bulk_set_priority",
470
+ "Convenience wrapper: set the same priority on many tasks in one call.",
471
+ {
472
+ projectId: z.number().describe("Project ID - all tasks must belong to this project"),
473
+ taskIds: z.array(z.number()).min(1).describe("Task IDs to reprioritize"),
474
+ priorityId: z.number().describe("Target priority ID (from opsee_list_task_priorities)"),
475
+ },
476
+ { readOnlyHint: false, destructiveHint: false },
477
+ async ({ projectId, taskIds, priorityId }) => {
478
+ try {
479
+ const clients = getClients();
480
+ const res = await clients.tasks.bulkEditTasks({
481
+ projectId,
482
+ taskIds,
483
+ taskPriorityId: priorityId,
484
+ repositoryIds: [],
485
+ labelIds: [],
486
+ });
487
+ const text = `Set priority ${priorityId} on ${res.updatedCount} of ${taskIds.length} task(s).`;
488
+ return { content: [{ type: "text", text }] };
489
+ } catch (error) {
490
+ return { content: [{ type: "text", text: formatError(error) }], isError: true };
491
+ }
492
+ },
493
+ );
494
+
495
+ server.tool(
496
+ "opsee_replace_task_labels",
497
+ "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.",
498
+ {
499
+ taskId: z.number().describe("The task ID"),
500
+ labelIds: z.array(z.number().int().min(1)).describe("Label IDs to set (empty array clears all labels)"),
501
+ },
502
+ { readOnlyHint: false, destructiveHint: false },
503
+ async ({ taskId, labelIds }) => {
504
+ try {
505
+ const clients = getClients();
506
+ const getRes = await clients.tasks.getTask({ id: taskId });
507
+ const task = getRes.task;
508
+ if (!task) {
509
+ return { content: [{ type: "text", text: "Task not found." }] };
510
+ }
511
+ const res = await clients.tasks.editTask({
512
+ id: task.id,
513
+ identifier: task.identifier,
514
+ title: task.title,
515
+ description: task.description,
516
+ displayOrder: task.displayOrder,
517
+ storyPoints: task.storyPoints,
518
+ estimatedHours: task.estimatedHours,
519
+ actualHours: task.actualHours,
520
+ dueDate: task.dueDate,
521
+ aiModeEnabled: task.aiModeEnabled,
522
+ metadataJson: task.metadataJson,
523
+ boardId: task.board?.id ?? 0,
524
+ boardColumnId: task.boardColumn?.id ?? 0,
525
+ projectId: task.project?.id ?? 0,
526
+ taskTypeId: task.taskType?.id ?? 0,
527
+ taskPriorityId: task.taskPriority?.id ?? 0,
528
+ reporterUserId: task.reporterUser?.id ?? 0,
529
+ assignedUserId: task.assignedUser?.id,
530
+ cycleId: task.cycle?.id,
531
+ repositoryIds: task.taskRepositories?.map((r: { id: number }) => r.id) ?? [],
532
+ labelIds,
533
+ });
534
+ if (!res.task) {
535
+ 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 };
536
+ }
537
+ const verb = labelIds.length === 0 ? "Cleared all labels on" : `Set ${labelIds.length} label(s) on`;
538
+ return { content: [{ type: "text", text: `${verb} ${res.task.identifier}.` }] };
539
+ } catch (error) {
540
+ return { content: [{ type: "text", text: formatError(error) }], isError: true };
541
+ }
542
+ },
543
+ );
544
+
545
+ server.tool(
546
+ "opsee_delete_task",
547
+ "Delete a task by ID. This is permanent.",
548
+ { taskId: z.number().describe("The task ID to delete") },
549
+ { readOnlyHint: false, destructiveHint: true },
550
+ async ({ taskId }) => {
551
+ try {
552
+ const clients = getClients();
553
+ await clients.tasks.deleteTask({ id: taskId });
554
+ return { content: [{ type: "text", text: "Task deleted." }] };
555
+ } catch (error) {
556
+ return { content: [{ type: "text", text: formatError(error) }], isError: true };
557
+ }
558
+ },
559
+ );
560
+
561
+ server.tool(
562
+ "opsee_bulk_delete_tasks",
563
+ "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.",
564
+ {
565
+ projectId: z.number().describe("Project ID - all tasks must belong to this project"),
566
+ taskIds: z.array(z.number()).min(1).describe("Task IDs to delete (at least one)"),
567
+ },
568
+ { readOnlyHint: false, destructiveHint: true },
569
+ async ({ projectId, taskIds }) => {
570
+ try {
571
+ const clients = getClients();
572
+ const res = await clients.tasks.bulkDeleteTasks({ projectId, taskIds });
573
+ const requested = taskIds.length;
574
+ const deleted = res.deletedCount;
575
+ let text = `Deleted ${deleted} of ${requested} task(s).`;
576
+ if (deleted < requested) {
577
+ text += " (Tasks not visible to your company or not found were skipped.)";
578
+ }
579
+ return { content: [{ type: "text", text }] };
580
+ } catch (error) {
581
+ return { content: [{ type: "text", text: formatError(error) }], isError: true };
582
+ }
583
+ },
584
+ );
232
585
  }
package/src/tools/user.ts CHANGED
@@ -1,6 +1,8 @@
1
+ import { z } from "zod";
1
2
  import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
3
  import type { ApiClients } from "../client/api.js";
3
- import { formatError } from "../utils/format.js";
4
+ import { defaultPagination } from "../client/api.js";
5
+ import { formatError, formatUser, formatUserList } from "../utils/format.js";
4
6
 
5
7
  export function registerUserTools(
6
8
  server: McpServer,
@@ -31,4 +33,42 @@ export function registerUserTools(
31
33
  }
32
34
  },
33
35
  );
36
+
37
+ server.tool(
38
+ "opsee_list_users",
39
+ "Lists users in the authenticated company. Opsee scopes users at the Company level — there is no project-scoped user listing because Users do not have a per-project relation. Use this to resolve assignee names to IDs.",
40
+ {
41
+ page: z.number().optional().describe("Page number (default: 1)"),
42
+ pageSize: z.number().optional().describe("Items per page (default: 50)"),
43
+ },
44
+ { readOnlyHint: true, destructiveHint: false },
45
+ async ({ page, pageSize }) => {
46
+ try {
47
+ const clients = getClients();
48
+ const res = await clients.users.getUsers({
49
+ pagination: defaultPagination(page || 1, pageSize || 50),
50
+ });
51
+ return { content: [{ type: "text", text: formatUserList(res.users) }] };
52
+ } catch (error) {
53
+ return { content: [{ type: "text", text: formatError(error) }], isError: true };
54
+ }
55
+ },
56
+ );
57
+
58
+ server.tool(
59
+ "opsee_get_user",
60
+ "Get full details of a specific user by ID.",
61
+ { userId: z.number().describe("The user ID") },
62
+ { readOnlyHint: true, destructiveHint: false },
63
+ async ({ userId }) => {
64
+ try {
65
+ const clients = getClients();
66
+ const res = await clients.users.getUser({ id: userId });
67
+ if (!res.user) return { content: [{ type: "text", text: "User not found. Use opsee_list_users to see available users." }] };
68
+ return { content: [{ type: "text", text: formatUser(res.user) }] };
69
+ } catch (error) {
70
+ return { content: [{ type: "text", text: formatError(error) }], isError: true };
71
+ }
72
+ },
73
+ );
34
74
  }
@@ -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
+ }