@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,342 @@
1
+ import { z } from 'zod';
2
+ import { buildIncludeMap, resolveName } from './include-resolver.js';
3
+ import { toMcpError } from '../utils/errors.js';
4
+ /** Coerce "true"/"false" strings to booleans (some MCP clients send strings). */
5
+ const coerceBoolean = z.preprocess((v) => (v === 'true' ? true : v === 'false' ? false : v), z.boolean());
6
+ // ---- Schemas ----
7
+ const listTodosSchema = z.object({
8
+ task_id: z.string().optional(),
9
+ status: z.enum(['open', 'closed']).optional(),
10
+ limit: z.coerce.number().min(1).max(200).default(50).optional(),
11
+ });
12
+ const getTodoSchema = z.object({
13
+ todo_id: z.string().min(1, 'Todo ID is required'),
14
+ });
15
+ const createTodoSchema = z.object({
16
+ description: z.string().min(1, 'Description is required'),
17
+ task_id: z.string().optional(),
18
+ deal_id: z.string().optional(),
19
+ assignee_id: z.string().optional(),
20
+ due_date: z.string().optional(),
21
+ });
22
+ const updateTodoSchema = z.object({
23
+ todo_id: z.string().min(1, 'Todo ID is required'),
24
+ description: z.string().optional(),
25
+ closed: coerceBoolean.optional(),
26
+ due_date: z.string().optional(),
27
+ });
28
+ const deleteTodoSchema = z.object({
29
+ todo_id: z.string().min(1, 'Todo ID is required'),
30
+ });
31
+ // ---- Handlers ----
32
+ export async function listTodosTool(client, args) {
33
+ try {
34
+ const params = listTodosSchema.parse(args);
35
+ const queryParams = {};
36
+ if (params.task_id)
37
+ queryParams.task_id = params.task_id;
38
+ if (params.status)
39
+ queryParams.status = params.status === 'open' ? 1 : 2;
40
+ if (params.limit)
41
+ queryParams.limit = params.limit;
42
+ const response = await client.listTodos(queryParams);
43
+ if (!response.data || response.data.length === 0) {
44
+ return {
45
+ content: [{ type: 'text', text: 'No todos found matching the criteria.' }],
46
+ };
47
+ }
48
+ let text = `Found ${response.data.length} todo(s):\n\n`;
49
+ const nameMap = buildIncludeMap(response.included);
50
+ for (const todo of response.data) {
51
+ const attrs = todo.attributes;
52
+ const closedStatus = attrs.closed ? 'Closed' : 'Open';
53
+ const assigneeId = todo.relationships?.assignee?.data?.id;
54
+ const taskId = todo.relationships?.task?.data?.id;
55
+ const dealId = todo.relationships?.deal?.data?.id;
56
+ const assigneeName = resolveName(nameMap, 'people', assigneeId);
57
+ const taskName = resolveName(nameMap, 'tasks', taskId);
58
+ const dealName = resolveName(nameMap, 'deals', dealId);
59
+ text += `- [${closedStatus}] ${attrs.description}\n`;
60
+ text += ` ID: ${todo.id}\n`;
61
+ if (attrs.due_date)
62
+ text += ` Due: ${attrs.due_date}\n`;
63
+ if (assigneeName)
64
+ text += ` Assignee: ${assigneeName}\n`;
65
+ else if (assigneeId)
66
+ text += ` Assignee ID: ${assigneeId}\n`;
67
+ if (taskName)
68
+ text += ` Task: ${taskName}\n`;
69
+ else if (taskId)
70
+ text += ` Task ID: ${taskId}\n`;
71
+ if (dealName)
72
+ text += ` Deal: ${dealName}\n`;
73
+ else if (dealId)
74
+ text += ` Deal ID: ${dealId}\n`;
75
+ text += `\n`;
76
+ }
77
+ return {
78
+ content: [{ type: 'text', text: text.trimEnd() }],
79
+ };
80
+ }
81
+ catch (error) {
82
+ throw toMcpError(error);
83
+ }
84
+ }
85
+ export async function getTodoTool(client, args) {
86
+ try {
87
+ const params = getTodoSchema.parse(args);
88
+ const response = await client.getTodo(params.todo_id);
89
+ const todo = response.data;
90
+ const attrs = todo.attributes;
91
+ let text = `Todo: ${attrs.description}\n`;
92
+ text += `ID: ${todo.id}\n`;
93
+ text += `Status: ${attrs.closed ? 'Closed' : 'Open'}\n`;
94
+ if (attrs.closed_at)
95
+ text += `Closed at: ${attrs.closed_at}\n`;
96
+ if (attrs.due_date)
97
+ text += `Due date: ${attrs.due_date}\n`;
98
+ if (attrs.due_time)
99
+ text += `Due time: ${attrs.due_time}\n`;
100
+ text += `Created at: ${attrs.created_at}\n`;
101
+ if (attrs.todoable_type)
102
+ text += `Todoable type: ${attrs.todoable_type}\n`;
103
+ if (attrs.position !== undefined)
104
+ text += `Position: ${attrs.position}\n`;
105
+ const nameMap = buildIncludeMap(response.included);
106
+ const taskId = todo.relationships?.task?.data?.id;
107
+ const dealId = todo.relationships?.deal?.data?.id;
108
+ const assigneeId = todo.relationships?.assignee?.data?.id;
109
+ if (taskId) {
110
+ const taskName = resolveName(nameMap, 'tasks', taskId);
111
+ text += taskName ? `Task: ${taskName}\n` : `Task ID: ${taskId}\n`;
112
+ }
113
+ if (dealId) {
114
+ const dealName = resolveName(nameMap, 'deals', dealId);
115
+ text += dealName ? `Deal: ${dealName}\n` : `Deal ID: ${dealId}\n`;
116
+ }
117
+ if (assigneeId) {
118
+ const assigneeName = resolveName(nameMap, 'people', assigneeId);
119
+ text += assigneeName ? `Assignee: ${assigneeName}\n` : `Assignee ID: ${assigneeId}\n`;
120
+ }
121
+ return {
122
+ content: [{ type: 'text', text: text.trimEnd() }],
123
+ };
124
+ }
125
+ catch (error) {
126
+ throw toMcpError(error);
127
+ }
128
+ }
129
+ export async function createTodoTool(client, args) {
130
+ try {
131
+ const params = createTodoSchema.parse(args);
132
+ const relationships = {};
133
+ if (params.task_id) {
134
+ relationships.task = { data: { id: params.task_id, type: 'tasks' } };
135
+ }
136
+ if (params.deal_id) {
137
+ relationships.deal = { data: { id: params.deal_id, type: 'deals' } };
138
+ }
139
+ if (params.assignee_id) {
140
+ relationships.assignee = { data: { id: params.assignee_id, type: 'people' } };
141
+ }
142
+ const todoData = {
143
+ data: {
144
+ type: 'todos',
145
+ attributes: {
146
+ description: params.description,
147
+ ...(params.due_date ? { due_date: params.due_date } : {}),
148
+ },
149
+ relationships,
150
+ },
151
+ };
152
+ const response = await client.createTodo(todoData);
153
+ const todo = response.data;
154
+ let text = `Todo created successfully!\n`;
155
+ text += `ID: ${todo.id}\n`;
156
+ text += `Description: ${todo.attributes.description}`;
157
+ if (todo.attributes.due_date)
158
+ text += `\nDue date: ${todo.attributes.due_date}`;
159
+ return {
160
+ content: [{ type: 'text', text }],
161
+ };
162
+ }
163
+ catch (error) {
164
+ throw toMcpError(error);
165
+ }
166
+ }
167
+ export async function updateTodoTool(client, args) {
168
+ try {
169
+ const params = updateTodoSchema.parse(args);
170
+ const attributes = {};
171
+ if (params.description !== undefined)
172
+ attributes.description = params.description;
173
+ if (params.closed !== undefined)
174
+ attributes.closed = params.closed;
175
+ if (params.due_date !== undefined)
176
+ attributes.due_date = params.due_date;
177
+ const todoData = {
178
+ data: {
179
+ type: 'todos',
180
+ id: params.todo_id,
181
+ attributes,
182
+ },
183
+ };
184
+ const response = await client.updateTodo(params.todo_id, todoData);
185
+ const todo = response.data;
186
+ let text = `Todo updated successfully!\n`;
187
+ text += `ID: ${todo.id}\n`;
188
+ text += `Description: ${todo.attributes.description}\n`;
189
+ text += `Status: ${todo.attributes.closed ? 'Closed' : 'Open'}`;
190
+ if (todo.attributes.due_date)
191
+ text += `\nDue date: ${todo.attributes.due_date}`;
192
+ return {
193
+ content: [{ type: 'text', text }],
194
+ };
195
+ }
196
+ catch (error) {
197
+ throw toMcpError(error);
198
+ }
199
+ }
200
+ export async function deleteTodoTool(client, args) {
201
+ try {
202
+ const params = deleteTodoSchema.parse(args);
203
+ await client.deleteTodo(params.todo_id);
204
+ return {
205
+ content: [{ type: 'text', text: `Todo ${params.todo_id} deleted successfully.` }],
206
+ };
207
+ }
208
+ catch (error) {
209
+ throw toMcpError(error);
210
+ }
211
+ }
212
+ // ---- Definitions ----
213
+ export const listTodosDefinition = {
214
+ name: 'list_todos',
215
+ description: 'List todo checklist items, each showing its open/closed state, description, due date, and resolved assignee/task/deal names. Filter by task_id and/or status. This is the entry point of the list_todos -> get_todo -> update_todo drill-down. Returns up to `limit` todos (default 50).',
216
+ inputSchema: {
217
+ type: 'object',
218
+ properties: {
219
+ task_id: {
220
+ type: 'string',
221
+ description: 'Filter to todos attached to a single task',
222
+ },
223
+ status: {
224
+ type: 'string',
225
+ enum: ['open', 'closed'],
226
+ description: 'Filter by state: "open" for outstanding todos, "closed" for completed ones',
227
+ },
228
+ limit: {
229
+ type: 'number',
230
+ description: 'Maximum number of todos to return (1-200, default 50)',
231
+ },
232
+ },
233
+ required: [],
234
+ },
235
+ annotations: { title: 'List todos', readOnlyHint: true, openWorldHint: true },
236
+ };
237
+ export const getTodoDefinition = {
238
+ name: 'get_todo',
239
+ description: 'Fetch one todo by ID with its full detail — description, open/closed state and closed_at, due date and time, position, and linked task/deal/assignee. Use after list_todos to inspect a single item before editing it with update_todo.',
240
+ inputSchema: {
241
+ type: 'object',
242
+ properties: {
243
+ todo_id: {
244
+ type: 'string',
245
+ description: 'ID of the todo to retrieve (required)',
246
+ },
247
+ },
248
+ required: ['todo_id'],
249
+ },
250
+ annotations: { title: 'Get todo', readOnlyHint: true, openWorldHint: true },
251
+ };
252
+ export const createTodoDefinition = {
253
+ name: 'create_todo',
254
+ description: 'Create a todo checklist item, attaching it to a task and/or deal and optionally assigning it to a person with a due date. New todos start open; use update_todo later to close it or change its text.',
255
+ inputSchema: {
256
+ type: 'object',
257
+ properties: {
258
+ description: {
259
+ type: 'string',
260
+ description: 'Text of the todo item (required)',
261
+ },
262
+ task_id: {
263
+ type: 'string',
264
+ description: 'ID of the task to attach this todo to',
265
+ },
266
+ deal_id: {
267
+ type: 'string',
268
+ description: 'ID of the deal to attach this todo to',
269
+ },
270
+ assignee_id: {
271
+ type: 'string',
272
+ description: 'ID of the person to assign this todo to',
273
+ },
274
+ due_date: {
275
+ type: 'string',
276
+ description: 'Due date in YYYY-MM-DD format',
277
+ },
278
+ },
279
+ required: ['description'],
280
+ },
281
+ annotations: {
282
+ title: 'Create todo',
283
+ readOnlyHint: false,
284
+ destructiveHint: false,
285
+ idempotentHint: false,
286
+ openWorldHint: true,
287
+ },
288
+ };
289
+ export const updateTodoDefinition = {
290
+ name: 'update_todo',
291
+ description: 'Edit an existing todo: change its description or due date, or set closed=true to mark it done (closed=false reopens it) — the equivalent of ticking or unticking its checkbox. Omit a field to leave it unchanged. To remove a todo entirely rather than complete it, use delete_todo.',
292
+ inputSchema: {
293
+ type: 'object',
294
+ properties: {
295
+ todo_id: {
296
+ type: 'string',
297
+ description: 'ID of the todo to update (required)',
298
+ },
299
+ description: {
300
+ type: 'string',
301
+ description: 'Updated text for the todo',
302
+ },
303
+ closed: {
304
+ type: 'boolean',
305
+ description: 'Set true to close/complete the todo, false to reopen it',
306
+ },
307
+ due_date: {
308
+ type: 'string',
309
+ description: 'Updated due date in YYYY-MM-DD format',
310
+ },
311
+ },
312
+ required: ['todo_id'],
313
+ },
314
+ annotations: {
315
+ title: 'Update todo',
316
+ readOnlyHint: false,
317
+ destructiveHint: false,
318
+ idempotentHint: true,
319
+ openWorldHint: true,
320
+ },
321
+ };
322
+ export const deleteTodoDefinition = {
323
+ name: 'delete_todo',
324
+ description: 'Delete a todo, removing it from its task or deal entirely. This is distinct from completing it: to tick it off the checklist while keeping it, use update_todo with closed=true instead. The delete is not undoable through this server.',
325
+ inputSchema: {
326
+ type: 'object',
327
+ properties: {
328
+ todo_id: {
329
+ type: 'string',
330
+ description: 'ID of the todo to delete (required)',
331
+ },
332
+ },
333
+ required: ['todo_id'],
334
+ },
335
+ annotations: {
336
+ title: 'Delete todo',
337
+ readOnlyHint: false,
338
+ destructiveHint: true,
339
+ idempotentHint: true,
340
+ openWorldHint: true,
341
+ },
342
+ };
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Small helpers shared by the resource-management tools, kept in one place so
3
+ * absence, booking and capacity tools behave identically.
4
+ */
5
+ import { z } from 'zod';
6
+ import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
7
+ import { countWorkingDays } from '../api/bookings-client.js';
8
+ import { parseAvailabilities, workingDaysInRange, } from '../api/capacity.js';
9
+ import { toMcpError } from '../utils/errors.js';
10
+ /** Some MCP clients send booleans as strings; accept both. */
11
+ export const coerceBoolean = z.preprocess((v) => (v === 'true' ? true : v === 'false' ? false : v), z.boolean());
12
+ /** Resolve the "me" shorthand against the configured user. */
13
+ export function resolvePersonId(value, config) {
14
+ if (value !== 'me')
15
+ return value;
16
+ if (!config?.PRODUCTIVE_USER_ID) {
17
+ throw new McpError(ErrorCode.InvalidParams, 'Cannot use "me" - PRODUCTIVE_USER_ID is not configured in this deployment. Pass an explicit person_id.');
18
+ }
19
+ return config.PRODUCTIVE_USER_ID;
20
+ }
21
+ /**
22
+ * Best-effort display name for a person.
23
+ *
24
+ * Used in confirmation previews so a mistyped ID is visible before anything is
25
+ * written. Falls back to the bare ID rather than failing the whole call.
26
+ */
27
+ export async function describePerson(client, personId) {
28
+ try {
29
+ const person = await client.getPerson(personId);
30
+ const first = person.data.attributes.first_name ?? '';
31
+ const last = person.data.attributes.last_name ?? '';
32
+ const name = `${first} ${last}`.trim();
33
+ return name ? `${name} (ID ${personId})` : `ID ${personId}`;
34
+ }
35
+ catch {
36
+ return `ID ${personId}`;
37
+ }
38
+ }
39
+ /**
40
+ * The person's contracted working pattern, or an empty pattern when unknown.
41
+ *
42
+ * Never fails the call: a booking is still writable for somebody whose pattern
43
+ * cannot be read, it just falls back to a calendar week.
44
+ */
45
+ export async function personPattern(client, personId) {
46
+ try {
47
+ const person = await client.getPerson(personId);
48
+ return parseAvailabilities(person.data.attributes.availabilities);
49
+ }
50
+ catch {
51
+ return [];
52
+ }
53
+ }
54
+ /**
55
+ * Working days in a range as the *person* works them.
56
+ *
57
+ * Only relevant where hours are multiplied by days (booking_method_id 3): using
58
+ * calendar Mon-Fri there charges a Mon-Thu contract for the Friday too, so a
59
+ * plain week of leave is written as 40h against 32h contracted and comes back
60
+ * out of get_capacity_overview flagged OVERBOOKED. Falls back to the calendar
61
+ * for a person with no pattern on file.
62
+ */
63
+ export async function personWorkingDays(client, personId, from, to) {
64
+ if (!personId)
65
+ return countWorkingDays(from, to);
66
+ const slices = await personPattern(client, personId);
67
+ return slices.length > 0 ? workingDaysInRange(slices, from, to) : countWorkingDays(from, to);
68
+ }
69
+ /** Translate the API failures worth explaining; rethrow everything else as-is. */
70
+ export function translateBookingError(message) {
71
+ if (/has no allowance for this person/i.test(message)) {
72
+ return new McpError(ErrorCode.InvalidParams, 'This absence type has a limited allowance and none is set up for this person. ' +
73
+ 'Someone with admin rights has to grant the allowance in Productive first, or pick an absence type that is not capped.');
74
+ }
75
+ if (/unavailable for booking during selected period/i.test(message)) {
76
+ return new McpError(ErrorCode.InvalidParams, 'That service cannot take this person for the selected period. Its budget usually has to run over the whole booking period and the person has to be a member of it. ' +
77
+ 'Pick a service whose budget covers these dates, or shorten the period.');
78
+ }
79
+ if (/data\/attributes\/person/i.test(message)) {
80
+ return new McpError(ErrorCode.InvalidParams, 'Productive rejected the person for this booking. The person may be deactivated, or the ID may not exist.');
81
+ }
82
+ return null;
83
+ }
84
+ /**
85
+ * Normalise anything thrown inside a tool into an McpError.
86
+ *
87
+ * Only the booking-specific translation lives here; everything else is handed
88
+ * to `toMcpError`, which is what every other tool in this repo uses. Rolling
89
+ * the mapping by hand loses what that function knows: a 404/422 from the API is
90
+ * the caller's fault (InvalidParams), and a 429 needs the rate-limit numbers
91
+ * spelled out. Both came back as a bare InternalError before.
92
+ */
93
+ export function rethrowToolError(error) {
94
+ if (error instanceof Error && !(error instanceof McpError)) {
95
+ const translated = translateBookingError(error.message);
96
+ if (translated)
97
+ throw translated;
98
+ }
99
+ throw toMcpError(error);
100
+ }
101
+ /**
102
+ * A Productive ID as the number `POST /bookings` expects in `attributes`.
103
+ *
104
+ * `Number('abc')` is NaN and JSON.stringify writes that as `null`, so a
105
+ * mistyped ID would reach the API as a missing field and come back as a
106
+ * confusing 422 about the person. Reject it here, where the field name is known.
107
+ */
108
+ export function toNumericId(value, field) {
109
+ const trimmed = value.trim();
110
+ if (!/^\d+$/.test(trimmed)) {
111
+ throw new McpError(ErrorCode.InvalidParams, `${field} must be a numeric Productive ID, got "${value}".`);
112
+ }
113
+ return Number(trimmed);
114
+ }
@@ -0,0 +1,153 @@
1
+ /**
2
+ * Toolsets group the server's tools into domains so a deployment can enable
3
+ * only a subset via PRODUCTIVE_TOOLSETS (see config/worker-config.ts,
4
+ * config/index.ts). Adding a new tool to registry.ts? Add its name here too --
5
+ * tests/unit/toolsets.test.ts asserts every tool in getToolDefinitions()
6
+ * belongs to exactly one toolset.
7
+ */
8
+ export const TOOLSETS = {
9
+ core: [
10
+ 'whoami',
11
+ 'list_companies',
12
+ 'list_projects',
13
+ 'list_people',
14
+ 'get_person',
15
+ 'list_workflow_statuses',
16
+ 'list_activities',
17
+ 'get_recent_updates',
18
+ ],
19
+ tasks: [
20
+ 'list_task_lists',
21
+ 'create_task_list',
22
+ 'get_task_list',
23
+ 'update_task_list',
24
+ 'archive_task_list',
25
+ 'restore_task_list',
26
+ 'copy_task_list',
27
+ 'move_task_list',
28
+ 'reposition_task_list',
29
+ 'list_tasks',
30
+ 'get_project_tasks',
31
+ 'get_task',
32
+ 'create_task',
33
+ 'update_task',
34
+ 'update_task_status',
35
+ 'my_tasks',
36
+ 'move_task_to_list',
37
+ 'add_to_backlog',
38
+ 'reposition_task',
39
+ 'delete_task',
40
+ 'list_subtasks',
41
+ 'create_subtask',
42
+ 'list_task_dependencies',
43
+ 'get_task_dependency',
44
+ 'create_task_dependency',
45
+ 'delete_task_dependency',
46
+ ],
47
+ custom_fields: ['list_custom_fields', 'list_custom_field_options'],
48
+ comments: [
49
+ 'add_task_comment',
50
+ 'list_comments',
51
+ 'get_comment',
52
+ 'update_comment',
53
+ 'delete_comment',
54
+ 'pin_comment',
55
+ 'unpin_comment',
56
+ 'add_comment_reaction',
57
+ ],
58
+ time_tracking: [
59
+ 'list_time_entries',
60
+ 'create_time_entry',
61
+ 'list_project_deals',
62
+ 'list_deal_services',
63
+ 'list_services',
64
+ 'get_project_services',
65
+ 'create_budget_service',
66
+ 'update_budget_service',
67
+ 'update_time_entry',
68
+ 'delete_time_entry',
69
+ 'set_time_entry_approval',
70
+ 'get_timer',
71
+ 'start_timer',
72
+ 'stop_timer',
73
+ ],
74
+ invoicing: [
75
+ 'list_invoices',
76
+ 'list_company_budgets',
77
+ 'create_budget',
78
+ 'update_budget',
79
+ 'create_budget_from_deal',
80
+ 'get_invoice',
81
+ 'create_invoice',
82
+ 'update_invoice',
83
+ 'generate_line_items',
84
+ 'finalize_invoice',
85
+ 'get_invoice_pdf_url',
86
+ 'delete_invoice',
87
+ 'get_timesheet_report_url',
88
+ 'get_invoice_time_entries',
89
+ 'mark_invoice_paid',
90
+ ],
91
+ docs: [
92
+ 'list_folders',
93
+ 'get_folder',
94
+ 'create_folder',
95
+ 'update_folder',
96
+ 'archive_folder',
97
+ 'restore_folder',
98
+ 'copy_folder',
99
+ 'move_folder',
100
+ 'reposition_folder',
101
+ 'list_pages',
102
+ 'list_page_children',
103
+ 'get_page',
104
+ 'create_page',
105
+ 'update_page',
106
+ 'delete_page',
107
+ 'move_page',
108
+ 'copy_page',
109
+ ],
110
+ todos: ['list_todos', 'get_todo', 'create_todo', 'update_todo', 'delete_todo'],
111
+ resource_management: [
112
+ 'list_absence_types',
113
+ 'create_absence',
114
+ 'list_absences',
115
+ 'create_booking',
116
+ 'update_booking',
117
+ 'delete_booking',
118
+ 'list_bookings',
119
+ 'get_capacity_overview',
120
+ ],
121
+ };
122
+ /**
123
+ * Resolves PRODUCTIVE_TOOLSETS into the set of enabled tool names.
124
+ * Returns null to mean "no filtering -- all tools" (unset, empty, 'all', or
125
+ * every provided name being invalid -- fail open rather than exposing zero tools).
126
+ */
127
+ export function getEnabledToolNames(raw) {
128
+ if (!raw || raw.trim() === '' || raw.trim().toLowerCase() === 'all') {
129
+ return null;
130
+ }
131
+ const requested = raw
132
+ .split(',')
133
+ .map((s) => s.trim())
134
+ .filter(Boolean);
135
+ const enabled = new Set();
136
+ for (const toolset of requested) {
137
+ const names = TOOLSETS[toolset];
138
+ if (!names) {
139
+ console.error(`Unknown toolset "${toolset}" in PRODUCTIVE_TOOLSETS -- ignoring it.`);
140
+ continue;
141
+ }
142
+ names.forEach((name) => enabled.add(name));
143
+ }
144
+ if (enabled.size === 0) {
145
+ console.error('PRODUCTIVE_TOOLSETS contained no valid toolset names -- enabling all tools.');
146
+ return null;
147
+ }
148
+ return enabled;
149
+ }
150
+ /** Reverse lookup used to give a helpful hint when a disabled tool is called. */
151
+ export function findToolsetForName(name) {
152
+ return Object.entries(TOOLSETS).find(([, names]) => names.includes(name))?.[0];
153
+ }
@@ -0,0 +1,64 @@
1
+ import { z } from 'zod';
2
+ import { toMcpError } from '../utils/errors.js';
3
+ const WhoAmIArgsSchema = z.object({});
4
+ export async function whoAmI(client, args, config) {
5
+ try {
6
+ WhoAmIArgsSchema.parse(args);
7
+ if (!config?.PRODUCTIVE_USER_ID) {
8
+ return {
9
+ content: [
10
+ {
11
+ type: 'text',
12
+ text: 'No user is configured. Set PRODUCTIVE_USER_ID environment variable to enable user context.',
13
+ },
14
+ ],
15
+ };
16
+ }
17
+ // Try to get the user details from the API
18
+ try {
19
+ const response = await client.listPeople({
20
+ limit: 1,
21
+ });
22
+ // Find the configured user in the response
23
+ const currentUser = response.data.find((person) => person.id === config.PRODUCTIVE_USER_ID);
24
+ if (currentUser) {
25
+ const fullName = `${currentUser.attributes.first_name} ${currentUser.attributes.last_name}`.trim();
26
+ return {
27
+ content: [
28
+ {
29
+ type: 'text',
30
+ text: `Current user: ${fullName} (ID: ${config.PRODUCTIVE_USER_ID}, Email: ${currentUser.attributes.email})
31
+
32
+ When you use "me" in any command, it refers to this user.`,
33
+ },
34
+ ],
35
+ };
36
+ }
37
+ }
38
+ catch (error) {
39
+ // If we can't fetch user details, just show the ID
40
+ }
41
+ return {
42
+ content: [
43
+ {
44
+ type: 'text',
45
+ text: `Current user ID: ${config.PRODUCTIVE_USER_ID}
46
+
47
+ When you use "me" in any command, it refers to this user ID.`,
48
+ },
49
+ ],
50
+ };
51
+ }
52
+ catch (error) {
53
+ throw toMcpError(error);
54
+ }
55
+ }
56
+ export const whoAmITool = {
57
+ name: 'whoami',
58
+ description: 'Get the current user context. Shows which user ID is configured as "me" for all operations.',
59
+ inputSchema: {
60
+ type: 'object',
61
+ properties: {},
62
+ },
63
+ annotations: { title: 'Who am I', readOnlyHint: true, openWorldHint: true },
64
+ };