planko-mcp-server 0.9.0 → 0.11.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 +10 -5
- package/index.js +6 -2
- package/package.json +1 -1
- package/src/api.js +18 -4
- package/src/runnerTools.js +82 -20
package/README.md
CHANGED
|
@@ -322,8 +322,10 @@ Runner mode serves the agent that executes Planko **agentic tasks**. It is enabl
|
|
|
322
322
|
setting `PLANKO_RUNNER_TOKEN` to a runner token generated in the Planko app (screen
|
|
323
323
|
*Agente → Conectar agente*). A runner token:
|
|
324
324
|
|
|
325
|
-
- belongs to one user and is
|
|
326
|
-
|
|
325
|
+
- belongs to one user and is one of that user's **agents**: the runner executes the
|
|
326
|
+
user's queued agentic tasks **whose agent is this runner** (the task's executor). The
|
|
327
|
+
projects of a runner only make it the default agent suggested for those projects; they
|
|
328
|
+
do not restrict what it runs, and a task without a project runs too;
|
|
327
329
|
- is **shown once**, when it is created; Planko stores only its hash. Lost token →
|
|
328
330
|
create a new one. Revoking it stops the runner immediately and returns any task it
|
|
329
331
|
was running to the queue.
|
|
@@ -333,9 +335,12 @@ CRUD, no folder sync), all authenticated with the runner token:
|
|
|
333
335
|
|
|
334
336
|
| Tool | What it does |
|
|
335
337
|
|---|---|
|
|
336
|
-
| `planko_agent_claim` | Long-poll for the oldest queued agentic task (`waitSeconds` 0–25)
|
|
337
|
-
| `planko_agent_finish` | Report the result (Markdown) of a claimed task with the `claimSeq` returned by the claim,
|
|
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. |
|
|
338
|
+
| `planko_agent_claim` | Long-poll for the oldest queued agentic task (`waitSeconds` 0–25), or `No task available.`. Returns the back's standardized payload with the same names: `id`, `claimSeq`, `name`, `projectName`, `timeoutMin`, `description` (the task **Instrução** in Markdown, organized in Contexto/Instrução/Entrega or not), `instructions` (the agent's **basic instructions**, applied before the task instruction — the task wins on conflict; `null` when none), `context.attachments` (`attachmentId`, `name`, `size`, `mime`), `output.suggestSubtasks`, `level`, `sourceId`, `executorKind`, `availableAt`, `releaseCount`, `recentRejections` and `parentContext` (`id`, `name`, `description`). Missing fields from an older back get safe defaults (`[]`, `suggestSubtasks: true`, `null`, `executorKind: "claude_code"`, `0`). There are no "human instructions" any more. |
|
|
339
|
+
| `planko_agent_finish` | Report the result (Markdown) of a claimed task with the `claimSeq` returned by the claim, `error: true` when it failed, and an optional `runMeta` — the run summary shown to the owner (`executorKind`, `model`, `steps`, `inputTokens`, `outputTokens`, `costUsd`, `durationMs`, `queueLatencyMs`, `stoppedBy`, …; unknown keys are refused). The task goes to validation, or is concluded automatically when its recurring model does not require validation. |
|
|
340
|
+
| `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. When it depends on a decision only the owner can make, write the question and the options in the description: the owner edits the instruction before accepting. |
|
|
341
|
+
|
|
342
|
+
**Compatibility:** against a back that does not know `runMeta` yet, `planko_agent_finish`
|
|
343
|
+
sends the result once more without it, so the task still closes (the summary is dropped).
|
|
339
344
|
|
|
340
345
|
Every error (invalid/revoked token, task outside the token's scope, stale claim) is
|
|
341
346
|
returned as a tool error carrying the HTTP status.
|
package/index.js
CHANGED
|
@@ -17,8 +17,12 @@
|
|
|
17
17
|
* planko_list_all — tasks + sticky notes + notes in one listing
|
|
18
18
|
* planko_recommend_task — suggest a task for the account owner to accept/reject
|
|
19
19
|
*
|
|
20
|
-
* Runner mode tools (PL330 agentic tasks):
|
|
21
|
-
* planko_agent_claim
|
|
20
|
+
* Runner mode tools (PL330 agentic tasks; E9/PL347 standardized contract):
|
|
21
|
+
* planko_agent_claim — the back claim payload with the same names (description, context,
|
|
22
|
+
* output, level, sourceId, executorKind, instructions, availableAt, releaseCount,
|
|
23
|
+
* recentRejections), never the owner's human instructions
|
|
24
|
+
* planko_agent_finish — result, error, claimSeq and an optional runMeta (run summary)
|
|
25
|
+
* planko_agent_suggest_subtask — a suggestion the owner accepts or rejects
|
|
22
26
|
*/
|
|
23
27
|
|
|
24
28
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
package/package.json
CHANGED
package/src/api.js
CHANGED
|
@@ -185,7 +185,7 @@ export function createApiClient({ apiKey, apiBase }) {
|
|
|
185
185
|
|
|
186
186
|
/**
|
|
187
187
|
* PL330 — API client of the agentic-tasks runner, authenticated with a runner
|
|
188
|
-
* token (`pk_run_…`, per
|
|
188
|
+
* token (`pk_run_…`, per executor), never with the user API key.
|
|
189
189
|
*/
|
|
190
190
|
export function createRunnerApiClient({ runnerToken, apiBase }) {
|
|
191
191
|
const request = makeRequest({
|
|
@@ -198,9 +198,23 @@ export function createRunnerApiClient({ runnerToken, apiBase }) {
|
|
|
198
198
|
/** POST /agent/runner/claim — long-poll; { task } or { task: null } */
|
|
199
199
|
claim: (waitSec) => request('POST', '/agent/runner/claim', waitSec == null ? {} : { waitSec }),
|
|
200
200
|
|
|
201
|
-
/**
|
|
202
|
-
|
|
203
|
-
|
|
201
|
+
/**
|
|
202
|
+
* POST /agent/runner/tasks/:taskId/finish — bound to the claim by claimSeq; optional runMeta
|
|
203
|
+
* (run summary, E9). A back older than E1a rejects the unknown key with a 400 that cites it:
|
|
204
|
+
* the finish is sent once more without runMeta so the task still closes.
|
|
205
|
+
*/
|
|
206
|
+
finish: async (taskId, { result, error, claimSeq, runMeta }) => {
|
|
207
|
+
const path = `/agent/runner/tasks/${taskId}/finish`;
|
|
208
|
+
const body = { result, error: !!error, claimSeq };
|
|
209
|
+
if (runMeta && Object.keys(runMeta).length) body.runMeta = runMeta;
|
|
210
|
+
try {
|
|
211
|
+
return await request('POST', path, body);
|
|
212
|
+
} catch (err) {
|
|
213
|
+
if (!body.runMeta || err.status !== 400 || !/runMeta/.test(err.message)) throw err;
|
|
214
|
+
delete body.runMeta;
|
|
215
|
+
return request('POST', path, body);
|
|
216
|
+
}
|
|
217
|
+
},
|
|
204
218
|
|
|
205
219
|
/** POST /agent/runner/tasks/:taskId/subtasks — suggest a subtask under an agentic task */
|
|
206
220
|
suggestSubtask: (taskId, body) => request('POST', `/agent/runner/tasks/${taskId}/subtasks`, body),
|
package/src/runnerTools.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* PL330 — tools of the agentic-tasks runner (runner mode, PLANKO_RUNNER_TOKEN).
|
|
3
3
|
* Each tool maps 1:1 to a /v1/agent/runner endpoint; the backend scopes every call
|
|
4
|
-
* to the token's
|
|
4
|
+
* to the token's owner and executor (the tasks whose agent is this runner).
|
|
5
|
+
* Errors are always returned as tool errors.
|
|
6
|
+
* E9 (PL347): the claim returns the standardized payload of the back with the same
|
|
7
|
+
* names, without the owner's "human instructions" (§12.9); finish forwards runMeta.
|
|
5
8
|
*/
|
|
6
9
|
import { z } from 'zod';
|
|
7
10
|
|
|
@@ -15,6 +18,72 @@ const ANNOTATIONS = {
|
|
|
15
18
|
|
|
16
19
|
const objectId = z.string().regex(/^[a-fA-F\d]{24}$/, 'Must be a 24-character hex ObjectId');
|
|
17
20
|
|
|
21
|
+
// Whitelist of agentRunMeta (arquitetura §2.1); mirrors the back Joi. .strict(): the agent cannot invent keys.
|
|
22
|
+
const RUN_META_NUMBERS = [
|
|
23
|
+
'steps',
|
|
24
|
+
'inputTokens',
|
|
25
|
+
'outputTokens',
|
|
26
|
+
'costUsd',
|
|
27
|
+
'orFeeUsd',
|
|
28
|
+
'upstreamCostUsd',
|
|
29
|
+
'composioCalls',
|
|
30
|
+
'durationMs',
|
|
31
|
+
'queueLatencyMs',
|
|
32
|
+
'writes',
|
|
33
|
+
];
|
|
34
|
+
const STOPPED_BY = ['submitted', 'step_cap', 'timeout', 'provider_error', 'deploy', 'interrupted'];
|
|
35
|
+
const keyList = z.array(z.string().max(200)).max(50).optional();
|
|
36
|
+
|
|
37
|
+
export const runMetaSchema = z
|
|
38
|
+
.object({
|
|
39
|
+
executorKind: z.enum(['claude_code', 'planko']).optional(),
|
|
40
|
+
model: z.string().max(100).optional(),
|
|
41
|
+
level: z.string().max(100).optional(),
|
|
42
|
+
...Object.fromEntries(RUN_META_NUMBERS.map((k) => [k, z.number().min(0).optional()])),
|
|
43
|
+
egressDomains: z.array(z.string().max(253)).max(100).optional(),
|
|
44
|
+
memory: z.object({ added: keyList, updated: keyList, removed: keyList }).strict().optional(),
|
|
45
|
+
stoppedBy: z.enum(STOPPED_BY).optional(),
|
|
46
|
+
traceId: z.string().max(200).optional(),
|
|
47
|
+
})
|
|
48
|
+
.strict();
|
|
49
|
+
|
|
50
|
+
const orNull = (v) => (v === undefined ? null : v);
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Standardized claim payload (arquitetura §3): same names as the back claim, safe defaults
|
|
54
|
+
* when an older back does not send them. Never carries humanInstructions (§12.9).
|
|
55
|
+
*/
|
|
56
|
+
export function claimPayload(task) {
|
|
57
|
+
const attachments = Array.isArray(task.context?.attachments) ? task.context.attachments : [];
|
|
58
|
+
return {
|
|
59
|
+
id: task.id,
|
|
60
|
+
claimSeq: task.claimSeq,
|
|
61
|
+
name: task.name,
|
|
62
|
+
projectName: orNull(task.projectName),
|
|
63
|
+
timeoutMin: orNull(task.agentTimeoutMin),
|
|
64
|
+
description: descriptionToMarkdown(task.description),
|
|
65
|
+
context: {
|
|
66
|
+
attachments: attachments.map(({ attachmentId, name, size, mime }) => ({
|
|
67
|
+
attachmentId: String(attachmentId),
|
|
68
|
+
name: orNull(name),
|
|
69
|
+
size: orNull(size),
|
|
70
|
+
mime: orNull(mime),
|
|
71
|
+
})),
|
|
72
|
+
},
|
|
73
|
+
output: { suggestSubtasks: task.output?.suggestSubtasks !== false },
|
|
74
|
+
level: orNull(task.level),
|
|
75
|
+
sourceId: orNull(task.sourceId),
|
|
76
|
+
executorKind: task.executorKind ?? 'claude_code',
|
|
77
|
+
instructions: typeof task.instructions === 'string' && task.instructions.trim() ? task.instructions : null,
|
|
78
|
+
availableAt: orNull(task.availableAt),
|
|
79
|
+
releaseCount: Number.isInteger(task.releaseCount) ? task.releaseCount : 0,
|
|
80
|
+
recentRejections: Array.isArray(task.recentRejections) ? task.recentRejections : [],
|
|
81
|
+
parentContext: task.parent
|
|
82
|
+
? { id: task.parent.id, name: task.parent.name, description: descriptionToMarkdown(task.parent.description) }
|
|
83
|
+
: null,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
18
87
|
export function registerRunnerTools(server, { api }) {
|
|
19
88
|
// ---- planko_agent_claim ----
|
|
20
89
|
server.registerTool(
|
|
@@ -22,7 +91,9 @@ export function registerRunnerTools(server, { api }) {
|
|
|
22
91
|
{
|
|
23
92
|
title: 'Claim agentic task',
|
|
24
93
|
description:
|
|
25
|
-
'Take the oldest queued agentic task of this runner (long-poll)
|
|
94
|
+
'Take the oldest queued agentic task of this runner (long-poll), or "No task available.". Returns id, claimSeq (send it back on planko_agent_finish), name, projectName, timeoutMin, ' +
|
|
95
|
+
'description (the task instruction, Markdown), instructions (the basic instructions of this agent: apply them before the task instruction; on conflict the task wins; null when none), ' +
|
|
96
|
+
'context.attachments (files of the instruction), output.suggestSubtasks (when false, do not suggest subtasks), level, sourceId, executorKind, availableAt, releaseCount, recentRejections and parentContext.',
|
|
26
97
|
inputSchema: {
|
|
27
98
|
waitSeconds: z
|
|
28
99
|
.number()
|
|
@@ -38,21 +109,7 @@ export function registerRunnerTools(server, { api }) {
|
|
|
38
109
|
try {
|
|
39
110
|
const { task } = await api.claim(waitSeconds);
|
|
40
111
|
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
|
-
parentContext: task.parent
|
|
49
|
-
? {
|
|
50
|
-
id: task.parent.id,
|
|
51
|
-
name: task.parent.name,
|
|
52
|
-
instructions: descriptionToMarkdown(task.parent.description),
|
|
53
|
-
}
|
|
54
|
-
: null,
|
|
55
|
-
};
|
|
112
|
+
const payload = claimPayload(task);
|
|
56
113
|
return toolOk(`Claimed task ${task.id}.\n\n${JSON.stringify(payload, null, 2)}`);
|
|
57
114
|
} catch (err) {
|
|
58
115
|
return toolError(`planko_agent_claim failed: ${err.message}`);
|
|
@@ -72,12 +129,15 @@ export function registerRunnerTools(server, { api }) {
|
|
|
72
129
|
claimSeq: z.number().int().min(1).describe('claimSeq returned by planko_agent_claim for this task'),
|
|
73
130
|
result: z.string().max(100000).describe('Markdown output'),
|
|
74
131
|
error: z.boolean().optional().describe('true when the task failed'),
|
|
132
|
+
runMeta: runMetaSchema.optional().describe('Run summary (cost, tokens, steps, duration…) shown to the owner'),
|
|
75
133
|
},
|
|
76
134
|
annotations: ANNOTATIONS.IDEMPOTENT_WRITE,
|
|
77
135
|
},
|
|
78
|
-
async ({ taskId, claimSeq, result, error }) => {
|
|
136
|
+
async ({ taskId, claimSeq, result, error, runMeta }) => {
|
|
79
137
|
try {
|
|
80
|
-
const
|
|
138
|
+
const body = { result, error: !!error, claimSeq };
|
|
139
|
+
if (runMeta) body.runMeta = runMeta;
|
|
140
|
+
const { task } = await api.finish(taskId, body);
|
|
81
141
|
const auto = task.agentDecision === 'auto' ? ' (auto)' : '';
|
|
82
142
|
return toolOk(`Finished task ${task.id}: ${task.agentStatus}${auto}`);
|
|
83
143
|
} catch (err) {
|
|
@@ -92,7 +152,9 @@ export function registerRunnerTools(server, { api }) {
|
|
|
92
152
|
{
|
|
93
153
|
title: 'Suggest subtask',
|
|
94
154
|
description:
|
|
95
|
-
'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.'
|
|
155
|
+
'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. ' +
|
|
156
|
+
'If it depends on a decision only the owner can make, write the question and the options in the description (e.g. "A) …, B) …, C) …, or another one"): ' +
|
|
157
|
+
'the owner edits the instruction before accepting.',
|
|
96
158
|
inputSchema: {
|
|
97
159
|
parentTaskId: objectId.describe('Id of the agentic parent task'),
|
|
98
160
|
name: z.string().min(1).max(200).describe('Subtask title'),
|