@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,100 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { toMcpError } from '../utils/errors.js';
|
|
3
|
+
function resolveWorkflowStatus(task, included) {
|
|
4
|
+
const statusId = task.relationships?.workflow_status?.data?.id;
|
|
5
|
+
if (!statusId || !included)
|
|
6
|
+
return undefined;
|
|
7
|
+
const status = included.find((item) => item.type === 'workflow_statuses' && item.id === statusId);
|
|
8
|
+
return status?.attributes?.name || undefined;
|
|
9
|
+
}
|
|
10
|
+
const myTasksSchema = z.object({
|
|
11
|
+
status: z.enum(['open', 'closed']).optional(),
|
|
12
|
+
limit: z.coerce.number().min(1).max(200).default(30).optional(),
|
|
13
|
+
});
|
|
14
|
+
export async function myTasksTool(client, config, args) {
|
|
15
|
+
try {
|
|
16
|
+
// Check if user ID is configured
|
|
17
|
+
if (!config.PRODUCTIVE_USER_ID) {
|
|
18
|
+
return {
|
|
19
|
+
content: [
|
|
20
|
+
{
|
|
21
|
+
type: 'text',
|
|
22
|
+
text: 'User ID not configured. Please set PRODUCTIVE_USER_ID in your environment variables to use this feature.',
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const params = myTasksSchema.parse(args || {});
|
|
28
|
+
const response = await client.listTasks({
|
|
29
|
+
assignee_id: config.PRODUCTIVE_USER_ID,
|
|
30
|
+
status: params.status,
|
|
31
|
+
limit: params.limit,
|
|
32
|
+
});
|
|
33
|
+
if (!response || !response.data || response.data.length === 0) {
|
|
34
|
+
return {
|
|
35
|
+
content: [
|
|
36
|
+
{
|
|
37
|
+
type: 'text',
|
|
38
|
+
text: 'You have no tasks assigned to you.',
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const tasksText = response.data
|
|
44
|
+
.filter((task) => task && task.attributes)
|
|
45
|
+
.map((task) => {
|
|
46
|
+
const projectId = task.relationships?.project?.data?.id;
|
|
47
|
+
const workflowStatusName = resolveWorkflowStatus(task, response.included);
|
|
48
|
+
const fallbackStatus = task.attributes.status === 1
|
|
49
|
+
? 'open'
|
|
50
|
+
: task.attributes.status === 2
|
|
51
|
+
? 'closed'
|
|
52
|
+
: `status ${task.attributes.status}`;
|
|
53
|
+
const statusIcon = task.attributes.status === 2 ? '✓' : '○';
|
|
54
|
+
const statusText = workflowStatusName || fallbackStatus;
|
|
55
|
+
return `${statusIcon} ${task.attributes.title} (ID: ${task.id})
|
|
56
|
+
Status: ${statusText}
|
|
57
|
+
${task.attributes.due_date ? `Due: ${task.attributes.due_date}` : 'No due date'}
|
|
58
|
+
${projectId ? `Project ID: ${projectId}` : ''}
|
|
59
|
+
${task.attributes.description ? `Description: ${task.attributes.description}` : ''}`;
|
|
60
|
+
})
|
|
61
|
+
.join('\n\n');
|
|
62
|
+
const summary = `You have ${response.data.length} task${response.data.length !== 1 ? 's' : ''} assigned to you${response.meta?.total_count ? ` (showing ${response.data.length} of ${response.meta.total_count})` : ''}:\n\n${tasksText}`;
|
|
63
|
+
return {
|
|
64
|
+
content: [
|
|
65
|
+
{
|
|
66
|
+
type: 'text',
|
|
67
|
+
text: summary,
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
throw toMcpError(error);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export const myTasksDefinition = {
|
|
77
|
+
name: 'my_tasks',
|
|
78
|
+
description: 'List tasks assigned to the current user (resolved from the configured PRODUCTIVE_USER_ID) — the fast path for ' +
|
|
79
|
+
'"my tasks" / "what am I working on". Prefer this over list_tasks with assignee_id whenever the target is the ' +
|
|
80
|
+
'calling user themselves. Filter by open/closed status; paginated (default 30, max 200). ' +
|
|
81
|
+
'Returns a configuration hint if PRODUCTIVE_USER_ID is not set.',
|
|
82
|
+
inputSchema: {
|
|
83
|
+
type: 'object',
|
|
84
|
+
properties: {
|
|
85
|
+
status: {
|
|
86
|
+
type: 'string',
|
|
87
|
+
enum: ['open', 'closed'],
|
|
88
|
+
description: 'Filter by task status (open or closed). Omit to return both.',
|
|
89
|
+
},
|
|
90
|
+
limit: {
|
|
91
|
+
type: 'number',
|
|
92
|
+
description: 'Number of tasks to return (1-200, default 30).',
|
|
93
|
+
minimum: 1,
|
|
94
|
+
maximum: 200,
|
|
95
|
+
default: 30,
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
annotations: { title: 'My tasks', readOnlyHint: true, openWorldHint: true },
|
|
100
|
+
};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { buildChildIndex, collectSubtree, countNodes, renderTree, UNTITLED, } from '../api/pages-tree.js';
|
|
3
|
+
import { toMcpError } from '../utils/errors.js';
|
|
4
|
+
/** Largest page size the API accepts. */
|
|
5
|
+
const SWEEP_PAGE_SIZE = 200;
|
|
6
|
+
/** Ceiling on the sweep, so one enormous Doc cannot exhaust the Worker's subrequest budget. */
|
|
7
|
+
const MAX_SWEEP_PAGES = 10;
|
|
8
|
+
/**
|
|
9
|
+
* Everything the tree needs, and nothing else.
|
|
10
|
+
*
|
|
11
|
+
* Without a sparse fieldset the collection response ships each page's full
|
|
12
|
+
* `body` -- a whole document-format JSON document per row -- so a 200-page
|
|
13
|
+
* sweep would move megabytes to render a list of titles.
|
|
14
|
+
*/
|
|
15
|
+
const SWEEP_FIELDS = [
|
|
16
|
+
'title',
|
|
17
|
+
'parent_page_id',
|
|
18
|
+
'root_page_id',
|
|
19
|
+
'position',
|
|
20
|
+
'edited_at',
|
|
21
|
+
'version_number',
|
|
22
|
+
];
|
|
23
|
+
const listPageChildrenSchema = z.object({
|
|
24
|
+
page_id: z.string().min(1, 'Page ID is required'),
|
|
25
|
+
max_depth: z.coerce.number().int().min(1).max(10).optional(),
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* Fetch every page in scope, one request per page of results.
|
|
29
|
+
*
|
|
30
|
+
* One sweep for the whole Doc rather than a request per level: the tree is
|
|
31
|
+
* assembled from the `parent_page_id` links afterwards, so depth costs nothing
|
|
32
|
+
* extra. Sequential on purpose -- whether page n+1 exists is only known after
|
|
33
|
+
* page n, and serialising keeps the request rate flat.
|
|
34
|
+
*/
|
|
35
|
+
async function collectDocPages(client, scope, maxPages = MAX_SWEEP_PAGES) {
|
|
36
|
+
const pages = [];
|
|
37
|
+
for (let page = 1; page <= maxPages; page += 1) {
|
|
38
|
+
// A fixed sort is what makes paging safe: without one the order across
|
|
39
|
+
// pages is not guaranteed and rows duplicate or vanish at the boundaries.
|
|
40
|
+
// `id` because `sort=position` is rejected by the API (400).
|
|
41
|
+
const response = await client.listPages({
|
|
42
|
+
...scope,
|
|
43
|
+
fields: SWEEP_FIELDS,
|
|
44
|
+
limit: SWEEP_PAGE_SIZE,
|
|
45
|
+
page,
|
|
46
|
+
sort: 'id',
|
|
47
|
+
});
|
|
48
|
+
const rows = response.data ?? [];
|
|
49
|
+
pages.push(...rows);
|
|
50
|
+
const totalPages = response.meta?.total_pages;
|
|
51
|
+
if (typeof totalPages === 'number' && page >= totalPages)
|
|
52
|
+
break;
|
|
53
|
+
// A short page is the last one, whether or not meta said so.
|
|
54
|
+
if (rows.length < SWEEP_PAGE_SIZE)
|
|
55
|
+
break;
|
|
56
|
+
if (page === maxPages)
|
|
57
|
+
return { pages, truncated: true };
|
|
58
|
+
}
|
|
59
|
+
return { pages, truncated: false };
|
|
60
|
+
}
|
|
61
|
+
export async function listPageChildrenTool(client, args) {
|
|
62
|
+
try {
|
|
63
|
+
const params = listPageChildrenSchema.parse(args);
|
|
64
|
+
// Also validates the id: an unknown page 404s here rather than coming back
|
|
65
|
+
// as a silently empty tree. This one response carries a body we do not
|
|
66
|
+
// need, and there is no way to decline it -- see getPage.
|
|
67
|
+
const startResponse = await client.getPage(params.page_id);
|
|
68
|
+
const start = startResponse.data;
|
|
69
|
+
const startTitle = start.attributes?.title?.trim() || UNTITLED;
|
|
70
|
+
// A root Doc carries no root_page_id -- it *is* the root. Every other page
|
|
71
|
+
// names the top Doc, so one sweep covers the whole hierarchy either way.
|
|
72
|
+
const rootId = start.attributes?.root_page_id
|
|
73
|
+
? String(start.attributes.root_page_id)
|
|
74
|
+
: params.page_id;
|
|
75
|
+
// `max_depth: 1` wants nothing but the direct children, and the API selects
|
|
76
|
+
// those itself (verified live in the integration suite that the filter
|
|
77
|
+
// really filters). Scoping to the Doc would page through every page in it
|
|
78
|
+
// -- up to ten requests -- to then throw all but one level away.
|
|
79
|
+
const scope = params.max_depth === 1 ? { parent_page_id: params.page_id } : { root_page_id: rootId };
|
|
80
|
+
const { pages, truncated } = await collectDocPages(client, scope);
|
|
81
|
+
const tree = collectSubtree(params.page_id, buildChildIndex(pages), params.max_depth);
|
|
82
|
+
return {
|
|
83
|
+
content: [{ type: 'text', text: format(startTitle, params.page_id, tree, truncated) }],
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
throw toMcpError(error);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function format(title, pageId, tree, truncated) {
|
|
91
|
+
const header = `${title} (ID: ${pageId})`;
|
|
92
|
+
if (tree.length === 0) {
|
|
93
|
+
return truncated
|
|
94
|
+
? `${header}\n\nNo child pages found -- but the document exceeded ${MAX_SWEEP_PAGES * SWEEP_PAGE_SIZE} pages, so this is not conclusive.`
|
|
95
|
+
: `${header}\n\nThis page has no child pages.`;
|
|
96
|
+
}
|
|
97
|
+
const total = countNodes(tree);
|
|
98
|
+
const warning = truncated
|
|
99
|
+
? `\n\nIncomplete: the sweep stopped at ${MAX_SWEEP_PAGES * SWEEP_PAGE_SIZE} pages, so deeper or later pages may be missing.`
|
|
100
|
+
: '';
|
|
101
|
+
return `${header} — ${total} child page${total !== 1 ? 's' : ''}\n\n${renderTree(tree)}${warning}`;
|
|
102
|
+
}
|
|
103
|
+
export const listPageChildrenDefinition = {
|
|
104
|
+
name: 'list_page_children',
|
|
105
|
+
description: "List every page nested under one document page, as an indented tree. Recurses through the whole subtree by default -- children, grandchildren and deeper -- showing each page's title, ID, version number and last-edited date, but no body content. Works both for a top-level Doc and for a page in the middle of a hierarchy. The version number makes it possible to detect a concurrent edit across a whole document in one call, since update_page takes no version parameter. Use max_depth to stop at a given level (1 = direct children only), then get_page for the body of any page listed.",
|
|
106
|
+
inputSchema: {
|
|
107
|
+
type: 'object',
|
|
108
|
+
properties: {
|
|
109
|
+
page_id: {
|
|
110
|
+
type: 'string',
|
|
111
|
+
description: 'ID of the page whose children to list (required)',
|
|
112
|
+
},
|
|
113
|
+
max_depth: {
|
|
114
|
+
type: 'number',
|
|
115
|
+
description: 'How many levels below the page to include (1-10, default: the entire subtree). 1 returns only direct children.',
|
|
116
|
+
minimum: 1,
|
|
117
|
+
maximum: 10,
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
required: ['page_id'],
|
|
121
|
+
},
|
|
122
|
+
annotations: {
|
|
123
|
+
title: 'List page children',
|
|
124
|
+
readOnlyHint: true,
|
|
125
|
+
destructiveHint: false,
|
|
126
|
+
idempotentHint: true,
|
|
127
|
+
openWorldHint: true,
|
|
128
|
+
},
|
|
129
|
+
};
|
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
|
|
3
|
+
import { toMcpError } from '../utils/errors.js';
|
|
4
|
+
// ---- Schemas ----
|
|
5
|
+
const listPagesSchema = z.object({
|
|
6
|
+
project_id: z.string().optional(),
|
|
7
|
+
sort: z.enum(['created_at', 'title', 'edited_at', 'updated_at']).optional(),
|
|
8
|
+
limit: z.coerce.number().min(1).max(200).default(30).optional(),
|
|
9
|
+
});
|
|
10
|
+
const getPageSchema = z.object({
|
|
11
|
+
page_id: z.string().min(1, 'Page ID is required'),
|
|
12
|
+
});
|
|
13
|
+
const createPageSchema = z.object({
|
|
14
|
+
project_id: z.string().min(1, 'Project ID is required'),
|
|
15
|
+
title: z.string().min(1, 'Title is required'),
|
|
16
|
+
markdown: z.string().optional(),
|
|
17
|
+
parent_page_id: z.coerce
|
|
18
|
+
.number()
|
|
19
|
+
.optional()
|
|
20
|
+
.describe('ID of parent page (must also set root_page_id)'),
|
|
21
|
+
root_page_id: z
|
|
22
|
+
.number()
|
|
23
|
+
.optional()
|
|
24
|
+
.describe('ID of root page in the hierarchy (must also set parent_page_id)'),
|
|
25
|
+
});
|
|
26
|
+
const updatePageSchema = z.object({
|
|
27
|
+
page_id: z.string().min(1, 'Page ID is required'),
|
|
28
|
+
title: z.string().optional(),
|
|
29
|
+
markdown: z.string().optional(),
|
|
30
|
+
append: z.boolean().optional().default(false),
|
|
31
|
+
});
|
|
32
|
+
const deletePageSchema = z.object({
|
|
33
|
+
page_id: z.string().min(1, 'Page ID is required'),
|
|
34
|
+
});
|
|
35
|
+
const movePageSchema = z.object({
|
|
36
|
+
page_id: z.string().min(1, 'Page ID is required'),
|
|
37
|
+
target_doc_id: z.string().min(1, 'Target document ID is required'),
|
|
38
|
+
});
|
|
39
|
+
const copyPageSchema = z.object({
|
|
40
|
+
template_id: z.string().min(1, 'Template ID (page to copy) is required'),
|
|
41
|
+
project_id: z
|
|
42
|
+
.string()
|
|
43
|
+
.optional()
|
|
44
|
+
.describe('Project ID to copy the page into (defaults to same project)'),
|
|
45
|
+
});
|
|
46
|
+
// ---- Handlers ----
|
|
47
|
+
export async function listPagesTool(client, args) {
|
|
48
|
+
try {
|
|
49
|
+
const params = listPagesSchema.parse(args || {});
|
|
50
|
+
const response = await client.listPages({
|
|
51
|
+
project_id: params.project_id,
|
|
52
|
+
sort: params.sort,
|
|
53
|
+
limit: params.limit,
|
|
54
|
+
});
|
|
55
|
+
if (!response || !response.data || response.data.length === 0) {
|
|
56
|
+
return {
|
|
57
|
+
content: [
|
|
58
|
+
{
|
|
59
|
+
type: 'text',
|
|
60
|
+
text: 'No pages found matching the criteria.',
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const pagesText = response.data
|
|
66
|
+
.filter((page) => page && page.attributes)
|
|
67
|
+
.map((page) => {
|
|
68
|
+
const projectId = page.relationships?.project?.data?.id;
|
|
69
|
+
return `• ${page.attributes.title} (ID: ${page.id})
|
|
70
|
+
${projectId ? `Project ID: ${projectId}` : ''}
|
|
71
|
+
${page.attributes.edited_at ? `Edited at: ${page.attributes.edited_at}` : ''}
|
|
72
|
+
${page.attributes.version_number != null ? `Version: ${page.attributes.version_number}` : ''}`;
|
|
73
|
+
})
|
|
74
|
+
.join('\n\n');
|
|
75
|
+
const summary = `Found ${response.data.length} page${response.data.length !== 1 ? 's' : ''}${response.meta?.total_count ? ` (showing ${response.data.length} of ${response.meta.total_count})` : ''}:\n\n${pagesText}`;
|
|
76
|
+
return {
|
|
77
|
+
content: [
|
|
78
|
+
{
|
|
79
|
+
type: 'text',
|
|
80
|
+
text: summary,
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
throw toMcpError(error);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
export async function getPageTool(client, args) {
|
|
90
|
+
try {
|
|
91
|
+
const params = getPageSchema.parse(args);
|
|
92
|
+
const response = await client.getPage(params.page_id);
|
|
93
|
+
const page = response.data;
|
|
94
|
+
const creatorId = page.relationships?.creator?.data?.id;
|
|
95
|
+
const creatorResource = creatorId && response.included
|
|
96
|
+
? response.included.find((item) => item.type === 'people' && item.id === creatorId)
|
|
97
|
+
: undefined;
|
|
98
|
+
const creatorName = creatorResource
|
|
99
|
+
? `${creatorResource.attributes.first_name || ''} ${creatorResource.attributes.last_name || ''}`.trim()
|
|
100
|
+
: undefined;
|
|
101
|
+
const projectId = page.relationships?.project?.data?.id;
|
|
102
|
+
const projectResource = projectId && response.included
|
|
103
|
+
? response.included.find((item) => item.type === 'projects' && item.id === projectId)
|
|
104
|
+
: undefined;
|
|
105
|
+
const projectName = projectResource?.attributes?.name;
|
|
106
|
+
let text = `Page: ${page.attributes.title} (ID: ${page.id})\n`;
|
|
107
|
+
if (projectName)
|
|
108
|
+
text += `Project: ${projectName} (ID: ${projectId})\n`;
|
|
109
|
+
else if (projectId)
|
|
110
|
+
text += `Project ID: ${projectId}\n`;
|
|
111
|
+
if (creatorName)
|
|
112
|
+
text += `Creator: ${creatorName}\n`;
|
|
113
|
+
if (page.attributes.public_access != null)
|
|
114
|
+
text += `Public access: ${page.attributes.public_access}\n`;
|
|
115
|
+
if (page.attributes.version_number != null)
|
|
116
|
+
text += `Version: ${page.attributes.version_number}\n`;
|
|
117
|
+
if (page.attributes.parent_page_id != null)
|
|
118
|
+
text += `Parent page ID: ${page.attributes.parent_page_id}\n`;
|
|
119
|
+
if (page.attributes.root_page_id != null)
|
|
120
|
+
text += `Root page ID: ${page.attributes.root_page_id}\n`;
|
|
121
|
+
text += `Created at: ${page.attributes.created_at}\n`;
|
|
122
|
+
text += `Updated at: ${page.attributes.updated_at}\n`;
|
|
123
|
+
if (page.attributes.edited_at)
|
|
124
|
+
text += `Edited at: ${page.attributes.edited_at}\n`;
|
|
125
|
+
if (page.attributes.last_activity_at)
|
|
126
|
+
text += `Last activity at: ${page.attributes.last_activity_at}\n`;
|
|
127
|
+
text += `\nBody:\n${page.attributes.body || '(empty)'}`;
|
|
128
|
+
return {
|
|
129
|
+
content: [
|
|
130
|
+
{
|
|
131
|
+
type: 'text',
|
|
132
|
+
text,
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
throw toMcpError(error);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
export async function createPageTool(client, args) {
|
|
142
|
+
try {
|
|
143
|
+
const params = createPageSchema.parse(args);
|
|
144
|
+
// project_id may only be set on root pages -- sending it together with
|
|
145
|
+
// parent_page_id/root_page_id is rejected as `page_project_root_page_only`.
|
|
146
|
+
const nested = params.parent_page_id != null || params.root_page_id != null;
|
|
147
|
+
const response = await client.createPage({
|
|
148
|
+
data: {
|
|
149
|
+
type: 'pages',
|
|
150
|
+
attributes: {
|
|
151
|
+
title: params.title,
|
|
152
|
+
markdown: params.markdown,
|
|
153
|
+
project_id: nested ? undefined : Number(params.project_id),
|
|
154
|
+
parent_page_id: params.parent_page_id,
|
|
155
|
+
root_page_id: params.root_page_id,
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
const page = response.data;
|
|
160
|
+
let text = `Page created successfully!\n`;
|
|
161
|
+
text += `Title: ${page.attributes.title}\n`;
|
|
162
|
+
text += `Page ID: ${page.id}\n`;
|
|
163
|
+
// A nested page inherits its project from the parent and params.project_id
|
|
164
|
+
// was never sent, so reporting it would be a lie. The create response only
|
|
165
|
+
// returns a relationship stub ({meta: {included: false}}), so in practice
|
|
166
|
+
// the line is simply omitted for nested pages.
|
|
167
|
+
const createdProjectId = nested ? page.relationships?.project?.data?.id : params.project_id;
|
|
168
|
+
if (createdProjectId != null)
|
|
169
|
+
text += `Project ID: ${createdProjectId}\n`;
|
|
170
|
+
if (params.parent_page_id != null)
|
|
171
|
+
text += `Parent page ID: ${params.parent_page_id}\n`;
|
|
172
|
+
text += `Created at: ${page.attributes.created_at}`;
|
|
173
|
+
return {
|
|
174
|
+
content: [
|
|
175
|
+
{
|
|
176
|
+
type: 'text',
|
|
177
|
+
text,
|
|
178
|
+
},
|
|
179
|
+
],
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
throw toMcpError(error);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
export async function updatePageTool(client, args) {
|
|
187
|
+
try {
|
|
188
|
+
const params = updatePageSchema.parse(args);
|
|
189
|
+
if (params.title === undefined && params.markdown === undefined) {
|
|
190
|
+
throw new McpError(ErrorCode.InvalidParams, 'Provide title, markdown, or both -- there is nothing to update otherwise');
|
|
191
|
+
}
|
|
192
|
+
// Title and body live on different routes: the title goes through the plain
|
|
193
|
+
// PATCH, the body through a markdown proxy that takes a flat payload.
|
|
194
|
+
let page = null;
|
|
195
|
+
if (params.title !== undefined) {
|
|
196
|
+
const response = await client.updatePage(params.page_id, {
|
|
197
|
+
data: { type: 'pages', id: params.page_id, attributes: { title: params.title } },
|
|
198
|
+
});
|
|
199
|
+
page = response.data;
|
|
200
|
+
}
|
|
201
|
+
if (params.markdown !== undefined) {
|
|
202
|
+
const response = params.append
|
|
203
|
+
? await client.appendPageBody(params.page_id, params.markdown)
|
|
204
|
+
: await client.replacePageBody(params.page_id, params.markdown);
|
|
205
|
+
page = response.data;
|
|
206
|
+
}
|
|
207
|
+
let text = `Page updated successfully!\n`;
|
|
208
|
+
text += `Title: ${page?.attributes.title}\n`;
|
|
209
|
+
text += `Page ID: ${page?.id ?? params.page_id}\n`;
|
|
210
|
+
if (params.markdown !== undefined) {
|
|
211
|
+
text += `Body ${params.append ? 'appended to' : 'replaced'}\n`;
|
|
212
|
+
}
|
|
213
|
+
text += `Updated at: ${page?.attributes.updated_at}`;
|
|
214
|
+
return {
|
|
215
|
+
content: [
|
|
216
|
+
{
|
|
217
|
+
type: 'text',
|
|
218
|
+
text,
|
|
219
|
+
},
|
|
220
|
+
],
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
throw toMcpError(error);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
export async function deletePageTool(client, args) {
|
|
228
|
+
try {
|
|
229
|
+
const params = deletePageSchema.parse(args);
|
|
230
|
+
await client.deletePage(params.page_id);
|
|
231
|
+
return {
|
|
232
|
+
content: [
|
|
233
|
+
{
|
|
234
|
+
type: 'text',
|
|
235
|
+
text: `Page ${params.page_id} deleted successfully.`,
|
|
236
|
+
},
|
|
237
|
+
],
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
throw toMcpError(error);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
export async function movePageTool(client, args) {
|
|
245
|
+
try {
|
|
246
|
+
const params = movePageSchema.parse(args);
|
|
247
|
+
await client.movePage(params.page_id, params.target_doc_id);
|
|
248
|
+
return {
|
|
249
|
+
content: [
|
|
250
|
+
{
|
|
251
|
+
type: 'text',
|
|
252
|
+
text: `Page ${params.page_id} moved under document ${params.target_doc_id} successfully.`,
|
|
253
|
+
},
|
|
254
|
+
],
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
catch (error) {
|
|
258
|
+
throw toMcpError(error);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
export async function copyPageTool(client, args) {
|
|
262
|
+
try {
|
|
263
|
+
const params = copyPageSchema.parse(args);
|
|
264
|
+
const response = await client.copyPage(params.template_id, params.project_id);
|
|
265
|
+
const page = response.data;
|
|
266
|
+
let text = `Page copied successfully!\n`;
|
|
267
|
+
text += `Title: ${page.attributes.title}\n`;
|
|
268
|
+
text += `New page ID: ${page.id}\n`;
|
|
269
|
+
text += `Created at: ${page.attributes.created_at}`;
|
|
270
|
+
return {
|
|
271
|
+
content: [
|
|
272
|
+
{
|
|
273
|
+
type: 'text',
|
|
274
|
+
text,
|
|
275
|
+
},
|
|
276
|
+
],
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
catch (error) {
|
|
280
|
+
throw toMcpError(error);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
// ---- Definitions ----
|
|
284
|
+
export const listPagesDefinition = {
|
|
285
|
+
name: 'list_pages',
|
|
286
|
+
description: 'List document pages, each showing title, ID, project, last-edited time, and version number (but not body content). Filter by project_id and sort by created_at, title, edited_at, or updated_at. Use this to locate a page ID, then call get_page for the full body. Returns up to `limit` pages (default 30).',
|
|
287
|
+
inputSchema: {
|
|
288
|
+
type: 'object',
|
|
289
|
+
properties: {
|
|
290
|
+
project_id: {
|
|
291
|
+
type: 'string',
|
|
292
|
+
description: 'Filter to pages belonging to a single project',
|
|
293
|
+
},
|
|
294
|
+
sort: {
|
|
295
|
+
type: 'string',
|
|
296
|
+
enum: ['created_at', 'title', 'edited_at', 'updated_at'],
|
|
297
|
+
description: 'Field to sort the returned pages by',
|
|
298
|
+
},
|
|
299
|
+
limit: {
|
|
300
|
+
type: 'number',
|
|
301
|
+
description: 'Maximum number of pages to return (1-200, default 30)',
|
|
302
|
+
},
|
|
303
|
+
},
|
|
304
|
+
required: [],
|
|
305
|
+
},
|
|
306
|
+
annotations: { title: 'List pages', readOnlyHint: true, openWorldHint: true },
|
|
307
|
+
};
|
|
308
|
+
export const getPageDefinition = {
|
|
309
|
+
name: 'get_page',
|
|
310
|
+
description: 'Fetch one document page by ID including its full body, creator, project, hierarchy (parent and root page IDs), version, and timestamps. The body is returned as a Productive Document Format document -- a JSON structure ({"type":"doc","content":[...]}), not HTML or plain text. Use this after list_pages, which returns page metadata but omits the body.',
|
|
311
|
+
inputSchema: {
|
|
312
|
+
type: 'object',
|
|
313
|
+
properties: {
|
|
314
|
+
page_id: {
|
|
315
|
+
type: 'string',
|
|
316
|
+
description: 'ID of the page to retrieve (required)',
|
|
317
|
+
},
|
|
318
|
+
},
|
|
319
|
+
required: ['page_id'],
|
|
320
|
+
},
|
|
321
|
+
annotations: { title: 'Get page', readOnlyHint: true, openWorldHint: true },
|
|
322
|
+
};
|
|
323
|
+
export const createPageDefinition = {
|
|
324
|
+
name: 'create_page',
|
|
325
|
+
description: 'Create a new document page inside a project. Content is written as Markdown. Optionally nest it under an existing page by supplying parent_page_id together with root_page_id -- for a nested page the project is inherited from the parent, so project_id is ignored. After creating, use move_page to re-parent it or copy_page to duplicate it elsewhere.',
|
|
326
|
+
inputSchema: {
|
|
327
|
+
type: 'object',
|
|
328
|
+
properties: {
|
|
329
|
+
project_id: {
|
|
330
|
+
type: 'string',
|
|
331
|
+
description: 'ID of the project to create the page in (required)',
|
|
332
|
+
},
|
|
333
|
+
title: {
|
|
334
|
+
type: 'string',
|
|
335
|
+
description: 'Title of the page (required)',
|
|
336
|
+
},
|
|
337
|
+
markdown: {
|
|
338
|
+
type: 'string',
|
|
339
|
+
description: 'Body content of the page as Markdown (optional). Headings, lists, tables, checklists, code blocks and links are supported.',
|
|
340
|
+
},
|
|
341
|
+
parent_page_id: {
|
|
342
|
+
type: 'number',
|
|
343
|
+
description: 'ID of the parent page to nest this page under. Must be set together with root_page_id.',
|
|
344
|
+
},
|
|
345
|
+
root_page_id: {
|
|
346
|
+
type: 'number',
|
|
347
|
+
description: 'ID of the root (top-level) page in the hierarchy. Must be set together with parent_page_id. For direct children of root, set both to the root page ID.',
|
|
348
|
+
},
|
|
349
|
+
},
|
|
350
|
+
required: ['project_id', 'title'],
|
|
351
|
+
},
|
|
352
|
+
annotations: {
|
|
353
|
+
title: 'Create page',
|
|
354
|
+
readOnlyHint: false,
|
|
355
|
+
destructiveHint: false,
|
|
356
|
+
idempotentHint: false,
|
|
357
|
+
openWorldHint: true,
|
|
358
|
+
},
|
|
359
|
+
};
|
|
360
|
+
export const updatePageDefinition = {
|
|
361
|
+
name: 'update_page',
|
|
362
|
+
description: "Update a document page's title and/or body. Body content is written as Markdown and replaces the previous content by default; set append: true to add to the end instead of rewriting the page. Omit a field to leave it unchanged. To relocate the page in the hierarchy instead of editing content, use move_page.",
|
|
363
|
+
inputSchema: {
|
|
364
|
+
type: 'object',
|
|
365
|
+
properties: {
|
|
366
|
+
page_id: {
|
|
367
|
+
type: 'string',
|
|
368
|
+
description: 'ID of the page to update (required)',
|
|
369
|
+
},
|
|
370
|
+
title: {
|
|
371
|
+
type: 'string',
|
|
372
|
+
description: 'New title for the page (omit to leave the title unchanged)',
|
|
373
|
+
},
|
|
374
|
+
markdown: {
|
|
375
|
+
type: 'string',
|
|
376
|
+
description: 'New body content as Markdown. Replaces the current body unless append is true. Omit to leave the body unchanged.',
|
|
377
|
+
},
|
|
378
|
+
append: {
|
|
379
|
+
type: 'boolean',
|
|
380
|
+
description: 'Append the markdown to the end of the page instead of replacing the body. Defaults to false.',
|
|
381
|
+
},
|
|
382
|
+
},
|
|
383
|
+
required: ['page_id'],
|
|
384
|
+
},
|
|
385
|
+
// Not idempotent, unlike the other update_* tools: with `append: true` the
|
|
386
|
+
// same call twice writes the markdown twice, so a client that retries an
|
|
387
|
+
// idempotent call after a timeout would duplicate the content.
|
|
388
|
+
annotations: {
|
|
389
|
+
title: 'Update page',
|
|
390
|
+
readOnlyHint: false,
|
|
391
|
+
destructiveHint: false,
|
|
392
|
+
idempotentHint: false,
|
|
393
|
+
openWorldHint: true,
|
|
394
|
+
},
|
|
395
|
+
};
|
|
396
|
+
export const deletePageDefinition = {
|
|
397
|
+
name: 'delete_page',
|
|
398
|
+
description: 'Delete a document page by ID. If you instead want to relocate the page under a different parent, use move_page; to duplicate it, use copy_page.',
|
|
399
|
+
inputSchema: {
|
|
400
|
+
type: 'object',
|
|
401
|
+
properties: {
|
|
402
|
+
page_id: {
|
|
403
|
+
type: 'string',
|
|
404
|
+
description: 'ID of the page to delete (required)',
|
|
405
|
+
},
|
|
406
|
+
},
|
|
407
|
+
required: ['page_id'],
|
|
408
|
+
},
|
|
409
|
+
annotations: {
|
|
410
|
+
title: 'Delete page',
|
|
411
|
+
readOnlyHint: false,
|
|
412
|
+
destructiveHint: true,
|
|
413
|
+
idempotentHint: true,
|
|
414
|
+
openWorldHint: true,
|
|
415
|
+
},
|
|
416
|
+
};
|
|
417
|
+
export const movePageDefinition = {
|
|
418
|
+
name: 'move_page',
|
|
419
|
+
description: 'Re-parent a document page, nesting it under a different page in the hierarchy. This changes where the page lives, not its content — use update_page to edit the title or body. To place a page under a new parent, call this again with a different target_doc_id.',
|
|
420
|
+
inputSchema: {
|
|
421
|
+
type: 'object',
|
|
422
|
+
properties: {
|
|
423
|
+
page_id: {
|
|
424
|
+
type: 'string',
|
|
425
|
+
description: 'ID of the page to move (required)',
|
|
426
|
+
},
|
|
427
|
+
target_doc_id: {
|
|
428
|
+
type: 'string',
|
|
429
|
+
description: 'ID of the page to move this page under, i.e. its new parent (required)',
|
|
430
|
+
},
|
|
431
|
+
},
|
|
432
|
+
required: ['page_id', 'target_doc_id'],
|
|
433
|
+
},
|
|
434
|
+
annotations: {
|
|
435
|
+
title: 'Move page',
|
|
436
|
+
readOnlyHint: false,
|
|
437
|
+
destructiveHint: false,
|
|
438
|
+
idempotentHint: true,
|
|
439
|
+
openWorldHint: true,
|
|
440
|
+
},
|
|
441
|
+
};
|
|
442
|
+
export const copyPageDefinition = {
|
|
443
|
+
name: 'copy_page',
|
|
444
|
+
description: "Duplicate an existing page (used as the template) into the same project, or into a different one via project_id — useful for spinning up a new page from a boilerplate. Returns the new page's ID; use move_page afterward to position the copy in the hierarchy.",
|
|
445
|
+
inputSchema: {
|
|
446
|
+
type: 'object',
|
|
447
|
+
properties: {
|
|
448
|
+
template_id: {
|
|
449
|
+
type: 'string',
|
|
450
|
+
description: 'ID of the page to copy from, used as the template (required)',
|
|
451
|
+
},
|
|
452
|
+
project_id: {
|
|
453
|
+
type: 'string',
|
|
454
|
+
description: "Project to create the copy in (optional; defaults to the template page's project)",
|
|
455
|
+
},
|
|
456
|
+
},
|
|
457
|
+
required: ['template_id'],
|
|
458
|
+
},
|
|
459
|
+
annotations: {
|
|
460
|
+
title: 'Copy page',
|
|
461
|
+
readOnlyHint: false,
|
|
462
|
+
destructiveHint: false,
|
|
463
|
+
idempotentHint: false,
|
|
464
|
+
openWorldHint: true,
|
|
465
|
+
},
|
|
466
|
+
};
|