@monadsag/productive-mcp 1.2.51 → 1.2.53

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
@@ -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
 
@@ -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: {
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@monadsag/productive-mcp",
3
- "version": "1.2.51",
3
+ "version": "1.2.53",
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.53",
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.53",
4
4
  "type": "module",
5
5
  "main": "./build/index.js",
6
6
  "bin": {