planko-mcp-server 0.5.2 → 0.6.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 +300 -139
- package/package.json +2 -2
- 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/README.md
CHANGED
|
@@ -4,7 +4,7 @@ MCP server for syncing [Planko](https://planko.io) tasks with local Markdown fil
|
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
- **
|
|
7
|
+
- **21 tools**: 3 folder-sync tools + 10 standalone task/note/sticky-note CRUD tools + 7 standalone read (list/view) tools + `planko_recommend_task` (suggest a task for the owner to accept or reject), incl. `planko_list_all` and kanban board/column filters
|
|
8
8
|
- **Type-aware sync**: each folder syncs either **tasks** (type=1) or **notes** (type=2), chosen at setup
|
|
9
9
|
- **Multi-folder**: sync multiple projects to different local folders
|
|
10
10
|
- **Bidirectional sync**: pull remote changes, push local changes
|
|
@@ -87,7 +87,9 @@ Tasks are pulled as `.md` files into your folder. Local changes are pushed back
|
|
|
87
87
|
|
|
88
88
|
## Tools
|
|
89
89
|
|
|
90
|
-
The server exposes
|
|
90
|
+
The server exposes 21 tools in four groups: **folder-sync** tools (bind a project to a local folder), **standalone CRUD** tools (create/edit/complete/delete directly via your API key, no folder needed), **standalone read** tools (list/view directly via your API key, no folder needed), and a **recommendation** tool (suggest a task that the account owner accepts or rejects).
|
|
91
|
+
|
|
92
|
+
Planko has three kinds of item, all stored as tasks with a `type`: **tasks** (`type=1`), **notes** (`type=2`) and **sticky notes** (`type=3`, a task-page item with every task property). Every kind has its own create/edit/delete/view/list tool; `planko_list_all` lists the three together.
|
|
91
93
|
|
|
92
94
|
### Folder-sync tools
|
|
93
95
|
|
|
@@ -99,17 +101,20 @@ The server exposes 14 tools in three groups: **folder-sync** tools (bind a proje
|
|
|
99
101
|
|
|
100
102
|
### Standalone CRUD tools
|
|
101
103
|
|
|
102
|
-
These work with the **same API key** and require **no folder setup**.
|
|
104
|
+
These work with the **same API key** and require **no folder setup**. Tasks, notes and sticky notes live in the same collection, so edit/delete work on any id regardless of the tool's name. `create_*` tools accept all task/note properties as optional params (only `name` is required); the Markdown `description` is converted to Planko's rich-text (BlockNote) format automatically.
|
|
103
105
|
|
|
104
106
|
| Tool | Description | Key parameters |
|
|
105
107
|
|---|---|---|
|
|
106
108
|
| `planko_create_task` | Create a task (type=1) | `name` (required), `projectName` (optional), plus any properties below |
|
|
107
109
|
| `planko_create_note` | Create a note (type=2) | `name` (required), `projectName` (optional), plus any properties below |
|
|
110
|
+
| `planko_create_sticky_note` | Create a sticky note (type=3) | `name` (required), `projectName` (optional), plus any properties below |
|
|
108
111
|
| `planko_edit_task` | Edit an existing task by id | `taskId` (required), plus any properties to change |
|
|
109
112
|
| `planko_edit_note` | Edit an existing note by id (shares the task edit endpoint) | `taskId` (required), plus any properties to change |
|
|
110
|
-
| `
|
|
113
|
+
| `planko_edit_sticky_note` | Edit an existing sticky note by id (shares the task edit endpoint) | `taskId` (required), plus any properties to change |
|
|
114
|
+
| `planko_complete_task` | Mark a task (or sticky note) complete (status=2) | `taskId` (required) |
|
|
111
115
|
| `planko_delete_task` | Delete a task by id | `taskId` (required) |
|
|
112
116
|
| `planko_delete_note` | Delete a note by id (shares the task delete endpoint) | `taskId` (required) |
|
|
117
|
+
| `planko_delete_sticky_note` | Delete a sticky note by id (shares the task delete endpoint) | `taskId` (required) |
|
|
113
118
|
|
|
114
119
|
**Optional properties** accepted by the create/edit tools (all optional; omit to leave unchanged):
|
|
115
120
|
|
|
@@ -123,12 +128,12 @@ These work with the **same API key** and require **no folder setup**. Notes are
|
|
|
123
128
|
| `alertLeadTime` | `null`\|`ontime`\|`15min`\|`30min`\|`1hour`\|`1day` | Reminder lead time |
|
|
124
129
|
| `priority` | `1`\|`2`\|`3` | |
|
|
125
130
|
| `repeat` | `null`\|`daily`\|`workdays`\|`weekly`\|`biweekly`\|`monthly`\|`custom_weekly`\|`yearly` | Recurrence rule |
|
|
126
|
-
| `repeatDate` |
|
|
131
|
+
| `repeatDate` | integer | Recurrence day, not a date: weekday `1`–`7` for `weekly`, day of month `1`–`31` for `monthly` |
|
|
127
132
|
| `selectedWeekdays` | array of `0`–`6` | For `custom_weekly` (0=Sunday) |
|
|
128
133
|
| `parentId` | ObjectId | Parent task, for subtasks |
|
|
129
134
|
| `tags` | array of ObjectId | Tag ids |
|
|
130
135
|
| `kanbanColumnId` / `boardId` | ObjectId | Kanban placement |
|
|
131
|
-
| `type` | `1`\|`2` | (edit tools only) switch task
|
|
136
|
+
| `type` | `1`\|`2`\|`3` | (edit tools only) switch between task, note and sticky note |
|
|
132
137
|
| `projectId` | ObjectId | (edit tools only) move to another project |
|
|
133
138
|
|
|
134
139
|
Notes:
|
|
@@ -147,6 +152,27 @@ planko_complete_task(taskId: "665f...c0")
|
|
|
147
152
|
planko_delete_note(taskId: "665f...aa")
|
|
148
153
|
```
|
|
149
154
|
|
|
155
|
+
### Recommendation tool
|
|
156
|
+
|
|
157
|
+
A recommendation is a **suggestion, not a write**. The backend stores it as `pending`, notifies the owner of the API key (notification centre + mobile push) with **Accept / Reject** buttons, and creates the task only when they accept. Use it when a human should approve before anything is written, or when the agent must not create tasks directly.
|
|
158
|
+
|
|
159
|
+
| Tool | Description | Key parameters |
|
|
160
|
+
|---|---|---|
|
|
161
|
+
| `planko_recommend_task` | Suggest a new task to the account owner | `title` (required), `projectName` (optional), plus any of the task properties above (applied to the task on accept) |
|
|
162
|
+
|
|
163
|
+
Notes:
|
|
164
|
+
|
|
165
|
+
- The recipient is **always the owner of the API key**, never other project members, even when the suggestion targets a shared workspace project.
|
|
166
|
+
- `description` is Markdown, converted to BlockNote like the create tools. `datePlain` is derived from the date part of `dueDate` when only `dueDate` is given, because the owner's notification card shows `datePlain` (plus `time` and `priority`).
|
|
167
|
+
- A reference the owner cannot access (`projectId`, `parentId`, `tags`, `boardId`, `kanbanColumnId`) is rejected at send time with a `400`. A reference that becomes stale later is dropped when the owner accepts; the task is still created.
|
|
168
|
+
- There is **no read-back**: the API has no endpoint to list recommendations or learn their outcome, and every call creates a new pending suggestion plus a new notification. Send each suggestion once; do not retry on a slow response.
|
|
169
|
+
- Under `PLANKO_PROJECT_LOCK` the suggestion always targets the locked project (see below).
|
|
170
|
+
|
|
171
|
+
```
|
|
172
|
+
planko_recommend_task(title: "Renovar contrato Acme", datePlain: "2026-10-01", time: "14:00", priority: 1)
|
|
173
|
+
planko_recommend_task(title: "Revisar proposta", projectName: "Comercial", description: "Pontos:\n- prazo\n- valor")
|
|
174
|
+
```
|
|
175
|
+
|
|
150
176
|
### Standalone read tools
|
|
151
177
|
|
|
152
178
|
These also work with the **same API key** and require **no folder setup**. `list_*` returns a concise, readable summary (one line per item plus a `total`/page footer) — never a raw JSON dump. `view_*` returns full detail with the `description` converted from BlockNote to **Markdown** for display.
|
|
@@ -154,15 +180,22 @@ These also work with the **same API key** and require **no folder setup**. `list
|
|
|
154
180
|
| Tool | Description | Key parameters |
|
|
155
181
|
|---|---|---|
|
|
156
182
|
| `planko_list_tasks` | List your tasks (type=1) | all filters below |
|
|
157
|
-
| `planko_list_notes` | List your notes (type=2) | filter subset: `showCompleted`, `projectName`/`projectId`, `tags`, `search`, `sortBy`, `limit`, `page` |
|
|
183
|
+
| `planko_list_notes` | List your notes (type=2) | filter subset: `showCompleted`, `projectName`/`projectId`, `tags`, `search`, board/column, `sortBy`, `limit`, `page` |
|
|
184
|
+
| `planko_list_sticky_notes` | List your sticky notes (type=3) | same filters as `planko_list_tasks` |
|
|
185
|
+
| `planko_list_all` | Tasks + sticky notes + notes together, ordered by last update | same filters as `planko_list_tasks`, except `page` (see below) |
|
|
158
186
|
| `planko_view_task` | View one task by id | `taskId` (required) |
|
|
159
187
|
| `planko_view_note` | View one note by id (shares the view endpoint) | `taskId` (required) |
|
|
188
|
+
| `planko_view_sticky_note` | View one sticky note by id (shares the view endpoint) | `taskId` (required) |
|
|
160
189
|
|
|
161
|
-
**Scope.** Without `projectId`/`projectName`, a list is scoped to **your own** items. With a project (resolved from `projectName` via your accessible projects), it includes that project's items **including workspace-shared** ones from other members. Use `assigneeId` to narrow a project listing to one member; omit it for all members. `view_*` returns the item if you own it or can access its project, otherwise it errors (404 if missing, 403 if not visible). `
|
|
190
|
+
**Scope.** Without `projectId`/`projectName`, a list is scoped to **your own** items. With a project (resolved from `projectName` via your accessible projects), it includes that project's items **including workspace-shared** ones from other members. Use `assigneeId` to narrow a project listing to one member; omit it for all members. `view_*` returns the item if you own it or can access its project, otherwise it errors (404 if missing, 403 if not visible). `view_*` tools do not filter by type — any id resolves; the `type:` line in the output reflects the item itself.
|
|
191
|
+
|
|
192
|
+
**`planko_list_all`.** Runs two backend queries with the same filters (tasks + sticky notes in one, notes in the other), each returning its first `limit` items by `sortBy`, then merges them by the same `sortBy` (default `updatedAt:desc`) and cuts the union to `limit`. Because the union has no server-side pagination there is no `page` parameter; the footer reports both totals. To page through one kind, use its own list tool. Note that a `dueDateFrom`/`dueDateTo` range is applied to the notes query too, which (as on the server for any dated notes query) includes recurring-note occurrences that an undated `planko_list_notes` hides.
|
|
162
193
|
|
|
163
194
|
**Owner in output.** When the backend populates an item's `userId` as an object `{ _id, name, email }`, list lines and `view_*` detail append `owner: <name>` so you can tell whose task it is in a multi-member project listing. If `userId` is a bare id/string, nothing extra is shown.
|
|
164
195
|
|
|
165
|
-
**
|
|
196
|
+
**Board / column in output.** Items on a kanban board show `board: <name>` and `column: <name>` (falling back to the id when the reference is not populated).
|
|
197
|
+
|
|
198
|
+
**List filters** (`planko_list_tasks`, `planko_list_sticky_notes` and `planko_list_all` accept all; `planko_list_notes` accepts the applicable subset):
|
|
166
199
|
|
|
167
200
|
| Filter | Type | Notes |
|
|
168
201
|
|---|---|---|
|
|
@@ -173,6 +206,9 @@ These also work with the **same API key** and require **no folder setup**. `list
|
|
|
173
206
|
| `projectId` | ObjectId | Alternative to `projectName` |
|
|
174
207
|
| `assigneeId` | ObjectId | Filter to a single project member by their user id. Omit for **all members**. Applies within a project listing (needs a project scope to be meaningful) |
|
|
175
208
|
| `parentId` | ObjectId | (tasks only) list subtasks of this parent |
|
|
209
|
+
| `boardName` | string | Kanban board name, case-insensitive, resolved against your own + workspace boards (`GET /mcp-project-sync/boards`). Errors listing the available boards on a miss |
|
|
210
|
+
| `kanbanColumnName` | string | Kanban column name (e.g. `To Do`). Resolved inside `boardName` when given; without a board it must be unique across your boards — default column names repeat on every board, so an ambiguous name errors with the `board › column` candidates instead of guessing |
|
|
211
|
+
| `boardId` / `kanbanColumnId` | ObjectId | Direct id alternatives to the names (not offered under project lock) |
|
|
176
212
|
| `tags` | array of ObjectId | AND semantics — item must have all tags |
|
|
177
213
|
| `search` | string | Case-insensitive match on the name |
|
|
178
214
|
| `dueDateFrom` / `dueDateTo` | `YYYY-MM-DD` | (tasks only) inclusive due-date bounds |
|
|
@@ -180,13 +216,18 @@ These also work with the **same API key** and require **no folder setup**. `list
|
|
|
180
216
|
| `limit` | int | Default 50, max 200 |
|
|
181
217
|
| `page` | int | Default 1 |
|
|
182
218
|
|
|
183
|
-
Notes-specific behavior: deleted notes and recurring-copy notes are excluded server-side. For tasks, recurring occurrences appear as separate dated items.
|
|
219
|
+
Notes-specific behavior: deleted notes and recurring-copy notes are excluded server-side. For tasks and sticky notes, recurring occurrences appear as separate dated items.
|
|
220
|
+
|
|
221
|
+
Board/column filters are ANDed onto the list scope. Boards belong to a user or a workspace, not to a project: with a project scope, a teammate's items placed on **their personal** board are not matched by a board filter (only your own and workspace boards are resolvable).
|
|
184
222
|
|
|
185
223
|
#### Examples
|
|
186
224
|
|
|
187
225
|
```
|
|
188
226
|
planko_list_tasks(status: 1, priority: 1, dueDateFrom: "2026-07-20", dueDateTo: "2026-07-26", sortBy: "dueDate:asc")
|
|
189
227
|
planko_list_tasks(projectName: "Work", search: "invoice", limit: 20)
|
|
228
|
+
planko_list_tasks(boardName: "Time Planko", kanbanColumnName: "In Progress")
|
|
229
|
+
planko_list_sticky_notes(showCompleted: false)
|
|
230
|
+
planko_list_all(search: "orçamento", limit: 20)
|
|
190
231
|
planko_list_notes(search: "meeting", showCompleted: false)
|
|
191
232
|
planko_view_task(taskId: "665f...c0")
|
|
192
233
|
planko_view_note(taskId: "665f...aa")
|
|
@@ -226,11 +267,23 @@ shared automation should only ever touch a single project.
|
|
|
226
267
|
|
|
227
268
|
When set, it changes behavior as follows:
|
|
228
269
|
|
|
229
|
-
- **Create** (`create_task` / `create_note`
|
|
270
|
+
- **Create** (`create_task` / `create_note` / `create_sticky_note`) and **Recommend**
|
|
271
|
+
(`recommend_task`): the new item (or the suggested task) always targets the
|
|
230
272
|
locked project; any `projectName` the caller passes is ignored (and not resolved).
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
273
|
+
A recommendation's response says so when that happens. Note that `priority`,
|
|
274
|
+
`parentId`, `boardId` and `kanbanColumnId` on create/recommend are NOT stripped
|
|
275
|
+
under a lock (unlike the list filters): a fabricated id is rejected by the backend
|
|
276
|
+
with a `400` rather than silently misplacing the item.
|
|
277
|
+
- **List** (`list_tasks` / `list_notes` / `list_sticky_notes` / `list_all`): always
|
|
278
|
+
scoped to the locked project (ignoring `projectName`/`projectId`), which yields
|
|
279
|
+
the all-members listing for that project. The `priority`, `projectName`,
|
|
280
|
+
`projectId`, `assigneeId`, `parentId`, `boardId` and `kanbanColumnId` filters are
|
|
281
|
+
**not offered** under a lock (and dropped if forced) — GPT-class callers reliably
|
|
282
|
+
fabricate them with plausible-but-wrong non-blank values that silently zero the
|
|
283
|
+
result. Narrow to one member with **`assigneeName`** (their name/email, matched
|
|
284
|
+
client-side against the owner) and to a board/column with **`boardName`** /
|
|
285
|
+
**`kanbanColumnName`** (resolved against the key owner's boards) instead; omit
|
|
286
|
+
them for all members / all boards.
|
|
234
287
|
- **Edit** (`edit_task` / `edit_note`): if the caller supplies a `projectId`, it is
|
|
235
288
|
forced back to the locked project (an edit can never move a task out of it). If no
|
|
236
289
|
project field is supplied, the project is left unchanged.
|
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,13 +21,28 @@ 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';
|
|
27
|
+
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';
|
|
23
37
|
import { isBlankValue, applyDueDateFallback } from './src/sanitize.js';
|
|
38
|
+
import {
|
|
39
|
+
buildRecommendationBody,
|
|
40
|
+
renderRecommendation,
|
|
41
|
+
describeLockError,
|
|
42
|
+
} from './src/recommend.js';
|
|
24
43
|
import {
|
|
25
44
|
lockProjectId,
|
|
26
45
|
sanitizeFilters,
|
|
27
|
-
ownerName,
|
|
28
46
|
assertProjectAllowed,
|
|
29
47
|
stripHallucinatedListFilters,
|
|
30
48
|
matchesAssignee,
|
|
@@ -373,9 +391,11 @@ async function executeSync(projectId, folder, sync) {
|
|
|
373
391
|
|
|
374
392
|
// --- MCP Server ---
|
|
375
393
|
|
|
394
|
+
const { version: PKG_VERSION } = createRequire(import.meta.url)('./package.json');
|
|
395
|
+
|
|
376
396
|
const server = new McpServer({
|
|
377
397
|
name: 'planko-mcp-server',
|
|
378
|
-
version:
|
|
398
|
+
version: PKG_VERSION,
|
|
379
399
|
});
|
|
380
400
|
|
|
381
401
|
// ---- planko_setup ----
|
|
@@ -429,16 +449,16 @@ server.tool(
|
|
|
429
449
|
const syncState = createSyncState(match._id, match.name, type);
|
|
430
450
|
writeSyncState(folderPath, syncState);
|
|
431
451
|
|
|
432
|
-
const
|
|
452
|
+
const syncLabel = type === 2 ? 'Notes' : 'Tasks';
|
|
433
453
|
|
|
434
454
|
return toolOk(
|
|
435
455
|
`Setup complete for project "${match.name}".\n` +
|
|
436
456
|
` Project ID: ${match._id}\n` +
|
|
437
457
|
` Folder: ${folderPath}\n` +
|
|
438
458
|
` Email: ${email}\n` +
|
|
439
|
-
` Syncs: ${
|
|
459
|
+
` Syncs: ${syncLabel} (type=${type})\n` +
|
|
440
460
|
` Workspace: ${match.isWorkspace ? 'Yes' : 'No (personal)'}\n\n` +
|
|
441
|
-
`Run planko_sync to pull ${
|
|
461
|
+
`Run planko_sync to pull ${syncLabel.toLowerCase()} into this folder.`
|
|
442
462
|
);
|
|
443
463
|
} catch (err) {
|
|
444
464
|
return toolError(`Setup failed: ${err.message}`);
|
|
@@ -591,8 +611,14 @@ server.tool(
|
|
|
591
611
|
|
|
592
612
|
// --- Standalone CRUD tools (Part B) ---
|
|
593
613
|
// 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
|
-
//
|
|
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');
|
|
596
622
|
|
|
597
623
|
const objectId = z
|
|
598
624
|
.string()
|
|
@@ -630,7 +656,14 @@ const taskProps = {
|
|
|
630
656
|
.nullable()
|
|
631
657
|
.optional()
|
|
632
658
|
.describe('Recurrence rule (null or one of the recurrence keywords)'),
|
|
633
|
-
|
|
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'),
|
|
634
667
|
selectedWeekdays: z
|
|
635
668
|
.array(z.number().int().min(0).max(6))
|
|
636
669
|
.optional()
|
|
@@ -752,7 +785,7 @@ async function handleEdit(params, kindLabel) {
|
|
|
752
785
|
// ---- planko_create_task ----
|
|
753
786
|
server.tool(
|
|
754
787
|
'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).',
|
|
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.',
|
|
756
789
|
{
|
|
757
790
|
name: z.string().describe('Task name (required)'),
|
|
758
791
|
projectName: z
|
|
@@ -763,7 +796,7 @@ server.tool(
|
|
|
763
796
|
},
|
|
764
797
|
async (params) => {
|
|
765
798
|
try {
|
|
766
|
-
return await handleCreate(
|
|
799
|
+
return await handleCreate(TYPE_TASK, params, 'task');
|
|
767
800
|
} catch (err) {
|
|
768
801
|
return toolError(`Create task failed: ${err.message}`);
|
|
769
802
|
}
|
|
@@ -784,13 +817,83 @@ server.tool(
|
|
|
784
817
|
},
|
|
785
818
|
async (params) => {
|
|
786
819
|
try {
|
|
787
|
-
return await handleCreate(
|
|
820
|
+
return await handleCreate(TYPE_NOTE, params, 'note');
|
|
788
821
|
} catch (err) {
|
|
789
822
|
return toolError(`Create note failed: ${err.message}`);
|
|
790
823
|
}
|
|
791
824
|
}
|
|
792
825
|
);
|
|
793
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
|
+
|
|
794
897
|
// ---- planko_edit_task ----
|
|
795
898
|
server.tool(
|
|
796
899
|
'planko_edit_task',
|
|
@@ -798,10 +901,7 @@ server.tool(
|
|
|
798
901
|
{
|
|
799
902
|
taskId: objectId.describe('Id of the task to edit (required)'),
|
|
800
903
|
name: z.string().optional().describe('New task name'),
|
|
801
|
-
type:
|
|
802
|
-
.union([z.literal(1), z.literal(2)])
|
|
803
|
-
.optional()
|
|
804
|
-
.describe('Change type: 1=task, 2=note'),
|
|
904
|
+
type: editableType,
|
|
805
905
|
projectId: objectId.optional().describe('Move to a different project by id'),
|
|
806
906
|
...taskProps,
|
|
807
907
|
},
|
|
@@ -821,10 +921,7 @@ server.tool(
|
|
|
821
921
|
{
|
|
822
922
|
taskId: objectId.describe('Id of the note to edit (required)'),
|
|
823
923
|
name: z.string().optional().describe('New note name'),
|
|
824
|
-
type:
|
|
825
|
-
.union([z.literal(1), z.literal(2)])
|
|
826
|
-
.optional()
|
|
827
|
-
.describe('Change type: 1=task, 2=note'),
|
|
924
|
+
type: editableType,
|
|
828
925
|
projectId: objectId.optional().describe('Move to a different project by id'),
|
|
829
926
|
...taskProps,
|
|
830
927
|
},
|
|
@@ -837,10 +934,30 @@ server.tool(
|
|
|
837
934
|
}
|
|
838
935
|
);
|
|
839
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
|
+
|
|
840
957
|
// ---- planko_complete_task ----
|
|
841
958
|
server.tool(
|
|
842
959
|
'planko_complete_task',
|
|
843
|
-
'Mark a Planko task complete (status=2) by id.',
|
|
960
|
+
'Mark a Planko task complete (status=2) by id. Also works on a sticky note id (sticky notes have the same status field).',
|
|
844
961
|
{
|
|
845
962
|
taskId: objectId.describe('Id of the task to complete (required)'),
|
|
846
963
|
},
|
|
@@ -892,10 +1009,29 @@ server.tool(
|
|
|
892
1009
|
}
|
|
893
1010
|
);
|
|
894
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
|
+
|
|
895
1030
|
// --- Standalone READ tools (Part C) ---
|
|
896
1031
|
// Read-only, user-scoped via API key; no folder setup required. List tools send
|
|
897
|
-
// `type` (1=tasks, 2=notes
|
|
898
|
-
//
|
|
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.
|
|
899
1035
|
|
|
900
1036
|
const datePlain = z
|
|
901
1037
|
.string()
|
|
@@ -907,34 +1043,23 @@ const sortBySchema = z
|
|
|
907
1043
|
"Sort as 'field:asc' or 'field:desc'. Allowed fields: dueDate, createdAt, updatedAt, priority, position, name. Default updatedAt:desc."
|
|
908
1044
|
);
|
|
909
1045
|
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
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. */
|
|
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
|
+
*/
|
|
927
1050
|
async function buildListParams(type, params) {
|
|
928
|
-
// assigneeName
|
|
929
|
-
//
|
|
930
|
-
const { projectName, assigneeName, ...rest } = 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;
|
|
931
1054
|
// Sanitize scalar filters (drops blank/placeholder values, incl. a blank
|
|
932
1055
|
// assigneeId => "all members").
|
|
933
|
-
const out = {
|
|
1056
|
+
const out = { ...sanitizeFilters(rest) };
|
|
1057
|
+
if (type != null) out.type = type;
|
|
934
1058
|
if (PROJECT_LOCK) {
|
|
935
|
-
// Drop the id
|
|
936
|
-
//
|
|
937
|
-
//
|
|
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.
|
|
938
1063
|
stripHallucinatedListFilters(out);
|
|
939
1064
|
// Hard override: force the project regardless of caller input. Do NOT
|
|
940
1065
|
// resolve projectName here — the override wins unconditionally, so an
|
|
@@ -944,67 +1069,17 @@ async function buildListParams(type, params) {
|
|
|
944
1069
|
// Unlocked (default) path: unchanged behavior.
|
|
945
1070
|
out.projectId = await resolveProjectId(projectName);
|
|
946
1071
|
}
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
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}).`;
|
|
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
|
+
);
|
|
977
1081
|
}
|
|
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');
|
|
1082
|
+
return out;
|
|
1008
1083
|
}
|
|
1009
1084
|
|
|
1010
1085
|
/** Extract a single item from a view response (shape-tolerant). */
|
|
@@ -1053,19 +1128,41 @@ const listAssigneeName = z
|
|
|
1053
1128
|
'Omit to list the WHOLE team (all members). Only set this when the user ' +
|
|
1054
1129
|
'explicitly names a person; never guess.'
|
|
1055
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');
|
|
1056
1148
|
|
|
1057
1149
|
// Build the list-filter schema. Under PROJECT_LOCK the project is forced and the
|
|
1058
1150
|
// caller is a bespoke, project-scoped agent whose model fabricates id/priority
|
|
1059
|
-
// narrowers (parentId/assigneeId/priority) that silently
|
|
1060
|
-
// those fields are NOT offered; member
|
|
1061
|
-
// instead. Unlocked (default, e.g. clawis) keeps the full
|
|
1062
|
-
|
|
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';
|
|
1063
1158
|
const base = { showCompleted: listShowCompleted };
|
|
1064
|
-
if (
|
|
1159
|
+
if (taskLike) base.status = listStatus;
|
|
1065
1160
|
const tail = {
|
|
1066
1161
|
tags: listTags,
|
|
1067
1162
|
search: listSearch,
|
|
1068
|
-
|
|
1163
|
+
boardName: listBoardName,
|
|
1164
|
+
kanbanColumnName: listKanbanColumnName,
|
|
1165
|
+
...(taskLike
|
|
1069
1166
|
? {
|
|
1070
1167
|
dueDateFrom: datePlain.optional().describe('Inclusive lower bound on due date (YYYY-MM-DD)'),
|
|
1071
1168
|
dueDateTo: datePlain.optional().describe('Inclusive upper bound on due date (YYYY-MM-DD)'),
|
|
@@ -1073,7 +1170,7 @@ function listSchema(kind /* 'task' | 'note' */) {
|
|
|
1073
1170
|
: {}),
|
|
1074
1171
|
sortBy: listSortBy,
|
|
1075
1172
|
limit: listLimit,
|
|
1076
|
-
page: listPage,
|
|
1173
|
+
...(kind === 'all' ? {} : { page: listPage }),
|
|
1077
1174
|
};
|
|
1078
1175
|
if (PROJECT_LOCK) {
|
|
1079
1176
|
return { ...base, assigneeName: listAssigneeName, ...tail };
|
|
@@ -1084,11 +1181,16 @@ function listSchema(kind /* 'task' | 'note' */) {
|
|
|
1084
1181
|
projectName: listProjectName,
|
|
1085
1182
|
projectId: listProjectId,
|
|
1086
1183
|
assigneeId: listAssigneeId,
|
|
1087
|
-
...(
|
|
1184
|
+
...(taskLike ? { parentId: listParentId } : {}),
|
|
1185
|
+
boardId: listBoardId,
|
|
1186
|
+
kanbanColumnId: listKanbanColumnId,
|
|
1088
1187
|
...tail,
|
|
1089
1188
|
};
|
|
1090
1189
|
}
|
|
1091
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
|
+
|
|
1092
1194
|
/**
|
|
1093
1195
|
* Client-side member narrowing by NAME (used under PROJECT_LOCK, where the
|
|
1094
1196
|
* agent narrows by a person's name instead of a fabricated user id). Returns
|
|
@@ -1110,18 +1212,24 @@ function applyAssigneeName(result, assigneeName) {
|
|
|
1110
1212
|
return { result: { ...result, tasks: filtered, total: filtered.length }, note: null };
|
|
1111
1213
|
}
|
|
1112
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
|
+
|
|
1113
1224
|
// ---- planko_list_tasks ----
|
|
1114
1225
|
server.tool(
|
|
1115
1226
|
'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.'
|
|
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,
|
|
1117
1229
|
listSchema('task'),
|
|
1118
1230
|
async (params) => {
|
|
1119
1231
|
try {
|
|
1120
|
-
|
|
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);
|
|
1232
|
+
return await handleList(TYPE_TASK, params, 'tasks');
|
|
1125
1233
|
} catch (err) {
|
|
1126
1234
|
return toolError(`List tasks failed: ${err.message}`);
|
|
1127
1235
|
}
|
|
@@ -1131,34 +1239,74 @@ server.tool(
|
|
|
1131
1239
|
// ---- planko_list_notes ----
|
|
1132
1240
|
server.tool(
|
|
1133
1241
|
'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.'
|
|
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,
|
|
1135
1244
|
listSchema('note'),
|
|
1136
1245
|
async (params) => {
|
|
1137
1246
|
try {
|
|
1138
|
-
|
|
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);
|
|
1247
|
+
return await handleList(TYPE_NOTE, params, 'notes');
|
|
1143
1248
|
} catch (err) {
|
|
1144
1249
|
return toolError(`List notes failed: ${err.message}`);
|
|
1145
1250
|
}
|
|
1146
1251
|
}
|
|
1147
1252
|
);
|
|
1148
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
|
+
|
|
1149
1300
|
// ---- planko_view_task ----
|
|
1150
1301
|
server.tool(
|
|
1151
1302
|
'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.',
|
|
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.',
|
|
1153
1304
|
{
|
|
1154
1305
|
taskId: objectId.describe('Id of the task to view (required)'),
|
|
1155
1306
|
},
|
|
1156
1307
|
async ({ taskId }) => {
|
|
1157
1308
|
try {
|
|
1158
|
-
|
|
1159
|
-
const item = unwrapItem(res);
|
|
1160
|
-
assertProjectAllowed(PROJECT_LOCK, item);
|
|
1161
|
-
return toolOk(renderItem(item, 'task'));
|
|
1309
|
+
return await handleView(taskId);
|
|
1162
1310
|
} catch (err) {
|
|
1163
1311
|
return toolError(`View task failed: ${err.message}`);
|
|
1164
1312
|
}
|
|
@@ -1168,22 +1316,35 @@ server.tool(
|
|
|
1168
1316
|
// ---- planko_view_note ----
|
|
1169
1317
|
server.tool(
|
|
1170
1318
|
'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.',
|
|
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.',
|
|
1172
1320
|
{
|
|
1173
1321
|
taskId: objectId.describe('Id of the note to view (required)'),
|
|
1174
1322
|
},
|
|
1175
1323
|
async ({ taskId }) => {
|
|
1176
1324
|
try {
|
|
1177
|
-
|
|
1178
|
-
const item = unwrapItem(res);
|
|
1179
|
-
assertProjectAllowed(PROJECT_LOCK, item);
|
|
1180
|
-
return toolOk(renderItem(item, 'note'));
|
|
1325
|
+
return await handleView(taskId);
|
|
1181
1326
|
} catch (err) {
|
|
1182
1327
|
return toolError(`View note failed: ${err.message}`);
|
|
1183
1328
|
}
|
|
1184
1329
|
}
|
|
1185
1330
|
);
|
|
1186
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
|
+
);
|
|
1347
|
+
|
|
1187
1348
|
// --- Start server ---
|
|
1188
1349
|
|
|
1189
1350
|
async function main() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "planko-mcp-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "MCP server for syncing Planko tasks with local Markdown files",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
19
|
"test": "vitest run",
|
|
20
|
-
"prepublishOnly": "node --check index.js && node --check src/api.js && node --check src/converters.js && node --check src/sync-state.js && node --check src/projectLock.js"
|
|
20
|
+
"prepublishOnly": "node --check index.js && node --check src/api.js && node --check src/converters.js && node --check src/sync-state.js && node --check src/projectLock.js && node --check src/sanitize.js && node --check src/listing.js && node --check src/recommend.js"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@modelcontextprotocol/sdk": "^1.12.1"
|
package/src/api.js
CHANGED
|
@@ -50,6 +50,14 @@ export function createApiClient({ apiKey, apiBase }) {
|
|
|
50
50
|
return request('GET', '/mcp-project-sync/projects');
|
|
51
51
|
},
|
|
52
52
|
|
|
53
|
+
/**
|
|
54
|
+
* GET /mcp-project-sync/boards — the caller's kanban boards (personal +
|
|
55
|
+
* workspace), each with its columns: { personal: [...], workspace: [...] }.
|
|
56
|
+
*/
|
|
57
|
+
async boards() {
|
|
58
|
+
return request('GET', '/mcp-project-sync/boards');
|
|
59
|
+
},
|
|
60
|
+
|
|
53
61
|
/**
|
|
54
62
|
* GET /mcp-project-sync/status?projectId=...&mcpLastSyncDate=...&type=...
|
|
55
63
|
* `type` (1=tasks, 2=notes) is appended whenever set, independent of mcpLastSyncDate.
|
|
@@ -121,6 +129,15 @@ export function createApiClient({ apiKey, apiBase }) {
|
|
|
121
129
|
return request('DELETE', `/mcp-project-sync/tasks/${taskId}`);
|
|
122
130
|
},
|
|
123
131
|
|
|
132
|
+
/**
|
|
133
|
+
* POST /mcp-project-sync/recommendations — suggest something to the API
|
|
134
|
+
* key's owner (PL274). Body { type, payload }; returns the Recommendation
|
|
135
|
+
* doc (status 'pending'). The task is only created when the owner accepts.
|
|
136
|
+
*/
|
|
137
|
+
async createRecommendation(body) {
|
|
138
|
+
return request('POST', '/mcp-project-sync/recommendations', body);
|
|
139
|
+
},
|
|
140
|
+
|
|
124
141
|
// --- Read (user-scoped, no folder sync required) ---
|
|
125
142
|
|
|
126
143
|
/**
|
package/src/listing.js
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure helpers for the list/view tools: type labels, kanban board/column name
|
|
3
|
+
* resolution, item rendering and the tasks+notes merge behind planko_list_all.
|
|
4
|
+
* No I/O here so everything is unit-testable; index.js wires them in.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { isBlankValue } from './sanitize.js';
|
|
8
|
+
import { ownerName } from './projectLock.js';
|
|
9
|
+
import { descriptionToMarkdown } from './converters.js';
|
|
10
|
+
|
|
11
|
+
export const TYPE_TASK = 1;
|
|
12
|
+
export const TYPE_NOTE = 2;
|
|
13
|
+
export const TYPE_STICKY = 3;
|
|
14
|
+
|
|
15
|
+
const TYPE_LABEL = { 1: 'task', 2: 'note', 3: 'sticky note' };
|
|
16
|
+
|
|
17
|
+
/** Human label for a Task.type code. */
|
|
18
|
+
export function typeLabel(type) {
|
|
19
|
+
return TYPE_LABEL[type] || 'task';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const STATUS_LABEL = { 1: 'open', 2: 'complete' };
|
|
23
|
+
|
|
24
|
+
/** Human label for a status code. */
|
|
25
|
+
export function statusLabel(status) {
|
|
26
|
+
return STATUS_LABEL[status] || (status == null ? 'unknown' : String(status));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Render a task/note's tags as a comma list of names (fallback to ids). */
|
|
30
|
+
export function formatTags(tags) {
|
|
31
|
+
if (!Array.isArray(tags) || tags.length === 0) return null;
|
|
32
|
+
return tags
|
|
33
|
+
.map((t) => (t && typeof t === 'object' ? t.name || t._id : t))
|
|
34
|
+
.filter(Boolean)
|
|
35
|
+
.join(', ');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Name of a populated reference ({ _id, name }) or null. A bare id string
|
|
40
|
+
* (reference not populated, or the board/column no longer exists) yields null
|
|
41
|
+
* so callers can fall back to the id.
|
|
42
|
+
*/
|
|
43
|
+
export function refName(ref) {
|
|
44
|
+
if (ref && typeof ref === 'object' && !Array.isArray(ref) && typeof ref.name === 'string') {
|
|
45
|
+
return ref.name.trim() || null;
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Comparable id string of a bare id or populated reference. */
|
|
51
|
+
export function refId(ref) {
|
|
52
|
+
if (ref && typeof ref === 'object') return ref._id != null ? String(ref._id) : ref.id != null ? String(ref.id) : '';
|
|
53
|
+
return ref != null ? String(ref) : '';
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Board label for output: name, else the id. */
|
|
57
|
+
export function boardLabel(item) {
|
|
58
|
+
return refName(item.boardId) || (item.boardId ? refId(item.boardId) : null);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Column label for output: name, else the id. */
|
|
62
|
+
export function columnLabel(item) {
|
|
63
|
+
return refName(item.kanbanColumnId) || (item.kanbanColumnId ? refId(item.kanbanColumnId) : null);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Flatten the /boards response ({ personal, workspace }) into one array. */
|
|
67
|
+
export function flattenBoards(res) {
|
|
68
|
+
const personal = Array.isArray(res?.personal) ? res.personal : [];
|
|
69
|
+
const workspace = Array.isArray(res?.workspace) ? res.workspace : [];
|
|
70
|
+
return [...personal, ...workspace];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function boardIdOf(b) {
|
|
74
|
+
return refId(b);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function normalize(s) {
|
|
78
|
+
return String(s).trim().toLowerCase();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function boardSummary(boards) {
|
|
82
|
+
return boards
|
|
83
|
+
.map((b) => {
|
|
84
|
+
const cols = (b.columns || []).map((c) => c.name).join(', ');
|
|
85
|
+
return ` - ${b.name}${b.ownerType === 'workspace' ? ' (workspace)' : ''}${cols ? `: ${cols}` : ''}`;
|
|
86
|
+
})
|
|
87
|
+
.join('\n');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Resolve board/column NAMES to ids against the caller's boards.
|
|
92
|
+
*
|
|
93
|
+
* Returns { boardId, kanbanColumnId } with only the keys that resolved. Rules:
|
|
94
|
+
* - an explicit id wins over a name for the same field;
|
|
95
|
+
* - boardName must match exactly one board (case-insensitive); otherwise an
|
|
96
|
+
* Error listing the available boards;
|
|
97
|
+
* - kanbanColumnName resolves inside the resolved board when there is one.
|
|
98
|
+
* Without a board it must be unique across ALL boards — default column
|
|
99
|
+
* names ("To Do", "Done") repeat on every board, so an ambiguous name is an
|
|
100
|
+
* Error listing "board › column" candidates rather than a silent guess.
|
|
101
|
+
*/
|
|
102
|
+
export function resolveBoardFilters(params, boards) {
|
|
103
|
+
const out = {};
|
|
104
|
+
const all = flattenBoards(boards);
|
|
105
|
+
const wantBoardName = !isBlankValue(params.boardName) && isBlankValue(params.boardId);
|
|
106
|
+
const wantColumnName = !isBlankValue(params.kanbanColumnName) && isBlankValue(params.kanbanColumnId);
|
|
107
|
+
|
|
108
|
+
if (!isBlankValue(params.boardId)) out.boardId = params.boardId;
|
|
109
|
+
if (!isBlankValue(params.kanbanColumnId)) out.kanbanColumnId = params.kanbanColumnId;
|
|
110
|
+
if (!wantBoardName && !wantColumnName) return out;
|
|
111
|
+
|
|
112
|
+
let board = null;
|
|
113
|
+
if (wantBoardName) {
|
|
114
|
+
const needle = normalize(params.boardName);
|
|
115
|
+
const matches = all.filter((b) => normalize(b.name) === needle);
|
|
116
|
+
if (matches.length !== 1) {
|
|
117
|
+
const why = matches.length === 0 ? 'not found' : 'matches more than one board';
|
|
118
|
+
throw new Error(
|
|
119
|
+
`Board "${params.boardName}" ${why}.\n\nAvailable boards:\n${boardSummary(all) || ' (none)'}`
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
[board] = matches;
|
|
123
|
+
out.boardId = boardIdOf(board);
|
|
124
|
+
} else if (!isBlankValue(params.boardId)) {
|
|
125
|
+
board = all.find((b) => boardIdOf(b) === String(params.boardId)) || null;
|
|
126
|
+
if (!board) {
|
|
127
|
+
throw new Error(
|
|
128
|
+
`Board id "${params.boardId}" is not one of your boards.\n\nAvailable boards:\n${boardSummary(all) || ' (none)'}`
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (wantColumnName) {
|
|
134
|
+
const needle = normalize(params.kanbanColumnName);
|
|
135
|
+
const scope = board ? [board] : all;
|
|
136
|
+
const candidates = [];
|
|
137
|
+
for (const b of scope) {
|
|
138
|
+
for (const c of b.columns || []) {
|
|
139
|
+
if (normalize(c.name) === needle) candidates.push({ board: b, column: c });
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (candidates.length === 0) {
|
|
143
|
+
const where = board ? ` on board "${board.name}"` : '';
|
|
144
|
+
throw new Error(
|
|
145
|
+
`Column "${params.kanbanColumnName}" not found${where}.\n\nAvailable boards and columns:\n${boardSummary(scope) || ' (none)'}`
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
if (candidates.length > 1) {
|
|
149
|
+
const list = candidates.map((c) => ` - ${c.board.name} › ${c.column.name}`).join('\n');
|
|
150
|
+
throw new Error(
|
|
151
|
+
`Column "${params.kanbanColumnName}" exists on more than one board — also pass boardName to disambiguate:\n${list}`
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
out.kanbanColumnId = refId(candidates[0].column);
|
|
155
|
+
if (!out.boardId) out.boardId = boardIdOf(candidates[0].board);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return out;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** One concise summary line per item for list output. */
|
|
162
|
+
export function summarizeItem(item, index) {
|
|
163
|
+
const parts = [];
|
|
164
|
+
parts.push(`type: ${typeLabel(item.type)}`);
|
|
165
|
+
parts.push(`status: ${statusLabel(item.status)}`);
|
|
166
|
+
if (item.priority != null) parts.push(`priority: ${item.priority}`);
|
|
167
|
+
if (item.dueDate) parts.push(`due: ${item.dueDate}${item.time ? ` ${item.time}` : ''}`);
|
|
168
|
+
else if (item.datePlain) parts.push(`due: ${item.datePlain}${item.time ? ` ${item.time}` : ''}`);
|
|
169
|
+
const tagStr = formatTags(item.tags);
|
|
170
|
+
if (tagStr) parts.push(`tags: ${tagStr}`);
|
|
171
|
+
const board = boardLabel(item);
|
|
172
|
+
if (board) parts.push(`board: ${board}`);
|
|
173
|
+
const column = columnLabel(item);
|
|
174
|
+
if (column) parts.push(`column: ${column}`);
|
|
175
|
+
if (item.projectId) parts.push(`project: ${refId(item.projectId)}`);
|
|
176
|
+
const owner = ownerName(item.userId);
|
|
177
|
+
if (owner) parts.push(`owner: ${owner}`);
|
|
178
|
+
return (
|
|
179
|
+
`${index}. ${item.name || '(untitled)'} [id: ${item._id ?? item.id}]\n` +
|
|
180
|
+
` ${parts.join(' | ')}`
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Render a list response as a concise, readable summary (not raw JSON). */
|
|
185
|
+
export function renderList(result, kindLabelPlural) {
|
|
186
|
+
const tasks = Array.isArray(result?.tasks) ? result.tasks : [];
|
|
187
|
+
const total = result?.total ?? tasks.length;
|
|
188
|
+
const page = result?.page ?? 1;
|
|
189
|
+
const limit = result?.limit ?? tasks.length;
|
|
190
|
+
|
|
191
|
+
if (tasks.length === 0) {
|
|
192
|
+
return `No ${kindLabelPlural} found (total: ${total}, page ${page}).`;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const lines = tasks.map((t, i) => summarizeItem(t, i + 1));
|
|
196
|
+
const footer = `\nShowing ${tasks.length} of ${total} ${kindLabelPlural} (page ${page}, limit ${limit}).`;
|
|
197
|
+
return `${lines.join('\n')}\n${footer}`;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** Render one item's full detail with the description converted to Markdown. */
|
|
201
|
+
export function renderItem(item) {
|
|
202
|
+
const lines = [];
|
|
203
|
+
lines.push(`${item.name || '(untitled)'}`);
|
|
204
|
+
lines.push(`id: ${item._id ?? item.id}`);
|
|
205
|
+
lines.push(`type: ${typeLabel(item.type)}`);
|
|
206
|
+
lines.push(`status: ${statusLabel(item.status)}`);
|
|
207
|
+
if (item.priority != null) lines.push(`priority: ${item.priority}`);
|
|
208
|
+
if (item.dueDate) lines.push(`due: ${item.dueDate}${item.time ? ` ${item.time}` : ''}`);
|
|
209
|
+
else if (item.datePlain) lines.push(`due: ${item.datePlain}${item.time ? ` ${item.time}` : ''}`);
|
|
210
|
+
const tagStr = formatTags(item.tags);
|
|
211
|
+
if (tagStr) lines.push(`tags: ${tagStr}`);
|
|
212
|
+
const board = boardLabel(item);
|
|
213
|
+
if (board) lines.push(`board: ${board}`);
|
|
214
|
+
const column = columnLabel(item);
|
|
215
|
+
if (column) lines.push(`column: ${column}`);
|
|
216
|
+
if (item.projectId) lines.push(`project: ${refId(item.projectId)}`);
|
|
217
|
+
const owner = ownerName(item.userId);
|
|
218
|
+
if (owner) lines.push(`owner: ${owner}`);
|
|
219
|
+
if (item.parentId) lines.push(`parent: ${item.parentId}`);
|
|
220
|
+
if (item.createdAt) lines.push(`created: ${item.createdAt}`);
|
|
221
|
+
if (item.updatedAt) lines.push(`updated: ${item.updatedAt}`);
|
|
222
|
+
|
|
223
|
+
const md = descriptionToMarkdown(item.description);
|
|
224
|
+
lines.push('');
|
|
225
|
+
lines.push('--- description ---');
|
|
226
|
+
lines.push(md && md.trim() ? md : '(empty)');
|
|
227
|
+
return lines.join('\n');
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const SORTABLE_FIELDS = new Set(['dueDate', 'createdAt', 'updatedAt', 'priority', 'position', 'name']);
|
|
231
|
+
const DATE_FIELDS = new Set(['dueDate', 'createdAt', 'updatedAt']);
|
|
232
|
+
|
|
233
|
+
/** Parse 'field:dir' with the backend's whitelist; default updatedAt:desc. */
|
|
234
|
+
export function parseSort(sortBy) {
|
|
235
|
+
if (typeof sortBy === 'string' && sortBy.includes(':')) {
|
|
236
|
+
const [field, dir] = sortBy.split(':');
|
|
237
|
+
if (SORTABLE_FIELDS.has(field)) return { field, dir: dir === 'asc' ? 'asc' : 'desc' };
|
|
238
|
+
}
|
|
239
|
+
return { field: 'updatedAt', dir: 'desc' };
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function sortValue(item, field) {
|
|
243
|
+
const v = item?.[field];
|
|
244
|
+
if (v == null) return null;
|
|
245
|
+
if (DATE_FIELDS.has(field)) {
|
|
246
|
+
const t = new Date(v).getTime();
|
|
247
|
+
return Number.isNaN(t) ? null : t;
|
|
248
|
+
}
|
|
249
|
+
return v;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function compareBy({ field, dir }) {
|
|
253
|
+
const sign = dir === 'asc' ? 1 : -1;
|
|
254
|
+
return (a, b) => {
|
|
255
|
+
const va = sortValue(a, field);
|
|
256
|
+
const vb = sortValue(b, field);
|
|
257
|
+
if (va === vb) return 0;
|
|
258
|
+
if (va == null) return 1;
|
|
259
|
+
if (vb == null) return -1;
|
|
260
|
+
if (typeof va === 'string' || typeof vb === 'string') return sign * String(va).localeCompare(String(vb));
|
|
261
|
+
return sign * (va < vb ? -1 : 1);
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Merge the two backend windows behind planko_list_all (tasks+sticky notes,
|
|
267
|
+
* and notes) into one list. Each input is a page-1 window of `limit` items
|
|
268
|
+
* sorted by `sortBy` on the server; the union is re-sorted by the same key and
|
|
269
|
+
* cut to `limit`. Missing values sort last regardless of direction.
|
|
270
|
+
*/
|
|
271
|
+
export function mergeAllLists(taskRes, noteRes, limit, sortBy) {
|
|
272
|
+
const tasks = Array.isArray(taskRes?.tasks) ? taskRes.tasks : [];
|
|
273
|
+
const notes = Array.isArray(noteRes?.tasks) ? noteRes.tasks : [];
|
|
274
|
+
const sort = parseSort(sortBy);
|
|
275
|
+
const merged = [...tasks, ...notes].sort(compareBy(sort)).slice(0, limit);
|
|
276
|
+
return {
|
|
277
|
+
tasks: merged,
|
|
278
|
+
totals: { tasksAndStickyNotes: taskRes?.total ?? tasks.length, notes: noteRes?.total ?? notes.length },
|
|
279
|
+
limit,
|
|
280
|
+
sort,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** Render the merged planko_list_all result. */
|
|
285
|
+
export function renderAll(merged) {
|
|
286
|
+
const { tasks, totals, limit, sort } = merged;
|
|
287
|
+
const total = totals.tasksAndStickyNotes + totals.notes;
|
|
288
|
+
if (tasks.length === 0) {
|
|
289
|
+
return `No items found (tasks + sticky notes: ${totals.tasksAndStickyNotes}, notes: ${totals.notes}).`;
|
|
290
|
+
}
|
|
291
|
+
const lines = tasks.map((t, i) => summarizeItem(t, i + 1));
|
|
292
|
+
const footer =
|
|
293
|
+
`\nShowing ${tasks.length} of ${total} items, ordered by ${sort.field}:${sort.dir}, limit ${limit} ` +
|
|
294
|
+
`(tasks + sticky notes: ${totals.tasksAndStickyNotes}, notes: ${totals.notes}). ` +
|
|
295
|
+
`Use planko_list_tasks / planko_list_notes / planko_list_sticky_notes to page through one kind.`;
|
|
296
|
+
return `${lines.join('\n')}\n${footer}`;
|
|
297
|
+
}
|
package/src/projectLock.js
CHANGED
|
@@ -90,7 +90,13 @@ export function assertProjectAllowed(lock, task) {
|
|
|
90
90
|
* reliably, so they are dropped from both the tool schema and (defensively) the
|
|
91
91
|
* API params. Member narrowing is done by NAME client-side (see matchesAssignee).
|
|
92
92
|
*/
|
|
93
|
-
export const HALLUCINATED_LIST_FILTERS = [
|
|
93
|
+
export const HALLUCINATED_LIST_FILTERS = [
|
|
94
|
+
'parentId',
|
|
95
|
+
'assigneeId',
|
|
96
|
+
'priority',
|
|
97
|
+
'boardId',
|
|
98
|
+
'kanbanColumnId',
|
|
99
|
+
];
|
|
94
100
|
|
|
95
101
|
/** Delete the fabrication-prone narrowing filters from an API param bag. */
|
|
96
102
|
export function stripHallucinatedListFilters(params) {
|
package/src/recommend.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recommendations (PL274) — pure helpers, no I/O.
|
|
3
|
+
*
|
|
4
|
+
* A recommendation is a SUGGESTION sent to the owner of the API key: the
|
|
5
|
+
* backend stores it as `pending`, notifies the owner (notification centre +
|
|
6
|
+
* push) and only creates the task when the owner accepts. Nothing is written
|
|
7
|
+
* to the task collection by the MCP call itself.
|
|
8
|
+
*
|
|
9
|
+
* Endpoint: POST /mcp-project-sync/recommendations
|
|
10
|
+
* body { type: 'new_task', payload: { title, ...task attributes } }
|
|
11
|
+
* response the Recommendation document (toJSON → `id`, never `_id`)
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { isBlankValue } from './sanitize.js';
|
|
15
|
+
|
|
16
|
+
export const RECOMMENDATION_NEW_TASK = 'new_task';
|
|
17
|
+
|
|
18
|
+
const DATE_PREFIX = /^\d{4}-\d{2}-\d{2}/;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Build the request body for a `new_task` recommendation.
|
|
22
|
+
*
|
|
23
|
+
* `taskBody` is an already-sanitized task attribute bag (blank values dropped,
|
|
24
|
+
* Markdown description converted, datePlain→dueDate mirrored). The owner's
|
|
25
|
+
* notification card previews `datePlain` only, so a dueDate-only suggestion
|
|
26
|
+
* would reach them with no visible date: derive datePlain from the date part
|
|
27
|
+
* of dueDate when it is missing. An explicit datePlain is never overridden.
|
|
28
|
+
*/
|
|
29
|
+
export function buildRecommendationBody(title, taskBody = {}) {
|
|
30
|
+
const payload = { title };
|
|
31
|
+
for (const [key, value] of Object.entries(taskBody)) {
|
|
32
|
+
if (isBlankValue(value)) continue;
|
|
33
|
+
payload[key] = value;
|
|
34
|
+
}
|
|
35
|
+
if (
|
|
36
|
+
isBlankValue(payload.datePlain) &&
|
|
37
|
+
typeof payload.dueDate === 'string' &&
|
|
38
|
+
DATE_PREFIX.test(payload.dueDate)
|
|
39
|
+
) {
|
|
40
|
+
payload.datePlain = payload.dueDate.slice(0, 10);
|
|
41
|
+
}
|
|
42
|
+
return { type: RECOMMENDATION_NEW_TASK, payload };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Text returned to the agent after a successful POST. Tolerates an unexpected
|
|
47
|
+
* response shape. `res.id` is the primary path on purpose: the recommendation
|
|
48
|
+
* doc goes through the toJSON plugin, which exposes `id` (unlike task
|
|
49
|
+
* responses, which may carry `_id`).
|
|
50
|
+
*/
|
|
51
|
+
export function renderRecommendation(res, { projectId, lock, projectNameIgnored } = {}) {
|
|
52
|
+
const doc = (res && typeof res === 'object' && (res.recommendation || res)) || {};
|
|
53
|
+
const id = doc.id || doc._id || 'unknown';
|
|
54
|
+
const status = doc.status || 'pending';
|
|
55
|
+
const title =
|
|
56
|
+
doc.payload && typeof doc.payload.title === 'string' ? doc.payload.title : '(untitled)';
|
|
57
|
+
const where = projectId ? ` in project ${projectId}` : " in the owner's default project";
|
|
58
|
+
|
|
59
|
+
const lines = [
|
|
60
|
+
`Recommendation sent (id: ${id}, status: ${status}): "${title}"${where}.`,
|
|
61
|
+
'Nothing was created yet. The account owner will see this suggestion in ' +
|
|
62
|
+
"Planko's notification centre (and as a push notification) and can accept " +
|
|
63
|
+
'it (which creates the task) or reject it.',
|
|
64
|
+
];
|
|
65
|
+
if (projectNameIgnored) {
|
|
66
|
+
lines.push(
|
|
67
|
+
`Note: projectName was ignored because this server is locked to project ${lock}.`
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
return lines.join('\n');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Under a project lock the caller never chose the project, so the backend's
|
|
75
|
+
* "Invalid projectId" would blame the wrong party. Rewrite it with lock context.
|
|
76
|
+
* Coupled to the literal message in planko-back's newTask.handler
|
|
77
|
+
* (`assertReferences`); if that wording changes the generic error still surfaces,
|
|
78
|
+
* only the friendlier text is lost.
|
|
79
|
+
*/
|
|
80
|
+
export function describeLockError(err, lock) {
|
|
81
|
+
if (lock && err && err.message === 'Invalid projectId') {
|
|
82
|
+
return new Error(
|
|
83
|
+
`The locked project (${lock}) is not accessible to this API key, so the recommendation was rejected.`
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
return err;
|
|
87
|
+
}
|