planko-mcp-server 0.5.2 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "planko-mcp-server",
3
- "version": "0.5.2",
3
+ "version": "0.7.0",
4
4
  "description": "MCP server for syncing Planko tasks with local Markdown files",
5
5
  "type": "module",
6
+ "exports": {
7
+ ".": "./index.js",
8
+ "./tools": "./src/tools.js"
9
+ },
6
10
  "bin": {
7
11
  "planko-mcp-server": "./index.js"
8
12
  },
@@ -17,10 +21,11 @@
17
21
  },
18
22
  "scripts": {
19
23
  "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"
24
+ "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 && node --check src/tools.js"
21
25
  },
22
26
  "dependencies": {
23
- "@modelcontextprotocol/sdk": "^1.12.1"
27
+ "@modelcontextprotocol/sdk": "^1.12.1",
28
+ "zod": "^4.3.6"
24
29
  },
25
30
  "devDependencies": {
26
31
  "vitest": "^3.1.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
+ }
@@ -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 = ['parentId', 'assigneeId', 'priority'];
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) {
@@ -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
+ }