planko-mcp-server 0.6.0 → 0.8.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/index.js CHANGED
@@ -24,35 +24,10 @@ import { join } from 'node:path';
24
24
  import { createRequire } from 'node:module';
25
25
 
26
26
  import { createApiClient } from './src/api.js';
27
+ import { registerStandaloneTools, toolOk, toolError } from './src/tools.js';
27
28
  import {
28
- TYPE_TASK,
29
- TYPE_NOTE,
30
- TYPE_STICKY,
31
- resolveBoardFilters,
32
- renderList,
33
- renderItem,
34
- mergeAllLists,
35
- renderAll,
36
- } from './src/listing.js';
37
- import { isBlankValue, applyDueDateFallback } from './src/sanitize.js';
38
- import {
39
- buildRecommendationBody,
40
- renderRecommendation,
41
- describeLockError,
42
- } from './src/recommend.js';
43
- import {
44
- lockProjectId,
45
- sanitizeFilters,
46
- assertProjectAllowed,
47
- stripHallucinatedListFilters,
48
- matchesAssignee,
49
- hasOwnerInfo,
50
- } from './src/projectLock.js';
51
- import {
52
- blockNoteToMarkdown,
53
29
  markdownToBlockNote,
54
30
  descriptionToMarkdown,
55
- markdownToDescription,
56
31
  } from './src/converters.js';
