@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,168 @@
1
+ import { z } from 'zod';
2
+ import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
3
+ import { toMcpError } from '../utils/errors.js';
4
+ // ---------------------------------------------------------------------------
5
+ // Tool: create_budget_service
6
+ // ---------------------------------------------------------------------------
7
+ const createBudgetServiceSchema = z.object({
8
+ budget_id: z.string().min(1, 'Budget ID is required'),
9
+ name: z.string().min(1, 'Name is required'),
10
+ unit_id: z.coerce.number().optional().default(1),
11
+ billing_type_id: z.coerce.number().optional().default(2),
12
+ description: z.string().optional(),
13
+ price: z.coerce.number().optional(),
14
+ quantity: z.coerce.number().optional(),
15
+ budgeted_time: z.coerce.number().optional(),
16
+ });
17
+ export async function createBudgetServiceTool(client, args) {
18
+ try {
19
+ const params = createBudgetServiceSchema.parse(args);
20
+ const data = {
21
+ data: {
22
+ type: 'services',
23
+ attributes: {
24
+ name: params.name,
25
+ unit_id: params.unit_id,
26
+ billing_type_id: params.billing_type_id,
27
+ ...(params.description !== undefined && { description: params.description }),
28
+ ...(params.price !== undefined && { price: params.price }),
29
+ ...(params.quantity !== undefined && { quantity: params.quantity }),
30
+ ...(params.budgeted_time !== undefined && { budgeted_time: params.budgeted_time }),
31
+ },
32
+ relationships: {
33
+ deal: { data: { id: params.budget_id, type: 'deals' } },
34
+ },
35
+ },
36
+ };
37
+ const response = await client.createService(data);
38
+ const id = response.data.id;
39
+ const serviceName = response.data.attributes.name;
40
+ return {
41
+ content: [
42
+ {
43
+ type: 'text',
44
+ text: `Service created! Service ID: ${id} (${serviceName}) on budget ${params.budget_id}\n\n` +
45
+ 'Next step: use update_budget_service to adjust fields, or list_deal_services to verify.',
46
+ },
47
+ ],
48
+ };
49
+ }
50
+ catch (error) {
51
+ throw toMcpError(error);
52
+ }
53
+ }
54
+ export const createBudgetServiceDefinition = {
55
+ name: 'create_budget_service',
56
+ description: 'Create a new service (line item) attached to an existing budget. Only budget_id and ' +
57
+ 'name are required — unit_id defaults to 1 (Hour), billing_type_id defaults to 2 (Actuals). ' +
58
+ 'Use list_company_budgets or create_budget to get budget_id.',
59
+ inputSchema: {
60
+ type: 'object',
61
+ required: ['budget_id', 'name'],
62
+ properties: {
63
+ budget_id: {
64
+ type: 'string',
65
+ description: "Budget ID to attach this service to. Internally this is sent to Productive.io as the API's `deal` relationship — the same ID returned by list_company_budgets/create_budget, not a separately-named resource.",
66
+ },
67
+ name: { type: 'string', description: 'Service name' },
68
+ unit_id: {
69
+ type: 'number',
70
+ description: 'Tracking unit: 1 = Hour, 2 = Piece, 3 = Day (default: 1)',
71
+ },
72
+ billing_type_id: {
73
+ type: 'number',
74
+ description: 'Billing type: 1 = Fixed, 2 = Actuals, 3 = None, 4 = Percentage (default: 2)',
75
+ },
76
+ description: { type: 'string', description: 'Service description' },
77
+ price: { type: 'number', description: 'Unit price' },
78
+ quantity: { type: 'number', description: 'Number of units (hours/days/pieces)' },
79
+ budgeted_time: { type: 'number', description: 'Allocated hours for this service' },
80
+ },
81
+ },
82
+ annotations: {
83
+ title: 'Create budget service',
84
+ readOnlyHint: false,
85
+ destructiveHint: false,
86
+ idempotentHint: false,
87
+ openWorldHint: true,
88
+ },
89
+ };
90
+ // ---------------------------------------------------------------------------
91
+ // Tool: update_budget_service
92
+ // ---------------------------------------------------------------------------
93
+ const updateBudgetServiceSchema = z.object({
94
+ service_id: z.string().min(1, 'Service ID is required'),
95
+ name: z.string().optional(),
96
+ description: z.string().optional(),
97
+ price: z.coerce.number().optional(),
98
+ quantity: z.coerce.number().optional(),
99
+ unit_id: z.coerce.number().optional(),
100
+ billing_type_id: z.coerce.number().optional(),
101
+ budgeted_time: z.coerce.number().optional(),
102
+ });
103
+ export async function updateBudgetServiceTool(client, args) {
104
+ try {
105
+ const { service_id, ...fields } = updateBudgetServiceSchema.parse(args);
106
+ const attributes = {};
107
+ for (const [key, value] of Object.entries(fields)) {
108
+ if (value !== undefined) {
109
+ attributes[key] = value;
110
+ }
111
+ }
112
+ if (Object.keys(attributes).length === 0) {
113
+ throw new McpError(ErrorCode.InvalidParams, 'No fields to update provided.');
114
+ }
115
+ const data = {
116
+ data: {
117
+ type: 'services',
118
+ id: service_id,
119
+ attributes: attributes,
120
+ },
121
+ };
122
+ const response = await client.updateService(service_id, data);
123
+ const service = response.data;
124
+ return {
125
+ content: [
126
+ {
127
+ type: 'text',
128
+ text: `Service ${service_id} updated.\n\nName: ${service.attributes.name}\nPrice: ${service.attributes.price ?? 'N/A'}\nQuantity: ${service.attributes.quantity ?? 'N/A'}`,
129
+ },
130
+ ],
131
+ };
132
+ }
133
+ catch (error) {
134
+ throw toMcpError(error);
135
+ }
136
+ }
137
+ export const updateBudgetServiceDefinition = {
138
+ name: 'update_budget_service',
139
+ description: 'Update a budget service (line item). Can change name, description, price, quantity, ' +
140
+ 'unit_id, billing_type_id, and budgeted_time. Cannot move the service to a different budget.',
141
+ inputSchema: {
142
+ type: 'object',
143
+ required: ['service_id'],
144
+ properties: {
145
+ service_id: { type: 'string', description: 'Service ID' },
146
+ name: { type: 'string', description: 'Service name' },
147
+ description: { type: 'string', description: 'Service description' },
148
+ price: { type: 'number', description: 'Unit price' },
149
+ quantity: { type: 'number', description: 'Number of units (hours/days/pieces)' },
150
+ unit_id: {
151
+ type: 'number',
152
+ description: 'Tracking unit: 1 = Hour, 2 = Piece, 3 = Day',
153
+ },
154
+ billing_type_id: {
155
+ type: 'number',
156
+ description: 'Billing type: 1 = Fixed, 2 = Actuals, 3 = None, 4 = Percentage',
157
+ },
158
+ budgeted_time: { type: 'number', description: 'Allocated hours for this service' },
159
+ },
160
+ },
161
+ annotations: {
162
+ title: 'Update budget service',
163
+ readOnlyHint: false,
164
+ destructiveHint: false,
165
+ idempotentHint: true,
166
+ openWorldHint: true,
167
+ },
168
+ };
@@ -0,0 +1,276 @@
1
+ import { z } from 'zod';
2
+ import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
3
+ import { toMcpError } from '../utils/errors.js';
4
+ // ---------------------------------------------------------------------------
5
+ // Tool: create_budget
6
+ // ---------------------------------------------------------------------------
7
+ const createBudgetSchema = z.object({
8
+ name: z.string().min(1, 'Name is required'),
9
+ company_id: z.string().min(1, 'Company ID is required'),
10
+ project_id: z.string().optional(),
11
+ responsible_id: z.string().optional(),
12
+ deal_type_id: z.coerce.number().optional().default(2),
13
+ date: z.string().optional(),
14
+ currency: z.string().optional().default('CHF'),
15
+ end_date: z.string().optional(),
16
+ deal_value: z.coerce.number().optional(),
17
+ purchase_order_number: z.string().optional(),
18
+ budget_warning: z.coerce.number().optional(),
19
+ });
20
+ export async function createBudgetTool(client, args, config) {
21
+ try {
22
+ const params = createBudgetSchema.parse(args);
23
+ // "me" mirrors the sentinel used by create_task/update_task;
24
+ // omitting the field entirely resolves to the same default.
25
+ const requestedResponsibleId = params.responsible_id === 'me' ? undefined : params.responsible_id;
26
+ const responsibleId = requestedResponsibleId ?? config?.PRODUCTIVE_USER_ID;
27
+ if (!responsibleId) {
28
+ throw new McpError(ErrorCode.InvalidParams, 'responsible_id is required: no value was provided and PRODUCTIVE_USER_ID is not ' +
29
+ 'configured in the environment to default to.');
30
+ }
31
+ const data = {
32
+ data: {
33
+ type: 'deals',
34
+ attributes: {
35
+ name: params.name,
36
+ deal_type_id: params.deal_type_id,
37
+ date: params.date ?? new Date().toISOString().slice(0, 10),
38
+ currency: params.currency,
39
+ budget: true,
40
+ ...(params.end_date !== undefined && { end_date: params.end_date }),
41
+ ...(params.deal_value !== undefined && { deal_value: params.deal_value }),
42
+ ...(params.purchase_order_number !== undefined && {
43
+ purchase_order_number: params.purchase_order_number,
44
+ }),
45
+ ...(params.budget_warning !== undefined && { budget_warning: params.budget_warning }),
46
+ },
47
+ relationships: {
48
+ company: { data: { id: params.company_id, type: 'companies' } },
49
+ responsible: { data: { id: responsibleId, type: 'people' } },
50
+ ...(params.project_id !== undefined && {
51
+ project: { data: { id: params.project_id, type: 'projects' } },
52
+ }),
53
+ },
54
+ },
55
+ };
56
+ const response = await client.createDeal(data);
57
+ const id = response.data.id;
58
+ const budgetName = response.data.attributes.name;
59
+ return {
60
+ content: [
61
+ {
62
+ type: 'text',
63
+ text: `Budget created! Budget ID: ${id} (${budgetName})\n\n` +
64
+ 'Next step: use update_budget to adjust fields, or list_company_budgets to verify.',
65
+ },
66
+ ],
67
+ };
68
+ }
69
+ catch (error) {
70
+ throw toMcpError(error);
71
+ }
72
+ }
73
+ export const createBudgetDefinition = {
74
+ name: 'create_budget',
75
+ description: 'Create a new budget for a company. Only name and company_id are required — ' +
76
+ 'responsible_id defaults to the configured user (PRODUCTIVE_USER_ID) if omitted, ' +
77
+ 'deal_type_id defaults to 2 (client), date defaults to today, currency defaults to "CHF". ' +
78
+ 'Always creates a budget (not a plain deal). Use list_companies to get company_id and ' +
79
+ 'list_projects to get project_id.',
80
+ inputSchema: {
81
+ type: 'object',
82
+ required: ['name', 'company_id'],
83
+ properties: {
84
+ name: { type: 'string', description: 'Budget name' },
85
+ company_id: { type: 'string', description: 'Company ID (use list_companies to find)' },
86
+ project_id: { type: 'string', description: 'Project ID to link this budget to (optional)' },
87
+ responsible_id: {
88
+ type: 'string',
89
+ description: 'Person ID of the budget owner. Defaults to PRODUCTIVE_USER_ID if configured and ' +
90
+ 'omitted, or pass "me" explicitly to the same effect.',
91
+ },
92
+ deal_type_id: {
93
+ type: 'number',
94
+ description: 'Deal type: 1 = internal, 2 = client (default: 2)',
95
+ },
96
+ date: { type: 'string', description: 'Start date YYYY-MM-DD (default: today)' },
97
+ currency: { type: 'string', description: 'Currency code (default: "CHF")' },
98
+ end_date: { type: 'string', description: 'End date YYYY-MM-DD' },
99
+ deal_value: { type: 'number', description: 'Budget value' },
100
+ purchase_order_number: { type: 'string', description: 'PO number' },
101
+ budget_warning: {
102
+ type: 'number',
103
+ description: 'Budget consumption percentage that triggers a warning',
104
+ },
105
+ },
106
+ },
107
+ annotations: {
108
+ title: 'Create budget',
109
+ readOnlyHint: false,
110
+ destructiveHint: false,
111
+ idempotentHint: false,
112
+ openWorldHint: true,
113
+ },
114
+ };
115
+ // ---------------------------------------------------------------------------
116
+ // Tool: update_budget
117
+ // ---------------------------------------------------------------------------
118
+ const updateBudgetSchema = z.object({
119
+ budget_id: z.string().min(1, 'Budget ID is required'),
120
+ name: z.string().optional(),
121
+ date: z.string().optional(),
122
+ end_date: z.string().optional(),
123
+ currency: z.string().optional(),
124
+ deal_value: z.coerce.number().optional(),
125
+ purchase_order_number: z.string().optional(),
126
+ budget_warning: z.coerce.number().optional(),
127
+ });
128
+ export async function updateBudgetTool(client, args) {
129
+ try {
130
+ const { budget_id, ...fields } = updateBudgetSchema.parse(args);
131
+ const attributes = {};
132
+ for (const [key, value] of Object.entries(fields)) {
133
+ if (value !== undefined) {
134
+ attributes[key] = value;
135
+ }
136
+ }
137
+ if (Object.keys(attributes).length === 0) {
138
+ throw new McpError(ErrorCode.InvalidParams, 'No fields to update provided.');
139
+ }
140
+ const data = {
141
+ data: {
142
+ type: 'deals',
143
+ id: budget_id,
144
+ attributes: attributes,
145
+ },
146
+ };
147
+ const response = await client.updateDeal(budget_id, data);
148
+ const budget = response.data;
149
+ return {
150
+ content: [
151
+ {
152
+ type: 'text',
153
+ text: `Budget ${budget_id} updated.\n\nName: ${budget.attributes.name}\nEnd date: ${budget.attributes.end_date ?? 'N/A'}`,
154
+ },
155
+ ],
156
+ };
157
+ }
158
+ catch (error) {
159
+ throw toMcpError(error);
160
+ }
161
+ }
162
+ export const updateBudgetDefinition = {
163
+ name: 'update_budget',
164
+ description: "Edit an existing budget's own attributes — its name, start/end dates, currency, value, PO number, or budget-warning threshold. Partial update: pass budget_id plus only the fields you want to change. This is the follow-up editor for budgets made via create_budget or create_budget_from_deal; find budget_id with list_company_budgets. To add or edit the budget's line items instead, use create_budget_service/update_budget_service.",
165
+ inputSchema: {
166
+ type: 'object',
167
+ required: ['budget_id'],
168
+ properties: {
169
+ budget_id: { type: 'string', description: 'Budget ID' },
170
+ name: { type: 'string', description: 'Budget name' },
171
+ date: { type: 'string', description: 'Start date YYYY-MM-DD' },
172
+ end_date: { type: 'string', description: 'End date YYYY-MM-DD' },
173
+ currency: { type: 'string', description: 'Currency code' },
174
+ deal_value: { type: 'number', description: 'Budget value' },
175
+ purchase_order_number: { type: 'string', description: 'PO number' },
176
+ budget_warning: {
177
+ type: 'number',
178
+ description: 'Budget consumption percentage that triggers a warning',
179
+ },
180
+ },
181
+ },
182
+ annotations: {
183
+ title: 'Update budget',
184
+ readOnlyHint: false,
185
+ destructiveHint: false,
186
+ idempotentHint: true,
187
+ openWorldHint: true,
188
+ },
189
+ };
190
+ // ---------------------------------------------------------------------------
191
+ // Tool: create_budget_from_deal
192
+ // ---------------------------------------------------------------------------
193
+ const createBudgetFromDealSchema = z.object({
194
+ // Unlike every other *_id field in this file, origin_deal_id is sent to
195
+ // Productive as a plain numeric attribute, not a relationship — hence the
196
+ // coercion to number here despite the string-typed JSON schema below,
197
+ // which stays "string" only for input-shape consistency with company_id/
198
+ // project_id/etc.
199
+ origin_deal_id: z.coerce.number(),
200
+ project_id: z.string().min(1, 'Project ID is required'),
201
+ name: z.string().optional(),
202
+ date: z.string().optional(),
203
+ end_date: z.string().optional(),
204
+ });
205
+ export async function createBudgetFromDealTool(client, args) {
206
+ try {
207
+ const params = createBudgetFromDealSchema.parse(args);
208
+ // Advisory only — if this check itself fails (network blip, transient
209
+ // 5xx), proceed with creation rather than blocking it. The point is to
210
+ // warn about likely duplicates, not to gate the primary operation.
211
+ let existingIds = [];
212
+ try {
213
+ const existing = await client.listDealsByOriginId(params.origin_deal_id.toString());
214
+ existingIds = existing.data.map((d) => d.id);
215
+ }
216
+ catch {
217
+ // couldn't verify — proceed without a duplicate warning
218
+ }
219
+ const data = {
220
+ data: {
221
+ type: 'deals',
222
+ attributes: {
223
+ origin_deal_id: params.origin_deal_id,
224
+ ...(params.name !== undefined && { name: params.name }),
225
+ ...(params.date !== undefined && { date: params.date }),
226
+ ...(params.end_date !== undefined && { end_date: params.end_date }),
227
+ },
228
+ relationships: {
229
+ project: { data: { id: params.project_id, type: 'projects' } },
230
+ },
231
+ },
232
+ };
233
+ const response = await client.createDealFromOrigin(data);
234
+ const id = response.data.id;
235
+ const budgetName = response.data.attributes.name;
236
+ let text = `Budget created from deal ${params.origin_deal_id}! Budget ID: ${id} (${budgetName})`;
237
+ if (existingIds.length > 0) {
238
+ text +=
239
+ `\n\nWarning: ${existingIds.length} budget(s) were already derived from this deal: ` +
240
+ `${existingIds.join(', ')}. This may be a duplicate.`;
241
+ }
242
+ return { content: [{ type: 'text', text }] };
243
+ }
244
+ catch (error) {
245
+ throw toMcpError(error);
246
+ }
247
+ }
248
+ export const createBudgetFromDealDefinition = {
249
+ name: 'create_budget_from_deal',
250
+ description: 'Derive a new budget from an existing deal (contract). The origin deal must be in a "Won" ' +
251
+ 'status — Productive rejects derivation from open/lost deals. Productive copies the deal ' +
252
+ 'value, budgeted time, PO number, currency, and deal type from the origin deal ' +
253
+ 'automatically. Warns (but does not block) if a budget was already derived from this deal. ' +
254
+ 'Use list_project_deals to find origin_deal_id.',
255
+ inputSchema: {
256
+ type: 'object',
257
+ required: ['origin_deal_id', 'project_id'],
258
+ properties: {
259
+ origin_deal_id: {
260
+ type: 'string',
261
+ description: 'ID of the source deal to derive the budget from',
262
+ },
263
+ project_id: { type: 'string', description: 'Project ID to link the new budget to' },
264
+ name: { type: 'string', description: 'Override the derived budget name' },
265
+ date: { type: 'string', description: 'Override start date YYYY-MM-DD (default: today)' },
266
+ end_date: { type: 'string', description: 'Override end date YYYY-MM-DD' },
267
+ },
268
+ },
269
+ annotations: {
270
+ title: 'Create budget from deal',
271
+ readOnlyHint: false,
272
+ destructiveHint: false,
273
+ idempotentHint: false,
274
+ openWorldHint: true,
275
+ },
276
+ };