@monadsag/productive-mcp 1.2.48
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.
- package/LICENSE +190 -0
- package/NOTICE +6 -0
- package/README.md +353 -0
- package/build/api/bookings-client.js +249 -0
- package/build/api/capacity.js +279 -0
- package/build/api/client.js +1296 -0
- package/build/api/errors.js +50 -0
- package/build/api/invoice-time-entries.js +256 -0
- package/build/api/pages-tree.js +106 -0
- package/build/api/time-entry-notes.js +75 -0
- package/build/api/types.js +1 -0
- package/build/auth/logo.js +21 -0
- package/build/auth/self-resolver.js +61 -0
- package/build/config/index.js +24 -0
- package/build/index.js +15 -0
- package/build/prompts/timesheet.js +285 -0
- package/build/server.js +55 -0
- package/build/tools/absences.js +502 -0
- package/build/tools/activities.js +140 -0
- package/build/tools/bookings.js +531 -0
- package/build/tools/budget-services.js +168 -0
- package/build/tools/budgets.js +276 -0
- package/build/tools/capacity.js +281 -0
- package/build/tools/changeset.js +41 -0
- package/build/tools/comments.js +469 -0
- package/build/tools/companies.js +73 -0
- package/build/tools/custom-field-resolver.js +92 -0
- package/build/tools/custom-fields.js +155 -0
- package/build/tools/folders.js +516 -0
- package/build/tools/include-resolver.js +45 -0
- package/build/tools/invoice-actions.js +476 -0
- package/build/tools/invoice-defaults.js +65 -0
- package/build/tools/invoice-time-entries.js +320 -0
- package/build/tools/invoices.js +657 -0
- package/build/tools/my-tasks.js +100 -0
- package/build/tools/page-children.js +129 -0
- package/build/tools/pages.js +466 -0
- package/build/tools/people.js +147 -0
- package/build/tools/projects.js +77 -0
- package/build/tools/recent-updates.js +112 -0
- package/build/tools/registry.js +409 -0
- package/build/tools/subtasks.js +245 -0
- package/build/tools/task-backlog.js +106 -0
- package/build/tools/task-dependencies.js +244 -0
- package/build/tools/task-list-move.js +65 -0
- package/build/tools/task-lists.js +535 -0
- package/build/tools/task-reposition.js +199 -0
- package/build/tools/task-status.js +178 -0
- package/build/tools/tasks.js +738 -0
- package/build/tools/time-entries.js +736 -0
- package/build/tools/time-entry-approval.js +103 -0
- package/build/tools/time-entry-delete.js +72 -0
- package/build/tools/time-entry-update.js +126 -0
- package/build/tools/timers.js +195 -0
- package/build/tools/todos.js +342 -0
- package/build/tools/tool-helpers.js +114 -0
- package/build/tools/toolsets.js +153 -0
- package/build/tools/whoami.js +64 -0
- package/build/tools/workflow-statuses.js +81 -0
- package/build/utils/errors.js +67 -0
- package/build/utils/mentions.js +98 -0
- package/npm-shrinkwrap.json +1159 -0
- package/package.json +79 -0
|
@@ -0,0 +1,738 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
|
|
3
|
+
import { buildIncludeMap, resolveName } from './include-resolver.js';
|
|
4
|
+
import { buildCustomFieldValueMap, resolveCustomFieldsText } from './custom-field-resolver.js';
|
|
5
|
+
import { toMcpError } from '../utils/errors.js';
|
|
6
|
+
function resolveWorkflowStatus(task, included) {
|
|
7
|
+
const statusId = task.relationships?.workflow_status?.data?.id;
|
|
8
|
+
if (!statusId || !included)
|
|
9
|
+
return undefined;
|
|
10
|
+
const status = included.find((item) => item.type === 'workflow_statuses' && item.id === statusId);
|
|
11
|
+
return status?.attributes?.name || undefined;
|
|
12
|
+
}
|
|
13
|
+
const listTasksSchema = z.object({
|
|
14
|
+
project_id: z.string().optional(),
|
|
15
|
+
assignee_id: z.string().optional(),
|
|
16
|
+
status: z.enum(['open', 'closed']).optional(),
|
|
17
|
+
limit: z.coerce.number().min(1).max(200).default(30).optional(),
|
|
18
|
+
});
|
|
19
|
+
const getProjectTasksSchema = z.object({
|
|
20
|
+
project_id: z.string().min(1, 'Project ID is required'),
|
|
21
|
+
status: z.enum(['open', 'closed']).optional(),
|
|
22
|
+
});
|
|
23
|
+
const getTaskSchema = z.object({
|
|
24
|
+
task_id: z.string().min(1, 'Task ID is required'),
|
|
25
|
+
});
|
|
26
|
+
export async function listTasksTool(client, args) {
|
|
27
|
+
try {
|
|
28
|
+
const params = listTasksSchema.parse(args || {});
|
|
29
|
+
const response = await client.listTasks({
|
|
30
|
+
project_id: params.project_id,
|
|
31
|
+
assignee_id: params.assignee_id,
|
|
32
|
+
status: params.status,
|
|
33
|
+
limit: params.limit,
|
|
34
|
+
});
|
|
35
|
+
if (!response || !response.data || response.data.length === 0) {
|
|
36
|
+
return {
|
|
37
|
+
content: [
|
|
38
|
+
{
|
|
39
|
+
type: 'text',
|
|
40
|
+
text: 'No tasks found matching the criteria.',
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const nameMap = buildIncludeMap(response.included);
|
|
46
|
+
const customFieldMap = await buildCustomFieldValueMap(client, response.data);
|
|
47
|
+
const tasksText = response.data
|
|
48
|
+
.filter((task) => task && task.attributes)
|
|
49
|
+
.map((task) => {
|
|
50
|
+
const projectId = task.relationships?.project?.data?.id;
|
|
51
|
+
const assigneeId = task.relationships?.assignee?.data?.id;
|
|
52
|
+
const assigneeName = resolveName(nameMap, 'people', assigneeId);
|
|
53
|
+
const projectName = resolveName(nameMap, 'projects', projectId);
|
|
54
|
+
const workflowStatusName = resolveWorkflowStatus(task, response.included);
|
|
55
|
+
const fallbackStatus = task.attributes.status === 1
|
|
56
|
+
? 'open'
|
|
57
|
+
: task.attributes.status === 2
|
|
58
|
+
? 'closed'
|
|
59
|
+
: `status ${task.attributes.status}`;
|
|
60
|
+
const statusText = workflowStatusName || fallbackStatus;
|
|
61
|
+
const assigneeDisplay = assigneeName
|
|
62
|
+
? `Assignee: ${assigneeName}`
|
|
63
|
+
: assigneeId
|
|
64
|
+
? `Assignee ID: ${assigneeId}`
|
|
65
|
+
: 'Unassigned';
|
|
66
|
+
const customFieldsLines = resolveCustomFieldsText(customFieldMap, task.attributes.custom_fields);
|
|
67
|
+
const customFieldsSuffix = customFieldsLines.length > 0 ? `\n Custom Fields: ${customFieldsLines.join('; ')}` : '';
|
|
68
|
+
return `• ${task.attributes.title} (ID: ${task.id})
|
|
69
|
+
Status: ${statusText}
|
|
70
|
+
${task.attributes.due_date ? `Due: ${task.attributes.due_date}` : 'No due date'}
|
|
71
|
+
${projectName ? `Project: ${projectName}` : projectId ? `Project ID: ${projectId}` : ''}
|
|
72
|
+
${assigneeDisplay}
|
|
73
|
+
${task.attributes.description ? `Description: ${task.attributes.description}` : ''}${customFieldsSuffix}`;
|
|
74
|
+
})
|
|
75
|
+
.join('\n\n');
|
|
76
|
+
const summary = `Found ${response.data.length} task${response.data.length !== 1 ? 's' : ''}${response.meta?.total_count ? ` (showing ${response.data.length} of ${response.meta.total_count})` : ''}:\n\n${tasksText}`;
|
|
77
|
+
return {
|
|
78
|
+
content: [
|
|
79
|
+
{
|
|
80
|
+
type: 'text',
|
|
81
|
+
text: summary,
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
throw toMcpError(error);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
export async function getProjectTasksTool(client, args) {
|
|
91
|
+
try {
|
|
92
|
+
const params = getProjectTasksSchema.parse(args);
|
|
93
|
+
const response = await client.listTasks({
|
|
94
|
+
project_id: params.project_id,
|
|
95
|
+
status: params.status,
|
|
96
|
+
limit: 200, // Get maximum tasks for a project
|
|
97
|
+
});
|
|
98
|
+
if (!response || !response.data || response.data.length === 0) {
|
|
99
|
+
return {
|
|
100
|
+
content: [
|
|
101
|
+
{
|
|
102
|
+
type: 'text',
|
|
103
|
+
text: `No tasks found for project ${params.project_id}.`,
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
const nameMap = buildIncludeMap(response.included);
|
|
109
|
+
const customFieldMap = await buildCustomFieldValueMap(client, response.data);
|
|
110
|
+
const tasksText = response.data
|
|
111
|
+
.filter((task) => task && task.attributes)
|
|
112
|
+
.map((task) => {
|
|
113
|
+
const assigneeId = task.relationships?.assignee?.data?.id;
|
|
114
|
+
const assigneeName = resolveName(nameMap, 'people', assigneeId);
|
|
115
|
+
const workflowStatusName = resolveWorkflowStatus(task, response.included);
|
|
116
|
+
const fallbackStatus = task.attributes.status === 1
|
|
117
|
+
? 'open'
|
|
118
|
+
: task.attributes.status === 2
|
|
119
|
+
? 'closed'
|
|
120
|
+
: `status ${task.attributes.status}`;
|
|
121
|
+
const statusText = workflowStatusName || fallbackStatus;
|
|
122
|
+
const assigneeDisplay = assigneeName
|
|
123
|
+
? `Assignee: ${assigneeName}`
|
|
124
|
+
: assigneeId
|
|
125
|
+
? `Assignee ID: ${assigneeId}`
|
|
126
|
+
: 'Unassigned';
|
|
127
|
+
const customFieldsLines = resolveCustomFieldsText(customFieldMap, task.attributes.custom_fields);
|
|
128
|
+
const customFieldsSuffix = customFieldsLines.length > 0 ? `\n Custom Fields: ${customFieldsLines.join('; ')}` : '';
|
|
129
|
+
return `• ${task.attributes.title} (ID: ${task.id})
|
|
130
|
+
Status: ${statusText}
|
|
131
|
+
${task.attributes.due_date ? `Due: ${task.attributes.due_date}` : 'No due date'}
|
|
132
|
+
${assigneeDisplay}
|
|
133
|
+
${task.attributes.description ? `Description: ${task.attributes.description}` : ''}${customFieldsSuffix}`;
|
|
134
|
+
})
|
|
135
|
+
.join('\n\n');
|
|
136
|
+
const summary = `Project ${params.project_id} has ${response.data.length} task${response.data.length !== 1 ? 's' : ''}:\n\n${tasksText}`;
|
|
137
|
+
return {
|
|
138
|
+
content: [
|
|
139
|
+
{
|
|
140
|
+
type: 'text',
|
|
141
|
+
text: summary,
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
throw toMcpError(error);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
export async function getTaskTool(client, args) {
|
|
151
|
+
try {
|
|
152
|
+
const params = getTaskSchema.parse(args);
|
|
153
|
+
const response = await client.getTask(params.task_id);
|
|
154
|
+
const task = response.data;
|
|
155
|
+
const included = response.included;
|
|
156
|
+
const nameMap = buildIncludeMap(included);
|
|
157
|
+
const projectId = task.relationships?.project?.data?.id;
|
|
158
|
+
const assigneeId = task.relationships?.assignee?.data?.id;
|
|
159
|
+
const taskListId = task.relationships?.task_list?.data?.id;
|
|
160
|
+
const projectName = resolveName(nameMap, 'projects', projectId);
|
|
161
|
+
const assigneeName = resolveName(nameMap, 'people', assigneeId);
|
|
162
|
+
const taskListName = resolveName(nameMap, 'task_lists', taskListId);
|
|
163
|
+
// Resolve workflow status name from included data, fall back to closed boolean
|
|
164
|
+
const workflowStatusName = resolveWorkflowStatus(task, included);
|
|
165
|
+
const fallbackStatus = task.attributes.closed === false
|
|
166
|
+
? 'open'
|
|
167
|
+
: task.attributes.closed === true
|
|
168
|
+
? 'closed'
|
|
169
|
+
: 'unknown';
|
|
170
|
+
const statusText = workflowStatusName || fallbackStatus;
|
|
171
|
+
let text = `Task Details:\n\n`;
|
|
172
|
+
text += `Title: ${task.attributes.title}\n`;
|
|
173
|
+
text += `ID: ${task.id}\n`;
|
|
174
|
+
text += `Status: ${statusText}\n`;
|
|
175
|
+
if (task.attributes.description) {
|
|
176
|
+
text += `Description: ${task.attributes.description}\n`;
|
|
177
|
+
}
|
|
178
|
+
if (task.attributes.due_date) {
|
|
179
|
+
text += `Due Date: ${task.attributes.due_date}\n`;
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
text += `Due Date: No due date set\n`;
|
|
183
|
+
}
|
|
184
|
+
if (projectId) {
|
|
185
|
+
text += projectName ? `Project: ${projectName}\n` : `Project ID: ${projectId}\n`;
|
|
186
|
+
}
|
|
187
|
+
if (assigneeId) {
|
|
188
|
+
text += assigneeName ? `Assignee: ${assigneeName}\n` : `Assignee ID: ${assigneeId}\n`;
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
text += `Assignee: Unassigned\n`;
|
|
192
|
+
}
|
|
193
|
+
if (task.attributes.created_at) {
|
|
194
|
+
text += `Created: ${task.attributes.created_at}\n`;
|
|
195
|
+
}
|
|
196
|
+
if (task.attributes.updated_at) {
|
|
197
|
+
text += `Updated: ${task.attributes.updated_at}\n`;
|
|
198
|
+
}
|
|
199
|
+
if (task.attributes.priority !== undefined) {
|
|
200
|
+
text += `Priority: ${task.attributes.priority}\n`;
|
|
201
|
+
}
|
|
202
|
+
if (task.attributes.placement !== undefined) {
|
|
203
|
+
text += `Position: ${task.attributes.placement}\n`;
|
|
204
|
+
}
|
|
205
|
+
if (task.attributes.task_number) {
|
|
206
|
+
text += `Task Number: ${task.attributes.task_number}\n`;
|
|
207
|
+
}
|
|
208
|
+
if (task.attributes.private !== undefined) {
|
|
209
|
+
text += `Private: ${task.attributes.private ? 'Yes' : 'No'}\n`;
|
|
210
|
+
}
|
|
211
|
+
if (task.attributes.initial_estimate) {
|
|
212
|
+
text += `Initial Estimate: ${task.attributes.initial_estimate}\n`;
|
|
213
|
+
}
|
|
214
|
+
if (task.attributes.worked_time) {
|
|
215
|
+
text += `Worked Time: ${task.attributes.worked_time}\n`;
|
|
216
|
+
}
|
|
217
|
+
if (task.attributes.last_activity_at) {
|
|
218
|
+
text += `Last Activity: ${task.attributes.last_activity_at}\n`;
|
|
219
|
+
}
|
|
220
|
+
if (taskListId) {
|
|
221
|
+
text += taskListName ? `Task List: ${taskListName}\n` : `Task List ID: ${taskListId}\n`;
|
|
222
|
+
}
|
|
223
|
+
if (task.attributes.custom_fields && Object.keys(task.attributes.custom_fields).length > 0) {
|
|
224
|
+
const customFieldMap = await buildCustomFieldValueMap(client, [task]);
|
|
225
|
+
text += formatCustomFieldsBlock(customFieldMap, task.attributes.custom_fields);
|
|
226
|
+
}
|
|
227
|
+
return {
|
|
228
|
+
content: [
|
|
229
|
+
{
|
|
230
|
+
type: 'text',
|
|
231
|
+
text: text,
|
|
232
|
+
},
|
|
233
|
+
],
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
catch (error) {
|
|
237
|
+
throw toMcpError(error);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Formats a "Custom Fields:" block (header + one indented "name: value" line per
|
|
242
|
+
* entry, each ending with a trailing newline) for appending to trailing-newline-style
|
|
243
|
+
* text output. Returns an empty string when there are no custom fields to show.
|
|
244
|
+
*/
|
|
245
|
+
function formatCustomFieldsBlock(map, rawCustomFields) {
|
|
246
|
+
const lines = resolveCustomFieldsText(map, rawCustomFields);
|
|
247
|
+
if (lines.length === 0)
|
|
248
|
+
return '';
|
|
249
|
+
return `Custom Fields:\n${lines.map((line) => ` ${line}\n`).join('')}`;
|
|
250
|
+
}
|
|
251
|
+
export const listTasksDefinition = {
|
|
252
|
+
name: 'list_tasks',
|
|
253
|
+
description: 'List tasks across Productive.io, optionally filtered by project, assignee, and open/closed status. ' +
|
|
254
|
+
'Reach for this for flexible or cross-project queries and whenever you are filtering by assignee. ' +
|
|
255
|
+
"Prefer get_project_tasks when you want one project's complete task list (it fetches up to 200; this defaults to 30), " +
|
|
256
|
+
"get_task when you already have a task ID and need its full record, or my_tasks for the current user's own tasks. " +
|
|
257
|
+
'Returns a paginated summary (default 30, max 200).',
|
|
258
|
+
inputSchema: {
|
|
259
|
+
type: 'object',
|
|
260
|
+
properties: {
|
|
261
|
+
project_id: {
|
|
262
|
+
type: 'string',
|
|
263
|
+
description: 'Filter to tasks in this project ID. Omit to search across all projects.',
|
|
264
|
+
},
|
|
265
|
+
assignee_id: {
|
|
266
|
+
type: 'string',
|
|
267
|
+
description: "Filter to tasks assigned to this person ID. For the current user's own tasks, prefer my_tasks.",
|
|
268
|
+
},
|
|
269
|
+
status: {
|
|
270
|
+
type: 'string',
|
|
271
|
+
enum: ['open', 'closed'],
|
|
272
|
+
description: 'Filter by task status (open or closed). Omit to return both.',
|
|
273
|
+
},
|
|
274
|
+
limit: {
|
|
275
|
+
type: 'number',
|
|
276
|
+
description: 'Number of tasks to return (1-200, default 30).',
|
|
277
|
+
minimum: 1,
|
|
278
|
+
maximum: 200,
|
|
279
|
+
default: 30,
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
annotations: { title: 'List tasks', readOnlyHint: true, openWorldHint: true },
|
|
284
|
+
};
|
|
285
|
+
export const getProjectTasksDefinition = {
|
|
286
|
+
name: 'get_project_tasks',
|
|
287
|
+
description: 'Get all tasks for a single project (fetches up to 200 in one call, unlike list_tasks which defaults to 30). ' +
|
|
288
|
+
"Prefer this over list_tasks when you need one project's complete task list; use list_tasks for cross-project or assignee-filtered queries. " +
|
|
289
|
+
'ALSO used as STEP 4 in the timesheet workflow to find task_id for linking time entries to specific tasks. ' +
|
|
290
|
+
'Workflow: list_projects → list_project_deals → list_deal_services → get_project_tasks → create_time_entry.',
|
|
291
|
+
inputSchema: {
|
|
292
|
+
type: 'object',
|
|
293
|
+
properties: {
|
|
294
|
+
project_id: {
|
|
295
|
+
type: 'string',
|
|
296
|
+
description: 'The ID of the project',
|
|
297
|
+
},
|
|
298
|
+
status: {
|
|
299
|
+
type: 'string',
|
|
300
|
+
enum: ['open', 'closed'],
|
|
301
|
+
description: 'Filter by task status (open or closed)',
|
|
302
|
+
},
|
|
303
|
+
},
|
|
304
|
+
required: ['project_id'],
|
|
305
|
+
},
|
|
306
|
+
annotations: { title: 'Get project tasks', readOnlyHint: true, openWorldHint: true },
|
|
307
|
+
};
|
|
308
|
+
export const getTaskDefinition = {
|
|
309
|
+
name: 'get_task',
|
|
310
|
+
description: 'Get the full record for one task by its ID — title, description, status, assignee, project, task list, ' +
|
|
311
|
+
'due/created/updated dates, priority, position, estimate, worked time, and resolved custom fields. ' +
|
|
312
|
+
'Use this when you already have a task_id and need its complete details; use list_tasks or get_project_tasks ' +
|
|
313
|
+
"to discover task IDs first, or list_subtasks to see a task's children.",
|
|
314
|
+
inputSchema: {
|
|
315
|
+
type: 'object',
|
|
316
|
+
properties: {
|
|
317
|
+
task_id: {
|
|
318
|
+
type: 'string',
|
|
319
|
+
description: 'The ID of the task to retrieve',
|
|
320
|
+
},
|
|
321
|
+
},
|
|
322
|
+
required: ['task_id'],
|
|
323
|
+
},
|
|
324
|
+
annotations: { title: 'Get task', readOnlyHint: true, openWorldHint: true },
|
|
325
|
+
};
|
|
326
|
+
const createTaskSchema = z.object({
|
|
327
|
+
title: z.string().min(1, 'Task title is required'),
|
|
328
|
+
description: z.string().optional(),
|
|
329
|
+
description_html: z.string().optional(),
|
|
330
|
+
project_id: z.string().optional(),
|
|
331
|
+
board_id: z.string().optional(),
|
|
332
|
+
task_list_id: z.string().optional(),
|
|
333
|
+
assignee_id: z.string().optional(),
|
|
334
|
+
due_date: z.string().optional(),
|
|
335
|
+
status: z.enum(['open', 'closed']).optional().default('open'),
|
|
336
|
+
custom_fields: z
|
|
337
|
+
.record(z.string(), z.union([z.string(), z.number(), z.boolean(), z.array(z.string()), z.null()]))
|
|
338
|
+
.optional(),
|
|
339
|
+
});
|
|
340
|
+
export async function createTaskTool(client, args, config) {
|
|
341
|
+
try {
|
|
342
|
+
const params = createTaskSchema.parse(args || {});
|
|
343
|
+
// Handle "me" reference for assignee
|
|
344
|
+
let assigneeId = params.assignee_id;
|
|
345
|
+
if (assigneeId === 'me') {
|
|
346
|
+
if (!config?.PRODUCTIVE_USER_ID) {
|
|
347
|
+
throw new McpError(ErrorCode.InvalidParams, 'Cannot use "me" reference - PRODUCTIVE_USER_ID is not configured in environment');
|
|
348
|
+
}
|
|
349
|
+
assigneeId = config.PRODUCTIVE_USER_ID;
|
|
350
|
+
}
|
|
351
|
+
// Use description_html if provided, otherwise fall back to description
|
|
352
|
+
const descriptionValue = params.description_html || params.description;
|
|
353
|
+
const taskData = {
|
|
354
|
+
data: {
|
|
355
|
+
type: 'tasks',
|
|
356
|
+
attributes: {
|
|
357
|
+
title: params.title,
|
|
358
|
+
description: descriptionValue,
|
|
359
|
+
due_date: params.due_date,
|
|
360
|
+
status: params.status === 'open' ? 1 : 2,
|
|
361
|
+
},
|
|
362
|
+
relationships: {},
|
|
363
|
+
},
|
|
364
|
+
};
|
|
365
|
+
if (params.custom_fields) {
|
|
366
|
+
taskData.data.attributes.custom_fields = params.custom_fields;
|
|
367
|
+
}
|
|
368
|
+
// Add relationships if provided
|
|
369
|
+
if (params.project_id) {
|
|
370
|
+
taskData.data.relationships.project = {
|
|
371
|
+
data: {
|
|
372
|
+
id: params.project_id,
|
|
373
|
+
type: 'projects',
|
|
374
|
+
},
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
if (params.board_id) {
|
|
378
|
+
taskData.data.relationships.board = {
|
|
379
|
+
data: {
|
|
380
|
+
id: params.board_id,
|
|
381
|
+
type: 'boards',
|
|
382
|
+
},
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
if (params.task_list_id) {
|
|
386
|
+
taskData.data.relationships.task_list = {
|
|
387
|
+
data: {
|
|
388
|
+
id: params.task_list_id,
|
|
389
|
+
type: 'task_lists',
|
|
390
|
+
},
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
if (assigneeId) {
|
|
394
|
+
taskData.data.relationships.assignee = {
|
|
395
|
+
data: {
|
|
396
|
+
id: assigneeId,
|
|
397
|
+
type: 'people',
|
|
398
|
+
},
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
const response = await client.createTask(taskData);
|
|
402
|
+
let text = `Task created successfully!\n`;
|
|
403
|
+
text += `Title: ${response.data.attributes.title} (ID: ${response.data.id})`;
|
|
404
|
+
if (response.data.attributes.description) {
|
|
405
|
+
text += `\nDescription: ${response.data.attributes.description}`;
|
|
406
|
+
}
|
|
407
|
+
const statusText = response.data.attributes.status === 1 ? 'open' : 'closed';
|
|
408
|
+
text += `\nStatus: ${statusText}`;
|
|
409
|
+
if (response.data.attributes.due_date) {
|
|
410
|
+
text += `\nDue date: ${response.data.attributes.due_date}`;
|
|
411
|
+
}
|
|
412
|
+
if (params.project_id) {
|
|
413
|
+
text += `\nProject ID: ${params.project_id}`;
|
|
414
|
+
}
|
|
415
|
+
if (params.board_id) {
|
|
416
|
+
text += `\nBoard ID: ${params.board_id}`;
|
|
417
|
+
}
|
|
418
|
+
if (params.task_list_id) {
|
|
419
|
+
text += `\nTask List ID: ${params.task_list_id}`;
|
|
420
|
+
}
|
|
421
|
+
if (assigneeId) {
|
|
422
|
+
text += `\nAssignee ID: ${assigneeId}`;
|
|
423
|
+
if (params.assignee_id === 'me' && config?.PRODUCTIVE_USER_ID) {
|
|
424
|
+
text += ` (me)`;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
if (response.data.attributes.created_at) {
|
|
428
|
+
text += `\nCreated at: ${response.data.attributes.created_at}`;
|
|
429
|
+
}
|
|
430
|
+
if (response.data.attributes.custom_fields &&
|
|
431
|
+
Object.keys(response.data.attributes.custom_fields).length > 0) {
|
|
432
|
+
const customFieldMap = await buildCustomFieldValueMap(client, [response.data]);
|
|
433
|
+
const block = formatCustomFieldsBlock(customFieldMap, response.data.attributes.custom_fields);
|
|
434
|
+
if (block) {
|
|
435
|
+
text += `\n${block}`;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
return {
|
|
439
|
+
content: [
|
|
440
|
+
{
|
|
441
|
+
type: 'text',
|
|
442
|
+
text: text,
|
|
443
|
+
},
|
|
444
|
+
],
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
catch (error) {
|
|
448
|
+
throw toMcpError(error);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
export const createTaskDefinition = {
|
|
452
|
+
name: 'create_task',
|
|
453
|
+
description: 'Create a new task in Productive.io. If PRODUCTIVE_USER_ID is configured, you can use "me" to refer to the configured user when assigning.',
|
|
454
|
+
inputSchema: {
|
|
455
|
+
type: 'object',
|
|
456
|
+
properties: {
|
|
457
|
+
title: {
|
|
458
|
+
type: 'string',
|
|
459
|
+
description: 'Task title (required)',
|
|
460
|
+
},
|
|
461
|
+
description: {
|
|
462
|
+
type: 'string',
|
|
463
|
+
description: 'Task description (plain text)',
|
|
464
|
+
},
|
|
465
|
+
description_html: {
|
|
466
|
+
type: 'string',
|
|
467
|
+
description: 'Task description with HTML formatting. Supports tags like <h2>, <p>, <ul>, <li>, <strong>, <em>, <a href="">. Takes precedence over description if both provided.',
|
|
468
|
+
},
|
|
469
|
+
project_id: {
|
|
470
|
+
type: 'string',
|
|
471
|
+
description: 'ID of the project to add the task to',
|
|
472
|
+
},
|
|
473
|
+
board_id: {
|
|
474
|
+
type: 'string',
|
|
475
|
+
description: 'ID of the board to add the task to',
|
|
476
|
+
},
|
|
477
|
+
task_list_id: {
|
|
478
|
+
type: 'string',
|
|
479
|
+
description: 'ID of the task list to add the task to',
|
|
480
|
+
},
|
|
481
|
+
assignee_id: {
|
|
482
|
+
type: 'string',
|
|
483
|
+
description: 'ID of the person to assign the task to. If PRODUCTIVE_USER_ID is configured in environment, "me" refers to that user.',
|
|
484
|
+
},
|
|
485
|
+
due_date: {
|
|
486
|
+
type: 'string',
|
|
487
|
+
description: 'Due date in YYYY-MM-DD format',
|
|
488
|
+
},
|
|
489
|
+
status: {
|
|
490
|
+
type: 'string',
|
|
491
|
+
enum: ['open', 'closed'],
|
|
492
|
+
description: 'Task status (default: open)',
|
|
493
|
+
},
|
|
494
|
+
custom_fields: {
|
|
495
|
+
type: 'object',
|
|
496
|
+
additionalProperties: true,
|
|
497
|
+
description: 'Custom field values, keyed by custom field ID. Use list_custom_fields to find valid ' +
|
|
498
|
+
'field IDs and list_custom_field_options to find valid option IDs for dropdown/select ' +
|
|
499
|
+
"fields. The value shape depends on the field's type: a string for text fields, a number " +
|
|
500
|
+
'for numeric fields, a boolean for checkboxes, an ISO date string (YYYY-MM-DD) for date ' +
|
|
501
|
+
'fields, an array of option ID strings for dropdown/multi-select fields, or null to clear ' +
|
|
502
|
+
'the field.',
|
|
503
|
+
},
|
|
504
|
+
},
|
|
505
|
+
required: ['title'],
|
|
506
|
+
},
|
|
507
|
+
annotations: {
|
|
508
|
+
title: 'Create task',
|
|
509
|
+
readOnlyHint: false,
|
|
510
|
+
destructiveHint: false,
|
|
511
|
+
idempotentHint: false,
|
|
512
|
+
openWorldHint: true,
|
|
513
|
+
},
|
|
514
|
+
};
|
|
515
|
+
const updateTaskSchema = z.object({
|
|
516
|
+
task_id: z.string().min(1, 'Task ID is required'),
|
|
517
|
+
title: z.string().min(1, 'Task title cannot be empty').optional(),
|
|
518
|
+
description: z.string().optional(),
|
|
519
|
+
description_html: z.string().optional(),
|
|
520
|
+
assignee_id: z
|
|
521
|
+
.string()
|
|
522
|
+
.nullable()
|
|
523
|
+
.optional()
|
|
524
|
+
.describe('ID of the person to assign, or null to unassign'),
|
|
525
|
+
custom_fields: z
|
|
526
|
+
.record(z.string(), z.union([z.string(), z.number(), z.boolean(), z.array(z.string()), z.null()]))
|
|
527
|
+
.optional(),
|
|
528
|
+
});
|
|
529
|
+
export async function updateTaskTool(client, args, config) {
|
|
530
|
+
try {
|
|
531
|
+
const params = updateTaskSchema.parse(args);
|
|
532
|
+
if (!params.title &&
|
|
533
|
+
params.description === undefined &&
|
|
534
|
+
params.description_html === undefined &&
|
|
535
|
+
params.assignee_id === undefined &&
|
|
536
|
+
params.custom_fields === undefined) {
|
|
537
|
+
throw new McpError(ErrorCode.InvalidParams, 'At least one field (title, description, description_html, assignee_id, or custom_fields) must be provided for update');
|
|
538
|
+
}
|
|
539
|
+
// Resolve "me" and null; leave undefined untouched (field not being updated)
|
|
540
|
+
let resolvedAssigneeId;
|
|
541
|
+
if (params.assignee_id !== undefined) {
|
|
542
|
+
if (params.assignee_id === 'me') {
|
|
543
|
+
if (!config?.PRODUCTIVE_USER_ID) {
|
|
544
|
+
throw new McpError(ErrorCode.InvalidParams, 'Cannot use "me" reference - PRODUCTIVE_USER_ID is not configured in environment');
|
|
545
|
+
}
|
|
546
|
+
resolvedAssigneeId = config.PRODUCTIVE_USER_ID;
|
|
547
|
+
}
|
|
548
|
+
else {
|
|
549
|
+
resolvedAssigneeId = params.assignee_id;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
const taskUpdate = {
|
|
553
|
+
data: {
|
|
554
|
+
type: 'tasks',
|
|
555
|
+
id: params.task_id,
|
|
556
|
+
},
|
|
557
|
+
};
|
|
558
|
+
const attributes = {};
|
|
559
|
+
if (params.title) {
|
|
560
|
+
attributes.title = params.title;
|
|
561
|
+
}
|
|
562
|
+
if (params.description_html !== undefined) {
|
|
563
|
+
attributes.description = params.description_html;
|
|
564
|
+
}
|
|
565
|
+
else if (params.description !== undefined) {
|
|
566
|
+
attributes.description = params.description;
|
|
567
|
+
}
|
|
568
|
+
if (params.custom_fields) {
|
|
569
|
+
// Productive REPLACES the whole custom_fields hash on PATCH, so sending only
|
|
570
|
+
// the fields being changed silently wipes every other custom field on the
|
|
571
|
+
// task (verified against the live API). Merge onto what is already stored.
|
|
572
|
+
const current = await client.getTask(params.task_id);
|
|
573
|
+
attributes.custom_fields = {
|
|
574
|
+
...(current.data.attributes.custom_fields ?? {}),
|
|
575
|
+
...params.custom_fields,
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
if (Object.keys(attributes).length > 0) {
|
|
579
|
+
taskUpdate.data.attributes = attributes;
|
|
580
|
+
}
|
|
581
|
+
if (resolvedAssigneeId !== undefined) {
|
|
582
|
+
taskUpdate.data.relationships = {
|
|
583
|
+
assignee: {
|
|
584
|
+
data: resolvedAssigneeId === null ? null : { id: resolvedAssigneeId, type: 'people' },
|
|
585
|
+
},
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
const response = await client.updateTask(params.task_id, taskUpdate);
|
|
589
|
+
let text = `Task updated successfully!\n`;
|
|
590
|
+
text += `Task: ${response.data.attributes.title} (ID: ${response.data.id})\n`;
|
|
591
|
+
if (params.title) {
|
|
592
|
+
text += `✓ Title updated to: "${response.data.attributes.title}"\n`;
|
|
593
|
+
}
|
|
594
|
+
if (params.description_html !== undefined || params.description !== undefined) {
|
|
595
|
+
if (response.data.attributes.description) {
|
|
596
|
+
const truncated = response.data.attributes.description.length > 100
|
|
597
|
+
? response.data.attributes.description.substring(0, 100) + '...'
|
|
598
|
+
: response.data.attributes.description;
|
|
599
|
+
text += `✓ Description updated${params.description_html ? ' (HTML)' : ''}: "${truncated}"\n`;
|
|
600
|
+
}
|
|
601
|
+
else {
|
|
602
|
+
text += `✓ Description cleared\n`;
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
if (resolvedAssigneeId !== undefined) {
|
|
606
|
+
if (resolvedAssigneeId) {
|
|
607
|
+
text += `✓ Assigned to: Person ID ${resolvedAssigneeId}`;
|
|
608
|
+
if (params.assignee_id === 'me' && config?.PRODUCTIVE_USER_ID) {
|
|
609
|
+
text += ` (me)`;
|
|
610
|
+
}
|
|
611
|
+
text += `\n`;
|
|
612
|
+
}
|
|
613
|
+
else {
|
|
614
|
+
text += `✓ Task is now unassigned\n`;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
if (params.custom_fields) {
|
|
618
|
+
const customFieldMap = await buildCustomFieldValueMap(client, [response.data]);
|
|
619
|
+
const block = formatCustomFieldsBlock(customFieldMap, response.data.attributes.custom_fields);
|
|
620
|
+
if (block) {
|
|
621
|
+
text += `${block}\n`;
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
if (response.data.attributes.updated_at) {
|
|
625
|
+
text += `Updated at: ${response.data.attributes.updated_at}`;
|
|
626
|
+
}
|
|
627
|
+
return {
|
|
628
|
+
content: [
|
|
629
|
+
{
|
|
630
|
+
type: 'text',
|
|
631
|
+
text: text,
|
|
632
|
+
},
|
|
633
|
+
],
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
catch (error) {
|
|
637
|
+
throw toMcpError(error);
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
export const updateTaskDefinition = {
|
|
641
|
+
name: 'update_task',
|
|
642
|
+
description: "Update an existing task's title, description, assignee, and/or custom fields in a single call. " +
|
|
643
|
+
"To change task status (open/closed) use update_task_status instead -- that's a separate workflow-state " +
|
|
644
|
+
'transition, not a content edit. To move a task between task lists, use move_task_to_list. ' +
|
|
645
|
+
'At least one field must be provided.',
|
|
646
|
+
inputSchema: {
|
|
647
|
+
type: 'object',
|
|
648
|
+
properties: {
|
|
649
|
+
task_id: {
|
|
650
|
+
type: 'string',
|
|
651
|
+
description: 'ID of the task to update (required)',
|
|
652
|
+
},
|
|
653
|
+
title: {
|
|
654
|
+
type: 'string',
|
|
655
|
+
description: 'New title/name for the task (optional, but cannot be empty if provided)',
|
|
656
|
+
},
|
|
657
|
+
description: {
|
|
658
|
+
type: 'string',
|
|
659
|
+
description: 'New description for the task in plain text (optional, use empty string to clear description)',
|
|
660
|
+
},
|
|
661
|
+
description_html: {
|
|
662
|
+
type: 'string',
|
|
663
|
+
description: 'New description with HTML formatting. Supports tags like <h2>, <p>, <ul>, <li>, <strong>, <em>, <a href="">. Takes precedence over description if both provided.',
|
|
664
|
+
},
|
|
665
|
+
assignee_id: {
|
|
666
|
+
type: ['string', 'null'],
|
|
667
|
+
description: 'ID of the person to assign the task to, or null to unassign. If PRODUCTIVE_USER_ID is ' +
|
|
668
|
+
'configured in environment, "me" resolves to that user.',
|
|
669
|
+
},
|
|
670
|
+
custom_fields: {
|
|
671
|
+
type: 'object',
|
|
672
|
+
additionalProperties: true,
|
|
673
|
+
description: 'Custom field values to set, keyed by custom field ID. Use list_custom_fields to find valid ' +
|
|
674
|
+
'field IDs and list_custom_field_options to find valid option IDs for dropdown/select ' +
|
|
675
|
+
"fields. The value shape depends on the field's type: a string for text fields, a number " +
|
|
676
|
+
'for numeric fields, a boolean for checkboxes, an ISO date string (YYYY-MM-DD) for date ' +
|
|
677
|
+
'fields, an array of option ID strings for dropdown/multi-select fields, or null to clear ' +
|
|
678
|
+
'the field.',
|
|
679
|
+
},
|
|
680
|
+
},
|
|
681
|
+
required: ['task_id'],
|
|
682
|
+
examples: [
|
|
683
|
+
{ task_id: '123', assignee_id: 'me' },
|
|
684
|
+
{
|
|
685
|
+
task_id: '123',
|
|
686
|
+
custom_fields: { '456': 'In Progress', '789': ['101', '102'] },
|
|
687
|
+
},
|
|
688
|
+
],
|
|
689
|
+
},
|
|
690
|
+
annotations: {
|
|
691
|
+
title: 'Update task',
|
|
692
|
+
readOnlyHint: false,
|
|
693
|
+
destructiveHint: false,
|
|
694
|
+
idempotentHint: true,
|
|
695
|
+
openWorldHint: true,
|
|
696
|
+
},
|
|
697
|
+
};
|
|
698
|
+
const deleteTaskSchema = z.object({
|
|
699
|
+
task_id: z.string().min(1, 'Task ID is required'),
|
|
700
|
+
});
|
|
701
|
+
export async function deleteTaskTool(client, args) {
|
|
702
|
+
try {
|
|
703
|
+
const params = deleteTaskSchema.parse(args);
|
|
704
|
+
await client.deleteTask(params.task_id);
|
|
705
|
+
return {
|
|
706
|
+
content: [
|
|
707
|
+
{
|
|
708
|
+
type: 'text',
|
|
709
|
+
text: `Task ${params.task_id} has been successfully deleted.`,
|
|
710
|
+
},
|
|
711
|
+
],
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
catch (error) {
|
|
715
|
+
throw toMcpError(error);
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
export const deleteTaskDefinition = {
|
|
719
|
+
name: 'delete_task',
|
|
720
|
+
description: 'Delete a task from Productive.io by its ID',
|
|
721
|
+
inputSchema: {
|
|
722
|
+
type: 'object',
|
|
723
|
+
properties: {
|
|
724
|
+
task_id: {
|
|
725
|
+
type: 'string',
|
|
726
|
+
description: 'The ID of the task to delete (required)',
|
|
727
|
+
},
|
|
728
|
+
},
|
|
729
|
+
required: ['task_id'],
|
|
730
|
+
},
|
|
731
|
+
annotations: {
|
|
732
|
+
title: 'Delete task',
|
|
733
|
+
readOnlyHint: false,
|
|
734
|
+
destructiveHint: true,
|
|
735
|
+
idempotentHint: true,
|
|
736
|
+
openWorldHint: true,
|
|
737
|
+
},
|
|
738
|
+
};
|