@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.
- package/LICENSE +190 -0
- package/NOTICE +6 -0
- package/README.md +353 -0
- package/build/api/bookings-client.js +249 -0
- package/build/api/capacity.js +279 -0
- package/build/api/client.js +1296 -0
- package/build/api/errors.js +50 -0
- package/build/api/invoice-time-entries.js +256 -0
- package/build/api/pages-tree.js +106 -0
- package/build/api/time-entry-notes.js +75 -0
- package/build/api/types.js +1 -0
- package/build/auth/logo.js +21 -0
- package/build/auth/self-resolver.js +61 -0
- package/build/config/index.js +24 -0
- package/build/index.js +15 -0
- package/build/prompts/timesheet.js +285 -0
- package/build/server.js +55 -0
- package/build/tools/absences.js +502 -0
- package/build/tools/activities.js +140 -0
- package/build/tools/bookings.js +531 -0
- package/build/tools/budget-services.js +168 -0
- package/build/tools/budgets.js +276 -0
- package/build/tools/capacity.js +281 -0
- package/build/tools/changeset.js +41 -0
- package/build/tools/comments.js +469 -0
- package/build/tools/companies.js +73 -0
- package/build/tools/custom-field-resolver.js +92 -0
- package/build/tools/custom-fields.js +155 -0
- package/build/tools/folders.js +516 -0
- package/build/tools/include-resolver.js +45 -0
- package/build/tools/invoice-actions.js +476 -0
- package/build/tools/invoice-defaults.js +65 -0
- package/build/tools/invoice-time-entries.js +320 -0
- package/build/tools/invoices.js +657 -0
- package/build/tools/my-tasks.js +100 -0
- package/build/tools/page-children.js +129 -0
- package/build/tools/pages.js +466 -0
- package/build/tools/people.js +147 -0
- package/build/tools/projects.js +77 -0
- package/build/tools/recent-updates.js +112 -0
- package/build/tools/registry.js +409 -0
- package/build/tools/subtasks.js +245 -0
- package/build/tools/task-backlog.js +106 -0
- package/build/tools/task-dependencies.js +244 -0
- package/build/tools/task-list-move.js +65 -0
- package/build/tools/task-lists.js +535 -0
- package/build/tools/task-reposition.js +199 -0
- package/build/tools/task-status.js +178 -0
- package/build/tools/tasks.js +738 -0
- package/build/tools/time-entries.js +736 -0
- package/build/tools/time-entry-approval.js +103 -0
- package/build/tools/time-entry-delete.js +72 -0
- package/build/tools/time-entry-update.js +126 -0
- package/build/tools/timers.js +195 -0
- package/build/tools/todos.js +342 -0
- package/build/tools/tool-helpers.js +114 -0
- package/build/tools/toolsets.js +153 -0
- package/build/tools/whoami.js +64 -0
- package/build/tools/workflow-statuses.js +81 -0
- package/build/utils/errors.js +67 -0
- package/build/utils/mentions.js +98 -0
- package/npm-shrinkwrap.json +1159 -0
- package/package.json +79 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { toMcpError } from '../utils/errors.js';
|
|
3
|
+
const listWorkflowStatusesSchema = z.object({
|
|
4
|
+
workflow_id: z.string().optional(),
|
|
5
|
+
category_id: z.coerce.number().int().min(1).max(3).optional(),
|
|
6
|
+
limit: z.coerce.number().min(1).max(200).default(50).optional(),
|
|
7
|
+
});
|
|
8
|
+
export async function listWorkflowStatusesTool(client, args) {
|
|
9
|
+
try {
|
|
10
|
+
const params = listWorkflowStatusesSchema.parse(args);
|
|
11
|
+
const response = await client.listWorkflowStatuses({
|
|
12
|
+
workflow_id: params.workflow_id,
|
|
13
|
+
category_id: params.category_id,
|
|
14
|
+
limit: params.limit,
|
|
15
|
+
});
|
|
16
|
+
if (!response.data || response.data.length === 0) {
|
|
17
|
+
return {
|
|
18
|
+
content: [
|
|
19
|
+
{
|
|
20
|
+
type: 'text',
|
|
21
|
+
text: 'No workflow statuses found.',
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const statusesText = response.data
|
|
27
|
+
.map((status) => {
|
|
28
|
+
const categoryName = status.attributes.category_id === 1
|
|
29
|
+
? 'Not Started'
|
|
30
|
+
: status.attributes.category_id === 2
|
|
31
|
+
? 'Started'
|
|
32
|
+
: status.attributes.category_id === 3
|
|
33
|
+
? 'Closed'
|
|
34
|
+
: `Category ${status.attributes.category_id}`;
|
|
35
|
+
return `• ${status.attributes.name} (ID: ${status.id})
|
|
36
|
+
Category: ${categoryName} (${status.attributes.category_id})
|
|
37
|
+
Workflow ID: ${status.relationships?.workflow?.data?.id || 'N/A'}
|
|
38
|
+
Position: ${status.attributes.position || 'N/A'}`;
|
|
39
|
+
})
|
|
40
|
+
.join('\n\n');
|
|
41
|
+
const summary = `Found ${response.data.length} workflow status${response.data.length !== 1 ? 'es' : ''}:\n\n${statusesText}`;
|
|
42
|
+
return {
|
|
43
|
+
content: [
|
|
44
|
+
{
|
|
45
|
+
type: 'text',
|
|
46
|
+
text: summary,
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
throw toMcpError(error);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export const listWorkflowStatusesDefinition = {
|
|
56
|
+
name: 'list_workflow_statuses',
|
|
57
|
+
description: "List the workflow statuses defined in the workspace, each with its ID, name, and category (1=Not Started, 2=Started, 3=Closed). A status ID from here is the value you pass to update_task_status to move a task. Filter by workflow_id to see one board/workflow's statuses, or by category_id to see every status in one category.",
|
|
58
|
+
inputSchema: {
|
|
59
|
+
type: 'object',
|
|
60
|
+
properties: {
|
|
61
|
+
workflow_id: {
|
|
62
|
+
type: 'string',
|
|
63
|
+
description: 'Filter to a single workflow by its ID',
|
|
64
|
+
},
|
|
65
|
+
category_id: {
|
|
66
|
+
type: 'number',
|
|
67
|
+
description: 'Filter by category: 1=Not Started, 2=Started, 3=Closed',
|
|
68
|
+
minimum: 1,
|
|
69
|
+
maximum: 3,
|
|
70
|
+
},
|
|
71
|
+
limit: {
|
|
72
|
+
type: 'number',
|
|
73
|
+
description: 'Number of statuses to return (default 50, max 200)',
|
|
74
|
+
minimum: 1,
|
|
75
|
+
maximum: 200,
|
|
76
|
+
default: 50,
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
annotations: { title: 'List workflow statuses', readOnlyHint: true, openWorldHint: true },
|
|
81
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
|
|
3
|
+
import { ProductiveApiError } from '../api/errors.js';
|
|
4
|
+
/**
|
|
5
|
+
* HTTP statuses that mean the caller's argument was wrong, rather than the
|
|
6
|
+
* server or the credentials being at fault.
|
|
7
|
+
*
|
|
8
|
+
* - 400 the query parameter is not supported (an unknown filter, sort, include)
|
|
9
|
+
* - 404 the ID given does not exist
|
|
10
|
+
* - 409 the request conflicts with current state -- a comment that is already
|
|
11
|
+
* pinned, a time entry already rejected. `docs/api-spec/` documents 409 on 22
|
|
12
|
+
* operations, four of which we call (pin/unpin comment, reject/unreject time
|
|
13
|
+
* entry); treating those as InternalError told the model to give up when the
|
|
14
|
+
* honest answer was "already done, move on".
|
|
15
|
+
* - 422 the value was well-formed but rejected (a locked timesheet period, an
|
|
16
|
+
* attribute the resource does not accept). By far the most common: the spec
|
|
17
|
+
* documents it on 203 operations, and it is also what the live API really
|
|
18
|
+
* answers for an unsupported filter, whichever status the guides claim.
|
|
19
|
+
*
|
|
20
|
+
* Deliberately excluded: 401 and 403 are a token or permission problem, 406 and
|
|
21
|
+
* 415 come from headers this client sends, and 429 and 5xx are transient or
|
|
22
|
+
* server-side. None of those are fixed by passing different arguments.
|
|
23
|
+
*
|
|
24
|
+
* Matched on the numeric status only, never on the JSON:API `code` field -- that
|
|
25
|
+
* field appears in neither the spec nor the guides, and its 422 values change on
|
|
26
|
+
* 2026-09-15 (`invalid_attribute` -> `invalid_attribute_value`, announced by
|
|
27
|
+
* email only). Reading the status keeps us out of that entirely.
|
|
28
|
+
*/
|
|
29
|
+
const CALLER_FAULT_STATUSES = new Set([400, 404, 409, 422]);
|
|
30
|
+
/**
|
|
31
|
+
* Convert any thrown value into an McpError with an accurate code.
|
|
32
|
+
*
|
|
33
|
+
* JSON-RPC offers two useful codes here: InvalidParams (-32602) means "you gave
|
|
34
|
+
* me a bad argument, fixing it is on you", InternalError (-32603) means
|
|
35
|
+
* "something failed at my end, retrying or changing your argument will not
|
|
36
|
+
* help". Collapsing everything into the latter -- which is what every tool did
|
|
37
|
+
* before -- tells the caller nothing.
|
|
38
|
+
*
|
|
39
|
+
* @param error - The caught value.
|
|
40
|
+
* @returns The McpError to throw.
|
|
41
|
+
*/
|
|
42
|
+
export function toMcpError(error) {
|
|
43
|
+
// Already mapped by the tool itself (a hand-written validation message, the
|
|
44
|
+
// toolset gate). Do not re-wrap and lose the code it chose.
|
|
45
|
+
if (error instanceof McpError) {
|
|
46
|
+
return error;
|
|
47
|
+
}
|
|
48
|
+
if (error instanceof z.ZodError) {
|
|
49
|
+
// Keep the field path Zod gives us ("limit: Number must be <= 200"): without
|
|
50
|
+
// it, a caller passing several arguments cannot tell which one was rejected.
|
|
51
|
+
const details = error.errors.map((e) => e.path.length > 0 ? `${e.path.join('.')}: ${e.message}` : e.message);
|
|
52
|
+
return new McpError(ErrorCode.InvalidParams, `Invalid parameters: ${details.join(', ')}`);
|
|
53
|
+
}
|
|
54
|
+
if (error instanceof ProductiveApiError) {
|
|
55
|
+
if (CALLER_FAULT_STATUSES.has(error.httpStatus)) {
|
|
56
|
+
return new McpError(ErrorCode.InvalidParams, error.message);
|
|
57
|
+
}
|
|
58
|
+
if (error.httpStatus === 429) {
|
|
59
|
+
// Productive publishes no Retry-After and no X-RateLimit-* headers, so
|
|
60
|
+
// there is nothing to retry against automatically -- say what the limits
|
|
61
|
+
// are instead. See docs/api-spec/guides/rate-limits.md.
|
|
62
|
+
return new McpError(ErrorCode.InternalError, `${error.message} -- Productive rate limit reached (100 requests/10s, 4000/30min; ` +
|
|
63
|
+
'reports 10/30s). Wait before retrying.');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return new McpError(ErrorCode.InternalError, error instanceof Error ? error.message : 'Unknown error occurred');
|
|
67
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Matches @FirstName or @First Last (up to 3 capitalized words). Each word
|
|
3
|
+
* may contain an internal apostrophe or hyphen (e.g. O'Brien, Anne-Marie) so
|
|
4
|
+
* those names aren't dropped or truncated mid-token.
|
|
5
|
+
* Won't match already-resolved @[{...}] patterns or @lowercase.
|
|
6
|
+
*/
|
|
7
|
+
const MENTION_REGEX = /@([A-Z][a-zA-Z]*(?:['-][A-Za-z]+)*(?:\s[A-Z][a-zA-Z]*(?:['-][A-Za-z]+)*){0,2})/g;
|
|
8
|
+
export function extractMentionTokens(body) {
|
|
9
|
+
const tokens = [];
|
|
10
|
+
let match;
|
|
11
|
+
MENTION_REGEX.lastIndex = 0;
|
|
12
|
+
while ((match = MENTION_REGEX.exec(body)) !== null) {
|
|
13
|
+
tokens.push({
|
|
14
|
+
raw: match[0],
|
|
15
|
+
name: match[1],
|
|
16
|
+
startIndex: match.index,
|
|
17
|
+
endIndex: match.index + match[0].length,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return tokens;
|
|
21
|
+
}
|
|
22
|
+
export function buildMentionReplacement(person) {
|
|
23
|
+
const mention = {
|
|
24
|
+
type: 'person',
|
|
25
|
+
id: person.id,
|
|
26
|
+
label: `${person.attributes.first_name} ${person.attributes.last_name}`.trim(),
|
|
27
|
+
avatar_url: person.attributes.avatar_url || null,
|
|
28
|
+
attachment_url: null,
|
|
29
|
+
is_done: false,
|
|
30
|
+
};
|
|
31
|
+
return `@[${JSON.stringify(mention)}]`;
|
|
32
|
+
}
|
|
33
|
+
function matchPerson(name, people) {
|
|
34
|
+
const lowerName = name.toLowerCase();
|
|
35
|
+
const fullMatches = people.filter((p) => {
|
|
36
|
+
const fullName = `${p.attributes.first_name} ${p.attributes.last_name}`.trim().toLowerCase();
|
|
37
|
+
return fullName === lowerName;
|
|
38
|
+
});
|
|
39
|
+
if (fullMatches.length > 0)
|
|
40
|
+
return fullMatches;
|
|
41
|
+
if (!name.includes(' ')) {
|
|
42
|
+
return people.filter((p) => p.attributes.first_name.toLowerCase() === lowerName);
|
|
43
|
+
}
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
/** Safety cap on pages fetched when resolving mentions, to bound worst-case org sizes. */
|
|
47
|
+
const MAX_MENTION_LOOKUP_PAGES = 10;
|
|
48
|
+
/** Fetches every person in the org (paginated), up to MAX_MENTION_LOOKUP_PAGES pages. */
|
|
49
|
+
async function listAllPeople(client) {
|
|
50
|
+
const people = [];
|
|
51
|
+
let page = 1;
|
|
52
|
+
while (page <= MAX_MENTION_LOOKUP_PAGES) {
|
|
53
|
+
const response = await client.listPeople({ limit: 200, page });
|
|
54
|
+
people.push(...(response.data || []));
|
|
55
|
+
const totalPages = response.meta?.total_pages ?? page;
|
|
56
|
+
if (page >= totalPages)
|
|
57
|
+
break;
|
|
58
|
+
page += 1;
|
|
59
|
+
}
|
|
60
|
+
return people;
|
|
61
|
+
}
|
|
62
|
+
export async function resolveMentions(body, client) {
|
|
63
|
+
const tokens = extractMentionTokens(body);
|
|
64
|
+
if (tokens.length === 0) {
|
|
65
|
+
return { resolvedBody: body, resolved: [], unresolved: [], ambiguous: [] };
|
|
66
|
+
}
|
|
67
|
+
const people = await listAllPeople(client);
|
|
68
|
+
const resolved = [];
|
|
69
|
+
const unresolved = [];
|
|
70
|
+
const ambiguous = [];
|
|
71
|
+
for (const token of tokens) {
|
|
72
|
+
const matches = matchPerson(token.name, people);
|
|
73
|
+
if (matches.length === 1) {
|
|
74
|
+
resolved.push({
|
|
75
|
+
token,
|
|
76
|
+
person: matches[0],
|
|
77
|
+
replacement: buildMentionReplacement(matches[0]),
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
else if (matches.length > 1) {
|
|
81
|
+
ambiguous.push({ token, candidates: matches });
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
unresolved.push(token);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (ambiguous.length > 0) {
|
|
88
|
+
return { resolvedBody: body, resolved: [], unresolved, ambiguous };
|
|
89
|
+
}
|
|
90
|
+
let resolvedBody = body;
|
|
91
|
+
for (const r of [...resolved].reverse()) {
|
|
92
|
+
resolvedBody =
|
|
93
|
+
resolvedBody.slice(0, r.token.startIndex) +
|
|
94
|
+
r.replacement +
|
|
95
|
+
resolvedBody.slice(r.token.endIndex);
|
|
96
|
+
}
|
|
97
|
+
return { resolvedBody, resolved, unresolved, ambiguous };
|
|
98
|
+
}
|