drafted 1.25.5 → 1.25.6
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/cli/drafted.mjs +21 -0
- package/mcp/flow-tools.mjs +88 -0
- package/mcp/server.mjs +1 -1
- package/package.json +3 -2
- package/src/shared/agent-output.mjs +29 -0
package/cli/drafted.mjs
CHANGED
|
@@ -2317,6 +2317,27 @@ actionCmd
|
|
|
2317
2317
|
else console.log(`${out.state}\t${out.decidedBy || ''}\t${out.note || ''}`);
|
|
2318
2318
|
});
|
|
2319
2319
|
|
|
2320
|
+
const flowToolsCmd = program.command('flow-tools').description('Read-only tools for an agent@1 flow step run outside Drafted (served by the drafted-flow-tools MCP server)');
|
|
2321
|
+
|
|
2322
|
+
flowToolsCmd
|
|
2323
|
+
.command('token')
|
|
2324
|
+
.description('Mint a run-scoped, read-only token for drafted-flow-tools: one project, the listed tools, expiring (default 60, at most 240 minutes). Prints the token once.')
|
|
2325
|
+
.requiredOption('--project <id>', 'project (id) the step runs in')
|
|
2326
|
+
.requiredOption('--tools <names>', 'comma-separated tools from the read-only toolset, e.g. search_wiki,read_frame')
|
|
2327
|
+
.option('--ttl <minutes>', 'minutes until it expires')
|
|
2328
|
+
.option('--format <fmt>', 'output format: json or text', 'text')
|
|
2329
|
+
.action(async (opts) => {
|
|
2330
|
+
const tools = String(opts.tools).split(',').map((t) => t.trim()).filter(Boolean);
|
|
2331
|
+
const r = await actionApi('POST', '/api/flow-tools/tokens', null, { projectId: opts.project, tools, ttlMinutes: opts.ttl ? Number(opts.ttl) : undefined });
|
|
2332
|
+
if (!r.ok) {
|
|
2333
|
+
const out = { status: 'error', error: r.data.error || `HTTP ${r.status}` };
|
|
2334
|
+
if (opts.format === 'json') console.log(JSON.stringify(out)); else console.error(`error\t${out.error}`);
|
|
2335
|
+
process.exit(1);
|
|
2336
|
+
}
|
|
2337
|
+
if (opts.format === 'json') console.log(JSON.stringify({ status: 'ok', token: r.data.token, expiresAt: r.data.expiresAt, tools: r.data.tools }));
|
|
2338
|
+
else console.log(r.data.token);
|
|
2339
|
+
});
|
|
2340
|
+
|
|
2320
2341
|
const minionCmd = program.command('minion').description('Minion management (checklist-driven intake surfaces). Requires the agent allowlist.');
|
|
2321
2342
|
|
|
2322
2343
|
minionCmd
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* drafted-flow-tools: the stdio MCP server an agent@1 step runs against when it
|
|
4
|
+
* runs OUTSIDE Drafted (a Causeway backend). It serves exactly two kinds of tool:
|
|
5
|
+
*
|
|
6
|
+
* - the step's read-only tools, listed and executed by Drafted itself
|
|
7
|
+
* (GET/POST /api/flow-tools, server/lib/flow-tools-routes.mjs) — the same
|
|
8
|
+
* code Drafted's own runner calls, so "search_wiki" means one thing;
|
|
9
|
+
* - submit_output, whose parameters ARE the author's output schema. An answer
|
|
10
|
+
* is checked with src/shared/agent-output.mjs (the same check Drafted's
|
|
11
|
+
* runner uses) and, when it fits, written to the step's output file.
|
|
12
|
+
*
|
|
13
|
+
* Configuration (environment):
|
|
14
|
+
* DRAFTED_FLOW_TOKEN a run-scoped token from POST /api/flow-tools/tokens
|
|
15
|
+
* DRAFTED_URL Drafted's base URL (default https://drafted.live)
|
|
16
|
+
* FLOW_OUTPUT_SCHEMA path to the step's output schema (JSON)
|
|
17
|
+
* FLOW_OUTPUT_FILE where an accepted answer is written (JSON)
|
|
18
|
+
*
|
|
19
|
+
* It holds no other credential and offers no other tool: a backend pointed at
|
|
20
|
+
* this server and nothing else can read what the token allows, and answer.
|
|
21
|
+
*/
|
|
22
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
23
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
24
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
25
|
+
import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
26
|
+
import { outputErrors } from '../src/shared/agent-output.mjs';
|
|
27
|
+
|
|
28
|
+
const SUBMIT = 'submit_output';
|
|
29
|
+
|
|
30
|
+
function config(env = process.env) {
|
|
31
|
+
const missing = ['DRAFTED_FLOW_TOKEN', 'FLOW_OUTPUT_SCHEMA', 'FLOW_OUTPUT_FILE'].filter((k) => !env[k]);
|
|
32
|
+
if (missing.length) throw new Error(`drafted-flow-tools: set ${missing.join(', ')}`);
|
|
33
|
+
return {
|
|
34
|
+
token: env.DRAFTED_FLOW_TOKEN,
|
|
35
|
+
base: (env.DRAFTED_URL || 'https://drafted.live').replace(/\/+$/, ''),
|
|
36
|
+
schema: JSON.parse(readFileSync(env.FLOW_OUTPUT_SCHEMA, 'utf8')),
|
|
37
|
+
outputFile: env.FLOW_OUTPUT_FILE,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function drafted(cfg, method, path, body) {
|
|
42
|
+
const res = await fetch(cfg.base + '/api/flow-tools' + path, {
|
|
43
|
+
method,
|
|
44
|
+
headers: { 'content-type': 'application/json', 'x-drafted-flow-token': cfg.token },
|
|
45
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
46
|
+
});
|
|
47
|
+
const json = await res.json().catch(() => ({}));
|
|
48
|
+
if (!res.ok) throw new Error(json.error || `Drafted answered ${res.status}`);
|
|
49
|
+
return json;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function main() {
|
|
53
|
+
const cfg = config();
|
|
54
|
+
const { tools } = await drafted(cfg, 'GET', '/tools');
|
|
55
|
+
const names = new Set(tools.map((t) => t.name));
|
|
56
|
+
let accepted = false;
|
|
57
|
+
const server = new Server({ name: 'drafted-flow-tools', version: '1' }, { capabilities: { tools: {} } });
|
|
58
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
59
|
+
tools: [
|
|
60
|
+
...tools.map((t) => ({ name: t.name, description: t.description, inputSchema: t.parameters })),
|
|
61
|
+
{ name: SUBMIT, description: 'Submit your final answer. Call it once, with arguments matching this schema exactly.', inputSchema: cfg.schema },
|
|
62
|
+
],
|
|
63
|
+
}));
|
|
64
|
+
server.setRequestHandler(CallToolRequestSchema, async (req) => {
|
|
65
|
+
const { name, arguments: args = {} } = req.params;
|
|
66
|
+
const text = (value) => ({ content: [{ type: 'text', text: typeof value === 'string' ? value : JSON.stringify(value) }] });
|
|
67
|
+
if (name === SUBMIT) {
|
|
68
|
+
if (accepted) return { ...text('An answer was already accepted for this step.'), isError: true };
|
|
69
|
+
const errors = outputErrors(cfg.schema, args);
|
|
70
|
+
if (errors.length) return { ...text(`Not accepted: ${errors.slice(0, 5).join('; ')}. Fix it and call submit_output again.`), isError: true };
|
|
71
|
+
writeFileSync(cfg.outputFile, JSON.stringify(args));
|
|
72
|
+
accepted = true;
|
|
73
|
+
return text('Accepted.');
|
|
74
|
+
}
|
|
75
|
+
if (!names.has(name)) return { ...text(`Tool not available: ${name}`), isError: true };
|
|
76
|
+
try {
|
|
77
|
+
return text(await drafted(cfg, 'POST', '/call', { name, args }));
|
|
78
|
+
} catch (err) {
|
|
79
|
+
return { ...text(`Error: ${err.message}`), isError: true };
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
await server.connect(new StdioServerTransport());
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
main().catch((err) => {
|
|
86
|
+
console.error(err.message || err);
|
|
87
|
+
process.exit(1);
|
|
88
|
+
});
|
package/mcp/server.mjs
CHANGED
|
@@ -2830,7 +2830,7 @@ tool('trigger', {
|
|
|
2830
2830
|
executor: z.enum(['queue', 'automation']).optional().describe('[create|update] who runs deliveries: "queue" (default) parks deliveries for a LOCAL agent to poll via pending/claim/complete — this is the Minion hand-off case and what a schedule would use; "automation" runs a skill\'s chain (automationSkill) at a pinned version in Drafted for each delivery, payload as the untrusted input trigger.json — only an org OWNER can create one or move its pin, and the chain must use built-ins Drafted runs (template@1, approval@1, when:). There is no webhook executor: the public ingress was retired on 2026-10-25.'),
|
|
2831
2831
|
automationSkill: z.string().optional().describe('[create|update, executor=automation] the skill whose chain runs: its slug or id, in the project\'s org.'),
|
|
2832
2832
|
automationChain: z.string().optional().describe('[create|update, executor=automation] which named chain (default "default").'),
|
|
2833
|
-
automationSkillVersion: z.number().optional().describe('[create|update, executor=automation] the
|
|
2833
|
+
automationSkillVersion: z.number().optional().describe('[create|update, executor=automation] the skill version to run (default: the skill\'s published version, else its current one). One version runs for every automation of a skill, so pinning one publishes it and moves the skill\'s other automation triggers too: owner only.'),
|
|
2834
2834
|
deliveryId: z.string().optional().describe('[complete] delivery ID returned by claim'),
|
|
2835
2835
|
ok: z.boolean().optional().describe('[complete] whether the claimed work succeeded (default true)'),
|
|
2836
2836
|
error: z.string().optional().describe('[complete] error note when ok=false'),
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drafted",
|
|
3
|
-
"version": "1.25.
|
|
3
|
+
"version": "1.25.6",
|
|
4
4
|
"description": "Drafted — visual thinking surface for humans and AI agents. Renders HTML, markdown, images, and code as frames on a zoomable canvas, with MCP tools for AI agents and real-time sync for humans.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"drafted": "cli/drafted.mjs",
|
|
8
|
-
"drafted-mcp": "mcp/server.mjs"
|
|
8
|
+
"drafted-mcp": "mcp/server.mjs",
|
|
9
|
+
"drafted-flow-tools": "mcp/flow-tools.mjs"
|
|
9
10
|
},
|
|
10
11
|
"files": [
|
|
11
12
|
"cli/",
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check an agent step's answer against the output schema its author wrote
|
|
3
|
+
* (the chain contract's subset: type, properties, required, items, enum,
|
|
4
|
+
* additionalProperties: false). One implementation for every runner: Drafted's
|
|
5
|
+
* in-process agent step and the drafted-flow-tools MCP server a Causeway
|
|
6
|
+
* backend calls both import it, so an answer accepted in one is accepted in the
|
|
7
|
+
* other. Returns a list of problems, empty when the answer fits.
|
|
8
|
+
*/
|
|
9
|
+
export function outputErrors(schema, value, at = 'output') {
|
|
10
|
+
const t = schema.type;
|
|
11
|
+
const ok = t === 'integer' ? Number.isInteger(value)
|
|
12
|
+
: t === 'number' ? typeof value === 'number' && Number.isFinite(value)
|
|
13
|
+
: t === 'array' ? Array.isArray(value)
|
|
14
|
+
: t === 'object' ? !!value && typeof value === 'object' && !Array.isArray(value)
|
|
15
|
+
: typeof value === t;
|
|
16
|
+
if (!ok) return [`${at} must be ${t}`];
|
|
17
|
+
if (schema.enum && !schema.enum.some((e) => e === value)) return [`${at} must be one of ${schema.enum.map((e) => JSON.stringify(e)).join(', ')}`];
|
|
18
|
+
const errs = [];
|
|
19
|
+
if (t === 'object') {
|
|
20
|
+
const props = schema.properties || {};
|
|
21
|
+
for (const r of schema.required || []) if (value[r] === undefined) errs.push(`${at}.${r} is required`);
|
|
22
|
+
for (const [k, v] of Object.entries(value)) {
|
|
23
|
+
if (props[k]) errs.push(...outputErrors(props[k], v, `${at}.${k}`));
|
|
24
|
+
else if (schema.additionalProperties === false) errs.push(`${at}.${k} is not allowed`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (t === 'array') value.forEach((v, i) => errs.push(...outputErrors(schema.items, v, `${at}[${i}]`)));
|
|
28
|
+
return errs;
|
|
29
|
+
}
|