planko-mcp-server 0.5.2 → 0.7.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 +67 -14
- package/index.js +15 -623
- package/package.json +8 -3
- package/src/api.js +17 -0
- package/src/listing.js +297 -0
- package/src/projectLock.js +7 -1
- package/src/recommend.js +87 -0
- package/src/tools.js +854 -0
package/index.js
CHANGED
|
@@ -8,9 +8,12 @@
|
|
|
8
8
|
* PLANKO_API_BASE — optional API base URL override
|
|
9
9
|
*
|
|
10
10
|
* Tools:
|
|
11
|
-
* planko_setup
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* planko_setup / planko_sync_preview / planko_sync — folder sync
|
|
12
|
+
* planko_create_* / planko_edit_* / planko_delete_* / planko_view_* / planko_list_*
|
|
13
|
+
* for tasks (type=1), notes (type=2) and sticky notes (type=3)
|
|
14
|
+
* planko_complete_task — works on any item id
|
|
15
|
+
* planko_list_all — tasks + sticky notes + notes in one listing
|
|
16
|
+
* planko_recommend_task — suggest a task for the account owner to accept/reject
|
|
14
17
|
*/
|
|
15
18
|
|
|
16
19
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
@@ -18,23 +21,13 @@ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
|
18
21
|
import { z } from 'zod';
|
|
19
22
|
import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs';
|
|
20
23
|
import { join } from 'node:path';
|
|
24
|
+
import { createRequire } from 'node:module';
|
|
21
25
|
|
|
22
26
|
import { createApiClient } from './src/api.js';
|
|
23
|
-
import {
|
|
27
|
+
import { registerStandaloneTools, toolOk, toolError } from './src/tools.js';
|
|
24
28
|
import {
|
|
25
|
-
lockProjectId,
|
|
26
|
-
sanitizeFilters,
|
|
27
|
-
ownerName,
|
|
28
|
-
assertProjectAllowed,
|
|
29
|
-
stripHallucinatedListFilters,
|
|
30
|
-
matchesAssignee,
|
|
31
|
-
hasOwnerInfo,
|
|
32
|
-
} from './src/projectLock.js';
|
|
33
|
-
import {
|
|
34
|
-
blockNoteToMarkdown,
|
|
35
29
|
markdownToBlockNote,
|
|
36
30
|
descriptionToMarkdown,
|
|
37
|
-
markdownToDescription,
|
|
38
31
|
} from './src/converters.js';
|
|
39
32
|
import {
|
|
40
33
|
readConfig,
|
|
@@ -68,16 +61,6 @@ const api = createApiClient({ apiKey: API_KEY });
|
|
|
68
61
|
// When null (the default) behavior is identical to before this feature.
|
|
69
62
|
const PROJECT_LOCK = (process.env.PLANKO_PROJECT_LOCK || '').trim() || null;
|
|
70
63
|
|
|
71
|
-
// --- Tool helpers ---
|
|
72
|
-
|
|
73
|
-
function toolOk(text) {
|
|
74
|
-
return { content: [{ type: 'text', text }] };
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function toolError(text) {
|
|
78
|
-
return { content: [{ type: 'text', text }], isError: true };
|
|
79
|
-
}
|
|
80
|
-
|
|
81
64
|
// --- Sync engine (shared by preview and sync) ---
|
|
82
65
|
|
|
83
66
|
/**
|
|
@@ -373,9 +356,11 @@ async function executeSync(projectId, folder, sync) {
|
|
|
373
356
|
|
|
374
357
|
// --- MCP Server ---
|
|
375
358
|
|
|
359
|
+
const { version: PKG_VERSION } = createRequire(import.meta.url)('./package.json');
|
|
360
|
+
|
|
376
361
|
const server = new McpServer({
|
|
377
362
|
name: 'planko-mcp-server',
|
|
378
|
-
version:
|
|
363
|
+
version: PKG_VERSION,
|
|
379
364
|
});
|
|
380
365
|
|
|
381
366
|
// ---- planko_setup ----
|
|
@@ -429,16 +414,16 @@ server.tool(
|
|
|
429
414
|
const syncState = createSyncState(match._id, match.name, type);
|
|
430
415
|
writeSyncState(folderPath, syncState);
|
|
431
416
|
|
|
432
|
-
const
|
|
417
|
+
const syncLabel = type === 2 ? 'Notes' : 'Tasks';
|
|
433
418
|
|
|
434
419
|
return toolOk(
|
|
435
420
|
`Setup complete for project "${match.name}".\n` +
|
|
436
421
|
` Project ID: ${match._id}\n` +
|
|
437
422
|
` Folder: ${folderPath}\n` +
|
|
438
423
|
` Email: ${email}\n` +
|
|
439
|
-
` Syncs: ${
|
|
424
|
+
` Syncs: ${syncLabel} (type=${type})\n` +
|
|
440
425
|
` Workspace: ${match.isWorkspace ? 'Yes' : 'No (personal)'}\n\n` +
|
|
441
|
-
`Run planko_sync to pull ${
|
|
426
|
+
`Run planko_sync to pull ${syncLabel.toLowerCase()} into this folder.`
|
|
442
427
|
);
|
|
443
428
|
} catch (err) {
|
|
444
429
|
return toolError(`Setup failed: ${err.message}`);
|
|
@@ -589,600 +574,7 @@ server.tool(
|
|
|
589
574
|
}
|
|
590
575
|
);
|
|
591
576
|
|
|
592
|
-
|
|
593
|
-
// These operate directly via the user-scoped API key and do NOT require any
|
|
594
|
-
// folder to be configured with planko_setup. Notes are Task docs with type=2;
|
|
595
|
-
// tasks are type=1. Edit/Delete work on both; Complete is task-oriented.
|
|
596
|
-
|
|
597
|
-
const objectId = z
|
|
598
|
-
.string()
|
|
599
|
-
.regex(/^[a-fA-F\d]{24}$/, 'Must be a 24-character hex ObjectId');
|
|
600
|
-
|
|
601
|
-
const timeRegex = /^([01]?[0-9]|2[0-3]):[0-5][0-9]$/;
|
|
602
|
-
|
|
603
|
-
// Shared editable task/note properties (all optional). `description` is Markdown
|
|
604
|
-
// here and is converted to BlockNote JSON before being sent to the backend.
|
|
605
|
-
const taskProps = {
|
|
606
|
-
description: z
|
|
607
|
-
.string()
|
|
608
|
-
.optional()
|
|
609
|
-
.describe('Body as Markdown (converted to BlockNote JSON before saving)'),
|
|
610
|
-
dueDate: z.string().optional().describe('Due date (ISO 8601 string)'),
|
|
611
|
-
datePlain: z
|
|
612
|
-
.string()
|
|
613
|
-
.regex(/^\d{4}-\d{2}-\d{2}$/, 'Must be YYYY-MM-DD')
|
|
614
|
-
.optional()
|
|
615
|
-
.describe('Plain date, YYYY-MM-DD'),
|
|
616
|
-
time: z.string().regex(timeRegex, 'Must be HH:MM').optional().describe('Start time, HH:MM'),
|
|
617
|
-
endTime: z.string().regex(timeRegex, 'Must be HH:MM').optional().describe('End time, HH:MM'),
|
|
618
|
-
alert: z.boolean().optional().describe('Whether an alert/reminder is enabled'),
|
|
619
|
-
alertLeadTime: z
|
|
620
|
-
.enum(['ontime', '15min', '30min', '1hour', '1day'])
|
|
621
|
-
.nullable()
|
|
622
|
-
.optional()
|
|
623
|
-
.describe('Reminder lead time (null or one of ontime/15min/30min/1hour/1day)'),
|
|
624
|
-
priority: z
|
|
625
|
-
.union([z.literal(1), z.literal(2), z.literal(3)])
|
|
626
|
-
.optional()
|
|
627
|
-
.describe('Priority: 1, 2, or 3'),
|
|
628
|
-
repeat: z
|
|
629
|
-
.enum(['daily', 'workdays', 'weekly', 'biweekly', 'monthly', 'custom_weekly', 'yearly'])
|
|
630
|
-
.nullable()
|
|
631
|
-
.optional()
|
|
632
|
-
.describe('Recurrence rule (null or one of the recurrence keywords)'),
|
|
633
|
-
repeatDate: z.string().optional().describe('Recurrence end/anchor date (ISO 8601 string)'),
|
|
634
|
-
selectedWeekdays: z
|
|
635
|
-
.array(z.number().int().min(0).max(6))
|
|
636
|
-
.optional()
|
|
637
|
-
.describe('Weekdays for custom_weekly repeat (0=Sunday..6=Saturday)'),
|
|
638
|
-
parentId: objectId.optional().describe('Parent task id (for subtasks)'),
|
|
639
|
-
tags: z.array(objectId).optional().describe('Array of tag ids'),
|
|
640
|
-
kanbanColumnId: objectId.optional().describe('Kanban column id'),
|
|
641
|
-
boardId: objectId.optional().describe('Board id'),
|
|
642
|
-
};
|
|
643
|
-
|
|
644
|
-
/**
|
|
645
|
-
* Build a request body from tool params: drop undefined values and convert the
|
|
646
|
-
* Markdown `description` into BlockNote JSON.
|
|
647
|
-
*/
|
|
648
|
-
function buildTaskBody(params) {
|
|
649
|
-
const body = {};
|
|
650
|
-
for (const [key, value] of Object.entries(params)) {
|
|
651
|
-
if (isBlankValue(value)) continue;
|
|
652
|
-
body[key] = value;
|
|
653
|
-
}
|
|
654
|
-
applyDueDateFallback(body);
|
|
655
|
-
if ('description' in body) {
|
|
656
|
-
body.description = markdownToDescription(body.description);
|
|
657
|
-
}
|
|
658
|
-
return body;
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
/**
|
|
662
|
-
* Resolve a project name to a project id via the user's accessible projects
|
|
663
|
-
* (NOT the local folder config), so create tools work without any setup.
|
|
664
|
-
*/
|
|
665
|
-
async function resolveProjectId(projectName) {
|
|
666
|
-
const { projects } = await api.projects();
|
|
667
|
-
const match = projects.find(
|
|
668
|
-
(p) => p.name.toLowerCase() === projectName.toLowerCase()
|
|
669
|
-
);
|
|
670
|
-
if (!match) {
|
|
671
|
-
const available = projects.map((p) => ` - ${p.name}`).join('\n');
|
|
672
|
-
throw new Error(
|
|
673
|
-
`Project "${projectName}" not found.\n\nAvailable projects:\n${available}`
|
|
674
|
-
);
|
|
675
|
-
}
|
|
676
|
-
return match._id;
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
/** Extract { id, name } from a create/edit response (shape-tolerant). */
|
|
680
|
-
function describeTask(res) {
|
|
681
|
-
const t = (res && (res.task || res.data)) || res || {};
|
|
682
|
-
return {
|
|
683
|
-
id: t._id || t.id || 'unknown',
|
|
684
|
-
name: t.name != null ? t.name : 'unknown',
|
|
685
|
-
};
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
/**
|
|
689
|
-
* When PROJECT_LOCK is set, fetch a by-id task and refuse the operation unless
|
|
690
|
-
* it belongs to the locked project. No-op when the lock is null.
|
|
691
|
-
*/
|
|
692
|
-
async function assertTaskInLock(taskId) {
|
|
693
|
-
if (!PROJECT_LOCK) return;
|
|
694
|
-
const res = await api.getTask(taskId);
|
|
695
|
-
assertProjectAllowed(PROJECT_LOCK, unwrapItem(res));
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
/**
|
|
699
|
-
* Shared create handler for tasks (type=1) and notes (type=2).
|
|
700
|
-
*/
|
|
701
|
-
async function handleCreate(type, params, kindLabel) {
|
|
702
|
-
const { name, projectName, ...rest } = params;
|
|
703
|
-
const body = buildTaskBody(rest);
|
|
704
|
-
body.name = name;
|
|
705
|
-
body.type = type;
|
|
706
|
-
|
|
707
|
-
if (PROJECT_LOCK) {
|
|
708
|
-
// Hard override: always the locked project; ignore any caller project field
|
|
709
|
-
// and do NOT resolve projectName.
|
|
710
|
-
body.projectId = lockProjectId(PROJECT_LOCK, body.projectId);
|
|
711
|
-
} else if (!isBlankValue(projectName)) {
|
|
712
|
-
// Resolve projectName -> projectId via the API. When omitted, OMIT the key
|
|
713
|
-
// entirely so the backend applies the user's default project.
|
|
714
|
-
body.projectId = await resolveProjectId(projectName);
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
const res = await api.createTask(body);
|
|
718
|
-
const { id, name: savedName } = describeTask(res);
|
|
719
|
-
const where = body.projectId
|
|
720
|
-
? ` in project ${body.projectId}`
|
|
721
|
-
: ' in your default project';
|
|
722
|
-
return toolOk(`Created ${kindLabel} "${savedName}" (id: ${id})${where}.`);
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
/**
|
|
726
|
-
* Shared edit handler for tasks and notes (same endpoint).
|
|
727
|
-
*/
|
|
728
|
-
async function handleEdit(params, kindLabel) {
|
|
729
|
-
const { taskId, ...rest } = params;
|
|
730
|
-
const body = buildTaskBody(rest);
|
|
731
|
-
const changed = Object.keys(body);
|
|
732
|
-
if (changed.length === 0) {
|
|
733
|
-
return toolError('Nothing to update: provide at least one field to change.');
|
|
734
|
-
}
|
|
735
|
-
if (PROJECT_LOCK) {
|
|
736
|
-
// Refuse to touch a task outside the locked project.
|
|
737
|
-
await assertTaskInLock(taskId);
|
|
738
|
-
// If the caller tried to move the task to another project, force it back to
|
|
739
|
-
// the lock (never let an edit move a task OUT of the locked project). If no
|
|
740
|
-
// project field was passed, leave the project unchanged.
|
|
741
|
-
if ('projectId' in body) {
|
|
742
|
-
body.projectId = lockProjectId(PROJECT_LOCK, body.projectId);
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
const res = await api.updateTask(taskId, body);
|
|
746
|
-
const { id, name: savedName } = describeTask(res);
|
|
747
|
-
return toolOk(
|
|
748
|
-
`Updated ${kindLabel} "${savedName}" (id: ${id}). Changed: ${changed.join(', ')}.`
|
|
749
|
-
);
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
// ---- planko_create_task ----
|
|
753
|
-
server.tool(
|
|
754
|
-
'planko_create_task',
|
|
755
|
-
'Create a Planko task (type=1) directly via your API key. Works without any folder setup. Provide a name (required); all other properties are optional. Optionally target a project by name (otherwise your default project is used).',
|
|
756
|
-
{
|
|
757
|
-
name: z.string().describe('Task name (required)'),
|
|
758
|
-
projectName: z
|
|
759
|
-
.string()
|
|
760
|
-
.optional()
|
|
761
|
-
.describe('Project name to create the task in (optional — omit for your default project)'),
|
|
762
|
-
...taskProps,
|
|
763
|
-
},
|
|
764
|
-
async (params) => {
|
|
765
|
-
try {
|
|
766
|
-
return await handleCreate(1, params, 'task');
|
|
767
|
-
} catch (err) {
|
|
768
|
-
return toolError(`Create task failed: ${err.message}`);
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
);
|
|
772
|
-
|
|
773
|
-
// ---- planko_create_note ----
|
|
774
|
-
server.tool(
|
|
775
|
-
'planko_create_note',
|
|
776
|
-
'Create a Planko note (type=2) directly via your API key. Works without any folder setup. Provide a name (required); all other properties are optional. Optionally target a project by name (otherwise your default project is used).',
|
|
777
|
-
{
|
|
778
|
-
name: z.string().describe('Note name (required)'),
|
|
779
|
-
projectName: z
|
|
780
|
-
.string()
|
|
781
|
-
.optional()
|
|
782
|
-
.describe('Project name to create the note in (optional — omit for your default project)'),
|
|
783
|
-
...taskProps,
|
|
784
|
-
},
|
|
785
|
-
async (params) => {
|
|
786
|
-
try {
|
|
787
|
-
return await handleCreate(2, params, 'note');
|
|
788
|
-
} catch (err) {
|
|
789
|
-
return toolError(`Create note failed: ${err.message}`);
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
);
|
|
793
|
-
|
|
794
|
-
// ---- planko_edit_task ----
|
|
795
|
-
server.tool(
|
|
796
|
-
'planko_edit_task',
|
|
797
|
-
'Edit an existing Planko task by id. Provide the taskId and any properties to change. The Markdown description is converted to BlockNote JSON.',
|
|
798
|
-
{
|
|
799
|
-
taskId: objectId.describe('Id of the task to edit (required)'),
|
|
800
|
-
name: z.string().optional().describe('New task name'),
|
|
801
|
-
type: z
|
|
802
|
-
.union([z.literal(1), z.literal(2)])
|
|
803
|
-
.optional()
|
|
804
|
-
.describe('Change type: 1=task, 2=note'),
|
|
805
|
-
projectId: objectId.optional().describe('Move to a different project by id'),
|
|
806
|
-
...taskProps,
|
|
807
|
-
},
|
|
808
|
-
async (params) => {
|
|
809
|
-
try {
|
|
810
|
-
return await handleEdit(params, 'task');
|
|
811
|
-
} catch (err) {
|
|
812
|
-
return toolError(`Edit task failed: ${err.message}`);
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
);
|
|
816
|
-
|
|
817
|
-
// ---- planko_edit_note ----
|
|
818
|
-
server.tool(
|
|
819
|
-
'planko_edit_note',
|
|
820
|
-
'Edit an existing Planko note by id (shares the task edit endpoint). Provide the taskId and any properties to change. The Markdown description is converted to BlockNote JSON.',
|
|
821
|
-
{
|
|
822
|
-
taskId: objectId.describe('Id of the note to edit (required)'),
|
|
823
|
-
name: z.string().optional().describe('New note name'),
|
|
824
|
-
type: z
|
|
825
|
-
.union([z.literal(1), z.literal(2)])
|
|
826
|
-
.optional()
|
|
827
|
-
.describe('Change type: 1=task, 2=note'),
|
|
828
|
-
projectId: objectId.optional().describe('Move to a different project by id'),
|
|
829
|
-
...taskProps,
|
|
830
|
-
},
|
|
831
|
-
async (params) => {
|
|
832
|
-
try {
|
|
833
|
-
return await handleEdit(params, 'note');
|
|
834
|
-
} catch (err) {
|
|
835
|
-
return toolError(`Edit note failed: ${err.message}`);
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
);
|
|
839
|
-
|
|
840
|
-
// ---- planko_complete_task ----
|
|
841
|
-
server.tool(
|
|
842
|
-
'planko_complete_task',
|
|
843
|
-
'Mark a Planko task complete (status=2) by id.',
|
|
844
|
-
{
|
|
845
|
-
taskId: objectId.describe('Id of the task to complete (required)'),
|
|
846
|
-
},
|
|
847
|
-
async ({ taskId }) => {
|
|
848
|
-
try {
|
|
849
|
-
await assertTaskInLock(taskId);
|
|
850
|
-
const res = await api.completeTask(taskId);
|
|
851
|
-
const { id, name } = describeTask(res);
|
|
852
|
-
return toolOk(`Completed task "${name}" (id: ${id}).`);
|
|
853
|
-
} catch (err) {
|
|
854
|
-
return toolError(`Complete task failed: ${err.message}`);
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
);
|
|
858
|
-
|
|
859
|
-
// ---- planko_delete_task ----
|
|
860
|
-
server.tool(
|
|
861
|
-
'planko_delete_task',
|
|
862
|
-
'Delete a Planko task by id.',
|
|
863
|
-
{
|
|
864
|
-
taskId: objectId.describe('Id of the task to delete (required)'),
|
|
865
|
-
},
|
|
866
|
-
async ({ taskId }) => {
|
|
867
|
-
try {
|
|
868
|
-
await assertTaskInLock(taskId);
|
|
869
|
-
await api.deleteTask(taskId);
|
|
870
|
-
return toolOk(`Deleted task (id: ${taskId}).`);
|
|
871
|
-
} catch (err) {
|
|
872
|
-
return toolError(`Delete task failed: ${err.message}`);
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
);
|
|
876
|
-
|
|
877
|
-
// ---- planko_delete_note ----
|
|
878
|
-
server.tool(
|
|
879
|
-
'planko_delete_note',
|
|
880
|
-
'Delete a Planko note by id (shares the task delete endpoint).',
|
|
881
|
-
{
|
|
882
|
-
taskId: objectId.describe('Id of the note to delete (required)'),
|
|
883
|
-
},
|
|
884
|
-
async ({ taskId }) => {
|
|
885
|
-
try {
|
|
886
|
-
await assertTaskInLock(taskId);
|
|
887
|
-
await api.deleteTask(taskId);
|
|
888
|
-
return toolOk(`Deleted note (id: ${taskId}).`);
|
|
889
|
-
} catch (err) {
|
|
890
|
-
return toolError(`Delete note failed: ${err.message}`);
|
|
891
|
-
}
|
|
892
|
-
}
|
|
893
|
-
);
|
|
894
|
-
|
|
895
|
-
// --- Standalone READ tools (Part C) ---
|
|
896
|
-
// Read-only, user-scoped via API key; no folder setup required. List tools send
|
|
897
|
-
// `type` (1=tasks, 2=notes) and parametrized filters; view tools fetch one item
|
|
898
|
-
// by id and render its BlockNote description as Markdown. No mutation.
|
|
899
|
-
|
|
900
|
-
const datePlain = z
|
|
901
|
-
.string()
|
|
902
|
-
.regex(/^\d{4}-\d{2}-\d{2}$/, 'Must be YYYY-MM-DD');
|
|
903
|
-
|
|
904
|
-
const sortBySchema = z
|
|
905
|
-
.string()
|
|
906
|
-
.describe(
|
|
907
|
-
"Sort as 'field:asc' or 'field:desc'. Allowed fields: dueDate, createdAt, updatedAt, priority, position, name. Default updatedAt:desc."
|
|
908
|
-
);
|
|
909
|
-
|
|
910
|
-
const STATUS_LABEL = { 1: 'open', 2: 'complete' };
|
|
911
|
-
|
|
912
|
-
/** Human label for a status code. */
|
|
913
|
-
function statusLabel(status) {
|
|
914
|
-
return STATUS_LABEL[status] || (status == null ? 'unknown' : String(status));
|
|
915
|
-
}
|
|
916
|
-
|
|
917
|
-
/** Render a task/note's tags as a comma list of names (fallback to ids). */
|
|
918
|
-
function formatTags(tags) {
|
|
919
|
-
if (!Array.isArray(tags) || tags.length === 0) return null;
|
|
920
|
-
return tags
|
|
921
|
-
.map((t) => (t && typeof t === 'object' ? t.name || t._id : t))
|
|
922
|
-
.filter(Boolean)
|
|
923
|
-
.join(', ');
|
|
924
|
-
}
|
|
925
|
-
|
|
926
|
-
/** Build the API filter params from tool params, resolving projectName. */
|
|
927
|
-
async function buildListParams(type, params) {
|
|
928
|
-
// assigneeName is a client-side member filter (see applyAssigneeName); never
|
|
929
|
-
// forward it to the backend, which doesn't know that key.
|
|
930
|
-
const { projectName, assigneeName, ...rest } = params;
|
|
931
|
-
// Sanitize scalar filters (drops blank/placeholder values, incl. a blank
|
|
932
|
-
// assigneeId => "all members").
|
|
933
|
-
const out = { type, ...sanitizeFilters(rest) };
|
|
934
|
-
if (PROJECT_LOCK) {
|
|
935
|
-
// Drop the id/priority narrowers this class of agent fabricates with
|
|
936
|
-
// non-blank garbage (parentId=projectId, assigneeId from a chat id, guessed
|
|
937
|
-
// priority) that would silently zero the "list the whole team" result.
|
|
938
|
-
stripHallucinatedListFilters(out);
|
|
939
|
-
// Hard override: force the project regardless of caller input. Do NOT
|
|
940
|
-
// resolve projectName here — the override wins unconditionally, so an
|
|
941
|
-
// invalid projectName must not be able to fail an otherwise-locked list.
|
|
942
|
-
out.projectId = lockProjectId(PROJECT_LOCK, out.projectId);
|
|
943
|
-
} else if (!isBlankValue(projectName)) {
|
|
944
|
-
// Unlocked (default) path: unchanged behavior.
|
|
945
|
-
out.projectId = await resolveProjectId(projectName);
|
|
946
|
-
}
|
|
947
|
-
return out;
|
|
948
|
-
}
|
|
949
|
-
|
|
950
|
-
/** One concise summary line per item for list output. */
|
|
951
|
-
function summarizeItem(item, index) {
|
|
952
|
-
const parts = [];
|
|
953
|
-
parts.push(`status: ${statusLabel(item.status)}`);
|
|
954
|
-
if (item.priority != null) parts.push(`priority: ${item.priority}`);
|
|
955
|
-
if (item.dueDate) parts.push(`due: ${item.dueDate}${item.time ? ` ${item.time}` : ''}`);
|
|
956
|
-
else if (item.datePlain) parts.push(`due: ${item.datePlain}${item.time ? ` ${item.time}` : ''}`);
|
|
957
|
-
const tagStr = formatTags(item.tags);
|
|
958
|
-
if (tagStr) parts.push(`tags: ${tagStr}`);
|
|
959
|
-
if (item.projectId) parts.push(`project: ${item.projectId}`);
|
|
960
|
-
const owner = ownerName(item.userId);
|
|
961
|
-
if (owner) parts.push(`owner: ${owner}`);
|
|
962
|
-
return (
|
|
963
|
-
`${index}. ${item.name || '(untitled)'} [id: ${item._id ?? item.id}]\n` +
|
|
964
|
-
` ${parts.join(' | ')}`
|
|
965
|
-
);
|
|
966
|
-
}
|
|
967
|
-
|
|
968
|
-
/** Render a list response as a concise, readable summary (not raw JSON). */
|
|
969
|
-
function renderList(result, kindLabelPlural) {
|
|
970
|
-
const tasks = Array.isArray(result?.tasks) ? result.tasks : [];
|
|
971
|
-
const total = result?.total ?? tasks.length;
|
|
972
|
-
const page = result?.page ?? 1;
|
|
973
|
-
const limit = result?.limit ?? tasks.length;
|
|
974
|
-
|
|
975
|
-
if (tasks.length === 0) {
|
|
976
|
-
return `No ${kindLabelPlural} found (total: ${total}, page ${page}).`;
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
const lines = tasks.map((t, i) => summarizeItem(t, i + 1));
|
|
980
|
-
const footer = `\nShowing ${tasks.length} of ${total} ${kindLabelPlural} (page ${page}, limit ${limit}).`;
|
|
981
|
-
return `${lines.join('\n')}\n${footer}`;
|
|
982
|
-
}
|
|
983
|
-
|
|
984
|
-
/** Render one item's full detail with the description converted to Markdown. */
|
|
985
|
-
function renderItem(item, kindLabel) {
|
|
986
|
-
const lines = [];
|
|
987
|
-
lines.push(`${item.name || '(untitled)'}`);
|
|
988
|
-
lines.push(`id: ${item._id ?? item.id}`);
|
|
989
|
-
lines.push(`type: ${item.type === 2 ? 'note' : 'task'} (${kindLabel})`);
|
|
990
|
-
lines.push(`status: ${statusLabel(item.status)}`);
|
|
991
|
-
if (item.priority != null) lines.push(`priority: ${item.priority}`);
|
|
992
|
-
if (item.dueDate) lines.push(`due: ${item.dueDate}${item.time ? ` ${item.time}` : ''}`);
|
|
993
|
-
else if (item.datePlain) lines.push(`due: ${item.datePlain}${item.time ? ` ${item.time}` : ''}`);
|
|
994
|
-
const tagStr = formatTags(item.tags);
|
|
995
|
-
if (tagStr) lines.push(`tags: ${tagStr}`);
|
|
996
|
-
if (item.projectId) lines.push(`project: ${item.projectId}`);
|
|
997
|
-
const owner = ownerName(item.userId);
|
|
998
|
-
if (owner) lines.push(`owner: ${owner}`);
|
|
999
|
-
if (item.parentId) lines.push(`parent: ${item.parentId}`);
|
|
1000
|
-
if (item.createdAt) lines.push(`created: ${item.createdAt}`);
|
|
1001
|
-
if (item.updatedAt) lines.push(`updated: ${item.updatedAt}`);
|
|
1002
|
-
|
|
1003
|
-
const md = descriptionToMarkdown(item.description);
|
|
1004
|
-
lines.push('');
|
|
1005
|
-
lines.push('--- description ---');
|
|
1006
|
-
lines.push(md && md.trim() ? md : '(empty)');
|
|
1007
|
-
return lines.join('\n');
|
|
1008
|
-
}
|
|
1009
|
-
|
|
1010
|
-
/** Extract a single item from a view response (shape-tolerant). */
|
|
1011
|
-
function unwrapItem(res) {
|
|
1012
|
-
return (res && (res.task || res.data)) || res || {};
|
|
1013
|
-
}
|
|
1014
|
-
|
|
1015
|
-
// Shared list filter surface (task tools use all; note tools use the applicable subset).
|
|
1016
|
-
const listStatus = z
|
|
1017
|
-
.union([z.literal(1), z.literal(2)])
|
|
1018
|
-
.optional()
|
|
1019
|
-
.describe('Filter by status: 1=open, 2=complete');
|
|
1020
|
-
const listShowCompleted = z
|
|
1021
|
-
.boolean()
|
|
1022
|
-
.optional()
|
|
1023
|
-
.describe('When false/omitted (and no explicit status), completed items are excluded');
|
|
1024
|
-
const listProjectName = z
|
|
1025
|
-
.string()
|
|
1026
|
-
.optional()
|
|
1027
|
-
.describe('Filter to a project by name (resolved to its id)');
|
|
1028
|
-
const listProjectId = objectId.optional().describe('Filter to a project by id');
|
|
1029
|
-
const listAssigneeId = objectId
|
|
1030
|
-
.optional()
|
|
1031
|
-
.describe('Filter to a single project member by their user id (omit for all members)');
|
|
1032
|
-
const listTags = z.array(objectId).optional().describe('Filter by tag ids (AND — item must have all)');
|
|
1033
|
-
const listSearch = z.string().optional().describe('Case-insensitive search on the name');
|
|
1034
|
-
const listSortBy = sortBySchema.optional();
|
|
1035
|
-
const listLimit = z
|
|
1036
|
-
.number()
|
|
1037
|
-
.int()
|
|
1038
|
-
.min(1)
|
|
1039
|
-
.max(200)
|
|
1040
|
-
.optional()
|
|
1041
|
-
.describe('Max items to return (default 50, max 200)');
|
|
1042
|
-
const listPage = z.number().int().min(1).optional().describe('Page number (default 1)');
|
|
1043
|
-
const listPriority = z
|
|
1044
|
-
.union([z.literal(1), z.literal(2), z.literal(3)])
|
|
1045
|
-
.optional()
|
|
1046
|
-
.describe('Filter by priority: 1, 2, or 3');
|
|
1047
|
-
const listParentId = objectId.optional().describe('List subtasks of this parent task id');
|
|
1048
|
-
const listAssigneeName = z
|
|
1049
|
-
.string()
|
|
1050
|
-
.optional()
|
|
1051
|
-
.describe(
|
|
1052
|
-
'Narrow to ONE team member by their NAME or email (case-insensitive). ' +
|
|
1053
|
-
'Omit to list the WHOLE team (all members). Only set this when the user ' +
|
|
1054
|
-
'explicitly names a person; never guess.'
|
|
1055
|
-
);
|
|
1056
|
-
|
|
1057
|
-
// Build the list-filter schema. Under PROJECT_LOCK the project is forced and the
|
|
1058
|
-
// caller is a bespoke, project-scoped agent whose model fabricates id/priority
|
|
1059
|
-
// narrowers (parentId/assigneeId/priority) that silently zero the result — so
|
|
1060
|
-
// those fields are NOT offered; member narrowing is by NAME (assigneeName)
|
|
1061
|
-
// instead. Unlocked (default, e.g. clawis) keeps the full, unchanged surface.
|
|
1062
|
-
function listSchema(kind /* 'task' | 'note' */) {
|
|
1063
|
-
const base = { showCompleted: listShowCompleted };
|
|
1064
|
-
if (kind === 'task') base.status = listStatus;
|
|
1065
|
-
const tail = {
|
|
1066
|
-
tags: listTags,
|
|
1067
|
-
search: listSearch,
|
|
1068
|
-
...(kind === 'task'
|
|
1069
|
-
? {
|
|
1070
|
-
dueDateFrom: datePlain.optional().describe('Inclusive lower bound on due date (YYYY-MM-DD)'),
|
|
1071
|
-
dueDateTo: datePlain.optional().describe('Inclusive upper bound on due date (YYYY-MM-DD)'),
|
|
1072
|
-
}
|
|
1073
|
-
: {}),
|
|
1074
|
-
sortBy: listSortBy,
|
|
1075
|
-
limit: listLimit,
|
|
1076
|
-
page: listPage,
|
|
1077
|
-
};
|
|
1078
|
-
if (PROJECT_LOCK) {
|
|
1079
|
-
return { ...base, assigneeName: listAssigneeName, ...tail };
|
|
1080
|
-
}
|
|
1081
|
-
return {
|
|
1082
|
-
...base,
|
|
1083
|
-
priority: listPriority,
|
|
1084
|
-
projectName: listProjectName,
|
|
1085
|
-
projectId: listProjectId,
|
|
1086
|
-
assigneeId: listAssigneeId,
|
|
1087
|
-
...(kind === 'task' ? { parentId: listParentId } : {}),
|
|
1088
|
-
...tail,
|
|
1089
|
-
};
|
|
1090
|
-
}
|
|
1091
|
-
|
|
1092
|
-
/**
|
|
1093
|
-
* Client-side member narrowing by NAME (used under PROJECT_LOCK, where the
|
|
1094
|
-
* agent narrows by a person's name instead of a fabricated user id). Returns
|
|
1095
|
-
* { result, note }. When assigneeName is blank, the result is unchanged. When
|
|
1096
|
-
* items lack populated owner info (backend owner-populate not deployed yet),
|
|
1097
|
-
* the filter can't be applied — the full list is returned with an explanatory
|
|
1098
|
-
* note rather than a misleading empty result.
|
|
1099
|
-
*/
|
|
1100
|
-
function applyAssigneeName(result, assigneeName) {
|
|
1101
|
-
if (isBlankValue(assigneeName)) return { result, note: null };
|
|
1102
|
-
const tasks = Array.isArray(result?.tasks) ? result.tasks : [];
|
|
1103
|
-
if (!hasOwnerInfo(tasks)) {
|
|
1104
|
-
return {
|
|
1105
|
-
result,
|
|
1106
|
-
note: `Could not narrow to "${assigneeName}" — owner info is not available yet; showing all members.`,
|
|
1107
|
-
};
|
|
1108
|
-
}
|
|
1109
|
-
const filtered = tasks.filter((t) => matchesAssignee(t.userId, assigneeName));
|
|
1110
|
-
return { result: { ...result, tasks: filtered, total: filtered.length }, note: null };
|
|
1111
|
-
}
|
|
1112
|
-
|
|
1113
|
-
// ---- planko_list_tasks ----
|
|
1114
|
-
server.tool(
|
|
1115
|
-
'planko_list_tasks',
|
|
1116
|
-
'List Planko tasks (type=1) via your API key, no folder setup required. All filters are optional; omit any the user did not explicitly ask for. Recurring tasks appear as separate dated occurrences. Returns a concise summary, not raw JSON.',
|
|
1117
|
-
listSchema('task'),
|
|
1118
|
-
async (params) => {
|
|
1119
|
-
try {
|
|
1120
|
-
const apiParams = await buildListParams(1, params);
|
|
1121
|
-
const result = await api.listTasks(apiParams);
|
|
1122
|
-
const { result: filtered, note } = applyAssigneeName(result, params.assigneeName);
|
|
1123
|
-
const out = renderList(filtered, 'tasks');
|
|
1124
|
-
return toolOk(note ? `${out}\n\nNote: ${note}` : out);
|
|
1125
|
-
} catch (err) {
|
|
1126
|
-
return toolError(`List tasks failed: ${err.message}`);
|
|
1127
|
-
}
|
|
1128
|
-
}
|
|
1129
|
-
);
|
|
1130
|
-
|
|
1131
|
-
// ---- planko_list_notes ----
|
|
1132
|
-
server.tool(
|
|
1133
|
-
'planko_list_notes',
|
|
1134
|
-
'List Planko notes (type=2) via your API key, no folder setup required. All filters are optional; omit any the user did not explicitly ask for. Deleted and recurring-copy notes are excluded. Returns a concise summary, not raw JSON.',
|
|
1135
|
-
listSchema('note'),
|
|
1136
|
-
async (params) => {
|
|
1137
|
-
try {
|
|
1138
|
-
const apiParams = await buildListParams(2, params);
|
|
1139
|
-
const result = await api.listTasks(apiParams);
|
|
1140
|
-
const { result: filtered, note } = applyAssigneeName(result, params.assigneeName);
|
|
1141
|
-
const out = renderList(filtered, 'notes');
|
|
1142
|
-
return toolOk(note ? `${out}\n\nNote: ${note}` : out);
|
|
1143
|
-
} catch (err) {
|
|
1144
|
-
return toolError(`List notes failed: ${err.message}`);
|
|
1145
|
-
}
|
|
1146
|
-
}
|
|
1147
|
-
);
|
|
1148
|
-
|
|
1149
|
-
// ---- planko_view_task ----
|
|
1150
|
-
server.tool(
|
|
1151
|
-
'planko_view_task',
|
|
1152
|
-
'View one Planko task by id, with its description rendered as Markdown. The type is informational — this endpoint returns the item regardless of task/note type.',
|
|
1153
|
-
{
|
|
1154
|
-
taskId: objectId.describe('Id of the task to view (required)'),
|
|
1155
|
-
},
|
|
1156
|
-
async ({ taskId }) => {
|
|
1157
|
-
try {
|
|
1158
|
-
const res = await api.getTask(taskId);
|
|
1159
|
-
const item = unwrapItem(res);
|
|
1160
|
-
assertProjectAllowed(PROJECT_LOCK, item);
|
|
1161
|
-
return toolOk(renderItem(item, 'task'));
|
|
1162
|
-
} catch (err) {
|
|
1163
|
-
return toolError(`View task failed: ${err.message}`);
|
|
1164
|
-
}
|
|
1165
|
-
}
|
|
1166
|
-
);
|
|
1167
|
-
|
|
1168
|
-
// ---- planko_view_note ----
|
|
1169
|
-
server.tool(
|
|
1170
|
-
'planko_view_note',
|
|
1171
|
-
'View one Planko note by id, with its description rendered as Markdown. The type is informational — this endpoint returns the item regardless of task/note type.',
|
|
1172
|
-
{
|
|
1173
|
-
taskId: objectId.describe('Id of the note to view (required)'),
|
|
1174
|
-
},
|
|
1175
|
-
async ({ taskId }) => {
|
|
1176
|
-
try {
|
|
1177
|
-
const res = await api.getTask(taskId);
|
|
1178
|
-
const item = unwrapItem(res);
|
|
1179
|
-
assertProjectAllowed(PROJECT_LOCK, item);
|
|
1180
|
-
return toolOk(renderItem(item, 'note'));
|
|
1181
|
-
} catch (err) {
|
|
1182
|
-
return toolError(`View note failed: ${err.message}`);
|
|
1183
|
-
}
|
|
1184
|
-
}
|
|
1185
|
-
);
|
|
577
|
+
registerStandaloneTools(server, { api, projectLock: PROJECT_LOCK });
|
|
1186
578
|
|
|
1187
579
|
// --- Start server ---
|
|
1188
580
|
|