@dod/planax-mcp 0.1.5 → 0.3.0
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 +26 -17
- package/dist/api-client.js +11 -4
- package/dist/server.js +4 -1
- package/dist/tools/comment.tools.js +27 -5
- package/dist/tools/document.tools.js +307 -129
- package/dist/tools/folder.tools.js +40 -17
- package/dist/tools/plan-items.tools.js +8 -4
- package/dist/tools/plan.tools.js +53 -22
- package/dist/tools/project.tools.js +22 -0
- package/dist/tools/resource-link.tools.js +14 -7
- package/dist/tools/shared.js +23 -0
- package/dist/tools/task.tools.js +80 -64
- package/dist/tools/workspace.tools.js +59 -0
- package/package.json +5 -3
|
@@ -2,6 +2,21 @@ import { readFile } from 'node:fs/promises';
|
|
|
2
2
|
import { basename } from 'node:path';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { successResponse, errorResponse } from './types.js';
|
|
5
|
+
import { DateOnlySchema, DocumentStatusSchema } from './shared.js';
|
|
6
|
+
const EMPTY_VALIDITY = { effectiveDate: null, effectiveEndDate: null, nextReviewDate: null };
|
|
7
|
+
/** 버전 목록을 끝까지 넘기며 versionId 의 현재 유효기간을 찾는다. 없으면 null */
|
|
8
|
+
async function findVersionValidity(apiClient, projectId, documentId, versionId) {
|
|
9
|
+
for (let page = 1;; page++) {
|
|
10
|
+
const res = await apiClient.get(`/projects/${projectId}/documents/${documentId}/versions?page=${page}&limit=100`);
|
|
11
|
+
const row = res.versions.find((v) => v.id === versionId);
|
|
12
|
+
if (row) {
|
|
13
|
+
const v = row.validity ?? EMPTY_VALIDITY;
|
|
14
|
+
return { effectiveDate: v.effectiveDate, effectiveEndDate: v.effectiveEndDate, nextReviewDate: v.nextReviewDate };
|
|
15
|
+
}
|
|
16
|
+
if (!res.totalPages || page >= res.totalPages)
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
5
20
|
const MAX_UPLOAD_BYTES = 50 * 1024 * 1024;
|
|
6
21
|
const MIME_BY_EXTENSION = {
|
|
7
22
|
pdf: 'application/pdf',
|
|
@@ -73,54 +88,68 @@ async function loadFilePart(filePath, contentBase64, fileName) {
|
|
|
73
88
|
export function register({ server, apiClient }) {
|
|
74
89
|
// ===== Document List =====
|
|
75
90
|
server.registerTool('document_list', {
|
|
76
|
-
description: `List
|
|
91
|
+
description: `List documents in a project with optional filtering. Returns the whole list (no pagination).
|
|
77
92
|
|
|
78
93
|
**When to use:**
|
|
79
94
|
- View all documents in a project
|
|
80
|
-
- Filter
|
|
81
|
-
-
|
|
82
|
-
-
|
|
83
|
-
- Search documents by title
|
|
95
|
+
- Filter by status, type (FILE, MARKDOWN, PLACEHOLDER, LINK), assignee, due date, or risk/order issues
|
|
96
|
+
- Browse documents in a specific folder, or only those at the root
|
|
97
|
+
- Search documents by title or description
|
|
84
98
|
|
|
85
99
|
**Examples:**
|
|
86
100
|
1. List all documents in a project:
|
|
87
101
|
{ projectId: "..." }
|
|
88
102
|
|
|
89
|
-
2. Filter by status:
|
|
103
|
+
2. Filter by status / type:
|
|
90
104
|
{ projectId: "...", status: "APPROVED" }
|
|
105
|
+
{ projectId: "...", type: "MARKDOWN" }
|
|
91
106
|
|
|
92
|
-
3.
|
|
107
|
+
3. Documents in a folder / only at the root:
|
|
93
108
|
{ projectId: "...", folderId: "folder-uuid" }
|
|
109
|
+
{ projectId: "...", rootOnly: true }
|
|
94
110
|
|
|
95
|
-
4.
|
|
96
|
-
{ projectId: "...",
|
|
111
|
+
4. My documents due by the end of January:
|
|
112
|
+
{ projectId: "...", assigneeId: "user-uuid", dueDateBefore: "2027-01-31" }
|
|
97
113
|
|
|
98
|
-
5. Search documents:
|
|
114
|
+
5. Search documents (title and description):
|
|
99
115
|
{ projectId: "...", search: "protocol" }
|
|
100
116
|
|
|
101
|
-
**Returns:**
|
|
117
|
+
**Returns:** Array of documents (same fields as document_get)`,
|
|
102
118
|
inputSchema: {
|
|
103
119
|
projectId: z.string().uuid().describe('Project ID (UUID) - required'),
|
|
104
|
-
folderId: z.string().uuid().optional().describe('
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
search: z.string().optional().describe('Search in title'),
|
|
120
|
+
folderId: z.string().uuid().optional().describe('Only documents in this folder'),
|
|
121
|
+
rootOnly: z.boolean().optional().describe('Only documents at the root (not in any folder). Do not combine with folderId'),
|
|
122
|
+
status: DocumentStatusSchema.optional().describe('Filter by document status'),
|
|
123
|
+
type: z.enum(['FILE', 'MARKDOWN', 'PLACEHOLDER', 'LINK']).optional().describe('Filter by document type'),
|
|
124
|
+
assigneeId: z.string().uuid().optional().describe('Filter by assignee user ID'),
|
|
125
|
+
dueDateBefore: DateOnlySchema.optional().describe('Expected end date on or before this date (YYYY-MM-DD)'),
|
|
126
|
+
riskyIssueOnly: z.boolean().optional().describe('Only documents with guideline (risk) issues'),
|
|
127
|
+
orderIssueOnly: z.boolean().optional().describe('Only documents with order issues'),
|
|
128
|
+
search: z.string().optional().describe('Search in title and description'),
|
|
114
129
|
},
|
|
115
|
-
}, async ({ projectId, folderId, status, type, search }) => {
|
|
130
|
+
}, async ({ projectId, folderId, rootOnly, status, type, assigneeId, dueDateBefore, riskyIssueOnly, orderIssueOnly, search }) => {
|
|
116
131
|
try {
|
|
132
|
+
if (rootOnly && folderId) {
|
|
133
|
+
return errorResponse(new Error('Use either folderId or rootOnly, not both'));
|
|
134
|
+
}
|
|
117
135
|
const params = new URLSearchParams();
|
|
118
|
-
|
|
136
|
+
// 백엔드: folderId 가 빈 문자열이면 루트만, 빼면 전체
|
|
137
|
+
if (rootOnly)
|
|
138
|
+
params.append('folderId', '');
|
|
139
|
+
else if (folderId)
|
|
119
140
|
params.append('folderId', folderId);
|
|
120
141
|
if (status)
|
|
121
142
|
params.append('status', status);
|
|
122
143
|
if (type)
|
|
123
144
|
params.append('type', type);
|
|
145
|
+
if (assigneeId)
|
|
146
|
+
params.append('assigneeId', assigneeId);
|
|
147
|
+
if (dueDateBefore)
|
|
148
|
+
params.append('dueDateBefore', dueDateBefore);
|
|
149
|
+
if (riskyIssueOnly)
|
|
150
|
+
params.append('riskyIssueOnly', 'true');
|
|
151
|
+
if (orderIssueOnly)
|
|
152
|
+
params.append('orderIssueOnly', 'true');
|
|
124
153
|
if (search)
|
|
125
154
|
params.append('search', search);
|
|
126
155
|
const queryString = params.toString();
|
|
@@ -137,21 +166,20 @@ export function register({ server, apiClient }) {
|
|
|
137
166
|
description: `Get detailed information about a specific document.
|
|
138
167
|
|
|
139
168
|
**When to use:**
|
|
140
|
-
- View full document details
|
|
141
|
-
- Check document metadata (file size, mime type, etc.)
|
|
142
|
-
- See version information
|
|
143
|
-
- View uploader and creation date
|
|
169
|
+
- View full document details: status, dates, assignee, phase, current version and its validity
|
|
144
170
|
|
|
145
171
|
**Examples:**
|
|
146
172
|
1. Get document details:
|
|
147
|
-
{ documentId: "
|
|
148
|
-
|
|
149
|
-
**Returns:** Document object
|
|
150
|
-
- id, title, description, status
|
|
151
|
-
-
|
|
152
|
-
-
|
|
153
|
-
- tags
|
|
154
|
-
-
|
|
173
|
+
{ projectId: "...", documentId: "..." }
|
|
174
|
+
|
|
175
|
+
**Returns:** Document object:
|
|
176
|
+
- id, title, description, projectId, documentType (FILE | MARKDOWN | PLACEHOLDER | LINK), status
|
|
177
|
+
- fileName, fileKey, mimeType, fileSize, uploadedBy (user id)
|
|
178
|
+
- version (current version number), versionLabel, currentVersionValidity { effectiveDate, effectiveEndDate, nextReviewDate, validityStatus, validityDays }
|
|
179
|
+
- folderId, tags, phaseId, phasePath
|
|
180
|
+
- startDate, expectedEndDate, actualEndDate, assigneeId, assigneeName, reviewerId, authorId
|
|
181
|
+
- riskAlerts, copyStatus, createdAt, updatedAt
|
|
182
|
+
The external URL of a LINK document is not in this response.`,
|
|
155
183
|
inputSchema: {
|
|
156
184
|
projectId: z.string().uuid().describe('Project ID (UUID)'),
|
|
157
185
|
documentId: z.string().uuid().describe('Document ID (UUID)'),
|
|
@@ -167,15 +195,15 @@ export function register({ server, apiClient }) {
|
|
|
167
195
|
});
|
|
168
196
|
// ===== Document Update =====
|
|
169
197
|
server.registerTool('document_update', {
|
|
170
|
-
description: `Update document metadata.
|
|
198
|
+
description: `Update document metadata (not the file or markdown body).
|
|
171
199
|
|
|
172
200
|
**When to use:**
|
|
173
|
-
- Change
|
|
174
|
-
-
|
|
175
|
-
-
|
|
176
|
-
- Update document metadata without changing the file itself
|
|
201
|
+
- Change title, description, status or tags
|
|
202
|
+
- Set or clear dates, assignee or reviewer
|
|
203
|
+
- Move to another folder or link to a phase
|
|
177
204
|
|
|
178
|
-
**
|
|
205
|
+
**Clearing:** send null for startDate, expectedEndDate, actualEndDate, assigneeId or reviewerId to clear it.
|
|
206
|
+
Dates are YYYY-MM-DD. To replace the file use document_replace_file; for markdown body use document_update_markdown_content.
|
|
179
207
|
|
|
180
208
|
**Examples:**
|
|
181
209
|
1. Update title:
|
|
@@ -184,24 +212,11 @@ export function register({ server, apiClient }) {
|
|
|
184
212
|
2. Change status to approved:
|
|
185
213
|
{ projectId: "...", documentId: "...", status: "APPROVED" }
|
|
186
214
|
|
|
187
|
-
3.
|
|
188
|
-
{
|
|
189
|
-
projectId: "...",
|
|
190
|
-
documentId: "...",
|
|
191
|
-
title: "Final Protocol",
|
|
192
|
-
description: "Approved by IRB on 2024-03-15",
|
|
193
|
-
status: "APPROVED",
|
|
194
|
-
tags: ["approved", "irb", "2024"]
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
4. Update tags only:
|
|
198
|
-
{ projectId: "...", documentId: "...", tags: ["review", "pending-approval"] }
|
|
215
|
+
3. Set dates and reviewer:
|
|
216
|
+
{ projectId: "...", documentId: "...", startDate: "2027-01-01", expectedEndDate: "2027-02-15", reviewerId: "user-uuid" }
|
|
199
217
|
|
|
200
|
-
|
|
201
|
-
{ projectId: "...", documentId: "...", assigneeId:
|
|
202
|
-
|
|
203
|
-
6. Unassign document:
|
|
204
|
-
{ projectId: "...", documentId: "...", assigneeId: null }
|
|
218
|
+
4. Clear the assignee and the due date:
|
|
219
|
+
{ projectId: "...", documentId: "...", assigneeId: null, expectedEndDate: null }
|
|
205
220
|
|
|
206
221
|
**Returns:** Updated document object`,
|
|
207
222
|
inputSchema: {
|
|
@@ -209,26 +224,20 @@ export function register({ server, apiClient }) {
|
|
|
209
224
|
documentId: z.string().uuid().describe('Document ID (UUID) - required'),
|
|
210
225
|
title: z.string().min(1).max(255).optional().describe('New document title'),
|
|
211
226
|
description: z.string().optional().describe('New document description'),
|
|
212
|
-
status:
|
|
213
|
-
.enum(['DRAFT', 'REVIEW', 'APPROVED', 'ARCHIVED', 'REJECTED'])
|
|
214
|
-
.optional()
|
|
215
|
-
.describe('New document status'),
|
|
227
|
+
status: DocumentStatusSchema.optional().describe('New document status'),
|
|
216
228
|
tags: z.array(z.string()).optional().describe('New tags (replaces existing)'),
|
|
217
|
-
|
|
229
|
+
folderId: z.string().uuid().optional().describe('Move to this folder'),
|
|
230
|
+
startDate: DateOnlySchema.nullable().optional().describe('Start date (YYYY-MM-DD), null to clear'),
|
|
231
|
+
expectedEndDate: DateOnlySchema.nullable().optional().describe('Expected end (due) date (YYYY-MM-DD), null to clear'),
|
|
232
|
+
actualEndDate: DateOnlySchema.nullable().optional().describe('Actual end date (YYYY-MM-DD), null to clear'),
|
|
233
|
+
assigneeId: z.string().uuid().nullable().optional().describe('Assignee user ID, null to unassign'),
|
|
234
|
+
reviewerId: z.string().uuid().nullable().optional().describe('Reviewer user ID, null to clear'),
|
|
235
|
+
phaseId: z.string().uuid().optional().describe('Link to this phase'),
|
|
218
236
|
},
|
|
219
|
-
}, async ({ projectId, documentId,
|
|
237
|
+
}, async ({ projectId, documentId, ...fields }) => {
|
|
220
238
|
try {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
updateData.title = title;
|
|
224
|
-
if (description !== undefined)
|
|
225
|
-
updateData.description = description;
|
|
226
|
-
if (status !== undefined)
|
|
227
|
-
updateData.status = status;
|
|
228
|
-
if (tags !== undefined)
|
|
229
|
-
updateData.tags = tags;
|
|
230
|
-
if (assigneeId !== undefined)
|
|
231
|
-
updateData.assigneeId = assigneeId;
|
|
239
|
+
// undefined 만 빼고 보낸다. null 은 지우기라 그대로 보낸다
|
|
240
|
+
const updateData = Object.fromEntries(Object.entries(fields).filter(([, v]) => v !== undefined));
|
|
232
241
|
const result = await apiClient.patch(`/projects/${projectId}/documents/${documentId}`, updateData);
|
|
233
242
|
return successResponse(result, 'Document updated successfully');
|
|
234
243
|
}
|
|
@@ -242,14 +251,14 @@ export function register({ server, apiClient }) {
|
|
|
242
251
|
|
|
243
252
|
**When to use:**
|
|
244
253
|
- Remove a document that is no longer needed
|
|
245
|
-
- Archive outdated documents
|
|
246
|
-
- Clean up rejected or obsolete files
|
|
247
254
|
|
|
248
|
-
**Note:**
|
|
255
|
+
**Note:**
|
|
256
|
+
- The document moves to the trash and can be restored (document_list_trash, document_restore).
|
|
257
|
+
- Fails (400) while a signature process is in progress on the document.
|
|
249
258
|
|
|
250
259
|
**Examples:**
|
|
251
260
|
1. Delete a document:
|
|
252
|
-
{ documentId: "
|
|
261
|
+
{ projectId: "...", documentId: "..." }
|
|
253
262
|
|
|
254
263
|
**Returns:** Success confirmation`,
|
|
255
264
|
inputSchema: {
|
|
@@ -276,10 +285,10 @@ export function register({ server, apiClient }) {
|
|
|
276
285
|
|
|
277
286
|
**Examples:**
|
|
278
287
|
1. Move to a folder:
|
|
279
|
-
{ documentId: "...", targetFolderId: "folder-uuid" }
|
|
288
|
+
{ projectId: "...", documentId: "...", targetFolderId: "folder-uuid" }
|
|
280
289
|
|
|
281
290
|
2. Move to root (no folder):
|
|
282
|
-
{ documentId: "...", targetFolderId: null }
|
|
291
|
+
{ projectId: "...", documentId: "...", targetFolderId: null }
|
|
283
292
|
|
|
284
293
|
**Returns:** Updated document with new folder location`,
|
|
285
294
|
inputSchema: {
|
|
@@ -299,36 +308,6 @@ export function register({ server, apiClient }) {
|
|
|
299
308
|
return errorResponse(error);
|
|
300
309
|
}
|
|
301
310
|
});
|
|
302
|
-
// ===== Document Get Related =====
|
|
303
|
-
server.registerTool('document_get_related', {
|
|
304
|
-
description: `Get related information for a document.
|
|
305
|
-
|
|
306
|
-
**When to use:**
|
|
307
|
-
- Find which tasks reference this document
|
|
308
|
-
- Find which phases this document is linked to
|
|
309
|
-
- Discover related documents
|
|
310
|
-
|
|
311
|
-
**Examples:**
|
|
312
|
-
1. Get related info:
|
|
313
|
-
{ documentId: "document-uuid" }
|
|
314
|
-
|
|
315
|
-
**Returns:** Object containing:
|
|
316
|
-
- relatedDocuments: Other documents related to this one
|
|
317
|
-
- linkedTasks: Tasks that reference this document
|
|
318
|
-
- linkedPhases: Plan phases this document is linked to`,
|
|
319
|
-
inputSchema: {
|
|
320
|
-
projectId: z.string().uuid().describe('Project ID (UUID)'),
|
|
321
|
-
documentId: z.string().uuid().describe('Document ID (UUID)'),
|
|
322
|
-
},
|
|
323
|
-
}, async ({ projectId, documentId }) => {
|
|
324
|
-
try {
|
|
325
|
-
const result = await apiClient.get(`/projects/${projectId}/documents/${documentId}/related`);
|
|
326
|
-
return successResponse(result);
|
|
327
|
-
}
|
|
328
|
-
catch (error) {
|
|
329
|
-
return errorResponse(error);
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
311
|
// ===== Document Get Markdown Content =====
|
|
333
312
|
server.registerTool('document_get_markdown_content', {
|
|
334
313
|
description: `Get the markdown content of a document.
|
|
@@ -342,7 +321,7 @@ export function register({ server, apiClient }) {
|
|
|
342
321
|
|
|
343
322
|
**Examples:**
|
|
344
323
|
1. Get markdown content:
|
|
345
|
-
{ documentId: "
|
|
324
|
+
{ projectId: "...", documentId: "..." }
|
|
346
325
|
|
|
347
326
|
**Returns:** Object with markdown content string`,
|
|
348
327
|
inputSchema: {
|
|
@@ -375,12 +354,14 @@ export function register({ server, apiClient }) {
|
|
|
375
354
|
**Examples:**
|
|
376
355
|
1. Overwrite the current version:
|
|
377
356
|
{
|
|
357
|
+
projectId: "...",
|
|
378
358
|
documentId: "...",
|
|
379
359
|
content: "# Updated Title\\n\\nNew content here..."
|
|
380
360
|
}
|
|
381
361
|
|
|
382
362
|
2. Create a new version with a change reason:
|
|
383
363
|
{
|
|
364
|
+
projectId: "...",
|
|
384
365
|
documentId: "...",
|
|
385
366
|
content: "# Protocol v2\\n\\nUpdated protocol...",
|
|
386
367
|
createNewVersion: true,
|
|
@@ -391,7 +372,7 @@ export function register({ server, apiClient }) {
|
|
|
391
372
|
inputSchema: {
|
|
392
373
|
projectId: z.string().uuid().describe('Project ID (UUID)'),
|
|
393
374
|
documentId: z.string().uuid().describe('Document ID (UUID) - must be MARKDOWN type'),
|
|
394
|
-
content: z.string().describe('New markdown content'),
|
|
375
|
+
content: z.string().min(1).describe('New markdown content (cannot be empty)'),
|
|
395
376
|
createNewVersion: z
|
|
396
377
|
.boolean()
|
|
397
378
|
.optional()
|
|
@@ -447,7 +428,7 @@ export function register({ server, apiClient }) {
|
|
|
447
428
|
inputSchema: {
|
|
448
429
|
projectId: z.string().uuid().describe('Project ID (UUID) - required'),
|
|
449
430
|
title: z.string().min(1).max(255).describe('Document title (required)'),
|
|
450
|
-
content: z.string().describe('Initial markdown content'),
|
|
431
|
+
content: z.string().optional().describe('Initial markdown content (optional)'),
|
|
451
432
|
description: z.string().optional().describe('Document description'),
|
|
452
433
|
folderId: z.string().uuid().optional().describe('Folder ID to place document in'),
|
|
453
434
|
tags: z.array(z.string()).optional().describe('Tags for categorization'),
|
|
@@ -472,29 +453,33 @@ export function register({ server, apiClient }) {
|
|
|
472
453
|
description: `Get version history of a document.
|
|
473
454
|
|
|
474
455
|
**When to use:**
|
|
475
|
-
- View all
|
|
476
|
-
-
|
|
477
|
-
- Find a specific version to download or review
|
|
456
|
+
- View all versions of a document and their signature / validity status
|
|
457
|
+
- Find a version id to set its validity period (document_update_version_validity) or download it
|
|
478
458
|
|
|
479
459
|
**Examples:**
|
|
480
|
-
1. Get
|
|
481
|
-
{ documentId: "
|
|
460
|
+
1. Get versions:
|
|
461
|
+
{ projectId: "...", documentId: "..." }
|
|
482
462
|
|
|
483
463
|
2. With pagination:
|
|
484
|
-
{ documentId: "...", page: 1, limit: 10 }
|
|
464
|
+
{ projectId: "...", documentId: "...", page: 1, limit: 10 }
|
|
465
|
+
|
|
466
|
+
**Returns:** { versions, total, page, limit, totalPages }. The FIRST row is the current version; the rest follow by version number (newest first).
|
|
467
|
+
Each row:
|
|
468
|
+
- id (= versionId for document_update_version_validity), version, versionLabel, fileName, mimeType, fileSize, changeReason
|
|
469
|
+
- createdAt, createdBy, createdByName, canDelete, isArchived
|
|
470
|
+
- versionSignatureStatus, requiredSignatureCount, signedRequiredSignatureCount, signedDocumentStatus, signedDocumentId
|
|
471
|
+
- validity { effectiveDate, effectiveEndDate, nextReviewDate, validityStatus: NONE | SCHEDULED | ACTIVE | EXPIRED, validityDays } (workspace timezone)
|
|
485
472
|
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
- createdAt, createdBy
|
|
489
|
-
- changeReason (if provided)
|
|
490
|
-
- fileSize`,
|
|
473
|
+
content (markdown body of each version) and signedUrl (download URL) are left out unless includeContent: true, because they make the response very large.
|
|
474
|
+
To download the signed PDF of a version use document_get_signed_download_url with its signedDocumentId.`,
|
|
491
475
|
inputSchema: {
|
|
492
476
|
projectId: z.string().uuid().describe('Project ID (UUID)'),
|
|
493
477
|
documentId: z.string().uuid().describe('Document ID (UUID)'),
|
|
494
478
|
page: z.number().int().min(1).optional().describe('Page number (default: 1)'),
|
|
495
479
|
limit: z.number().int().min(1).max(100).optional().describe('Items per page (default: 20)'),
|
|
480
|
+
includeContent: z.boolean().optional().describe('Include markdown content and download URL of each version (large)'),
|
|
496
481
|
},
|
|
497
|
-
}, async ({ projectId, documentId, page, limit }) => {
|
|
482
|
+
}, async ({ projectId, documentId, page, limit, includeContent }) => {
|
|
498
483
|
try {
|
|
499
484
|
const params = new URLSearchParams();
|
|
500
485
|
if (page)
|
|
@@ -504,12 +489,71 @@ export function register({ server, apiClient }) {
|
|
|
504
489
|
const queryString = params.toString();
|
|
505
490
|
const url = `/projects/${projectId}/documents/${documentId}/versions${queryString ? `?${queryString}` : ''}`;
|
|
506
491
|
const result = await apiClient.get(url);
|
|
492
|
+
if (!includeContent && Array.isArray(result?.versions)) {
|
|
493
|
+
result.versions = result.versions.map(({ content: _content, signedUrl: _signedUrl, ...rest }) => rest);
|
|
494
|
+
}
|
|
507
495
|
return successResponse(result);
|
|
508
496
|
}
|
|
509
497
|
catch (error) {
|
|
510
498
|
return errorResponse(error);
|
|
511
499
|
}
|
|
512
500
|
});
|
|
501
|
+
// ===== Document Update Version Validity =====
|
|
502
|
+
server.registerTool('document_update_version_validity', {
|
|
503
|
+
description: `Set the validity period of one document version: effective (start) date, effective end date, next review date.
|
|
504
|
+
|
|
505
|
+
**When to use:**
|
|
506
|
+
- After uploading/replacing a file or saving a new markdown version, record when that version is valid
|
|
507
|
+
- Change or clear a version's validity dates
|
|
508
|
+
|
|
509
|
+
**Flow:** document_get_versions -> pick the version's \`id\` (the first row is the current version) -> this tool.
|
|
510
|
+
|
|
511
|
+
**Important:** The three dates are replaced together. A date you leave out is CLEARED, unless you pass \`keepOthers: true\`
|
|
512
|
+
(then this tool reads the version's current dates first and keeps the ones you did not send).
|
|
513
|
+
|
|
514
|
+
**Rules (backend returns 400):**
|
|
515
|
+
- effectiveEndDate needs effectiveDate
|
|
516
|
+
- effectiveEndDate cannot be before effectiveDate
|
|
517
|
+
- PLACEHOLDER and LINK documents have no validity; documents still being copied cannot be changed
|
|
518
|
+
- Viewers cannot change validity
|
|
519
|
+
Signed versions and versions in a signature process can still be changed.
|
|
520
|
+
|
|
521
|
+
Status in responses: NONE (no period), SCHEDULED (before start), ACTIVE, EXPIRED. validityDays = days left (ACTIVE) or days since end (EXPIRED). Dates use the workspace timezone.
|
|
522
|
+
|
|
523
|
+
**Example:** { projectId: "...", documentId: "...", versionId: "...", effectiveDate: "2027-01-01", effectiveEndDate: "2027-12-31", nextReviewDate: "2027-06-30" }
|
|
524
|
+
|
|
525
|
+
**Returns:** The updated version row (same shape as one row of document_get_versions)`,
|
|
526
|
+
inputSchema: {
|
|
527
|
+
projectId: z.string().uuid().describe('Project ID (UUID)'),
|
|
528
|
+
documentId: z.string().uuid().describe('Document ID (UUID)'),
|
|
529
|
+
versionId: z.string().uuid().describe('Version ID: the `id` of a row from document_get_versions'),
|
|
530
|
+
effectiveDate: DateOnlySchema.nullable().optional().describe('Effective (start) date, YYYY-MM-DD. null clears'),
|
|
531
|
+
effectiveEndDate: DateOnlySchema.nullable().optional().describe('Effective end date, YYYY-MM-DD. null clears'),
|
|
532
|
+
nextReviewDate: DateOnlySchema.nullable().optional().describe('Next review date, YYYY-MM-DD. null clears'),
|
|
533
|
+
keepOthers: z.boolean().optional().describe('Keep current values for dates you do not send (default false = clear them)'),
|
|
534
|
+
},
|
|
535
|
+
}, async ({ projectId, documentId, versionId, effectiveDate, effectiveEndDate, nextReviewDate, keepOthers }) => {
|
|
536
|
+
try {
|
|
537
|
+
let current = EMPTY_VALIDITY;
|
|
538
|
+
if (keepOthers) {
|
|
539
|
+
const found = await findVersionValidity(apiClient, projectId, documentId, versionId);
|
|
540
|
+
if (!found) {
|
|
541
|
+
return errorResponse(new Error(`Version ${versionId} is not in this document's version list`));
|
|
542
|
+
}
|
|
543
|
+
current = found;
|
|
544
|
+
}
|
|
545
|
+
const body = {
|
|
546
|
+
effectiveDate: effectiveDate !== undefined ? effectiveDate : current.effectiveDate,
|
|
547
|
+
effectiveEndDate: effectiveEndDate !== undefined ? effectiveEndDate : current.effectiveEndDate,
|
|
548
|
+
nextReviewDate: nextReviewDate !== undefined ? nextReviewDate : current.nextReviewDate,
|
|
549
|
+
};
|
|
550
|
+
const result = await apiClient.patch(`/projects/${projectId}/documents/${documentId}/versions/${versionId}/validity`, body);
|
|
551
|
+
return successResponse(result, 'Version validity updated');
|
|
552
|
+
}
|
|
553
|
+
catch (error) {
|
|
554
|
+
return errorResponse(error);
|
|
555
|
+
}
|
|
556
|
+
});
|
|
513
557
|
// ===== Document Create Placeholder =====
|
|
514
558
|
server.registerTool('document_create_placeholder', {
|
|
515
559
|
description: `Create a placeholder document to be filled later.
|
|
@@ -698,13 +742,14 @@ export function register({ server, apiClient }) {
|
|
|
698
742
|
- Not allowed while a signature process is in progress on the document (cancel it first in the web app)
|
|
699
743
|
- A MARKDOWN document becomes a FILE document; its previous text stays in version history
|
|
700
744
|
- If the replaced version went through signing, the document status resets to DRAFT
|
|
745
|
+
- You can set the new version's validity dates (effectiveDate, effectiveEndDate, nextReviewDate). Wrong dates fail with 400 before the file is uploaded. Later changes: document_update_version_validity
|
|
701
746
|
|
|
702
747
|
**Input:** Provide either \`filePath\` (absolute path on the machine running this MCP server) or \`contentBase64\` with \`fileName\`. Max 50MB.
|
|
703
748
|
|
|
704
749
|
**Example:**
|
|
705
750
|
{ projectId: "...", documentId: "...", filePath: "/Users/me/Documents/protocol_v2.pdf", changeReason: "IRB 의견 반영" }
|
|
706
751
|
|
|
707
|
-
**Returns:** Updated document (new version number)`,
|
|
752
|
+
**Returns:** Updated document (new version number, currentVersionValidity)`,
|
|
708
753
|
inputSchema: {
|
|
709
754
|
projectId: z.string().uuid().describe('Project ID (UUID) - required'),
|
|
710
755
|
documentId: z.string().uuid().describe('Document ID (UUID) to replace the file of'),
|
|
@@ -713,8 +758,11 @@ export function register({ server, apiClient }) {
|
|
|
713
758
|
fileName: z.string().optional().describe('File name with extension (required with contentBase64)'),
|
|
714
759
|
changeReason: z.string().max(500).optional().describe('Reason shown in version history'),
|
|
715
760
|
versionLabel: z.string().optional().describe('Version label (e.g., "v2.0")'),
|
|
761
|
+
effectiveDate: DateOnlySchema.optional().describe('Validity start of the new version, YYYY-MM-DD'),
|
|
762
|
+
effectiveEndDate: DateOnlySchema.optional().describe('Validity end of the new version, YYYY-MM-DD (needs effectiveDate)'),
|
|
763
|
+
nextReviewDate: DateOnlySchema.optional().describe('Next review date of the new version, YYYY-MM-DD'),
|
|
716
764
|
},
|
|
717
|
-
}, async ({ projectId, documentId, filePath, contentBase64, fileName, changeReason, versionLabel }) => {
|
|
765
|
+
}, async ({ projectId, documentId, filePath, contentBase64, fileName, changeReason, versionLabel, effectiveDate, effectiveEndDate, nextReviewDate }) => {
|
|
718
766
|
try {
|
|
719
767
|
const { blob, name } = await loadFilePart(filePath, contentBase64, fileName);
|
|
720
768
|
const form = new FormData();
|
|
@@ -723,6 +771,12 @@ export function register({ server, apiClient }) {
|
|
|
723
771
|
form.append('changeReason', changeReason);
|
|
724
772
|
if (versionLabel)
|
|
725
773
|
form.append('versionLabel', versionLabel);
|
|
774
|
+
if (effectiveDate)
|
|
775
|
+
form.append('effectiveDate', effectiveDate);
|
|
776
|
+
if (effectiveEndDate)
|
|
777
|
+
form.append('effectiveEndDate', effectiveEndDate);
|
|
778
|
+
if (nextReviewDate)
|
|
779
|
+
form.append('nextReviewDate', nextReviewDate);
|
|
726
780
|
const result = await apiClient.patchForm(`/projects/${projectId}/documents/${documentId}/replace-file`, form);
|
|
727
781
|
return successResponse(result, `File replaced with "${name}" (new version)`);
|
|
728
782
|
}
|
|
@@ -744,6 +798,7 @@ export function register({ server, apiClient }) {
|
|
|
744
798
|
**Examples:**
|
|
745
799
|
1. Convert to markdown:
|
|
746
800
|
{
|
|
801
|
+
projectId: "...",
|
|
747
802
|
documentId: "...",
|
|
748
803
|
targetType: "MARKDOWN",
|
|
749
804
|
content: "# Document Title\\n\\nContent here..."
|
|
@@ -751,6 +806,7 @@ export function register({ server, apiClient }) {
|
|
|
751
806
|
|
|
752
807
|
2. Convert to an uploaded file:
|
|
753
808
|
{
|
|
809
|
+
projectId: "...",
|
|
754
810
|
documentId: "...",
|
|
755
811
|
targetType: "FILE",
|
|
756
812
|
filePath: "/Users/me/Documents/protocol.pdf"
|
|
@@ -758,6 +814,7 @@ export function register({ server, apiClient }) {
|
|
|
758
814
|
|
|
759
815
|
3. Convert to external link:
|
|
760
816
|
{
|
|
817
|
+
projectId: "...",
|
|
761
818
|
documentId: "...",
|
|
762
819
|
targetType: "LINK",
|
|
763
820
|
externalUrl: "https://docs.google.com/...",
|
|
@@ -766,6 +823,7 @@ export function register({ server, apiClient }) {
|
|
|
766
823
|
|
|
767
824
|
4. With change reason:
|
|
768
825
|
{
|
|
826
|
+
projectId: "...",
|
|
769
827
|
documentId: "...",
|
|
770
828
|
targetType: "MARKDOWN",
|
|
771
829
|
content: "# Protocol\\n\\nStudy protocol content...",
|
|
@@ -780,7 +838,7 @@ export function register({ server, apiClient }) {
|
|
|
780
838
|
filePath: z.string().optional().describe('Absolute path of local file (FILE conversion)'),
|
|
781
839
|
contentBase64: z.string().optional().describe('Base64 file content (FILE conversion, use with fileName)'),
|
|
782
840
|
fileName: z.string().optional().describe('File name with extension (required with contentBase64)'),
|
|
783
|
-
content: z.string().optional().describe('Markdown content
|
|
841
|
+
content: z.string().optional().describe('Markdown content for MARKDOWN conversion (optional)'),
|
|
784
842
|
externalUrl: z.string().url().optional().describe('External URL (required for LINK conversion)'),
|
|
785
843
|
linkType: z
|
|
786
844
|
.enum(['google-docs', 'notion', 'confluence', 'other'])
|
|
@@ -827,18 +885,21 @@ export function register({ server, apiClient }) {
|
|
|
827
885
|
**Examples:**
|
|
828
886
|
1. Update URL:
|
|
829
887
|
{
|
|
888
|
+
projectId: "...",
|
|
830
889
|
documentId: "...",
|
|
831
890
|
externalUrl: "https://new-url.example.com/doc"
|
|
832
891
|
}
|
|
833
892
|
|
|
834
893
|
2. Update link type:
|
|
835
894
|
{
|
|
895
|
+
projectId: "...",
|
|
836
896
|
documentId: "...",
|
|
837
897
|
linkType: "notion"
|
|
838
898
|
}
|
|
839
899
|
|
|
840
900
|
3. Update both:
|
|
841
901
|
{
|
|
902
|
+
projectId: "...",
|
|
842
903
|
documentId: "...",
|
|
843
904
|
externalUrl: "https://www.notion.so/new-page",
|
|
844
905
|
linkType: "notion"
|
|
@@ -868,4 +929,121 @@ export function register({ server, apiClient }) {
|
|
|
868
929
|
return errorResponse(error);
|
|
869
930
|
}
|
|
870
931
|
});
|
|
932
|
+
// ===== Document Trash / Restore =====
|
|
933
|
+
server.registerTool('document_list_trash', {
|
|
934
|
+
description: `List deleted documents (the project's trash), newest deletion first.
|
|
935
|
+
|
|
936
|
+
**When to use:**
|
|
937
|
+
- Find a document id to restore with document_restore
|
|
938
|
+
|
|
939
|
+
**Returns:** Array of deleted documents (same fields as document_get, plus deletedAt)`,
|
|
940
|
+
inputSchema: {
|
|
941
|
+
projectId: z.string().uuid().describe('Project ID (UUID)'),
|
|
942
|
+
},
|
|
943
|
+
}, async ({ projectId }) => {
|
|
944
|
+
try {
|
|
945
|
+
const result = await apiClient.get(`/projects/${projectId}/documents/trash`);
|
|
946
|
+
return successResponse(result);
|
|
947
|
+
}
|
|
948
|
+
catch (error) {
|
|
949
|
+
return errorResponse(error);
|
|
950
|
+
}
|
|
951
|
+
});
|
|
952
|
+
server.registerTool('document_restore', {
|
|
953
|
+
description: `Restore a deleted document from the trash.
|
|
954
|
+
|
|
955
|
+
**Example:** { projectId: "...", documentId: "..." }
|
|
956
|
+
|
|
957
|
+
**Returns:** Restored document`,
|
|
958
|
+
inputSchema: {
|
|
959
|
+
projectId: z.string().uuid().describe('Project ID (UUID)'),
|
|
960
|
+
documentId: z.string().uuid().describe('Deleted document ID (from document_list_trash)'),
|
|
961
|
+
},
|
|
962
|
+
}, async ({ projectId, documentId }) => {
|
|
963
|
+
try {
|
|
964
|
+
const result = await apiClient.post(`/projects/${projectId}/documents/${documentId}/restore`);
|
|
965
|
+
return successResponse(result, 'Document restored successfully');
|
|
966
|
+
}
|
|
967
|
+
catch (error) {
|
|
968
|
+
return errorResponse(error);
|
|
969
|
+
}
|
|
970
|
+
});
|
|
971
|
+
// ===== Document Download URL =====
|
|
972
|
+
server.registerTool('document_get_download_url', {
|
|
973
|
+
description: `Get a temporary download (or preview) URL for a FILE document.
|
|
974
|
+
|
|
975
|
+
**When to use:**
|
|
976
|
+
- Read or download the file of a document (current version, or a specific version from document_get_versions)
|
|
977
|
+
- MARKDOWN documents: use document_get_markdown_content instead
|
|
978
|
+
- This returns the ORIGINAL file. For the signed PDF use document_get_signed_download_url
|
|
979
|
+
|
|
980
|
+
**Examples:**
|
|
981
|
+
1. Current version: { projectId: "...", documentId: "..." }
|
|
982
|
+
2. A specific version: { projectId: "...", documentId: "...", versionId: "..." }
|
|
983
|
+
3. Preview (inline) URL: { projectId: "...", documentId: "...", preview: true }
|
|
984
|
+
|
|
985
|
+
**Returns:** { url, fileName, mimeType, expiresIn } — the URL expires after expiresIn seconds (1 hour).`,
|
|
986
|
+
inputSchema: {
|
|
987
|
+
projectId: z.string().uuid().describe('Project ID (UUID)'),
|
|
988
|
+
documentId: z.string().uuid().describe('Document ID (UUID)'),
|
|
989
|
+
versionId: z.string().uuid().optional().describe('Version ID (from document_get_versions); omit for the current version'),
|
|
990
|
+
preview: z.boolean().optional().describe('Preview URL instead of download (current version only)'),
|
|
991
|
+
},
|
|
992
|
+
}, async ({ projectId, documentId, versionId, preview }) => {
|
|
993
|
+
try {
|
|
994
|
+
if (versionId && preview) {
|
|
995
|
+
return errorResponse(new Error('preview works only for the current version; omit versionId'));
|
|
996
|
+
}
|
|
997
|
+
const base = `/projects/${projectId}/documents/${documentId}`;
|
|
998
|
+
const path = versionId ? `${base}/versions/${versionId}/download` : preview ? `${base}/preview` : `${base}/download`;
|
|
999
|
+
const result = await apiClient.get(path);
|
|
1000
|
+
return successResponse(result);
|
|
1001
|
+
}
|
|
1002
|
+
catch (error) {
|
|
1003
|
+
return errorResponse(error);
|
|
1004
|
+
}
|
|
1005
|
+
});
|
|
1006
|
+
// ===== Signed PDF Download URL =====
|
|
1007
|
+
server.registerTool('document_get_signed_download_url', {
|
|
1008
|
+
description: `Get a temporary download URL for a SIGNED PDF (the PDF with signatures and the audit log page), not the original file.
|
|
1009
|
+
|
|
1010
|
+
**When to use:**
|
|
1011
|
+
- Download the signed PDF of a document after its signature process completed
|
|
1012
|
+
- document_get_download_url returns the ORIGINAL file; use this tool for the signed one
|
|
1013
|
+
|
|
1014
|
+
**Flow:** document_list -> document_get_versions -> pick a row whose signedDocumentStatus is COMPLETED and use its signedDocumentId -> this tool.
|
|
1015
|
+
Omit signedDocumentId to get the signed PDF of the current (latest) version.
|
|
1016
|
+
|
|
1017
|
+
**Examples:**
|
|
1018
|
+
1. Signed PDF of a specific version: { projectId: "...", documentId: "...", signedDocumentId: "..." }
|
|
1019
|
+
2. Signed PDF of the current version: { projectId: "...", documentId: "..." }
|
|
1020
|
+
|
|
1021
|
+
**Errors:** 404 when that version has no completed signed PDF yet (signedDocumentStatus NONE / GENERATING / FAILED).
|
|
1022
|
+
|
|
1023
|
+
**Returns:** { url, fileName, fileSize, expiresIn } — the URL expires after expiresIn seconds (1 hour). fileName and fileSize are only known when signedDocumentId is given.`,
|
|
1024
|
+
inputSchema: {
|
|
1025
|
+
projectId: z.string().uuid().describe('Project ID (UUID)'),
|
|
1026
|
+
documentId: z.string().uuid().describe('Document ID (UUID)'),
|
|
1027
|
+
signedDocumentId: z
|
|
1028
|
+
.string()
|
|
1029
|
+
.uuid()
|
|
1030
|
+
.optional()
|
|
1031
|
+
.describe('signedDocumentId from a document_get_versions row (COMPLETED); omit for the current version'),
|
|
1032
|
+
},
|
|
1033
|
+
}, async ({ projectId, documentId, signedDocumentId }) => {
|
|
1034
|
+
try {
|
|
1035
|
+
const base = `/projects/${projectId}/documents/${documentId}`;
|
|
1036
|
+
if (signedDocumentId) {
|
|
1037
|
+
// 응답: { downloadUrl, expiresIn, fileName, fileSize }
|
|
1038
|
+
const r = await apiClient.get(`${base}/signed-versions/${signedDocumentId}/download`);
|
|
1039
|
+
return successResponse({ url: r?.downloadUrl, fileName: r?.fileName, fileSize: r?.fileSize, expiresIn: r?.expiresIn });
|
|
1040
|
+
}
|
|
1041
|
+
// 응답: { url } — 최신 버전에서 완료된 서명 절차의 서명본
|
|
1042
|
+
const r = await apiClient.get(`${base}/signed-pdf-url`);
|
|
1043
|
+
return successResponse({ url: r?.url, fileName: null, fileSize: null, expiresIn: 3600 });
|
|
1044
|
+
}
|
|
1045
|
+
catch (error) {
|
|
1046
|
+
return errorResponse(error);
|
|
1047
|
+
}
|
|
1048
|
+
});
|
|
871
1049
|
}
|