@monadsag/productive-mcp 1.2.51 → 1.2.61

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/README.md CHANGED
@@ -232,7 +232,7 @@ Productive's UI calls this resource a "folder"; the API models it as a "board" (
232
232
  | ---------------------------------------------------------------------------------------------------- | -------------------------------- |
233
233
  | `list_time_entries` / `create_time_entry` / `update_time_entry` | Time entry CRUD |
234
234
  | `set_time_entry_approval` | Approval workflow (action param) |
235
- | `start_timer` / `stop_timer` / `get_timer` | Real-time timers |
235
+ | `start_timer` / `stop_timer` / `get_timer` / `get_running_timer` | Real-time timers |
236
236
  | `list_services` / `get_project_services` / `list_project_deals` / `list_deal_services` | Budget & service lookup |
237
237
  | `create_budget_service` / `update_budget_service` | Budget service (line item) CRUD |
238
238
  | `list_budget_sections` / `create_budget_section` / `update_budget_section` / `delete_budget_section` | Budget sections (service groups) |
@@ -309,7 +309,7 @@ create_budget → create_budget_service → update_budget_service (optional)
309
309
  To group a budget's services, for example by project phase, create sections with
310
310
  `create_budget_section` and pass `section_id` to `create_budget_service` or `update_budget_service`.
311
311
  `list_budget_sections` shows each section with its services; `delete_budget_section` deletes only
312
- an empty section. `section_id: "none"` on `update_budget_service` takes a service out of its section.
312
+ an empty section.
313
313
 
314
314
  ## npm package / MCP hub
315
315
 
@@ -587,6 +587,23 @@ export class ProductiveAPIClient {
587
587
  async getTimerWithTimeEntry(timerId) {
588
588
  return this.makeRequest(`timers/${timerId}?include=time_entry`);
589
589
  }
590
+ /**
591
+ * A person's running timers with time entry, service and deal (budget) in one request.
592
+ *
593
+ * Live-verified (production org, 2026-11-01): an empty `filter[stopped_at]` returns only
594
+ * running timers -- 0 of a person's 20 stopped timers, and the one running timer of 24 in
595
+ * the org. `filter[stopped_at]=null` (also with `[eq]`) answers 400, "Expected a value of
596
+ * type 'Date'". The nested include carries the links, so the included time entry points to
597
+ * its service and the service to its deal.
598
+ */
599
+ async listRunningTimers(personId) {
600
+ const queryParams = new URLSearchParams();
601
+ queryParams.append('filter[person_id]', personId);
602
+ queryParams.append('filter[stopped_at]', '');
603
+ queryParams.append('sort', '-started_at');
604
+ queryParams.append('include', 'time_entry,time_entry.service,time_entry.service.deal');
605
+ return this.makeRequest(`timers?${queryParams.toString()}`);
606
+ }
590
607
  /**
591
608
  * Create and start a new timer
592
609
  */
@@ -62,40 +62,6 @@ async function sweepServices(fetchPage) {
62
62
  });
63
63
  return { rows: [...byId.values()], gaps };
64
64
  }
65
- /**
66
- * Read a service back and check that Productive kept the requested section,
67
- * or -- for `sectionId: null` -- that the service is in no section.
68
- *
69
- * The flat `section_id` attribute follows the spec and is not verified against
70
- * the live API. An API that accepted the field and ignored it would otherwise
71
- * report success for a service in the wrong section. Every failure here says
72
- * that the write itself happened, so a create is not retried into a duplicate.
73
- */
74
- export async function confirmSection(client, serviceId, sectionId, action) {
75
- const written = `Service ${serviceId} was ${action}`;
76
- const duplicateWarning = action === 'created' ? ' The service exists, do not create it again.' : '';
77
- const label = sectionId ?? 'none';
78
- let linkage;
79
- try {
80
- linkage = sectionOf((await client.getServiceWithSection(serviceId)).data);
81
- }
82
- catch (error) {
83
- const reason = error instanceof Error ? error.message : String(error);
84
- throw new McpError(ErrorCode.InternalError, `${written}, but reading it back to check its section (${label}) failed (${reason}).${duplicateWarning}`);
85
- }
86
- const kept = sectionId === null
87
- ? linkage.kind === 'none'
88
- : linkage.kind === 'linked' && linkage.id === sectionId;
89
- if (kept)
90
- return `Section: ${label} (confirmed by reading the service back)`;
91
- if (linkage.kind === 'unknown') {
92
- return `Section: ${label} requested, but Productive did not report the assignment, so it is not confirmed`;
93
- }
94
- const actual = linkage.kind === 'linked' ? `section ${linkage.id}` : 'no section';
95
- const intended = sectionId === null ? 'take it out of its section' : `put it into section ${sectionId}`;
96
- throw new McpError(ErrorCode.InternalError, `${written}, but Productive did not ${intended} (it reports ${actual}).` +
97
- `${duplicateWarning} Check the budget with list_budget_sections.`);
98
- }
99
65
  // ---------------------------------------------------------------------------
