@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,736 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
|
|
3
|
+
import { buildIncludeMap, resolveName } from './include-resolver.js';
|
|
4
|
+
import { toMcpError } from '../utils/errors.js';
|
|
5
|
+
/** Coerce "true"/"false" strings to booleans (some MCP clients send strings). */
|
|
6
|
+
const coerceBoolean = z.preprocess((v) => (v === 'true' ? true : v === 'false' ? false : v), z.boolean());
|
|
7
|
+
// Helper function to format minutes into a human-readable display string
|
|
8
|
+
export function formatMinutesDisplay(totalMinutes) {
|
|
9
|
+
const hours = Math.floor(totalMinutes / 60);
|
|
10
|
+
const minutes = totalMinutes % 60;
|
|
11
|
+
if (hours > 0) {
|
|
12
|
+
return minutes > 0 ? `${hours}h ${minutes}m` : `${hours}h`;
|
|
13
|
+
}
|
|
14
|
+
return `${minutes}m`;
|
|
15
|
+
}
|
|
16
|
+
// Helper function to parse time input into minutes
|
|
17
|
+
export function parseTimeToMinutes(timeInput) {
|
|
18
|
+
const input = timeInput.toLowerCase().trim();
|
|
19
|
+
// Handle hour formats: "2h", "2.5h", "2 hours"
|
|
20
|
+
const hourMatch = input.match(/^(\d*\.?\d+)\s*h(?:ours?)?$/);
|
|
21
|
+
if (hourMatch) {
|
|
22
|
+
return Math.round(parseFloat(hourMatch[1]) * 60);
|
|
23
|
+
}
|
|
24
|
+
// Handle minute formats: "120m", "120 minutes"
|
|
25
|
+
const minuteMatch = input.match(/^(\d+)\s*m(?:inutes?)?$/);
|
|
26
|
+
if (minuteMatch) {
|
|
27
|
+
return parseInt(minuteMatch[1], 10);
|
|
28
|
+
}
|
|
29
|
+
// Handle decimal hour formats: "2.5", "1.25"
|
|
30
|
+
const decimalMatch = input.match(/^(\d*\.?\d+)$/);
|
|
31
|
+
if (decimalMatch) {
|
|
32
|
+
return Math.round(parseFloat(decimalMatch[1]) * 60);
|
|
33
|
+
}
|
|
34
|
+
throw new Error(`Invalid time format: ${timeInput}. Use formats like "2h", "120m", or "2.5"`);
|
|
35
|
+
}
|
|
36
|
+
// Helper function to parse date input
|
|
37
|
+
export function parseDate(dateInput) {
|
|
38
|
+
const input = dateInput.toLowerCase().trim();
|
|
39
|
+
const today = new Date();
|
|
40
|
+
if (input === 'today') {
|
|
41
|
+
return today.toISOString().split('T')[0];
|
|
42
|
+
}
|
|
43
|
+
if (input === 'yesterday') {
|
|
44
|
+
const yesterday = new Date(today);
|
|
45
|
+
yesterday.setDate(yesterday.getDate() - 1);
|
|
46
|
+
return yesterday.toISOString().split('T')[0];
|
|
47
|
+
}
|
|
48
|
+
// Validate YYYY-MM-DD format
|
|
49
|
+
const dateMatch = input.match(/^(\d{4})-(\d{2})-(\d{2})$/);
|
|
50
|
+
if (dateMatch) {
|
|
51
|
+
const year = parseInt(dateMatch[1], 10);
|
|
52
|
+
const month = parseInt(dateMatch[2], 10);
|
|
53
|
+
const day = parseInt(dateMatch[3], 10);
|
|
54
|
+
// Basic validation
|
|
55
|
+
if (month < 1 || month > 12 || day < 1 || day > 31) {
|
|
56
|
+
throw new Error(`Invalid date: ${dateInput}`);
|
|
57
|
+
}
|
|
58
|
+
return input;
|
|
59
|
+
}
|
|
60
|
+
throw new Error(`Invalid date format: ${dateInput}. Use "today", "yesterday", or YYYY-MM-DD format`);
|
|
61
|
+
}
|
|
62
|
+
// Helper function to summarize a time entry's approval state for display
|
|
63
|
+
export function formatApprovalLine(entry, approverName) {
|
|
64
|
+
const approverId = entry.relationships?.approver?.data?.id;
|
|
65
|
+
if (entry.attributes.approved) {
|
|
66
|
+
return `Approval: Approved${approverName ? ` by ${approverName}` : approverId ? ` by ID ${approverId}` : ''}${entry.attributes.approved_at ? ` on ${entry.attributes.approved_at}` : ''}`;
|
|
67
|
+
}
|
|
68
|
+
if (entry.attributes.rejected) {
|
|
69
|
+
return `Approval: Rejected${entry.attributes.rejected_reason ? ` (${entry.attributes.rejected_reason})` : ''}${entry.attributes.rejected_at ? ` on ${entry.attributes.rejected_at}` : ''}`;
|
|
70
|
+
}
|
|
71
|
+
if (entry.attributes.submitted) {
|
|
72
|
+
return 'Approval: Submitted, awaiting decision';
|
|
73
|
+
}
|
|
74
|
+
return 'Approval: Not submitted';
|
|
75
|
+
}
|
|
76
|
+
const listTimeEntriesSchema = z.object({
|
|
77
|
+
date: z.string().optional(),
|
|
78
|
+
after: z.string().optional(),
|
|
79
|
+
before: z.string().optional(),
|
|
80
|
+
person_id: z.string().optional(),
|
|
81
|
+
project_id: z.string().optional(),
|
|
82
|
+
task_id: z.string().optional(),
|
|
83
|
+
service_id: z.string().optional(),
|
|
84
|
+
approved: coerceBoolean.optional(),
|
|
85
|
+
approver_id: z.string().optional(),
|
|
86
|
+
limit: z.coerce.number().min(1).max(200).default(30).optional(),
|
|
87
|
+
});
|
|
88
|
+
const createTimeEntrySchema = z.object({
|
|
89
|
+
date: z.string().min(1, 'Date is required'),
|
|
90
|
+
time: z.string().min(1, 'Time is required'),
|
|
91
|
+
person_id: z.string().min(1, 'Person ID is required'),
|
|
92
|
+
service_id: z.string().min(1, 'Service ID is required'),
|
|
93
|
+
task_id: z
|
|
94
|
+
.string()
|
|
95
|
+
.optional()
|
|
96
|
+
.describe('Optional task ID - use list_project_tasks to find available tasks for the project'),
|
|
97
|
+
note: z
|
|
98
|
+
.string()
|
|
99
|
+
.min(10, 'Work description must be at least 10 characters')
|
|
100
|
+
.describe('REQUIRED: Detailed description of work performed - be specific about what was accomplished, including bullet points if multiple items'),
|
|
101
|
+
billable_time: z.string().optional(),
|
|
102
|
+
confirm: coerceBoolean.optional().default(false),
|
|
103
|
+
});
|
|
104
|
+
const listServicesSchema = z.object({
|
|
105
|
+
company_id: z.string().optional(),
|
|
106
|
+
budget_status: z.coerce.number().min(1).max(2).optional(),
|
|
107
|
+
limit: z.coerce.number().min(1).max(200).default(30).optional(),
|
|
108
|
+
});
|
|
109
|
+
const getProjectServicesSchema = z.object({
|
|
110
|
+
project_id: z.string().min(1, 'Project ID is required'),
|
|
111
|
+
limit: z.coerce.number().min(1).max(200).default(30).optional(),
|
|
112
|
+
});
|
|
113
|
+
export async function listTimeEntresTool(client, args, config) {
|
|
114
|
+
try {
|
|
115
|
+
const params = listTimeEntriesSchema.parse(args);
|
|
116
|
+
// Handle "me" reference for person_id
|
|
117
|
+
let personId = params.person_id;
|
|
118
|
+
if (personId === 'me') {
|
|
119
|
+
if (!config?.PRODUCTIVE_USER_ID) {
|
|
120
|
+
throw new McpError(ErrorCode.InvalidParams, 'Cannot use "me" reference - PRODUCTIVE_USER_ID is not configured in environment');
|
|
121
|
+
}
|
|
122
|
+
personId = config.PRODUCTIVE_USER_ID;
|
|
123
|
+
}
|
|
124
|
+
const response = await client.listTimeEntries({
|
|
125
|
+
date: params.date,
|
|
126
|
+
after: params.after,
|
|
127
|
+
before: params.before,
|
|
128
|
+
person_id: personId,
|
|
129
|
+
project_id: params.project_id,
|
|
130
|
+
task_id: params.task_id,
|
|
131
|
+
service_id: params.service_id,
|
|
132
|
+
approved: params.approved,
|
|
133
|
+
approver_id: params.approver_id,
|
|
134
|
+
limit: params.limit,
|
|
135
|
+
});
|
|
136
|
+
if (!response.data || response.data.length === 0) {
|
|
137
|
+
return {
|
|
138
|
+
content: [
|
|
139
|
+
{
|
|
140
|
+
type: 'text',
|
|
141
|
+
text: 'No time entries found matching the criteria.',
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
const nameMap = buildIncludeMap(response.included);
|
|
147
|
+
const entriesText = response.data
|
|
148
|
+
.map((entry) => {
|
|
149
|
+
const personId = entry.relationships?.person?.data?.id;
|
|
150
|
+
const serviceId = entry.relationships?.service?.data?.id;
|
|
151
|
+
const taskId = entry.relationships?.task?.data?.id;
|
|
152
|
+
const projectId = entry.relationships?.project?.data?.id;
|
|
153
|
+
const approverId = entry.relationships?.approver?.data?.id;
|
|
154
|
+
const personName = resolveName(nameMap, 'people', personId) ?? 'Unknown';
|
|
155
|
+
const taskName = resolveName(nameMap, 'tasks', taskId);
|
|
156
|
+
const approverName = resolveName(nameMap, 'people', approverId);
|
|
157
|
+
const timeDisplay = formatMinutesDisplay(entry.attributes.time);
|
|
158
|
+
let billableDisplay = '';
|
|
159
|
+
if (entry.attributes.billable_time !== undefined &&
|
|
160
|
+
entry.attributes.billable_time !== entry.attributes.time) {
|
|
161
|
+
billableDisplay = ` (Billable: ${formatMinutesDisplay(entry.attributes.billable_time)})`;
|
|
162
|
+
}
|
|
163
|
+
return `• Time Entry (ID: ${entry.id})
|
|
164
|
+
Date: ${entry.attributes.date}
|
|
165
|
+
Time: ${timeDisplay}${billableDisplay}
|
|
166
|
+
Note: ${entry.attributes.note || 'No note'}
|
|
167
|
+
${formatApprovalLine(entry, approverName)}
|
|
168
|
+
Person: ${personName}${personId ? ` (ID: ${personId})` : ''}
|
|
169
|
+
Service ID: ${serviceId || 'Unknown'}
|
|
170
|
+
${taskName ? `Task: ${taskName}` : taskId ? `Task ID: ${taskId}` : 'Task: None'}
|
|
171
|
+
Project ID: ${projectId || 'None'}`;
|
|
172
|
+
})
|
|
173
|
+
.join('\n\n');
|
|
174
|
+
const totalMinutes = response.data.reduce((sum, entry) => sum + entry.attributes.time, 0);
|
|
175
|
+
const totalDisplay = formatMinutesDisplay(totalMinutes);
|
|
176
|
+
const summary = `Found ${response.data.length} time entr${response.data.length !== 1 ? 'ies' : 'y'}${response.meta?.total_count ? ` (showing ${response.data.length} of ${response.meta.total_count})` : ''}:\n\nTotal Time: ${totalDisplay}\n\n${entriesText}`;
|
|
177
|
+
return {
|
|
178
|
+
content: [
|
|
179
|
+
{
|
|
180
|
+
type: 'text',
|
|
181
|
+
text: summary,
|
|
182
|
+
},
|
|
183
|
+
],
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
throw toMcpError(error);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
export async function createTimeEntryTool(client, args, config) {
|
|
191
|
+
try {
|
|
192
|
+
const params = createTimeEntrySchema.parse(args);
|
|
193
|
+
// Handle "me" reference for person_id
|
|
194
|
+
let personId = params.person_id;
|
|
195
|
+
if (personId === 'me') {
|
|
196
|
+
if (!config?.PRODUCTIVE_USER_ID) {
|
|
197
|
+
throw new McpError(ErrorCode.InvalidParams, 'Cannot use "me" reference - PRODUCTIVE_USER_ID is not configured in environment');
|
|
198
|
+
}
|
|
199
|
+
personId = config.PRODUCTIVE_USER_ID;
|
|
200
|
+
}
|
|
201
|
+
// Parse and validate date
|
|
202
|
+
let parsedDate;
|
|
203
|
+
try {
|
|
204
|
+
parsedDate = parseDate(params.date);
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
throw new McpError(ErrorCode.InvalidParams, error instanceof Error ? error.message : 'Invalid date format');
|
|
208
|
+
}
|
|
209
|
+
// Parse and validate time
|
|
210
|
+
let timeInMinutes;
|
|
211
|
+
try {
|
|
212
|
+
timeInMinutes = parseTimeToMinutes(params.time);
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
throw new McpError(ErrorCode.InvalidParams, error instanceof Error ? error.message : 'Invalid time format');
|
|
216
|
+
}
|
|
217
|
+
// Parse billable time if provided
|
|
218
|
+
let billableTimeInMinutes;
|
|
219
|
+
if (params.billable_time) {
|
|
220
|
+
try {
|
|
221
|
+
billableTimeInMinutes = parseTimeToMinutes(params.billable_time);
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
throw new McpError(ErrorCode.InvalidParams, `Invalid billable time format: ${error instanceof Error ? error.message : 'Invalid time format'}`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
// If not confirmed, show confirmation details
|
|
228
|
+
if (!params.confirm) {
|
|
229
|
+
const timeDisplay = formatMinutesDisplay(timeInMinutes);
|
|
230
|
+
let billableDisplay = '';
|
|
231
|
+
if (billableTimeInMinutes !== undefined) {
|
|
232
|
+
billableDisplay = `\nBillable Time: ${formatMinutesDisplay(billableTimeInMinutes)}`;
|
|
233
|
+
}
|
|
234
|
+
return {
|
|
235
|
+
content: [
|
|
236
|
+
{
|
|
237
|
+
type: 'text',
|
|
238
|
+
text: `Time Entry Ready to Create:
|
|
239
|
+
|
|
240
|
+
Date: ${parsedDate}
|
|
241
|
+
Time: ${timeDisplay}${billableDisplay}
|
|
242
|
+
Person ID: ${personId}${params.person_id === 'me' ? ' (me)' : ''}
|
|
243
|
+
Service ID: ${params.service_id}
|
|
244
|
+
${params.task_id ? `Task ID: ${params.task_id}` : 'No task specified'}
|
|
245
|
+
${params.note ? `Note: ${params.note}` : 'No note'}
|
|
246
|
+
|
|
247
|
+
To create this time entry, call this tool again with the same parameters and add "confirm": true`,
|
|
248
|
+
},
|
|
249
|
+
],
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
const timeEntryData = {
|
|
253
|
+
data: {
|
|
254
|
+
type: 'time_entries',
|
|
255
|
+
attributes: {
|
|
256
|
+
date: parsedDate,
|
|
257
|
+
time: timeInMinutes,
|
|
258
|
+
...(billableTimeInMinutes !== undefined && {
|
|
259
|
+
billable_time: billableTimeInMinutes,
|
|
260
|
+
}),
|
|
261
|
+
...(params.note && { note: params.note }),
|
|
262
|
+
},
|
|
263
|
+
relationships: {
|
|
264
|
+
person: {
|
|
265
|
+
data: {
|
|
266
|
+
id: personId,
|
|
267
|
+
type: 'people',
|
|
268
|
+
},
|
|
269
|
+
},
|
|
270
|
+
service: {
|
|
271
|
+
data: {
|
|
272
|
+
id: params.service_id,
|
|
273
|
+
type: 'services',
|
|
274
|
+
},
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
};
|
|
279
|
+
// Add task relationship if provided
|
|
280
|
+
if (params.task_id) {
|
|
281
|
+
timeEntryData.data.relationships.task = {
|
|
282
|
+
data: {
|
|
283
|
+
id: params.task_id,
|
|
284
|
+
type: 'tasks',
|
|
285
|
+
},
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
const response = await client.createTimeEntry(timeEntryData);
|
|
289
|
+
const timeDisplay = formatMinutesDisplay(response.data.attributes.time);
|
|
290
|
+
let billableDisplay = '';
|
|
291
|
+
if (response.data.attributes.billable_time !== undefined &&
|
|
292
|
+
response.data.attributes.billable_time !== response.data.attributes.time) {
|
|
293
|
+
billableDisplay = `\nBillable Time: ${formatMinutesDisplay(response.data.attributes.billable_time)}`;
|
|
294
|
+
}
|
|
295
|
+
let text = `Time entry created successfully!
|
|
296
|
+
Date: ${response.data.attributes.date}
|
|
297
|
+
Time: ${timeDisplay}${billableDisplay}
|
|
298
|
+
ID: ${response.data.id}`;
|
|
299
|
+
if (response.data.attributes.note) {
|
|
300
|
+
text += `\nNote: ${response.data.attributes.note}`;
|
|
301
|
+
}
|
|
302
|
+
text += `\nPerson ID: ${personId}`;
|
|
303
|
+
if (params.person_id === 'me' && config?.PRODUCTIVE_USER_ID) {
|
|
304
|
+
text += ` (me)`;
|
|
305
|
+
}
|
|
306
|
+
text += `\nService ID: ${params.service_id}`;
|
|
307
|
+
if (params.task_id) {
|
|
308
|
+
text += `\nTask ID: ${params.task_id}`;
|
|
309
|
+
}
|
|
310
|
+
if (response.data.attributes.created_at) {
|
|
311
|
+
text += `\nCreated at: ${response.data.attributes.created_at}`;
|
|
312
|
+
}
|
|
313
|
+
return {
|
|
314
|
+
content: [
|
|
315
|
+
{
|
|
316
|
+
type: 'text',
|
|
317
|
+
text: text,
|
|
318
|
+
},
|
|
319
|
+
],
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
catch (error) {
|
|
323
|
+
throw toMcpError(error);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
export async function listServicesTool(client, args) {
|
|
327
|
+
try {
|
|
328
|
+
const params = listServicesSchema.parse(args);
|
|
329
|
+
const response = await client.listServices({
|
|
330
|
+
company_id: params.company_id,
|
|
331
|
+
budget_status: params.budget_status,
|
|
332
|
+
limit: params.limit,
|
|
333
|
+
});
|
|
334
|
+
if (!response.data || response.data.length === 0) {
|
|
335
|
+
return {
|
|
336
|
+
content: [
|
|
337
|
+
{
|
|
338
|
+
type: 'text',
|
|
339
|
+
text: 'No services found matching the criteria.',
|
|
340
|
+
},
|
|
341
|
+
],
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
const servicesText = response.data
|
|
345
|
+
.map((service) => {
|
|
346
|
+
const companyId = service.relationships?.company?.data?.id;
|
|
347
|
+
return `• ${service.attributes.name} (ID: ${service.id})
|
|
348
|
+
${companyId ? `Company ID: ${companyId}` : ''}
|
|
349
|
+
${service.attributes.description ? `Description: ${service.attributes.description}` : 'No description'}`;
|
|
350
|
+
})
|
|
351
|
+
.join('\n\n');
|
|
352
|
+
const summary = `Found ${response.data.length} service${response.data.length !== 1 ? 's' : ''}${response.meta?.total_count ? ` (showing ${response.data.length} of ${response.meta.total_count})` : ''}:\n\n${servicesText}`;
|
|
353
|
+
return {
|
|
354
|
+
content: [
|
|
355
|
+
{
|
|
356
|
+
type: 'text',
|
|
357
|
+
text: summary,
|
|
358
|
+
},
|
|
359
|
+
],
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
catch (error) {
|
|
363
|
+
throw toMcpError(error);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
export async function getProjectServicesTool(client, args) {
|
|
367
|
+
try {
|
|
368
|
+
const params = getProjectServicesSchema.parse(args);
|
|
369
|
+
// Step 1: get deals for this project
|
|
370
|
+
const dealsResponse = await client.listProjectDeals({ project_id: params.project_id });
|
|
371
|
+
if (!dealsResponse.data || dealsResponse.data.length === 0) {
|
|
372
|
+
return {
|
|
373
|
+
content: [
|
|
374
|
+
{
|
|
375
|
+
type: 'text',
|
|
376
|
+
text: `No deals found for project ${params.project_id}. Cannot determine available services.`,
|
|
377
|
+
},
|
|
378
|
+
],
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
// Step 2: collect services from all deals (deduplicated by service ID)
|
|
382
|
+
const serviceMap = new Map();
|
|
383
|
+
for (const deal of dealsResponse.data) {
|
|
384
|
+
const dealServices = await client.listDealServices({ deal_id: deal.id, limit: 100 });
|
|
385
|
+
for (const service of dealServices.data ?? []) {
|
|
386
|
+
if (!serviceMap.has(service.id)) {
|
|
387
|
+
serviceMap.set(service.id, {
|
|
388
|
+
name: service.attributes.name,
|
|
389
|
+
dealName: deal.attributes.name,
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
if (serviceMap.size === 0) {
|
|
395
|
+
return {
|
|
396
|
+
content: [
|
|
397
|
+
{
|
|
398
|
+
type: 'text',
|
|
399
|
+
text: `No services found for project ${params.project_id}.`,
|
|
400
|
+
},
|
|
401
|
+
],
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
const servicesText = Array.from(serviceMap.entries())
|
|
405
|
+
.map(([id, { name, dealName }]) => `• ${name} (ID: ${id})\n Deal: ${dealName}`)
|
|
406
|
+
.join('\n\n');
|
|
407
|
+
const summary = `Services for project ${params.project_id} (${serviceMap.size} service${serviceMap.size !== 1 ? 's' : ''}):\n\n${servicesText}`;
|
|
408
|
+
return {
|
|
409
|
+
content: [{ type: 'text', text: summary }],
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
catch (error) {
|
|
413
|
+
throw toMcpError(error);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
export const listTimeEntriesDefinition = {
|
|
417
|
+
name: 'list_time_entries',
|
|
418
|
+
description: 'View existing time entries from Productive.io with detailed information including service and budget relationships. Use this to see what time has been logged and to which projects/services. If PRODUCTIVE_USER_ID is configured, you can use "me" to refer to the configured user for person_id.',
|
|
419
|
+
inputSchema: {
|
|
420
|
+
type: 'object',
|
|
421
|
+
properties: {
|
|
422
|
+
date: {
|
|
423
|
+
type: 'string',
|
|
424
|
+
description: 'Filter by specific date (YYYY-MM-DD format)',
|
|
425
|
+
},
|
|
426
|
+
after: {
|
|
427
|
+
type: 'string',
|
|
428
|
+
description: 'Filter entries after this date (YYYY-MM-DD format)',
|
|
429
|
+
},
|
|
430
|
+
before: {
|
|
431
|
+
type: 'string',
|
|
432
|
+
description: 'Filter entries before this date (YYYY-MM-DD format)',
|
|
433
|
+
},
|
|
434
|
+
person_id: {
|
|
435
|
+
type: 'string',
|
|
436
|
+
description: 'Filter by person ID. If PRODUCTIVE_USER_ID is configured in environment, "me" refers to that user.',
|
|
437
|
+
},
|
|
438
|
+
project_id: {
|
|
439
|
+
type: 'string',
|
|
440
|
+
description: 'Filter by project ID',
|
|
441
|
+
},
|
|
442
|
+
task_id: {
|
|
443
|
+
type: 'string',
|
|
444
|
+
description: 'Filter by task ID',
|
|
445
|
+
},
|
|
446
|
+
service_id: {
|
|
447
|
+
type: 'string',
|
|
448
|
+
description: 'Filter by service ID',
|
|
449
|
+
},
|
|
450
|
+
approved: {
|
|
451
|
+
type: 'boolean',
|
|
452
|
+
description: "Filter by approval state: true = approved, false = not approved (no decision yet, or rejected/pending). Maps to Productive's undocumented filter[status] internally.",
|
|
453
|
+
},
|
|
454
|
+
approver_id: {
|
|
455
|
+
type: 'string',
|
|
456
|
+
description: 'Filter by the ID of the person who approved the time entry.',
|
|
457
|
+
},
|
|
458
|
+
limit: {
|
|
459
|
+
type: 'number',
|
|
460
|
+
description: 'Number of time entries to return (1-200)',
|
|
461
|
+
minimum: 1,
|
|
462
|
+
maximum: 200,
|
|
463
|
+
default: 30,
|
|
464
|
+
},
|
|
465
|
+
},
|
|
466
|
+
required: [],
|
|
467
|
+
},
|
|
468
|
+
annotations: { title: 'List time entries', readOnlyHint: true, openWorldHint: true },
|
|
469
|
+
};
|
|
470
|
+
export const createTimeEntryDefinition = {
|
|
471
|
+
name: 'create_time_entry',
|
|
472
|
+
description: 'STEP 5 (FINAL) of timesheet workflow: Create a time entry with detailed work description. COMPLETE WORKFLOW: 1) list_projects → 2) list_project_deals → 3) list_deal_services → 4) list_project_tasks (recommended) → 5) create_time_entry. You MUST provide: valid service_id from the hierarchy, detailed work notes (minimum 10 chars), and optionally link to a specific task_id. This tool requires confirmation before creating. If PRODUCTIVE_USER_ID is configured, use "me" for person_id.',
|
|
473
|
+
inputSchema: {
|
|
474
|
+
type: 'object',
|
|
475
|
+
properties: {
|
|
476
|
+
date: {
|
|
477
|
+
type: 'string',
|
|
478
|
+
description: 'Date for the time entry. Accepts "today", "yesterday", or YYYY-MM-DD format (required)',
|
|
479
|
+
},
|
|
480
|
+
time: {
|
|
481
|
+
type: 'string',
|
|
482
|
+
description: 'Time duration. Accepts formats like "2h", "120m", "2.5h", or "2.5" (assumed hours) (required)',
|
|
483
|
+
},
|
|
484
|
+
person_id: {
|
|
485
|
+
type: 'string',
|
|
486
|
+
description: 'ID of the person logging time. If PRODUCTIVE_USER_ID is configured in environment, "me" refers to that user. (required)',
|
|
487
|
+
},
|
|
488
|
+
service_id: {
|
|
489
|
+
type: 'string',
|
|
490
|
+
description: 'ID of the service being performed (required)',
|
|
491
|
+
},
|
|
492
|
+
task_id: {
|
|
493
|
+
type: 'string',
|
|
494
|
+
description: 'ID of the task being worked on (recommended - use list_project_tasks to find available tasks)',
|
|
495
|
+
},
|
|
496
|
+
note: {
|
|
497
|
+
type: 'string',
|
|
498
|
+
description: 'REQUIRED: Detailed description of work performed - be specific about what was accomplished, include bullet points if multiple items (minimum 10 characters)',
|
|
499
|
+
minLength: 10,
|
|
500
|
+
},
|
|
501
|
+
billable_time: {
|
|
502
|
+
type: 'string',
|
|
503
|
+
description: 'Billable time duration, same format as time field. If not specified, defaults to the time value (optional)',
|
|
504
|
+
},
|
|
505
|
+
confirm: {
|
|
506
|
+
type: 'boolean',
|
|
507
|
+
description: 'Set to true to confirm and create the time entry. First call without this to see confirmation details.',
|
|
508
|
+
default: false,
|
|
509
|
+
},
|
|
510
|
+
},
|
|
511
|
+
required: ['date', 'time', 'person_id', 'service_id', 'note'],
|
|
512
|
+
},
|
|
513
|
+
annotations: {
|
|
514
|
+
title: 'Create time entry',
|
|
515
|
+
readOnlyHint: false,
|
|
516
|
+
destructiveHint: false,
|
|
517
|
+
idempotentHint: false,
|
|
518
|
+
openWorldHint: true,
|
|
519
|
+
},
|
|
520
|
+
};
|
|
521
|
+
export const listServicesDefinition = {
|
|
522
|
+
name: 'list_services',
|
|
523
|
+
description: 'List services in the organization. NOTE: For timesheet entries, use the proper workflow instead: list_projects → list_project_deals → list_deal_services → create_time_entry. For timers, use this tool directly with budget_status=1 to find services with open budgets, then pass the service_id to start_timer.',
|
|
524
|
+
inputSchema: {
|
|
525
|
+
type: 'object',
|
|
526
|
+
properties: {
|
|
527
|
+
company_id: {
|
|
528
|
+
type: 'string',
|
|
529
|
+
description: 'Filter services by company ID',
|
|
530
|
+
},
|
|
531
|
+
budget_status: {
|
|
532
|
+
type: 'number',
|
|
533
|
+
description: 'Filter by budget status: 1 = open, 2 = delivered',
|
|
534
|
+
minimum: 1,
|
|
535
|
+
maximum: 2,
|
|
536
|
+
},
|
|
537
|
+
limit: {
|
|
538
|
+
type: 'number',
|
|
539
|
+
description: 'Number of services to return (1-200)',
|
|
540
|
+
minimum: 1,
|
|
541
|
+
maximum: 200,
|
|
542
|
+
default: 30,
|
|
543
|
+
},
|
|
544
|
+
},
|
|
545
|
+
required: [],
|
|
546
|
+
},
|
|
547
|
+
annotations: { title: 'List services', readOnlyHint: true, openWorldHint: true },
|
|
548
|
+
};
|
|
549
|
+
// Zod schema for list project deals/budgets
|
|
550
|
+
const listProjectDealsSchema = z.object({
|
|
551
|
+
project_id: z.string().min(1, 'Project ID is required'),
|
|
552
|
+
budget_type: z
|
|
553
|
+
.number()
|
|
554
|
+
.int()
|
|
555
|
+
.min(1)
|
|
556
|
+
.max(2)
|
|
557
|
+
.optional()
|
|
558
|
+
.describe('Budget type: 1 = deal, 2 = budget'),
|
|
559
|
+
limit: z.coerce.number().min(1).max(200).default(30).optional(),
|
|
560
|
+
});
|
|
561
|
+
// Tool function for list project deals/budgets
|
|
562
|
+
export async function listProjectDealsTool(client, args) {
|
|
563
|
+
try {
|
|
564
|
+
const params = listProjectDealsSchema.parse(args);
|
|
565
|
+
const response = await client.listProjectDeals({
|
|
566
|
+
project_id: params.project_id,
|
|
567
|
+
budget_type: params.budget_type,
|
|
568
|
+
limit: params.limit,
|
|
569
|
+
});
|
|
570
|
+
if (!response.data || response.data.length === 0) {
|
|
571
|
+
return {
|
|
572
|
+
content: [
|
|
573
|
+
{
|
|
574
|
+
type: 'text',
|
|
575
|
+
text: 'No deals/budgets found for this project.',
|
|
576
|
+
},
|
|
577
|
+
],
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
const dealsText = response.data
|
|
581
|
+
.map((deal) => {
|
|
582
|
+
// `budget` is the real flag (true = production budget, false = sales deal).
|
|
583
|
+
// The old `budget_type`/`value` attributes do not exist, which made every
|
|
584
|
+
// row read "Unknown" with no amount. Totals arrive in cents.
|
|
585
|
+
const budgetType = deal.attributes.budget ? 'Budget' : 'Deal';
|
|
586
|
+
// Deals send this as a number while other resources send amounts as
|
|
587
|
+
// strings, so coerce before comparing -- a bare truthiness test would
|
|
588
|
+
// print "Value: 0.00" for a zero amount that arrived as a string.
|
|
589
|
+
const total = Number(deal.attributes.deal_value_total ?? 0);
|
|
590
|
+
const currency = deal.attributes.currency ? ` ${deal.attributes.currency}` : '';
|
|
591
|
+
const value = Number.isFinite(total) && total !== 0
|
|
592
|
+
? ` (Value: ${(total / 100).toFixed(2)}${currency})`
|
|
593
|
+
: '';
|
|
594
|
+
return `• ${budgetType} (ID: ${deal.id})
|
|
595
|
+
Name: ${deal.attributes.name}${value}`;
|
|
596
|
+
})
|
|
597
|
+
.join('\n\n');
|
|
598
|
+
const typeFilter = params.budget_type === 1
|
|
599
|
+
? ' deals'
|
|
600
|
+
: params.budget_type === 2
|
|
601
|
+
? ' budgets'
|
|
602
|
+
: ' deals/budgets';
|
|
603
|
+
const summary = `Found ${response.data.length}${typeFilter} for project ${params.project_id}:\n\n${dealsText}`;
|
|
604
|
+
return {
|
|
605
|
+
content: [
|
|
606
|
+
{
|
|
607
|
+
type: 'text',
|
|
608
|
+
text: summary,
|
|
609
|
+
},
|
|
610
|
+
],
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
catch (error) {
|
|
614
|
+
throw toMcpError(error);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
// Zod schema for list deal services
|
|
618
|
+
const listDealServicesSchema = z.object({
|
|
619
|
+
deal_id: z.string().min(1, 'Deal/Budget ID is required'),
|
|
620
|
+
limit: z.coerce.number().min(1).max(200).default(30).optional(),
|
|
621
|
+
});
|
|
622
|
+
// Tool function for list deal services
|
|
623
|
+
export async function listDealServicesTool(client, args) {
|
|
624
|
+
try {
|
|
625
|
+
const params = listDealServicesSchema.parse(args);
|
|
626
|
+
const response = await client.listDealServices({
|
|
627
|
+
deal_id: params.deal_id,
|
|
628
|
+
limit: params.limit,
|
|
629
|
+
});
|
|
630
|
+
if (!response.data || response.data.length === 0) {
|
|
631
|
+
return {
|
|
632
|
+
content: [
|
|
633
|
+
{
|
|
634
|
+
type: 'text',
|
|
635
|
+
text: 'No services found for this deal/budget.',
|
|
636
|
+
},
|
|
637
|
+
],
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
const servicesText = response.data
|
|
641
|
+
.map((service) => {
|
|
642
|
+
return `• Service (ID: ${service.id})
|
|
643
|
+
Name: ${service.attributes.name || 'Unnamed Service'}
|
|
644
|
+
${service.attributes.description ? `Description: ${service.attributes.description}` : 'No description'}`;
|
|
645
|
+
})
|
|
646
|
+
.join('\n\n');
|
|
647
|
+
const summary = `Found ${response.data.length} service${response.data.length !== 1 ? 's' : ''} for deal/budget ${params.deal_id}:\n\n${servicesText}`;
|
|
648
|
+
return {
|
|
649
|
+
content: [
|
|
650
|
+
{
|
|
651
|
+
type: 'text',
|
|
652
|
+
text: summary,
|
|
653
|
+
},
|
|
654
|
+
],
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
catch (error) {
|
|
658
|
+
throw toMcpError(error);
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
export const listProjectDealsDefinition = {
|
|
662
|
+
name: 'list_project_deals',
|
|
663
|
+
description: 'STEP 2 of timesheet workflow: Get deals/budgets for a specific project. COMPLETE WORKFLOW: 1) list_projects → 2) list_project_deals → 3) list_deal_services → 4) list_project_tasks (recommended) → 5) create_time_entry. This follows: Project → Deal/Budget → Service → Task → Time Entry.',
|
|
664
|
+
inputSchema: {
|
|
665
|
+
type: 'object',
|
|
666
|
+
properties: {
|
|
667
|
+
project_id: {
|
|
668
|
+
type: 'string',
|
|
669
|
+
description: 'The ID of the project (required)',
|
|
670
|
+
},
|
|
671
|
+
budget_type: {
|
|
672
|
+
type: 'number',
|
|
673
|
+
description: 'Filter by budget type: 1 = deal, 2 = budget',
|
|
674
|
+
minimum: 1,
|
|
675
|
+
maximum: 2,
|
|
676
|
+
},
|
|
677
|
+
limit: {
|
|
678
|
+
type: 'number',
|
|
679
|
+
description: 'Number of deals/budgets to return (1-200)',
|
|
680
|
+
minimum: 1,
|
|
681
|
+
maximum: 200,
|
|
682
|
+
default: 30,
|
|
683
|
+
},
|
|
684
|
+
},
|
|
685
|
+
required: ['project_id'],
|
|
686
|
+
},
|
|
687
|
+
annotations: { title: 'List project deals', readOnlyHint: true, openWorldHint: true },
|
|
688
|
+
};
|
|
689
|
+
export const listDealServicesDefinition = {
|
|
690
|
+
name: 'list_deal_services',
|
|
691
|
+
description: 'STEP 3 of timesheet workflow: Get services for a specific deal/budget. COMPLETE WORKFLOW: 1) list_projects → 2) list_project_deals → 3) list_deal_services → 4) list_project_tasks (recommended) → 5) create_time_entry. After this, optionally use list_project_tasks to find specific tasks to link your time entry to.',
|
|
692
|
+
inputSchema: {
|
|
693
|
+
type: 'object',
|
|
694
|
+
properties: {
|
|
695
|
+
deal_id: {
|
|
696
|
+
type: 'string',
|
|
697
|
+
description: 'The ID of the deal/budget (required)',
|
|
698
|
+
},
|
|
699
|
+
limit: {
|
|
700
|
+
type: 'number',
|
|
701
|
+
description: 'Number of services to return (1-200)',
|
|
702
|
+
minimum: 1,
|
|
703
|
+
maximum: 200,
|
|
704
|
+
default: 30,
|
|
705
|
+
},
|
|
706
|
+
},
|
|
707
|
+
required: ['deal_id'],
|
|
708
|
+
},
|
|
709
|
+
annotations: { title: 'List deal services', readOnlyHint: true, openWorldHint: true },
|
|
710
|
+
};
|
|
711
|
+
export const getProjectServicesDefinition = {
|
|
712
|
+
name: 'get_project_services',
|
|
713
|
+
description: 'DEPRECATED — prefer list_project_deals followed by list_deal_services instead. This tool just re-implements that same two-step chain internally and less efficiently: it fetches every deal for the project, then makes one list_deal_services call per deal (N+1 API calls) to collect and de-duplicate their services. Kept only for backward compatibility; do not use it in new timesheet flows.',
|
|
714
|
+
inputSchema: {
|
|
715
|
+
type: 'object',
|
|
716
|
+
properties: {
|
|
717
|
+
project_id: {
|
|
718
|
+
type: 'string',
|
|
719
|
+
description: 'The ID of the project',
|
|
720
|
+
},
|
|
721
|
+
limit: {
|
|
722
|
+
type: 'number',
|
|
723
|
+
description: 'Number of services to return (1-200)',
|
|
724
|
+
minimum: 1,
|
|
725
|
+
maximum: 200,
|
|
726
|
+
default: 30,
|
|
727
|
+
},
|
|
728
|
+
},
|
|
729
|
+
required: ['project_id'],
|
|
730
|
+
},
|
|
731
|
+
annotations: {
|
|
732
|
+
title: 'Get project services (deprecated)',
|
|
733
|
+
readOnlyHint: true,
|
|
734
|
+
openWorldHint: true,
|
|
735
|
+
},
|
|
736
|
+
};
|