57
32
  import {
58
33
  readConfig,
@@ -86,16 +61,6 @@ const api = createApiClient({ apiKey: API_KEY });
86
61
  // When null (the default) behavior is identical to before this feature.
87
62
  const PROJECT_LOCK = (process.env.PLANKO_PROJECT_LOCK || '').trim() || null;
88
63
 
89
- // --- Tool helpers ---
90
-
91
- function toolOk(text) {
92
- return { content: [{ type: 'text', text }] };
93
- }
94
-
95
- function toolError(text) {
96
- return { content: [{ type: 'text', text }], isError: true };
97
- }
98
-
99
64
  // --- Sync engine (shared by preview and sync) ---
100
65
 
101
66
  /**
@@ -609,741 +574,7 @@ server.tool(
609
574
  }
610
575
  );
611
576
 
612
- // --- Standalone CRUD tools (Part B) ---
613
- // These operate directly via the user-scoped API key and do NOT require any
614
- // folder to be configured with planko_setup. Notes are Task docs with type=2,
615
- // sticky notes type=3, tasks type=1. Edit/Delete/View work on any of them;
616
- // Complete is task-oriented but accepts any id.
617
-
618
- const editableType = z
619
- .union([z.literal(1), z.literal(2), z.literal(3)])
620
- .optional()
621
- .describe('Change type: 1=task, 2=note, 3=sticky note');
622
-
623
- const objectId = z
624
- .string()
625
- .regex(/^[a-fA-F\d]{24}$/, 'Must be a 24-character hex ObjectId');
626
-
627
- const timeRegex = /^([01]?[0-9]|2[0-3]):[0-5][0-9]$/;
628
-
629
- // Shared editable task/note properties (all optional). `description` is Markdown
630
- // here and is converted to BlockNote JSON before being sent to the backend.
631
- const taskProps = {
632
- description: z
633
- .string()
634
- .optional()
635
- .describe('Body as Markdown (converted to BlockNote JSON before saving)'),
636
- dueDate: z.string().optional().describe('Due date (ISO 8601 string)'),
637
- datePlain: z
638
- .string()
639
- .regex(/^\d{4}-\d{2}-\d{2}$/, 'Must be YYYY-MM-DD')
640
- .optional()
641
- .describe('Plain date, YYYY-MM-DD'),
642
- time: z.string().regex(timeRegex, 'Must be HH:MM').optional().describe('Start time, HH:MM'),
643
- endTime: z.string().regex(timeRegex, 'Must be HH:MM').optional().describe('End time, HH:MM'),
644
- alert: z.boolean().optional().describe('Whether an alert/reminder is enabled'),
645
- alertLeadTime: z
646
- .enum(['ontime', '15min', '30min', '1hour', '1day'])
647
- .nullable()
648
- .optional()
649
- .describe('Reminder lead time (null or one of ontime/15min/30min/1hour/1day)'),
650
- priority: z
651
- .union([z.literal(1), z.literal(2), z.literal(3)])
652
- .optional()
653
- .describe('Priority: 1, 2, or 3'),
654
- repeat: z
655
- .enum(['daily', 'workdays', 'weekly', 'biweekly', 'monthly', 'custom_weekly', 'yearly'])
656
- .nullable()
657
- .optional()
658
- .describe('Recurrence rule (null or one of the recurrence keywords)'),
659
- // The backend stores an integer here (Joi.number().integer()), NOT a date:
660
- // the weekday (1-7) for weekly repeats or the day of month (1-31) for monthly.
661
- repeatDate: z
662
- .number()
663
- .int()
664
- .nullable()
665
- .optional()
666
- .describe('Recurrence day (integer, not a date): weekday 1-7 for weekly, day of month 1-31 for monthly'),
667
- selectedWeekdays: z
668
- .array(z.number().int().min(0).max(6))
669
- .optional()
670
- .describe('Weekdays for custom_weekly repeat (0=Sunday..6=Saturday)'),
671
- parentId: objectId.optional().describe('Parent task id (for subtasks)'),
672
- tags: z.array(objectId).optional().describe('Array of tag ids'),
673
- kanbanColumnId: objectId.optional().describe('Kanban column id'),
674
- boardId: objectId.optional().describe('Board id'),
675
- };
676
-
677
- /**
678
- * Build a request body from tool params: drop undefined values and convert the
679
- * Markdown `description` into BlockNote JSON.
680
- */
681
- function buildTaskBody(params) {
682
- const body = {};
683
- for (const [key, value] of Object.entries(params)) {
684
- if (isBlankValue(value)) continue;
685
- body[key] = value;
686
- }
687
- applyDueDateFallback(body);
688
- if ('description' in body) {
689
- body.description = markdownToDescription(body.description);
690
- }
691
- return body;
692
- }
693
-
694
- /**
695
- * Resolve a project name to a project id via the user's accessible projects
696
- * (NOT the local folder config), so create tools work without any setup.
697
- */
698
- async function resolveProjectId(projectName) {
699
- const { projects } = await api.projects();
700
- const match = projects.find(
701
- (p) => p.name.toLowerCase() === projectName.toLowerCase()
702
- );
703
- if (!match) {
704
- const available = projects.map((p) => ` - ${p.name}`).join('\n');
705
- throw new Error(
706
- `Project "${projectName}" not found.\n\nAvailable projects:\n${available}`
707
- );
708
- }
709
- return match._id;
710
- }
711
-
712
- /** Extract { id, name } from a create/edit response (shape-tolerant). */
713
- function describeTask(res) {
714
- const t = (res && (res.task || res.data)) || res || {};
715
- return {
716
- id: t._id || t.id || 'unknown',
717
- name: t.name != null ? t.name : 'unknown',
718
- };
719
- }
720
-
721
- /**
722
- * When PROJECT_LOCK is set, fetch a by-id task and refuse the operation unless
723
- * it belongs to the locked project. No-op when the lock is null.
724
- */
725
- async function assertTaskInLock(taskId) {
726
- if (!PROJECT_LOCK) return;
727
- const res = await api.getTask(taskId);
728
- assertProjectAllowed(PROJECT_LOCK, unwrapItem(res));
729
- }
730
-
731
- /**
732
- * Shared create handler for tasks (type=1) and notes (type=2).
733
- */
734
- async function handleCreate(type, params, kindLabel) {
735
- const { name, projectName, ...rest } = params;
736
- const body = buildTaskBody(rest);
737
- body.name = name;
738
- body.type = type;
739
-
740
- if (PROJECT_LOCK) {
741
- // Hard override: always the locked project; ignore any caller project field
742
- // and do NOT resolve projectName.
743
- body.projectId = lockProjectId(PROJECT_LOCK, body.projectId);
744
- } else if (!isBlankValue(projectName)) {
745
- // Resolve projectName -> projectId via the API. When omitted, OMIT the key
746
- // entirely so the backend applies the user's default project.
747
- body.projectId = await resolveProjectId(projectName);
748
- }
749
-
750
- const res = await api.createTask(body);
751
- const { id, name: savedName } = describeTask(res);
752
- const where = body.projectId
753
- ? ` in project ${body.projectId}`
754
- : ' in your default project';
755
- return toolOk(`Created ${kindLabel} "${savedName}" (id: ${id})${where}.`);
756
- }
757
-
758
- /**
759
- * Shared edit handler for tasks and notes (same endpoint).
760
- */
761
- async function handleEdit(params, kindLabel) {
762
- const { taskId, ...rest } = params;
763
- const body = buildTaskBody(rest);
764
- const changed = Object.keys(body);
765
- if (changed.length === 0) {
766
- return toolError('Nothing to update: provide at least one field to change.');
767
- }
768
- if (PROJECT_LOCK) {
769
- // Refuse to touch a task outside the locked project.
770
- await assertTaskInLock(taskId);
771
- // If the caller tried to move the task to another project, force it back to
772
- // the lock (never let an edit move a task OUT of the locked project). If no
773
- // project field was passed, leave the project unchanged.
774
- if ('projectId' in body) {
775
- body.projectId = lockProjectId(PROJECT_LOCK, body.projectId);
776
- }
777
- }
778
- const res = await api.updateTask(taskId, body);
779
- const { id, name: savedName } = describeTask(res);
780
- return toolOk(
781
- `Updated ${kindLabel} "${savedName}" (id: ${id}). Changed: ${changed.join(', ')}.`
782
- );
783
- }
784
-
785
- // ---- planko_create_task ----
786
- server.tool(
787
- 'planko_create_task',
788
- 'Create a Planko task (type=1) directly via your API key, immediately and without approval. 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). To propose a task for the account owner to accept or reject instead, use planko_recommend_task.',
789
- {
790
- name: z.string().describe('Task name (required)'),
791
- projectName: z
792
- .string()
793
- .optional()
794
- .describe('Project name to create the task in (optional — omit for your default project)'),
795
- ...taskProps,
796
- },
797
- async (params) => {
798
- try {
799
- return await handleCreate(TYPE_TASK, params, 'task');
800
- } catch (err) {
801
- return toolError(`Create task failed: ${err.message}`);
802
- }
803
- }
804
- );
805
-
806
- // ---- planko_create_note ----
807
- server.tool(
808
- 'planko_create_note',
809
- '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).',
810
- {
811
- name: z.string().describe('Note name (required)'),
812
- projectName: z
813
- .string()
814
- .optional()
815
- .describe('Project name to create the note in (optional — omit for your default project)'),
816
- ...taskProps,
817
- },
818
- async (params) => {
819
- try {
820
- return await handleCreate(TYPE_NOTE, params, 'note');
821
- } catch (err) {
822
- return toolError(`Create note failed: ${err.message}`);
823
- }
824
- }
825
- );
826
-
827
- // ---- planko_create_sticky_note ----
828
- server.tool(
829
- 'planko_create_sticky_note',
830
- 'Create a Planko sticky note (type=3) directly via your API key. A sticky note is a task-page item with every task property (dates, priority, tags, kanban column). Provide a name (required); all other properties are optional. Optionally target a project by name (otherwise your default project is used).',
831
- {
832
- name: z.string().describe('Sticky note name (required)'),
833
- projectName: z
834
- .string()
835
- .optional()
836
- .describe('Project name to create the sticky note in (optional — omit for your default project)'),
837
- ...taskProps,
838
- },
839
- async (params) => {
840
- try {
841
- return await handleCreate(TYPE_STICKY, params, 'sticky note');
842
- } catch (err) {
843
- return toolError(`Create sticky note failed: ${err.message}`);
844
- }
845
- }
846
- );
847
-
848
- // ---- planko_recommend_task ----
849
- // PL274: a SUGGESTION, not a write. The backend stores it as a pending
850
- // recommendation addressed to the API key's owner and notifies them; the task is
851
- // created only if they accept it in Planko. There is no read-back endpoint.
852
- server.tool(
853
- 'planko_recommend_task',
854
- 'Suggest a new task to the Planko account owner instead of creating it. The owner gets a notification (notification centre + push) with Accept/Reject buttons; the task is created only when they accept. Use this when a human should approve before anything is written, or when you must not create tasks directly; use planko_create_task to create immediately. The recipient is always the owner of the API key (never other project members). Provide a title (required); all other task properties are optional and are applied to the task on accept. The outcome cannot be read back afterwards and re-sending creates a duplicate suggestion, so send each suggestion once.',
855
- {
856
- title: z.string().trim().min(1).max(500).describe('Suggested task name (required, up to 500 characters)'),
857
- projectName: z
858
- .string()
859
- .optional()
860
- .describe('Project name the task would be created in (optional — omit for the owner\'s default project)'),
861
- ...taskProps,
862
- },
863
- async (params) => {
864
- try {
865
- const { title, projectName, ...rest } = params;
866
- const body = buildTaskBody(rest);
867
- let projectNameIgnored = false;
868
-
869
- if (PROJECT_LOCK) {
870
- // Same hard override as handleCreate: the suggestion can only target
871
- // the locked project; projectName is neither resolved nor honoured.
872
- body.projectId = lockProjectId(PROJECT_LOCK, body.projectId);
873
- projectNameIgnored = !isBlankValue(projectName);
874
- } else if (!isBlankValue(projectName)) {
875
- body.projectId = await resolveProjectId(projectName);
876
- }
877
-
878
- let res;
879
- try {
880
- res = await api.createRecommendation(buildRecommendationBody(title, body));
881
- } catch (err) {
882
- throw describeLockError(err, PROJECT_LOCK);
883
- }
884
- return toolOk(
885
- renderRecommendation(res, {
886
- projectId: body.projectId,
887
- lock: PROJECT_LOCK,
888
- projectNameIgnored,
889
- })
890
- );
891
- } catch (err) {
892
- return toolError(`Recommend task failed: ${err.message}`);
893
- }
894
- }
895
- );
896
-
897
- // ---- planko_edit_task ----
898
- server.tool(
899
- 'planko_edit_task',
900
- 'Edit an existing Planko task by id. Provide the taskId and any properties to change. The Markdown description is converted to BlockNote JSON.',
901
- {
902
- taskId: objectId.describe('Id of the task to edit (required)'),
903
- name: z.string().optional().describe('New task name'),
904
- type: editableType,
905
- projectId: objectId.optional().describe('Move to a different project by id'),
906
- ...taskProps,
907
- },
908
- async (params) => {
909
- try {
910
- return await handleEdit(params, 'task');
911
- } catch (err) {
912
- return toolError(`Edit task failed: ${err.message}`);
913
- }
914
- }
915
- );
916
-
917
- // ---- planko_edit_note ----
918
- server.tool(
919
- 'planko_edit_note',
920
- '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.',
921
- {
922
- taskId: objectId.describe('Id of the note to edit (required)'),
923
- name: z.string().optional().describe('New note name'),
924
- type: editableType,
925
- projectId: objectId.optional().describe('Move to a different project by id'),
926
- ...taskProps,
927
- },
928
- async (params) => {
929
- try {
930
- return await handleEdit(params, 'note');
931
- } catch (err) {
932
- return toolError(`Edit note failed: ${err.message}`);
933
- }
934
- }
935
- );
936
-
937
- // ---- planko_edit_sticky_note ----
938
- server.tool(
939
- 'planko_edit_sticky_note',
940
- 'Edit an existing Planko sticky note by id (shares the task edit endpoint). Provide the taskId and any properties to change. The Markdown description is converted to BlockNote JSON.',
941
- {
942
- taskId: objectId.describe('Id of the sticky note to edit (required)'),
943
- name: z.string().optional().describe('New sticky note name'),
944
- type: editableType,
945
- projectId: objectId.optional().describe('Move to a different project by id'),
946
- ...taskProps,
947
- },
948
- async (params) => {
949
- try {
950
- return await handleEdit(params, 'sticky note');
951
- } catch (err) {
952
- return toolError(`Edit sticky note failed: ${err.message}`);
953
- }
954
- }
955
- );
956
-
957
- // ---- planko_complete_task ----
958
- server.tool(
959
- 'planko_complete_task',
960
- 'Mark a Planko task complete (status=2) by id. Also works on a sticky note id (sticky notes have the same status field).',
961
- {
962
- taskId: objectId.describe('Id of the task to complete (required)'),
963
- },
964
- async ({ taskId }) => {
965
- try {
966
- await assertTaskInLock(taskId);
967
- const res = await api.completeTask(taskId);
968
- const { id, name } = describeTask(res);
969
- return toolOk(`Completed task "${name}" (id: ${id}).`);
970
- } catch (err) {
971
- return toolError(`Complete task failed: ${err.message}`);
972
- }
973
- }
974
- );
975
-
976
- // ---- planko_delete_task ----
977
- server.tool(
978
- 'planko_delete_task',
979
- 'Delete a Planko task by id.',
980
- {
981
- taskId: objectId.describe('Id of the task to delete (required)'),
982
- },
983
- async ({ taskId }) => {
984
- try {
985
- await assertTaskInLock(taskId);
986
- await api.deleteTask(taskId);
987
- return toolOk(`Deleted task (id: ${taskId}).`);
988
- } catch (err) {
989
- return toolError(`Delete task failed: ${err.message}`);
990
- }
991
- }
992
- );
993
-
994
- // ---- planko_delete_note ----
995
- server.tool(
996
- 'planko_delete_note',
997
- 'Delete a Planko note by id (shares the task delete endpoint).',
998
- {
999
- taskId: objectId.describe('Id of the note to delete (required)'),
1000
- },
1001
- async ({ taskId }) => {
1002
- try {
1003
- await assertTaskInLock(taskId);
1004
- await api.deleteTask(taskId);
1005
- return toolOk(`Deleted note (id: ${taskId}).`);
1006
- } catch (err) {
1007
- return toolError(`Delete note failed: ${err.message}`);
1008
- }
1009
- }
1010
- );
1011
-
1012
- // ---- planko_delete_sticky_note ----
1013
- server.tool(
1014
- 'planko_delete_sticky_note',
1015
- 'Delete a Planko sticky note by id (shares the task delete endpoint).',
1016
- {
1017
- taskId: objectId.describe('Id of the sticky note to delete (required)'),
1018
- },
1019
- async ({ taskId }) => {
1020
- try {
1021
- await assertTaskInLock(taskId);
1022
- await api.deleteTask(taskId);
1023
- return toolOk(`Deleted sticky note (id: ${taskId}).`);
1024
- } catch (err) {
1025
- return toolError(`Delete sticky note failed: ${err.message}`);
1026
- }
1027
- }
1028
- );
1029
-
1030
- // --- Standalone READ tools (Part C) ---
1031
- // Read-only, user-scoped via API key; no folder setup required. List tools send
1032
- // `type` (1=tasks, 2=notes, 3=sticky notes; omitted = tasks + sticky notes) and
1033
- // parametrized filters; view tools fetch one item by id and render its
1034
- // BlockNote description as Markdown. No mutation.
1035
-
1036
- const datePlain = z
1037
- .string()
1038
- .regex(/^\d{4}-\d{2}-\d{2}$/, 'Must be YYYY-MM-DD');
1039
-
1040
- const sortBySchema = z
1041
- .string()
1042
- .describe(
1043
- "Sort as 'field:asc' or 'field:desc'. Allowed fields: dueDate, createdAt, updatedAt, priority, position, name. Default updatedAt:desc."
1044
- );
1045
-
1046
- /**
1047
- * Build the API filter params from tool params, resolving projectName and the
1048
- * kanban board/column names. `type` may be undefined (backend: tasks + sticky).
1049
- */
1050
- async function buildListParams(type, params) {
1051
- // assigneeName / boardName / kanbanColumnName are resolved client-side and
1052
- // must never reach the backend, which rejects unknown query keys.
1053
- const { projectName, assigneeName, boardName, kanbanColumnName, ...rest } = params;
1054
- // Sanitize scalar filters (drops blank/placeholder values, incl. a blank
1055
- // assigneeId => "all members").
1056
- const out = { ...sanitizeFilters(rest) };
1057
- if (type != null) out.type = type;
1058
- if (PROJECT_LOCK) {
1059
- // Drop the id narrowers this class of agent fabricates with non-blank
1060
- // garbage (parentId=projectId, assigneeId from a chat id, guessed priority,
1061
- // a boardId copied from somewhere) that would silently zero the "list the
1062
- // whole team" result. Board/column narrowing under lock is by NAME below.
1063
- stripHallucinatedListFilters(out);
1064
- // Hard override: force the project regardless of caller input. Do NOT
1065
- // resolve projectName here — the override wins unconditionally, so an
1066
- // invalid projectName must not be able to fail an otherwise-locked list.
1067
- out.projectId = lockProjectId(PROJECT_LOCK, out.projectId);
1068
- } else if (!isBlankValue(projectName)) {
1069
- // Unlocked (default) path: unchanged behavior.
1070
- out.projectId = await resolveProjectId(projectName);
1071
- }
1072
- if (!isBlankValue(boardName) || !isBlankValue(kanbanColumnName)) {
1073
- const boards = await api.boards();
1074
- Object.assign(
1075
- out,
1076
- resolveBoardFilters(
1077
- { boardName, kanbanColumnName, boardId: out.boardId, kanbanColumnId: out.kanbanColumnId },
1078
- boards
1079
- )
1080
- );
1081
- }
1082
- return out;
1083
- }
1084
-
1085
- /** Extract a single item from a view response (shape-tolerant). */
1086
- function unwrapItem(res) {
1087
- return (res && (res.task || res.data)) || res || {};
1088
- }
1089
-
1090
- // Shared list filter surface (task tools use all; note tools use the applicable subset).
1091
- const listStatus = z
1092
- .union([z.literal(1), z.literal(2)])
1093
- .optional()
1094
- .describe('Filter by status: 1=open, 2=complete');
1095
- const listShowCompleted = z
1096
- .boolean()
1097
- .optional()
1098
- .describe('When false/omitted (and no explicit status), completed items are excluded');
1099
- const listProjectName = z
1100
- .string()
1101
- .optional()
1102
- .describe('Filter to a project by name (resolved to its id)');
1103
- const listProjectId = objectId.optional().describe('Filter to a project by id');
1104
- const listAssigneeId = objectId
1105
- .optional()
1106
- .describe('Filter to a single project member by their user id (omit for all members)');
1107
- const listTags = z.array(objectId).optional().describe('Filter by tag ids (AND — item must have all)');
1108
- const listSearch = z.string().optional().describe('Case-insensitive search on the name');
1109
- const listSortBy = sortBySchema.optional();
1110
- const listLimit = z
1111
- .number()
1112
- .int()
1113
- .min(1)
1114
- .max(200)
1115
- .optional()
1116
- .describe('Max items to return (default 50, max 200)');
1117
- const listPage = z.number().int().min(1).optional().describe('Page number (default 1)');
1118
- const listPriority = z
1119
- .union([z.literal(1), z.literal(2), z.literal(3)])
1120
- .optional()
1121
- .describe('Filter by priority: 1, 2, or 3');
1122
- const listParentId = objectId.optional().describe('List subtasks of this parent task id');
1123
- const listAssigneeName = z
1124
- .string()
1125
- .optional()
1126
- .describe(
1127
- 'Narrow to ONE team member by their NAME or email (case-insensitive). ' +
1128
- 'Omit to list the WHOLE team (all members). Only set this when the user ' +
1129
- 'explicitly names a person; never guess.'
1130
- );
1131
- const listBoardName = z
1132
- .string()
1133
- .optional()
1134
- .describe(
1135
- 'Filter by kanban board NAME (case-insensitive, resolved against your own and workspace boards). ' +
1136
- 'Only set this when the user explicitly names a board; never guess.'
1137
- );
1138
- const listKanbanColumnName = z
1139
- .string()
1140
- .optional()
1141
- .describe(
1142
- 'Filter by kanban column NAME (e.g. "To Do", "Done"). Resolved inside boardName when given; ' +
1143
- 'without a board the name must be unique across your boards. Only set this when the user ' +
1144
- 'explicitly names a column; never guess.'
1145
- );
1146
- const listBoardId = objectId.optional().describe('Filter by kanban board id');
1147
- const listKanbanColumnId = objectId.optional().describe('Filter by kanban column id');
1148
-
1149
- // Build the list-filter schema. Under PROJECT_LOCK the project is forced and the
1150
- // caller is a bespoke, project-scoped agent whose model fabricates id/priority
1151
- // narrowers (parentId/assigneeId/priority/boardId/kanbanColumnId) that silently
1152
- // zero the result — so those fields are NOT offered; member and board/column
1153
- // narrowing is by NAME instead. Unlocked (default, e.g. clawis) keeps the full
1154
- // surface. `kind`: 'task' | 'note' | 'sticky' | 'all' — status/due-date filters
1155
- // are offered for every task-page kind (sticky notes carry the same fields).
1156
- function listSchema(kind) {
1157
- const taskLike = kind !== 'note';
1158
- const base = { showCompleted: listShowCompleted };
1159
- if (taskLike) base.status = listStatus;
1160
- const tail = {
1161
- tags: listTags,
1162
- search: listSearch,
1163
- boardName: listBoardName,
1164
- kanbanColumnName: listKanbanColumnName,
1165
- ...(taskLike
1166
- ? {
1167
- dueDateFrom: datePlain.optional().describe('Inclusive lower bound on due date (YYYY-MM-DD)'),
1168
- dueDateTo: datePlain.optional().describe('Inclusive upper bound on due date (YYYY-MM-DD)'),
1169
- }
1170
- : {}),
1171
- sortBy: listSortBy,
1172
- limit: listLimit,
1173
- ...(kind === 'all' ? {} : { page: listPage }),
1174
- };
1175
- if (PROJECT_LOCK) {
1176
- return { ...base, assigneeName: listAssigneeName, ...tail };
1177
- }
1178
- return {
1179
- ...base,
1180
- priority: listPriority,
1181
- projectName: listProjectName,
1182
- projectId: listProjectId,
1183
- assigneeId: listAssigneeId,
1184
- ...(taskLike ? { parentId: listParentId } : {}),
1185
- boardId: listBoardId,
1186
- kanbanColumnId: listKanbanColumnId,
1187
- ...tail,
1188
- };
1189
- }
1190
-
1191
- const BOARD_SCOPE_NOTE =
1192
- ' Board/column filters match items on your own and workspace boards; with a project scope, teammates’ items on their personal boards are not matched.';
1193
-
1194
- /**
1195
- * Client-side member narrowing by NAME (used under PROJECT_LOCK, where the
1196
- * agent narrows by a person's name instead of a fabricated user id). Returns
1197
- * { result, note }. When assigneeName is blank, the result is unchanged. When
1198
- * items lack populated owner info (backend owner-populate not deployed yet),
1199
- * the filter can't be applied — the full list is returned with an explanatory
1200
- * note rather than a misleading empty result.
1201
- */
1202
- function applyAssigneeName(result, assigneeName) {
1203
- if (isBlankValue(assigneeName)) return { result, note: null };
1204
- const tasks = Array.isArray(result?.tasks) ? result.tasks : [];
1205
- if (!hasOwnerInfo(tasks)) {
1206
- return {
1207
- result,
1208
- note: `Could not narrow to "${assigneeName}" — owner info is not available yet; showing all members.`,
1209
- };
1210
- }
1211
- const filtered = tasks.filter((t) => matchesAssignee(t.userId, assigneeName));
1212
- return { result: { ...result, tasks: filtered, total: filtered.length }, note: null };
1213
- }
1214
-
1215
- /** Shared list handler: one backend call for a single type. */
1216
- async function handleList(type, params, kindLabelPlural) {
1217
- const apiParams = await buildListParams(type, params);
1218
- const result = await api.listTasks(apiParams);
1219
- const { result: filtered, note } = applyAssigneeName(result, params.assigneeName);
1220
- const out = renderList(filtered, kindLabelPlural);
1221
- return toolOk(note ? `${out}\n\nNote: ${note}` : out);
1222
- }
1223
-
1224
- // ---- planko_list_tasks ----
1225
- server.tool(
1226
- 'planko_list_tasks',
1227
- '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.' +
1228
- BOARD_SCOPE_NOTE,
1229
- listSchema('task'),
1230
- async (params) => {
1231
- try {
1232
- return await handleList(TYPE_TASK, params, 'tasks');
1233
- } catch (err) {
1234
- return toolError(`List tasks failed: ${err.message}`);
1235
- }
1236
- }
1237
- );
1238
-
1239
- // ---- planko_list_notes ----
1240
- server.tool(
1241
- 'planko_list_notes',
1242
- '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.' +
1243
- BOARD_SCOPE_NOTE,
1244
- listSchema('note'),
1245
- async (params) => {
1246
- try {
1247
- return await handleList(TYPE_NOTE, params, 'notes');
1248
- } catch (err) {
1249
- return toolError(`List notes failed: ${err.message}`);
1250
- }
1251
- }
1252
- );
1253
-
1254
- // ---- planko_list_sticky_notes ----
1255
- server.tool(
1256
- 'planko_list_sticky_notes',
1257
- 'List Planko sticky notes (type=3) via your API key, no folder setup required. Sticky notes are task-page items, so the same filters as planko_list_tasks apply. All filters are optional; omit any the user did not explicitly ask for. Returns a concise summary, not raw JSON.' +
1258
- BOARD_SCOPE_NOTE,
1259
- listSchema('sticky'),
1260
- async (params) => {
1261
- try {
1262
- return await handleList(TYPE_STICKY, params, 'sticky notes');
1263
- } catch (err) {
1264
- return toolError(`List sticky notes failed: ${err.message}`);
1265
- }
1266
- }
1267
- );
1268
-
1269
- // ---- planko_list_all ----
1270
- server.tool(
1271
- 'planko_list_all',
1272
- 'List Planko tasks, sticky notes AND notes together in one result. Runs two backend queries (tasks + sticky notes; notes) with the same filters and merges them by sortBy (default updatedAt:desc), cut to `limit`; there is no page parameter. All filters are optional; omit any the user did not explicitly ask for. Returns a concise summary, not raw JSON.' +
1273
- BOARD_SCOPE_NOTE,
1274
- listSchema('all'),
1275
- async (params) => {
1276
- try {
1277
- const limit = params.limit || 50;
1278
- const taskParams = await buildListParams(undefined, { ...params, limit, page: 1 });
1279
- const noteParams = { ...taskParams, type: TYPE_NOTE };
1280
- const [taskRes, noteRes] = await Promise.all([api.listTasks(taskParams), api.listTasks(noteParams)]);
1281
- const t = applyAssigneeName(taskRes, params.assigneeName);
1282
- const n = applyAssigneeName(noteRes, params.assigneeName);
1283
- const out = renderAll(mergeAllLists(t.result, n.result, limit, params.sortBy));
1284
- const notes = [t.note, n.note].filter(Boolean);
1285
- return toolOk(notes.length ? `${out}\n\nNote: ${notes.join(' ')}` : out);
1286
- } catch (err) {
1287
- return toolError(`List all failed: ${err.message}`);
1288
- }
1289
- }
1290
- );
1291
-
1292
- /** Shared view handler: the type shown comes from the item itself. */
1293
- async function handleView(taskId) {
1294
- const res = await api.getTask(taskId);
1295
- const item = unwrapItem(res);
1296
- assertProjectAllowed(PROJECT_LOCK, item);
1297
- return toolOk(renderItem(item));
1298
- }
1299
-
1300
- // ---- planko_view_task ----
1301
- server.tool(
1302
- 'planko_view_task',
1303
- '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/sticky-note type.',
1304
- {
1305
- taskId: objectId.describe('Id of the task to view (required)'),
1306
- },
1307
- async ({ taskId }) => {
1308
- try {
1309
- return await handleView(taskId);
1310
- } catch (err) {
1311
- return toolError(`View task failed: ${err.message}`);
1312
- }
1313
- }
1314
- );
1315
-
1316
- // ---- planko_view_note ----
1317
- server.tool(
1318
- 'planko_view_note',
1319
- '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/sticky-note type.',
1320
- {
1321
- taskId: objectId.describe('Id of the note to view (required)'),
1322
- },
1323
- async ({ taskId }) => {
1324
- try {
1325
- return await handleView(taskId);
1326
- } catch (err) {
1327
- return toolError(`View note failed: ${err.message}`);
1328
- }
1329
- }
1330
- );
1331
-
1332
- // ---- planko_view_sticky_note ----
1333
- server.tool(
1334
- 'planko_view_sticky_note',
1335
- 'View one Planko sticky note by id, with its description rendered as Markdown. The type is informational — this endpoint returns the item regardless of task/note/sticky-note type.',
1336
- {
1337
- taskId: objectId.describe('Id of the sticky note to view (required)'),
1338
- },
1339
- async ({ taskId }) => {
1340
- try {
1341
- return await handleView(taskId);
1342
- } catch (err) {
1343
- return toolError(`View sticky note failed: ${err.message}`);
1344
- }
1345
- }
1346
- );
577
+ registerStandaloneTools(server, { api, projectLock: PROJECT_LOCK });
1347
578
 
1348
579
  // --- Start server ---
1349
580