100
66
  // Tool: list_budget_sections
101
67
  // ---------------------------------------------------------------------------
@@ -114,9 +80,20 @@ function serviceLines(services) {
114
80
  function countLabel(n) {
115
81
  return n === 0 ? 'no services' : `${n} service${n === 1 ? '' : 's'}`;
116
82
  }
83
+ /**
84
+ * A section's name, or null when it has none: Productive keeps sections with
85
+ * an empty name (seen live), and a blank in the output reads like a bug.
86
+ */
87
+ function nameOf(section) {
88
+ return section.attributes.name?.trim() ? section.attributes.name : null;
89
+ }
117
90
  function sectionHeading(section, members) {
118
91
  const unreported = readLinkage(section.relationships?.deal).kind === 'linked' ? '' : ', budget not reported';
119
- return `Section ${section.id}: ${section.attributes.name} (${countLabel(members)}${unreported})`;
92
+ const details = `${countLabel(members)}${unreported}`;
93
+ const name = nameOf(section);
94
+ return name === null
95
+ ? `Section ${section.id} (unnamed, ${details})`
96
+ : `Section ${section.id}: ${name} (${details})`;
120
97
  }
121
98
  function formatSectionList(budgetId, sections, services, notes) {
122
99
  const lines = [
@@ -331,10 +308,9 @@ async function assertSectionEmpty(client, section, sectionId) {
331
308
  // and a link that contradict each other could hide a service here.
332
309
  const inside = services.rows.filter((s) => isIn(s, sectionId));
333
310
  if (inside.length > 0) {
334
- throw new McpError(ErrorCode.InvalidParams, `Section ${sectionId} (${section.attributes.name}) still contains ${countLabel(inside.length)}:\n` +
311
+ throw new McpError(ErrorCode.InvalidParams, `Section ${sectionId} (${nameOf(section) ?? 'unnamed'}) still contains ${countLabel(inside.length)}:\n` +
335
312
  `${serviceLines(inside).join('\n')}\n` +
336
- 'Move them to another section, or take them out with section_id "none", using ' +
337
- 'update_budget_service first. Nothing was deleted.');
313
+ 'Move them to another section with update_budget_service first. Nothing was deleted.');
338
314
  }
339
315
  }
340
316
  export async function deleteBudgetSectionTool(client, args) {
@@ -351,7 +327,10 @@ export async function deleteBudgetSectionTool(client, args) {
351
327
  const from = budget.kind === 'linked' ? ` from budget ${budget.id}` : '';
352
328
  return {
353
329
  content: [
354
- { type: 'text', text: `Section ${sectionId} (${section.attributes.name}) deleted${from}.` },
330
+ {
331
+ type: 'text',
332
+ text: `Section ${sectionId} (${nameOf(section) ?? 'unnamed'}) deleted${from}.`,
333
+ },
355
334
  ],
356
335
  };
357
336
  }
@@ -362,8 +341,8 @@ export async function deleteBudgetSectionTool(client, args) {
362
341
  export const deleteBudgetSectionDefinition = {
363
342
  name: 'delete_budget_section',
364
343
  description: 'Delete a budget section. Only an empty section can be deleted: while any service is still ' +
365
- 'in it, the call is refused and names the services; move them to another section, or take ' +
366
- 'them out with section_id "none", using update_budget_service first. It is also refused ' +
344
+ 'in it, the call is refused and names the services; move them to another section with ' +
345
+ 'update_budget_service first. It is also refused ' +
367
346
  "when Productive's answer does not prove the section empty. Cannot be undone.",
368
347
  inputSchema: {
369
348
  type: 'object',
@@ -2,7 +2,37 @@ import { z } from 'zod';
2
2
  import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
3
3
  import { toMcpError } from '../utils/errors.js';
4
4
  import { toNumericId } from './tool-helpers.js';
5
- import { confirmSection } from './budget-sections.js';
5
+ import { readLinkage } from './budget-sections.js';
6
+ /**
7
+ * Read a service back and check that Productive kept the requested section.
8
+ *
9
+ * Setting the section through the flat `section_id` attribute is verified live;
10
+ * the read-back stays because a field that is accepted and then ignored would
11
+ * otherwise report success for a service in the wrong section. Every failure
12
+ * here says that the write itself happened, so a create is not retried into a
13
+ * duplicate.
14
+ */
15
+ async function confirmSection(client, serviceId, sectionId, action) {
16
+ const written = `Service ${serviceId} was ${action}`;
17
+ const duplicateWarning = action === 'created' ? ' The service exists, do not create it again.' : '';
18
+ let linkage;
19
+ try {
20
+ linkage = readLinkage((await client.getServiceWithSection(serviceId)).data.relationships?.section);
21
+ }
22
+ catch (error) {
23
+ const reason = error instanceof Error ? error.message : String(error);
24
+ throw new McpError(ErrorCode.InternalError, `${written}, but reading it back to check its section (${sectionId}) failed (${reason}).${duplicateWarning}`);
25
+ }
26
+ if (linkage.kind === 'linked' && linkage.id === sectionId) {
27
+ return `Section: ${sectionId} (confirmed by reading the service back)`;
28
+ }
29
+ if (linkage.kind === 'unknown') {
30
+ return `Section: ${sectionId} requested, but Productive did not report the assignment, so it is not confirmed`;
31
+ }
32
+ const actual = linkage.kind === 'linked' ? `section ${linkage.id}` : 'no section';
33
+ throw new McpError(ErrorCode.InternalError, `${written}, but Productive did not put it into section ${sectionId} (it reports ${actual}).` +
34
+ `${duplicateWarning} Check the budget with list_budget_sections.`);
35
+ }
6
36
  // ---------------------------------------------------------------------------
7
37
  // Tool: create_budget_service
8
38
  // ---------------------------------------------------------------------------
@@ -19,20 +49,10 @@ const createBudgetServiceSchema = z.object({
19
49
  });
20
50
  const SECTION_HINT = 'Use a section of the same budget (from list_budget_sections or create_budget_section). ' +
21
51
  'The service is read back to confirm the assignment.';
22
- const createSectionIdProperty = {
52
+ const sectionIdProperty = {
23
53
  type: 'string',
24
54
  description: `Section to put the service into. ${SECTION_HINT}`,
25
55
  };
26
- const updateSectionIdProperty = {
27
- type: 'string',
28
- description: `Section to put the service into, or "none" to take it out of its section. ${SECTION_HINT}`,
29
- };
30
- /** `"none"` takes a service out of its section, sent as `section_id: null`. */
31
- function sectionChoice(value) {
32
- if (value === undefined)
33
- return undefined;
34
- return value.trim().toLowerCase() === 'none' ? null : toNumericId(value, 'section_id');
35
- }
36
56
  export async function createBudgetServiceTool(client, args) {
37
57
  try {
38
58
  const params = createBudgetServiceSchema.parse(args);
@@ -101,7 +121,7 @@ export const createBudgetServiceDefinition = {
101
121
  price: { type: 'number', description: 'Unit price' },
102
122
  quantity: { type: 'number', description: 'Number of units (hours/days/pieces)' },
103
123
  budgeted_time: { type: 'number', description: 'Allocated hours for this service' },
104
- section_id: createSectionIdProperty,
124
+ section_id: sectionIdProperty,
105
125
  },
106
126
  },
107
127
  annotations: {
@@ -135,7 +155,7 @@ export async function updateBudgetServiceTool(client, args) {
135
155
  attributes[key] = value;
136
156
  }
137
157
  }
138
- const sectionId = sectionChoice(section_id);
158
+ const sectionId = section_id === undefined ? undefined : toNumericId(section_id, 'section_id');
139
159
  if (sectionId !== undefined) {
140
160
  attributes.section_id = sectionId;
141
161
  }
@@ -151,10 +171,9 @@ export async function updateBudgetServiceTool(client, args) {
151
171
  };
152
172
  const response = await client.updateService(service_id, data);
153
173
  const service = response.data;
154
- const expected = sectionId === null ? null : String(sectionId);
155
174
  const sectionNote = sectionId === undefined
156
175
  ? ''
157
- : `\n${await confirmSection(client, service_id, expected, 'updated')}`;
176
+ : `\n${await confirmSection(client, service_id, String(sectionId), 'updated')}`;
158
177
  return {
159
178
  content: [
160
179
  {
@@ -171,8 +190,9 @@ export async function updateBudgetServiceTool(client, args) {
171
190
  export const updateBudgetServiceDefinition = {
172
191
  name: 'update_budget_service',
173
192
  description: 'Update a budget service (line item). Can change name, description, price, quantity, ' +
174
- 'unit_id, billing_type_id, budgeted_time and the section (section_id, or "none" to take ' +
175
- 'the service out of its section). Cannot move the service to a different budget.',
193
+ 'unit_id, billing_type_id, budgeted_time and the section (section_id). Cannot move the ' +
194
+ 'service to a different budget, and cannot take it out of its section: Productive rejects ' +
195
+ 'an empty section, so move it to another section instead.',
176
196
  inputSchema: {
177
197
  type: 'object',
178
198
  required: ['service_id'],
@@ -191,7 +211,7 @@ export const updateBudgetServiceDefinition = {
191
211
  description: 'Billing type: 1 = Fixed, 2 = Actuals, 3 = None, 4 = Percentage',
192
212
  },
193
213
  budgeted_time: { type: 'number', description: 'Allocated hours for this service' },
194
- section_id: updateSectionIdProperty,
214
+ section_id: sectionIdProperty,
195
215
  },
196
216
  },
197
217
  annotations: {
@@ -17,7 +17,7 @@ import { listTimeEntresTool, createTimeEntryTool, listServicesTool, getProjectSe
17
17
  import { updateTimeEntryTool, updateTimeEntryDefinition } from './time-entry-update.js';
18
18
  import { deleteTimeEntryTool, deleteTimeEntryDefinition } from './time-entry-delete.js';
19
19
  import { setTimeEntryApprovalTool, setTimeEntryApprovalDefinition } from './time-entry-approval.js';
20
- import { getTimerTool, getTimerDefinition, startTimerTool, startTimerDefinition, stopTimerTool, stopTimerDefinition, } from './timers.js';
20
+ import { getTimerTool, getTimerDefinition, getRunningTimerTool, getRunningTimerDefinition, startTimerTool, startTimerDefinition, stopTimerTool, stopTimerDefinition, } from './timers.js';
21
21
  import { moveTaskToList, moveTaskToListTool } from './task-list-move.js';
22
22
  import { addToBacklog, addToBacklogTool } from './task-backlog.js';
23
23
  import { taskRepositionTool, taskRepositionDefinition, } from './task-reposition.js';
@@ -81,6 +81,7 @@ export function getToolDefinitions(enabledToolNames) {
81
81
  deleteTimeEntryDefinition,
82
82
  setTimeEntryApprovalDefinition,
83
83
  getTimerDefinition,
84
+ getRunningTimerDefinition,
84
85
  startTimerDefinition,
85
86
  stopTimerDefinition,
86
87
  listCustomFieldsDefinition,
@@ -248,6 +249,8 @@ export async function handleToolCall(name, args, apiClient, config, enabledToolN
248
249
  return await setTimeEntryApprovalTool(apiClient, args);
249
250
  case 'get_timer':
250
251
  return await getTimerTool(apiClient, args);
252
+ case 'get_running_timer':
253
+ return await getRunningTimerTool(apiClient, args, config);
251
254
  case 'start_timer':
252
255
  return await startTimerTool(apiClient, args);
253
256
  case 'stop_timer':
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { formatMinutesDisplay } from './time-entries.js';
3
+ import { resolvePersonId } from './tool-helpers.js';
3
4
  import { toMcpError } from '../utils/errors.js';
4
5
  const getTimerSchema = z.object({
5
6
  timer_id: z.string().min(1, 'Timer ID is required'),
@@ -12,6 +13,9 @@ const startTimerSchema = z.object({
12
13
  const stopTimerSchema = z.object({
13
14
  timer_id: z.string().min(1, 'Timer ID is required'),
14
15
  });
16
+ const getRunningTimerSchema = z.object({
17
+ person_id: z.string().min(1).default('me'),
18
+ });
15
19
  function formatTimerResponse(action, timer) {
16
20
  const isRunning = timer.attributes.stopped_at === null;
17
21
  let text = `Timer ${action}!\n`;
@@ -127,6 +131,78 @@ export async function stopTimerTool(client, args) {
127
131
  throw toMcpError(error);
128
132
  }
129
133
  }
134
+ /** Note, service, budget and time-entry lines of a running timer, read from `included`. */
135
+ function describeTimerContext(timer, included) {
136
+ const find = (type, id) => id ? included.find((r) => r.type === type && r.id === id) : undefined;
137
+ const timeEntryId = timer.relationships?.time_entry?.data?.id;
138
+ const entry = find('time_entries', timeEntryId);
139
+ const serviceId = entry?.relationships?.service?.data?.id;
140
+ const service = find('services', serviceId);
141
+ const dealId = service?.relationships?.deal?.data?.id;
142
+ const deal = find('deals', dealId);
143
+ let text = '';
144
+ if (entry?.attributes.note) {
145
+ text += `\nNote: ${entry.attributes.note}`;
146
+ }
147
+ if (service) {
148
+ text += `\nService: ${service.attributes.name} (ID: ${serviceId})`;
149
+ }
150
+ if (deal) {
151
+ text += `\nBudget: ${deal.attributes.name} (ID: ${dealId})`;
152
+ }
153
+ if (timeEntryId) {
154
+ text += `\nTime Entry ID: ${timeEntryId}`;
155
+ }
156
+ return text;
157
+ }
158
+ /**
159
+ * The running timer of a person, wherever it was started (web app, phone, start_timer).
160
+ * One request returns it with its time entry, service and budget (see listRunningTimers).
161
+ */
162
+ export async function getRunningTimerTool(client, args, config) {
163
+ try {
164
+ const params = getRunningTimerSchema.parse(args ?? {});
165
+ const personId = resolvePersonId(params.person_id, config);
166
+ const who = `person ${personId}${params.person_id === 'me' ? ' (me)' : ''}`;
167
+ const response = await client.listRunningTimers(personId);
168
+ // The API filters both; checked again so that a filter that stops working never shows a
169
+ // stopped timer or another person's timer.
170
+ const own = response.data.filter((t) => String(t.attributes.person_id) === personId);
171
+ const timer = own.find((t) => t.attributes.stopped_at === null);
172
+ if (!timer) {
173
+ if (own.length < response.data.length) {
174
+ // Other people's timers came back: the person's timer may sit beyond this page.
175
+ throw new Error(`Productive ignored the person filter, so whether ${who} has a running timer is unknown.`);
176
+ }
177
+ return { content: [{ type: 'text', text: `No running timer for ${who}.` }] };
178
+ }
179
+ const minutes = Math.max(0, Math.floor((Date.now() - new Date(timer.attributes.started_at).getTime()) / 60000));
180
+ let text = `Running timer for ${who}\n`;
181
+ text += `ID: ${timer.id}\n`;
182
+ text += `Started at: ${timer.attributes.started_at}\n`;
183
+ text += `Running for: ${formatMinutesDisplay(minutes)}`;
184
+ text += describeTimerContext(timer, response.included ?? []);
185
+ return { content: [{ type: 'text', text }] };
186
+ }
187
+ catch (error) {
188
+ throw toMcpError(error);
189
+ }
190
+ }
191
+ export const getRunningTimerDefinition = {
192
+ name: 'get_running_timer',
193
+ description: 'Find the timer that is running right now for a person, no matter where it was started (Productive web app, phone, or start_timer) -- unlike get_timer, which needs the timer ID. Returns the timer ID, start time, how long it has been running, the note, the service and budget, and the linked time-entry ID, or says that no timer is running. Read-only.',
194
+ inputSchema: {
195
+ type: 'object',
196
+ properties: {
197
+ person_id: {
198
+ type: 'string',
199
+ description: 'Person whose running timer to find. "me" uses PRODUCTIVE_USER_ID. Default "me".',
200
+ default: 'me',
201
+ },
202
+ },
203
+ },
204
+ annotations: { title: 'Get running timer', readOnlyHint: true, openWorldHint: true },
205
+ };
130
206
  export const getTimerDefinition = {
131
207
  name: 'get_timer',
132
208
  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).",
@@ -72,6 +72,7 @@ export const TOOLSETS = {
72
72
  'delete_time_entry',
73
73
  'set_time_entry_approval',
74
74
  'get_timer',
75
+ 'get_running_timer',
75
76
  'start_timer',
76
77
  'stop_timer',
77
78
  ],
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@monadsag/productive-mcp",
3
- "version": "1.2.51",
3
+ "version": "1.2.61",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@monadsag/productive-mcp",
9
- "version": "1.2.51",
9
+ "version": "1.2.61",
10
10
  "license": "Apache-2.0",
11
11
  "dependencies": {
12
12
  "@modelcontextprotocol/sdk": "^1.13.2",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monadsag/productive-mcp",
3
- "version": "1.2.51",
3
+ "version": "1.2.61",
4
4
  "type": "module",
5
5
  "main": "./build/index.js",
6
6
  "bin": {