planko-mcp-server 0.8.0 → 0.10.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 CHANGED
@@ -261,7 +261,8 @@ Sync order: delete, pull, push. Local changes overwrite remote on conflict.
261
261
 
262
262
  | Variable | Required | Description |
263
263
  |---|---|---|
264
- | `PLANKO_API_KEY` | Yes | Your MCP API key from app.planko.io/integrations |
264
+ | `PLANKO_API_KEY` | Yes (user mode) | Your MCP API key from app.planko.io/integrations |
265
+ | `PLANKO_RUNNER_TOKEN` | No | Runner token (`pk_run_…`). When set, the server starts in **runner mode** (see below) and `PLANKO_API_KEY` is not required. |
265
266
  | `PLANKO_API_BASE` | No | API base URL override (defaults to production) |
266
267
  | `PLANKO_PROJECT_LOCK` | No | Confine every operation to a single project id (see below). **Off by default** — when unset the server behaves exactly as before. |
267
268
 
@@ -315,6 +316,44 @@ applies and the server is fully backward-compatible.
315
316
  }
316
317
  ```
317
318
 
319
+ ### Runner mode (`PLANKO_RUNNER_TOKEN`)
320
+
321
+ Runner mode serves the agent that executes Planko **agentic tasks**. It is enabled by
322
+ setting `PLANKO_RUNNER_TOKEN` to a runner token generated in the Planko app (screen
323
+ *Agente → Conectar agente*). A runner token:
324
+
325
+ - belongs to one user and is bound to **one or more projects** of that user — the
326
+ runner only ever sees that user's queued agentic tasks of those projects;
327
+ - is **shown once**, when it is created; Planko stores only its hash. Lost token →
328
+ create a new one. Revoking it stops the runner immediately and returns any task it
329
+ was running to the queue.
330
+
331
+ Runner mode is **exclusive**: it registers only the three runner tools below (no user
332
+ CRUD, no folder sync), all authenticated with the runner token:
333
+
334
+ | Tool | What it does |
335
+ |---|---|
336
+ | `planko_agent_claim` | Long-poll for the oldest queued agentic task (`waitSeconds` 0–25). Returns its id, `claimSeq`, name, project, timeout, instructions (Markdown), the owner's `humanInstructions` (+ `humanInstructionsLabel`, null when empty) and the parent context for a subtask, or `No task available.` |
337
+ | `planko_agent_finish` | Report the result (Markdown) of a claimed task with the `claimSeq` returned by the claim, and `error: true` when it failed. The task goes to validation, or is concluded automatically when its recurring model does not require validation. |
338
+ | `planko_agent_suggest_subtask` | Suggest a subtask (name, Markdown instructions, optional `timeoutMin`) under an agentic task. The owner accepts or rejects it in the app. With `requireHumanInstructions: true` (+ `humanInstructionsLabel`, ≤200 chars, e.g. "Decidir entre A, B, C ou outro") the owner must fill in "Instruções humanas" before accepting — for a decision between options or an instruction only the owner can give. |
339
+
340
+ Every error (invalid/revoked token, task outside the token's scope, stale claim) is
341
+ returned as a tool error carrying the HTTP status.
342
+
343
+ ```json
344
+ {
345
+ "mcpServers": {
346
+ "planko-runner": {
347
+ "command": "npx",
348
+ "args": ["-y", "planko-mcp-server"],
349
+ "env": {
350
+ "PLANKO_RUNNER_TOKEN": "pk_run_..."
351
+ }
352
+ }
353
+ }
354
+ }
355
+ ```
356
+
318
357
  ## How it works
319
358
 
320
359
  - Each Planko task/note maps to a local `.md` file (task name becomes filename)
package/index.js CHANGED
@@ -4,7 +4,9 @@
4
4
  * planko-mcp-server — MCP server for syncing Planko tasks with local .md files.
5
5
  *
6
6
  * Environment variables:
7
- * PLANKO_API_KEY (required) — user-scoped MCP API key
7
+ * PLANKO_API_KEY (required in user mode) — user-scoped MCP API key
8
+ * PLANKO_RUNNER_TOKEN — runner token (pk_run_…); when set, the server starts in
9
+ * runner mode and exposes ONLY the runner tools (PLANKO_API_KEY not required)
8
10
  * PLANKO_API_BASE — optional API base URL override
9
11
  *
10
12
  * Tools:
@@ -14,6 +16,9 @@
14
16
  * planko_complete_task — works on any item id
15
17
  * planko_list_all — tasks + sticky notes + notes in one listing
16
18
  * planko_recommend_task — suggest a task for the account owner to accept/reject
19
+ *
20
+ * Runner mode tools (PL330 agentic tasks):
21
+ * planko_agent_claim / planko_agent_finish / planko_agent_suggest_subtask
17
22
  */
18
23
 
19
24
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
@@ -23,8 +28,9 @@ import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs';
23
28
  import { join } from 'node:path';
24
29
  import { createRequire } from 'node:module';
25
30
 
26
- import { createApiClient } from './src/api.js';
31
+ import { createApiClient, createRunnerApiClient } from './src/api.js';
27
32
  import { registerStandaloneTools, toolOk, toolError } from './src/tools.js';
33
+ import { registerRunnerTools } from './src/runnerTools.js';
28
34
  import {
29
35
  markdownToBlockNote,
30
36
  descriptionToMarkdown,
@@ -46,8 +52,11 @@ import {
46
52
 
47
53
  // --- Startup validation ---
48
54
 
55
+ // PL330: runner mode — token-scoped, exclusive (no user-wide CRUD), no API key needed.
56
+ const RUNNER_TOKEN = (process.env.PLANKO_RUNNER_TOKEN || '').trim();
57
+
49
58
  const API_KEY = process.env.PLANKO_API_KEY;
50
- if (!API_KEY) {
59
+ if (!API_KEY && !RUNNER_TOKEN) {
51
60
  console.error(
52
61
  'Fatal: PLANKO_API_KEY environment variable is required.'
53
62
  );
@@ -579,6 +588,12 @@ registerStandaloneTools(server, { api, projectLock: PROJECT_LOCK });
579
588
  // --- Start server ---
580
589
 
581
590
  async function main() {
591
+ if (RUNNER_TOKEN) {
592
+ const runnerServer = new McpServer({ name: 'planko-runner', version: PKG_VERSION });
593
+ registerRunnerTools(runnerServer, { api: createRunnerApiClient({ runnerToken: RUNNER_TOKEN }) });
594
+ await runnerServer.connect(new StdioServerTransport());
595
+ return;
596
+ }
582
597
  const transport = new StdioServerTransport();
583
598
  await server.connect(transport);
584
599
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "planko-mcp-server",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "description": "MCP server for syncing Planko tasks with local Markdown files",
5
5
  "type": "module",
6
6
  "exports": {
@@ -21,7 +21,7 @@
21
21
  },
22
22
  "scripts": {
23
23
  "test": "vitest run",
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"
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 && node --check src/runnerTools.js"
25
25
  },
26
26
  "dependencies": {
27
27
  "@modelcontextprotocol/sdk": "^1.12.1",
package/src/api.js CHANGED
@@ -7,12 +7,15 @@
7
7
 
8
8
  const DEFAULT_API_BASE = 'https://api.planko.io/v1';
9
9
 
10
- export function createApiClient({ apiKey, apiBase }) {
11
- const base = apiBase || process.env.PLANKO_API_BASE || DEFAULT_API_BASE;
12
-
13
- async function request(method, path, body) {
10
+ /**
11
+ * Build a JSON request function bound to a base URL and auth headers.
12
+ * `statusInMessage` prefixes errors with the HTTP status (runner mode: the agent
13
+ * must see *why* a call failed). The user client keeps the plain backend message.
14
+ */
15
+ function makeRequest({ base, headers: authHeaders, statusInMessage = false }) {
16
+ return async function request(method, path, body) {
14
17
  const url = `${base}${path}`;
15
- const headers = { 'x-api-key': apiKey };
18
+ const headers = { ...authHeaders };
16
19
 
17
20
  const options = { method, headers };
18
21
 
@@ -36,11 +39,18 @@ export function createApiClient({ apiKey, apiBase }) {
36
39
  typeof data === 'object' && data.message
37
40
  ? data.message
38
41
  : `API returned HTTP ${res.status}`;
39
- throw new Error(msg);
42
+ const err = new Error(statusInMessage ? `HTTP ${res.status}: ${msg}` : msg);
43
+ err.status = res.status;
44
+ throw err;
40
45
  }
41
46
 
42
47
  return data;
43
- }
48
+ };
49
+ }
50
+
51
+ export function createApiClient({ apiKey, apiBase }) {
52
+ const base = apiBase || process.env.PLANKO_API_BASE || DEFAULT_API_BASE;
53
+ const request = makeRequest({ base, headers: { 'x-api-key': apiKey } });
44
54
 
45
55
  return {
46
56
  /**
@@ -172,3 +182,27 @@ export function createApiClient({ apiKey, apiBase }) {
172
182
  },
173
183
  };
174
184
  }
185
+
186
+ /**
187
+ * PL330 — API client of the agentic-tasks runner, authenticated with a runner
188
+ * token (`pk_run_…`, per project), never with the user API key.
189
+ */
190
+ export function createRunnerApiClient({ runnerToken, apiBase }) {
191
+ const request = makeRequest({
192
+ base: apiBase || process.env.PLANKO_API_BASE || DEFAULT_API_BASE,
193
+ headers: { Authorization: `Bearer ${runnerToken}` },
194
+ statusInMessage: true,
195
+ });
196
+
197
+ return {
198
+ /** POST /agent/runner/claim — long-poll; { task } or { task: null } */
199
+ claim: (waitSec) => request('POST', '/agent/runner/claim', waitSec == null ? {} : { waitSec }),
200
+
201
+ /** POST /agent/runner/tasks/:taskId/finish — bound to the claim by claimSeq */
202
+ finish: (taskId, { result, error, claimSeq }) =>
203
+ request('POST', `/agent/runner/tasks/${taskId}/finish`, { result, error: !!error, claimSeq }),
204
+
205
+ /** POST /agent/runner/tasks/:taskId/subtasks — suggest a subtask under an agentic task */
206
+ suggestSubtask: (taskId, body) => request('POST', `/agent/runner/tasks/${taskId}/subtasks`, body),
207
+ };
208
+ }
@@ -0,0 +1,140 @@
1
+ /**
2
+ * PL330 — tools of the agentic-tasks runner (runner mode, PLANKO_RUNNER_TOKEN).
3
+ * Each tool maps 1:1 to a /v1/agent/runner endpoint; the backend scopes every call
4
+ * to the token's projects and owner. Errors are always returned as tool errors.
5
+ */
6
+ import { z } from 'zod';
7
+
8
+ import { toolOk, toolError } from './tools.js';
9
+ import { descriptionToMarkdown, markdownToDescription } from './converters.js';
10
+
11
+ const ANNOTATIONS = {
12
+ WRITE: { readOnlyHint: false, destructiveHint: false, openWorldHint: false },
13
+ IDEMPOTENT_WRITE: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
14
+ };
15
+
16
+ const objectId = z.string().regex(/^[a-fA-F\d]{24}$/, 'Must be a 24-character hex ObjectId');
17
+
18
+ export function registerRunnerTools(server, { api }) {
19
+ // ---- planko_agent_claim ----
20
+ server.registerTool(
21
+ 'planko_agent_claim',
22
+ {
23
+ title: 'Claim agentic task',
24
+ description:
25
+ 'Take the oldest queued agentic task of this runner (long-poll). Returns its id, claimSeq and instructions, or "No task available.". The claimSeq must be sent back on planko_agent_finish.',
26
+ inputSchema: {
27
+ waitSeconds: z
28
+ .number()
29
+ .int()
30
+ .min(0)
31
+ .max(25)
32
+ .optional()
33
+ .describe('How long to wait for a task, in seconds (default: server maximum)'),
34
+ },
35
+ annotations: ANNOTATIONS.WRITE,
36
+ },
37
+ async ({ waitSeconds }) => {
38
+ try {
39
+ const { task } = await api.claim(waitSeconds);
40
+ if (!task) return toolOk('No task available.');
41
+ const payload = {
42
+ id: task.id,
43
+ claimSeq: task.claimSeq,
44
+ name: task.name,
45
+ projectName: task.projectName ?? null,
46
+ timeoutMin: task.agentTimeoutMin ?? null,
47
+ instructions: descriptionToMarkdown(task.description),
48
+ // PL331: the owner's instructions prevail over the description
49
+ humanInstructions: task.humanInstructions ?? null,
50
+ humanInstructionsLabel: task.humanInstructionsLabel ?? null,
51
+ parentContext: task.parent
52
+ ? {
53
+ id: task.parent.id,
54
+ name: task.parent.name,
55
+ instructions: descriptionToMarkdown(task.parent.description),
56
+ }
57
+ : null,
58
+ };
59
+ return toolOk(`Claimed task ${task.id}.\n\n${JSON.stringify(payload, null, 2)}`);
60
+ } catch (err) {
61
+ return toolError(`planko_agent_claim failed: ${err.message}`);
62
+ }
63
+ }
64
+ );
65
+
66
+ // ---- planko_agent_finish ----
67
+ server.registerTool(
68
+ 'planko_agent_finish',
69
+ {
70
+ title: 'Finish agentic task',
71
+ description:
72
+ 'Report the result of a claimed agentic task (Markdown). Set error=true when the task could not be completed. The task goes to validation, or is concluded automatically when its model allows it.',
73
+ inputSchema: {
74
+ taskId: objectId.describe('Id of the claimed task'),
75
+ claimSeq: z.number().int().min(1).describe('claimSeq returned by planko_agent_claim for this task'),
76
+ result: z.string().max(100000).describe('Markdown output'),
77
+ error: z.boolean().optional().describe('true when the task failed'),
78
+ },
79
+ annotations: ANNOTATIONS.IDEMPOTENT_WRITE,
80
+ },
81
+ async ({ taskId, claimSeq, result, error }) => {
82
+ try {
83
+ const { task } = await api.finish(taskId, { result, error: !!error, claimSeq });
84
+ const auto = task.agentDecision === 'auto' ? ' (auto)' : '';
85
+ return toolOk(`Finished task ${task.id}: ${task.agentStatus}${auto}`);
86
+ } catch (err) {
87
+ return toolError(`planko_agent_finish failed: ${err.message}`);
88
+ }
89
+ }
90
+ );
91
+
92
+ // ---- planko_agent_suggest_subtask ----
93
+ server.registerTool(
94
+ 'planko_agent_suggest_subtask',
95
+ {
96
+ title: 'Suggest subtask',
97
+ description:
98
+ 'Suggest a subtask under an agentic task. It is created as a suggestion that the owner accepts or rejects; it never runs before being accepted. ' +
99
+ 'When the subtask needs a decision between options or an instruction only the owner can give, set requireHumanInstructions=true: ' +
100
+ 'the owner must fill in the "Instruções humanas" field before accepting, and the run receives that text. ' +
101
+ 'Detail the options in the description (e.g. "A) …, B) …, C) …, or another one") and summarize them in humanInstructionsLabel, ' +
102
+ 'e.g. "Decidir entre A, B, C ou outro".',
103
+ inputSchema: {
104
+ parentTaskId: objectId.describe('Id of the agentic parent task'),
105
+ name: z.string().min(1).max(200).describe('Subtask title'),
106
+ description: z.string().optional().describe('Instructions for the subtask, as Markdown'),
107
+ timeoutMin: z.number().int().min(1).max(1440).optional().describe('Timeout in minutes (default 60)'),
108
+ requireHumanInstructions: z
109
+ .boolean()
110
+ .optional()
111
+ .describe('true when the owner must write instructions (e.g. pick an option) before accepting'),
112
+ humanInstructionsLabel: z
113
+ .string()
114
+ .trim()
115
+ .min(1)
116
+ .max(200)
117
+ .optional()
118
+ .describe('Caption of the owner instructions field, e.g. "Decidir entre A, B, C ou outro". Required when requireHumanInstructions=true'),
119
+ },
120
+ annotations: ANNOTATIONS.WRITE,
121
+ },
122
+ async ({ parentTaskId, name, description, timeoutMin, requireHumanInstructions, humanInstructionsLabel }) => {
123
+ if (requireHumanInstructions === true && !humanInstructionsLabel?.trim()) {
124
+ return toolError('planko_agent_suggest_subtask failed: humanInstructionsLabel is required when requireHumanInstructions is true');
125
+ }
126
+ try {
127
+ const body = { name, description: markdownToDescription(description) };
128
+ if (timeoutMin !== undefined) body.agentTimeoutMin = timeoutMin;
129
+ if (requireHumanInstructions !== undefined) body.requireHumanInstructions = requireHumanInstructions;
130
+ if (humanInstructionsLabel !== undefined) body.humanInstructionsLabel = humanInstructionsLabel;
131
+ if (body.description == null) delete body.description;
132
+ const { task } = await api.suggestSubtask(parentTaskId, body);
133
+ const needs = requireHumanInstructions === true ? ' (needs the owner instructions)' : '';
134
+ return toolOk(`Suggested subtask "${task.name}" (id: ${task.id}) under ${parentTaskId}: ${task.agentStatus}${needs}`);
135
+ } catch (err) {
136
+ return toolError(`planko_agent_suggest_subtask failed: ${err.message}`);
137
+ }
138
+ }
139
+ );
140
+ }