@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.
Files changed (63) hide show
  1. package/LICENSE +190 -0
  2. package/NOTICE +6 -0
  3. package/README.md +353 -0
  4. package/build/api/bookings-client.js +249 -0
  5. package/build/api/capacity.js +279 -0
  6. package/build/api/client.js +1296 -0
  7. package/build/api/errors.js +50 -0
  8. package/build/api/invoice-time-entries.js +256 -0
  9. package/build/api/pages-tree.js +106 -0
  10. package/build/api/time-entry-notes.js +75 -0
  11. package/build/api/types.js +1 -0
  12. package/build/auth/logo.js +21 -0
  13. package/build/auth/self-resolver.js +61 -0
  14. package/build/config/index.js +24 -0
  15. package/build/index.js +15 -0
  16. package/build/prompts/timesheet.js +285 -0
  17. package/build/server.js +55 -0
  18. package/build/tools/absences.js +502 -0
  19. package/build/tools/activities.js +140 -0
  20. package/build/tools/bookings.js +531 -0
  21. package/build/tools/budget-services.js +168 -0
  22. package/build/tools/budgets.js +276 -0
  23. package/build/tools/capacity.js +281 -0
  24. package/build/tools/changeset.js +41 -0
  25. package/build/tools/comments.js +469 -0
  26. package/build/tools/companies.js +73 -0
  27. package/build/tools/custom-field-resolver.js +92 -0
  28. package/build/tools/custom-fields.js +155 -0
  29. package/build/tools/folders.js +516 -0
  30. package/build/tools/include-resolver.js +45 -0
  31. package/build/tools/invoice-actions.js +476 -0
  32. package/build/tools/invoice-defaults.js +65 -0
  33. package/build/tools/invoice-time-entries.js +320 -0
  34. package/build/tools/invoices.js +657 -0
  35. package/build/tools/my-tasks.js +100 -0
  36. package/build/tools/page-children.js +129 -0
  37. package/build/tools/pages.js +466 -0
  38. package/build/tools/people.js +147 -0
  39. package/build/tools/projects.js +77 -0
  40. package/build/tools/recent-updates.js +112 -0
  41. package/build/tools/registry.js +409 -0
  42. package/build/tools/subtasks.js +245 -0
  43. package/build/tools/task-backlog.js +106 -0
  44. package/build/tools/task-dependencies.js +244 -0
  45. package/build/tools/task-list-move.js +65 -0
  46. package/build/tools/task-lists.js +535 -0
  47. package/build/tools/task-reposition.js +199 -0
  48. package/build/tools/task-status.js +178 -0
  49. package/build/tools/tasks.js +738 -0
  50. package/build/tools/time-entries.js +736 -0
  51. package/build/tools/time-entry-approval.js +103 -0
  52. package/build/tools/time-entry-delete.js +72 -0
  53. package/build/tools/time-entry-update.js +126 -0
  54. package/build/tools/timers.js +195 -0
  55. package/build/tools/todos.js +342 -0
  56. package/build/tools/tool-helpers.js +114 -0
  57. package/build/tools/toolsets.js +153 -0
  58. package/build/tools/whoami.js +64 -0
  59. package/build/tools/workflow-statuses.js +81 -0
  60. package/build/utils/errors.js +67 -0
  61. package/build/utils/mentions.js +98 -0
  62. package/npm-shrinkwrap.json +1159 -0
  63. package/package.json +79 -0
@@ -0,0 +1,103 @@
1
+ import { z } from 'zod';
2
+ import { formatApprovalLine, formatMinutesDisplay } from './time-entries.js';
3
+ import { toMcpError } from '../utils/errors.js';
4
+ const setTimeEntryApprovalSchema = z
5
+ .object({
6
+ time_entry_id: z.string().min(1, 'Time entry ID is required'),
7
+ action: z.enum(['approve', 'unapprove', 'reject', 'unreject']),
8
+ rejected_reason: z.string().optional(),
9
+ })
10
+ .superRefine((data, ctx) => {
11
+ if (data.rejected_reason !== undefined && data.action !== 'reject') {
12
+ ctx.addIssue({
13
+ code: z.ZodIssueCode.custom,
14
+ path: ['rejected_reason'],
15
+ message: 'rejected_reason is only valid when action is "reject"',
16
+ });
17
+ }
18
+ });
19
+ function formatTimeEntryResponse(action, entry, extra) {
20
+ let text = `Time entry ${action}!\n`;
21
+ text += `ID: ${entry.id}\n`;
22
+ text += `Date: ${entry.attributes.date}\n`;
23
+ text += `Time: ${formatMinutesDisplay(entry.attributes.time)}`;
24
+ text += `\n${formatApprovalLine(entry)}`;
25
+ if (extra) {
26
+ text += `\n${extra}`;
27
+ }
28
+ if (entry.attributes.note) {
29
+ text += `\nNote: ${entry.attributes.note}`;
30
+ }
31
+ if (entry.attributes.updated_at) {
32
+ text += `\nUpdated at: ${entry.attributes.updated_at}`;
33
+ }
34
+ return { content: [{ type: 'text', text }] };
35
+ }
36
+ export async function setTimeEntryApprovalTool(client, args) {
37
+ try {
38
+ const params = setTimeEntryApprovalSchema.parse(args);
39
+ switch (params.action) {
40
+ case 'approve': {
41
+ const response = await client.approveTimeEntry(params.time_entry_id);
42
+ return formatTimeEntryResponse('approved successfully', response.data);
43
+ }
44
+ case 'unapprove': {
45
+ const response = await client.unapproveTimeEntry(params.time_entry_id);
46
+ return formatTimeEntryResponse('unapproved successfully', response.data);
47
+ }
48
+ case 'reject': {
49
+ const response = await client.rejectTimeEntry(params.time_entry_id, params.rejected_reason);
50
+ const extra = params.rejected_reason ? `Reason: ${params.rejected_reason}` : undefined;
51
+ return formatTimeEntryResponse('rejected', response.data, extra);
52
+ }
53
+ case 'unreject': {
54
+ const response = await client.unrejectTimeEntry(params.time_entry_id);
55
+ return formatTimeEntryResponse('unrejected successfully', response.data);
56
+ }
57
+ }
58
+ }
59
+ catch (error) {
60
+ throw toMcpError(error);
61
+ }
62
+ }
63
+ export const setTimeEntryApprovalDefinition = {
64
+ name: 'set_time_entry_approval',
65
+ description: 'Change the approval state of a time entry: approve/unapprove (reviewer sign-off) or ' +
66
+ 'reject/unreject (send back for correction, with an optional reason). Use list_time_entries ' +
67
+ 'first to find the time_entry_id. This is a single state machine -- the four Productive.io ' +
68
+ 'sub-endpoints (/approve, /unapprove, /reject, /unreject) are dispatched from the action value.',
69
+ inputSchema: {
70
+ type: 'object',
71
+ properties: {
72
+ time_entry_id: {
73
+ type: 'string',
74
+ description: 'ID of the time entry to update (required)',
75
+ },
76
+ action: {
77
+ type: 'string',
78
+ enum: ['approve', 'unapprove', 'reject', 'unreject'],
79
+ description: 'The approval action to apply.',
80
+ },
81
+ rejected_reason: {
82
+ type: 'string',
83
+ description: 'Reason for rejecting the time entry. Only valid when action is "reject".',
84
+ },
85
+ },
86
+ required: ['time_entry_id', 'action'],
87
+ examples: [
88
+ { time_entry_id: '123', action: 'approve' },
89
+ {
90
+ time_entry_id: '123',
91
+ action: 'reject',
92
+ rejected_reason: 'Logged against the wrong project',
93
+ },
94
+ ],
95
+ },
96
+ annotations: {
97
+ title: 'Set time entry approval',
98
+ readOnlyHint: false,
99
+ destructiveHint: false,
100
+ idempotentHint: true,
101
+ openWorldHint: true,
102
+ },
103
+ };
@@ -0,0 +1,72 @@
1
+ import { z } from 'zod';
2
+ import { toMcpError } from '../utils/errors.js';
3
+ import { formatMinutesDisplay, formatApprovalLine } from './time-entries.js';
4
+ import { coerceBoolean } from './tool-helpers.js';
5
+ const deleteTimeEntrySchema = z.object({
6
+ time_entry_id: z.string().min(1, 'time_entry_id is required'),
7
+ confirm: coerceBoolean.optional().default(false),
8
+ });
9
+ export async function deleteTimeEntryTool(client, args) {
10
+ try {
11
+ const params = deleteTimeEntrySchema.parse(args);
12
+ // Read first: an id alone says nothing about whose entry, what date, how
13
+ // much time, or its approval state -- and deletion can't be undone.
14
+ const current = await client.getTimeEntry(params.time_entry_id);
15
+ const entry = current.data;
16
+ const a = entry.attributes;
17
+ if (!params.confirm) {
18
+ return {
19
+ content: [
20
+ {
21
+ type: 'text',
22
+ text: `Time entry ${params.time_entry_id}
23
+ Date: ${a.date}
24
+ Time: ${formatMinutesDisplay(a.time)}${a.note ? `\nNote: ${a.note}` : ''}
25
+ ${formatApprovalLine(entry)}
26
+
27
+ Deleting removes it outright -- there is no undo.
28
+
29
+ Call again with "confirm": true to delete it.`,
30
+ },
31
+ ],
32
+ };
33
+ }
34
+ await client.deleteTimeEntry(params.time_entry_id);
35
+ return {
36
+ content: [
37
+ {
38
+ type: 'text',
39
+ text: `Time entry ${params.time_entry_id} (${a.date}, ${formatMinutesDisplay(a.time)}) has been deleted.`,
40
+ },
41
+ ],
42
+ };
43
+ }
44
+ catch (error) {
45
+ throw toMcpError(error);
46
+ }
47
+ }
48
+ export const deleteTimeEntryDefinition = {
49
+ name: 'delete_time_entry',
50
+ description: "Delete a time entry from Productive.io by its ID. Irreversible -- shows the entry's date, duration, note, and approval status and requires a follow-up call with confirm: true before deleting. Find time_entry_id via list_time_entries.",
51
+ inputSchema: {
52
+ type: 'object',
53
+ properties: {
54
+ time_entry_id: {
55
+ type: 'string',
56
+ description: 'ID of the time entry to delete (required)',
57
+ },
58
+ confirm: {
59
+ type: 'boolean',
60
+ description: 'Must be true to actually delete; omitted/false returns a preview instead',
61
+ },
62
+ },
63
+ required: ['time_entry_id'],
64
+ },
65
+ annotations: {
66
+ title: 'Delete time entry',
67
+ readOnlyHint: false,
68
+ destructiveHint: true,
69
+ idempotentHint: true,
70
+ openWorldHint: true,
71
+ },
72
+ };
@@ -0,0 +1,126 @@
1
+ import { z } from 'zod';
2
+ import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
3
+ import { parseTimeToMinutes, parseDate, formatMinutesDisplay } from './time-entries.js';
4
+ import { toMcpError } from '../utils/errors.js';
5
+ const updateTimeEntrySchema = z.object({
6
+ time_entry_id: z.string().min(1, 'Time entry ID is required'),
7
+ date: z.string().optional(),
8
+ time: z.string().optional(),
9
+ billable_time: z.string().optional(),
10
+ note: z.string().optional(),
11
+ service_id: z.string().optional(),
12
+ });
13
+ export async function updateTimeEntryTool(client, args) {
14
+ try {
15
+ const params = updateTimeEntrySchema.parse(args);
16
+ const attributes = {};
17
+ if (params.date !== undefined) {
18
+ try {
19
+ attributes.date = parseDate(params.date);
20
+ }
21
+ catch (error) {
22
+ throw new McpError(ErrorCode.InvalidParams, error instanceof Error ? error.message : 'Invalid date format');
23
+ }
24
+ }
25
+ if (params.time !== undefined) {
26
+ try {
27
+ attributes.time = parseTimeToMinutes(params.time);
28
+ }
29
+ catch (error) {
30
+ throw new McpError(ErrorCode.InvalidParams, error instanceof Error ? error.message : 'Invalid time format');
31
+ }
32
+ }
33
+ if (params.billable_time !== undefined) {
34
+ try {
35
+ attributes.billable_time = parseTimeToMinutes(params.billable_time);
36
+ }
37
+ catch (error) {
38
+ throw new McpError(ErrorCode.InvalidParams, `Invalid billable time format: ${error instanceof Error ? error.message : 'Invalid time format'}`);
39
+ }
40
+ }
41
+ if (params.note !== undefined) {
42
+ attributes.note = params.note;
43
+ }
44
+ const relationships = {};
45
+ if (params.service_id !== undefined) {
46
+ relationships.service = { data: { id: params.service_id, type: 'services' } };
47
+ }
48
+ if (Object.keys(attributes).length === 0 && Object.keys(relationships).length === 0) {
49
+ throw new McpError(ErrorCode.InvalidParams, 'At least one field to update must be provided (date, time, billable_time, note, or service_id)');
50
+ }
51
+ const updateData = {
52
+ data: {
53
+ type: 'time_entries',
54
+ id: params.time_entry_id,
55
+ attributes,
56
+ ...(Object.keys(relationships).length > 0 ? { relationships } : {}),
57
+ },
58
+ };
59
+ const response = await client.updateTimeEntry(params.time_entry_id, updateData);
60
+ const entry = response.data;
61
+ let text = `Time entry updated successfully!\n`;
62
+ text += `ID: ${entry.id}\n`;
63
+ text += `Date: ${entry.attributes.date}\n`;
64
+ text += `Time: ${formatMinutesDisplay(entry.attributes.time)}`;
65
+ if (entry.attributes.billable_time !== undefined &&
66
+ entry.attributes.billable_time !== entry.attributes.time) {
67
+ text += ` (Billable: ${formatMinutesDisplay(entry.attributes.billable_time)})`;
68
+ }
69
+ if (entry.attributes.note) {
70
+ text += `\nNote: ${entry.attributes.note}`;
71
+ }
72
+ if (params.service_id !== undefined) {
73
+ text += `\nReassigned to Service ID: ${params.service_id}`;
74
+ }
75
+ if (entry.attributes.updated_at) {
76
+ text += `\nUpdated at: ${entry.attributes.updated_at}`;
77
+ }
78
+ return {
79
+ content: [{ type: 'text', text }],
80
+ };
81
+ }
82
+ catch (error) {
83
+ throw toMcpError(error);
84
+ }
85
+ }
86
+ export const updateTimeEntryDefinition = {
87
+ name: 'update_time_entry',
88
+ description: "Edit fields on a time entry that already exists — its date, duration, billable duration, note, or service. Use this to correct or annotate a previously logged entry, as opposed to create_time_entry which logs a new one. Partial update: pass only the fields you want to change; every field except time_entry_id is optional and untouched fields are left as-is. Passing service_id reassigns the entry to a different service, which moves it onto that service's budget/deal — this is how you switch a time entry from one budget to another. Find the target service_id via list_services or get_project_services. Cannot reassign task or person. Find time_entry_id via list_time_entries.",
89
+ inputSchema: {
90
+ type: 'object',
91
+ properties: {
92
+ time_entry_id: {
93
+ type: 'string',
94
+ description: 'ID of the time entry to update (required)',
95
+ },
96
+ date: {
97
+ type: 'string',
98
+ description: 'New date. Accepts "today", "yesterday", or YYYY-MM-DD format',
99
+ },
100
+ time: {
101
+ type: 'string',
102
+ description: 'New time duration. Accepts formats like "2h", "120m", "2.5h", or "2.5" (assumed hours)',
103
+ },
104
+ billable_time: {
105
+ type: 'string',
106
+ description: 'New billable time duration. Same formats as time field',
107
+ },
108
+ note: {
109
+ type: 'string',
110
+ description: 'Updated work description',
111
+ },
112
+ service_id: {
113
+ type: 'string',
114
+ description: "Reassign the entry to a different service ID, moving it onto that service's budget/deal. Use list_services or get_project_services to find the target service ID.",
115
+ },
116
+ },
117
+ required: ['time_entry_id'],
118
+ },
119
+ annotations: {
120
+ title: 'Update time entry',
121
+ readOnlyHint: false,
122
+ destructiveHint: false,
123
+ idempotentHint: true,
124
+ openWorldHint: true,
125
+ },
126
+ };
@@ -0,0 +1,195 @@
1
+ import { z } from 'zod';
2
+ import { formatMinutesDisplay } from './time-entries.js';
3
+ import { toMcpError } from '../utils/errors.js';
4
+ const getTimerSchema = z.object({
5
+ timer_id: z.string().min(1, 'Timer ID is required'),
6
+ });
7
+ const startTimerSchema = z.object({
8
+ service_id: z.string().optional(),
9
+ time_entry_id: z.string().optional(),
10
+ note: z.string().min(5, 'Work description must be at least 5 characters'),
11
+ });
12
+ const stopTimerSchema = z.object({
13
+ timer_id: z.string().min(1, 'Timer ID is required'),
14
+ });
15
+ function formatTimerResponse(action, timer) {
16
+ const isRunning = timer.attributes.stopped_at === null;
17
+ let text = `Timer ${action}!\n`;
18
+ text += `ID: ${timer.id}\n`;
19
+ text += `Status: ${isRunning ? 'Running' : 'Stopped'}\n`;
20
+ text += `Started at: ${timer.attributes.started_at}`;
21
+ if (timer.attributes.stopped_at) {
22
+ text += `\nStopped at: ${timer.attributes.stopped_at}`;
23
+ }
24
+ if (timer.attributes.total_time > 0) {
25
+ text += `\nTotal time: ${formatMinutesDisplay(timer.attributes.total_time)}`;
26
+ }
27
+ const timeEntryId = timer.relationships?.time_entry?.data?.id;
28
+ if (timeEntryId) {
29
+ text += `\nTime Entry ID: ${timeEntryId}`;
30
+ }
31
+ return { content: [{ type: 'text', text }] };
32
+ }
33
+ function formatServicesList(services) {
34
+ return services.map((s) => `• ${s.attributes.name} (ID: ${s.id})`).join('\n');
35
+ }
36
+ export async function getTimerTool(client, args) {
37
+ try {
38
+ const params = getTimerSchema.parse(args);
39
+ const response = await client.getTimer(params.timer_id);
40
+ return formatTimerResponse('found', response.data);
41
+ }
42
+ catch (error) {
43
+ throw toMcpError(error);
44
+ }
45
+ }
46
+ export async function startTimerTool(client, args) {
47
+ try {
48
+ const params = startTimerSchema.parse(args);
49
+ let resolvedServiceId = params.service_id;
50
+ // If no service_id and no time_entry_id, show available services
51
+ if (!resolvedServiceId && !params.time_entry_id) {
52
+ const services = await client.listServices({ budget_status: 1, limit: 200 });
53
+ if (!services.data || services.data.length === 0) {
54
+ return {
55
+ content: [{ type: 'text', text: 'No services with open budgets found.' }],
56
+ };
57
+ }
58
+ return {
59
+ content: [
60
+ {
61
+ type: 'text',
62
+ text: `Please choose a service and call start_timer again with the service_id:\n\n${formatServicesList(services.data)}`,
63
+ },
64
+ ],
65
+ };
66
+ }
67
+ const timerData = {
68
+ data: {
69
+ type: 'timers',
70
+ attributes: {},
71
+ relationships: {},
72
+ },
73
+ };
74
+ if (params.time_entry_id) {
75
+ timerData.data.relationships.time_entry = {
76
+ data: { id: params.time_entry_id, type: 'time_entries' },
77
+ };
78
+ }
79
+ else if (resolvedServiceId) {
80
+ timerData.data.relationships.service = {
81
+ data: { id: resolvedServiceId, type: 'services' },
82
+ };
83
+ }
84
+ const response = await client.createTimer(timerData);
85
+ // Resolve the time entry ID to set the note
86
+ let timeEntryId = params.time_entry_id;
87
+ if (!timeEntryId) {
88
+ const timerDetail = await client.getTimerWithTimeEntry(response.data.id);
89
+ timeEntryId = timerDetail.data.relationships?.time_entry?.data?.id;
90
+ }
91
+ let noteWarning = '';
92
+ if (timeEntryId) {
93
+ try {
94
+ const updateData = {
95
+ data: {
96
+ type: 'time_entries',
97
+ id: timeEntryId,
98
+ attributes: { note: params.note },
99
+ },
100
+ };
101
+ await client.updateTimeEntry(timeEntryId, updateData);
102
+ }
103
+ catch {
104
+ noteWarning = '\nWarning: Timer started but note could not be set on the time entry.';
105
+ }
106
+ }
107
+ else {
108
+ noteWarning = '\nWarning: Could not resolve time entry ID — note was not set.';
109
+ }
110
+ const result = formatTimerResponse('started', response.data);
111
+ if (noteWarning) {
112
+ result.content[0].text += noteWarning;
113
+ }
114
+ return result;
115
+ }
116
+ catch (error) {
117
+ throw toMcpError(error);
118
+ }
119
+ }
120
+ export async function stopTimerTool(client, args) {
121
+ try {
122
+ const params = stopTimerSchema.parse(args);
123
+ const response = await client.stopTimer(params.timer_id);
124
+ return formatTimerResponse('stopped', response.data);
125
+ }
126
+ catch (error) {
127
+ throw toMcpError(error);
128
+ }
129
+ }
130
+ export const getTimerDefinition = {
131
+ name: 'get_timer',
132
+ description: "Read a timer's current state by ID — returns whether it is running or stopped, its start time, elapsed total_time, and the linked time-entry ID. Call this after start_timer to poll a running timer's progress without changing it; it is the read-only companion to start_timer/stop_timer and never mutates the timer (unlike stop_timer, which ends it).",
133
+ inputSchema: {
134
+ type: 'object',
135
+ properties: {
136
+ timer_id: {
137
+ type: 'string',
138
+ description: 'ID of the timer to check (required)',
139
+ },
140
+ },
141
+ required: ['timer_id'],
142
+ },
143
+ annotations: { title: 'Get timer', readOnlyHint: true, openWorldHint: true },
144
+ };
145
+ export const startTimerDefinition = {
146
+ name: 'start_timer',
147
+ description: 'Start a new running timer for live time tracking (as opposed to create_time_entry, which logs a fixed duration after the fact). If no service_id is provided, this returns the list of services with open budgets so the user can pick one, then call start_timer again with that service_id. A work description (note) is always required. Afterwards, poll the timer with get_timer and end it with stop_timer.',
148
+ inputSchema: {
149
+ type: 'object',
150
+ properties: {
151
+ service_id: {
152
+ type: 'string',
153
+ description: 'Service ID to track time against. If not provided, a list of available services will be returned.',
154
+ },
155
+ time_entry_id: {
156
+ type: 'string',
157
+ description: 'Existing time entry ID to attach timer to (optional).',
158
+ },
159
+ note: {
160
+ type: 'string',
161
+ description: 'REQUIRED: Description of work being performed (minimum 5 characters).',
162
+ minLength: 5,
163
+ },
164
+ },
165
+ required: ['note'],
166
+ },
167
+ annotations: {
168
+ title: 'Start timer',
169
+ readOnlyHint: false,
170
+ destructiveHint: false,
171
+ idempotentHint: false,
172
+ openWorldHint: true,
173
+ },
174
+ };
175
+ export const stopTimerDefinition = {
176
+ name: 'stop_timer',
177
+ description: `Stop a running timer. The timer's total_time will be added to the associated time entry.`,
178
+ inputSchema: {
179
+ type: 'object',
180
+ properties: {
181
+ timer_id: {
182
+ type: 'string',
183
+ description: 'ID of the timer to stop (required)',
184
+ },
185
+ },
186
+ required: ['timer_id'],
187
+ },
188
+ annotations: {
189
+ title: 'Stop timer',
190
+ readOnlyHint: false,
191
+ destructiveHint: false,
192
+ idempotentHint: true,
193
+ openWorldHint: true,
194
+ },
195
+ };