@addai/flows-mcp 1.1.0-rc.1 → 1.2.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 +190 -190
- package/dist/client.d.ts +5 -0
- package/dist/client.js +19 -4
- package/dist/client.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/instructions.js +151 -150
- package/dist/instructions.js.map +1 -1
- package/dist/oauth.js +3 -3
- package/dist/prompts.js +728 -728
- package/dist/tools/runs.js +51 -37
- package/dist/tools/runs.js.map +1 -1
- package/dist/tools/workspaces.d.ts +2 -1
- package/dist/tools/workspaces.js +47 -4
- package/dist/tools/workspaces.js.map +1 -1
- package/dist/v2-client.d.ts +5 -0
- package/dist/v2-client.js +11 -0
- package/dist/v2-client.js.map +1 -1
- package/package.json +42 -42
- package/skill/SKILL.md +89 -89
- package/skill/anti-patterns.md +285 -285
- package/skill/flow-semantics.md +142 -142
- package/skill/recipes.md +294 -294
package/dist/tools/runs.js
CHANGED
|
@@ -30,22 +30,32 @@ export function registerRunTools(server, client) {
|
|
|
30
30
|
if (!runId) {
|
|
31
31
|
return { content: [{ type: 'text', text: JSON.stringify({ error: 'No run_id returned', response: testResult }, null, 2) }] };
|
|
32
32
|
}
|
|
33
|
-
// 2. Poll until completion
|
|
34
|
-
|
|
33
|
+
// 2. Poll until completion.
|
|
34
|
+
// Poll via list-runs (GET /v1/flows/:id/runs) rather than get-run
|
|
35
|
+
// (GET /v1/runs/:id): list-runs returns the full run — including
|
|
36
|
+
// node_outputs — and stays available on backends where the single-run
|
|
37
|
+
// endpoint is not. A flow that reaches a Goal/Exit node finishes with
|
|
38
|
+
// status "goal"/"exit", so those are terminal alongside the generic
|
|
39
|
+
// completed/failed/cancelled states — otherwise a successful run is
|
|
40
|
+
// never recognised as done and always reports a false timeout.
|
|
41
|
+
const terminalStatuses = ['completed', 'goal', 'exit', 'failed', 'cancelled', 'error'];
|
|
35
42
|
let runData = null;
|
|
36
43
|
const startTime = Date.now();
|
|
37
44
|
while (Date.now() - startTime < maxWait) {
|
|
38
|
-
await new Promise(resolve => setTimeout(resolve, pollInterval));
|
|
39
45
|
try {
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
46
|
+
const runsResult = await client.listFlowRuns(flow_id);
|
|
47
|
+
const runs = runsResult.data || [];
|
|
48
|
+
const match = runs.find((r) => r.id === runId);
|
|
49
|
+
if (match) {
|
|
50
|
+
runData = match;
|
|
51
|
+
if (terminalStatuses.includes(runData.status))
|
|
52
|
+
break;
|
|
44
53
|
}
|
|
45
54
|
}
|
|
46
55
|
catch {
|
|
47
|
-
// Run may not be queryable yet, keep polling
|
|
56
|
+
// Run may not be queryable yet, keep polling.
|
|
48
57
|
}
|
|
58
|
+
await new Promise(resolve => setTimeout(resolve, pollInterval));
|
|
49
59
|
}
|
|
50
60
|
if (!runData || !terminalStatuses.includes(runData.status)) {
|
|
51
61
|
return {
|
|
@@ -54,62 +64,66 @@ export function registerRunTools(server, client) {
|
|
|
54
64
|
text: JSON.stringify({
|
|
55
65
|
status: 'timeout',
|
|
56
66
|
run_id: runId,
|
|
57
|
-
message: `Flow did not complete within ${timeout_seconds || 120}s. Current status: ${runData?.status || 'unknown'}. Use get_run("${runId}") to check later.`
|
|
67
|
+
message: `Flow did not complete within ${timeout_seconds || 120}s. Current status: ${runData?.status || 'unknown'}. Use list_runs(flow_id) or get_run("${runId}") to check later.`
|
|
58
68
|
}, null, 2)
|
|
59
69
|
}]
|
|
60
70
|
};
|
|
61
71
|
}
|
|
62
|
-
// 3.
|
|
72
|
+
// 3. Node execution summary (status + timing per node).
|
|
63
73
|
let nodeLogs = [];
|
|
64
74
|
try {
|
|
65
75
|
const logsResult = await client.getNodeLogsSummary(runId);
|
|
66
76
|
nodeLogs = logsResult.data || [];
|
|
67
77
|
}
|
|
68
78
|
catch {
|
|
69
|
-
// Logs may not be available
|
|
79
|
+
// Logs may not be available.
|
|
70
80
|
}
|
|
71
|
-
// 4.
|
|
81
|
+
// 4. Attach each node's output. Prefer the outputs already embedded in
|
|
82
|
+
// the run (keyed by node label, or by id for lightweight summaries);
|
|
83
|
+
// fall back to the per-node output endpoint when they aren't present.
|
|
84
|
+
const embedded = runData.node_outputs || {};
|
|
72
85
|
const nodeOutputs = {};
|
|
73
86
|
for (const log of nodeLogs) {
|
|
74
87
|
const nodeId = log.node_id;
|
|
75
88
|
if (!nodeId)
|
|
76
89
|
continue;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
output
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
label: log.node_label || log.node_type,
|
|
90
|
-
type: log.node_type,
|
|
91
|
-
status: log.status,
|
|
92
|
-
duration_ms: log.duration_ms,
|
|
93
|
-
output: null,
|
|
94
|
-
error: 'Failed to fetch output'
|
|
95
|
-
};
|
|
90
|
+
let output = embedded[log.node_label] ?? embedded[nodeId];
|
|
91
|
+
// Skip the lightweight "_summary" placeholders keyed by node id.
|
|
92
|
+
if (output && output._summary)
|
|
93
|
+
output = undefined;
|
|
94
|
+
if (output === undefined) {
|
|
95
|
+
try {
|
|
96
|
+
const outputResult = await client.getNodeLogOutput(runId, nodeId);
|
|
97
|
+
output = outputResult.data;
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
output = null;
|
|
101
|
+
}
|
|
96
102
|
}
|
|
103
|
+
nodeOutputs[nodeId] = {
|
|
104
|
+
label: log.node_label || log.node_type,
|
|
105
|
+
type: log.node_type,
|
|
106
|
+
status: log.status,
|
|
107
|
+
duration_ms: log.duration_ms,
|
|
108
|
+
output: output ?? null,
|
|
109
|
+
...(output === null ? { error: 'Failed to fetch output' } : {})
|
|
110
|
+
};
|
|
97
111
|
}
|
|
98
112
|
// 5. Build summary
|
|
99
113
|
const summary = {
|
|
100
114
|
run_id: runId,
|
|
101
115
|
flow_id: flow_id,
|
|
102
116
|
status: runData.status,
|
|
103
|
-
started_at: runData.started_at || runData.created_date,
|
|
104
|
-
completed_at: runData.completed_at || runData.updated_date,
|
|
117
|
+
started_at: runData.started_at || runData.started_date || runData.created_date,
|
|
118
|
+
completed_at: runData.completed_at || runData.completed_date || runData.updated_date,
|
|
105
119
|
node_count: nodeLogs.length,
|
|
106
120
|
nodes: nodeOutputs
|
|
107
121
|
};
|
|
108
|
-
// Include error info if
|
|
109
|
-
if (
|
|
110
|
-
summary.error = runData.error || runData.node_outputs?.error;
|
|
122
|
+
// Include error info if the run did not succeed.
|
|
123
|
+
if (['failed', 'error', 'cancelled'].includes(runData.status)) {
|
|
124
|
+
summary.error = runData.error || runData.error_message || runData.node_outputs?.error;
|
|
111
125
|
// Find which node failed
|
|
112
|
-
const failedNode = nodeLogs.find(l => l.status === 'error' || l.status === 'failed');
|
|
126
|
+
const failedNode = nodeLogs.find((l) => l.status === 'error' || l.status === 'failed');
|
|
113
127
|
if (failedNode) {
|
|
114
128
|
summary.failed_node = {
|
|
115
129
|
id: failedNode.node_id,
|
package/dist/tools/runs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runs.js","sourceRoot":"","sources":["../../src/tools/runs.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,MAAM,UAAU,gBAAgB,CAAC,MAAiB,EAAE,MAAsB;IAExE,MAAM,CAAC,IAAI,CACT,UAAU,EACV,8GAA8G,EAC9G;QACE,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,oBAAoB,CAAC;QAClD,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,iCAAiC,CAAC;KACrF,EACD,KAAK,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE;Q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B,CAAC;KACpF,EACD,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE;QAC3B,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAQ,CAAC;QAC7D,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;IAClH,CAAC,CACF,CAAC;IAEF,MAAM,CAAC,IAAI,CACT,gBAAgB,EAChB,6EAA6E,EAC7E,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,EAC7C,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;QACnB,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,MAAM,CAAQ,CAAC;QAC9D,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;IACrF,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
2
|
import type { FlowsApiClient } from '../client.js';
|
|
3
|
-
|
|
3
|
+
import type { McpV2Client } from '../v2-client.js';
|
|
4
|
+
export declare function registerWorkspaceTools(server: McpServer, client: FlowsApiClient, v2: McpV2Client): void;
|
package/dist/tools/workspaces.js
CHANGED
|
@@ -1,6 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
function asText(value) {
|
|
3
|
+
return { content: [{ type: 'text', text: JSON.stringify(value, null, 2) }] };
|
|
4
|
+
}
|
|
5
|
+
// list_workspaces itself lives in tools/discover.ts (MCP v2 surface). This module
|
|
6
|
+
// owns workspace SELECTION, which must update BOTH clients so every subsequent
|
|
7
|
+
// request (Cloud Run and mcp-v2) targets the chosen workspace via X-Workspace-Id.
|
|
8
|
+
export function registerWorkspaceTools(server, client, v2) {
|
|
9
|
+
server.tool('set_active_workspace', 'Choose which workspace subsequent flow operations act in. The API key must be '
|
|
10
|
+
+ 'authorized for it — call list_workspaces first to see the allowed ids and which is '
|
|
11
|
+
+ 'default. Pass a workspace_id, or null to reset to the key default. Applies to every '
|
|
12
|
+
+ 'later tool call in this session.', {
|
|
13
|
+
workspace_id: z
|
|
14
|
+
.string()
|
|
15
|
+
.nullable()
|
|
16
|
+
.describe('Target workspace id from list_workspaces, or null to reset to the key default'),
|
|
17
|
+
}, async ({ workspace_id }) => {
|
|
18
|
+
if (!workspace_id) {
|
|
19
|
+
client.setActiveWorkspace(null);
|
|
20
|
+
v2.setActiveWorkspace(null);
|
|
21
|
+
return asText({ ok: true, active_workspace_id: null, note: 'Reset to the key default workspace.' });
|
|
22
|
+
}
|
|
23
|
+
// Validate against the workspaces this key may actually access.
|
|
24
|
+
let list = [];
|
|
25
|
+
try {
|
|
26
|
+
const res = await client.listWorkspaces();
|
|
27
|
+
list = Array.isArray(res) ? res : (res?.data ?? []);
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
return asText({
|
|
31
|
+
ok: false,
|
|
32
|
+
error: `Could not verify workspace access: ${err instanceof Error ? err.message : String(err)}`,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
const match = list.find((w) => w?.id === workspace_id);
|
|
36
|
+
if (!match) {
|
|
37
|
+
return asText({
|
|
38
|
+
ok: false,
|
|
39
|
+
error: `This API key is not authorized for workspace ${workspace_id}.`,
|
|
40
|
+
available_workspaces: list,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
client.setActiveWorkspace(workspace_id);
|
|
44
|
+
v2.setActiveWorkspace(workspace_id);
|
|
45
|
+
return asText({ ok: true, active_workspace: match });
|
|
46
|
+
});
|
|
47
|
+
server.tool('get_active_workspace', 'Return the workspace id that subsequent operations act in (null = the key default).', {}, async () => asText({ active_workspace_id: client.getActiveWorkspace() }));
|
|
5
48
|
}
|
|
6
49
|
//# sourceMappingURL=workspaces.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workspaces.js","sourceRoot":"","sources":["../../src/tools/workspaces.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"workspaces.js","sourceRoot":"","sources":["../../src/tools/workspaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,SAAS,MAAM,CAAC,KAAc;IAC5B,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;AAC/E,CAAC;AAED,kFAAkF;AAClF,+EAA+E;AAC/E,kFAAkF;AAClF,MAAM,UAAU,sBAAsB,CAAC,MAAiB,EAAE,MAAsB,EAAE,EAAe;IAC/F,MAAM,CAAC,IAAI,CACT,sBAAsB,EACtB,gFAAgF;UAC5E,qFAAqF;UACrF,sFAAsF;UACtF,kCAAkC,EACtC;QACE,YAAY,EAAE,CAAC;aACZ,MAAM,EAAE;aACR,QAAQ,EAAE;aACV,QAAQ,CAAC,+EAA+E,CAAC;KAC7F,EACD,KAAK,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE;QACzB,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,MAAM,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;YAChC,EAAE,CAAC,kBAAkB,CAAC,IAAI,CA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rF,EAAE,EACF,KAAK,IAAI,EAAE,CAAC,MAAM,CAAC,EAAE,mBAAmB,EAAE,MAAM,CAAC,kBAAkB,EAAE,EAAE,CAAC,CACzE,CAAC;AACJ,CAAC"}
|
package/dist/v2-client.d.ts
CHANGED
|
@@ -38,7 +38,12 @@ export declare class McpV2Client {
|
|
|
38
38
|
private readonly sessionId;
|
|
39
39
|
private readonly catalogCache;
|
|
40
40
|
private readonly flowEtags;
|
|
41
|
+
private activeWorkspaceId;
|
|
41
42
|
constructor(apiKey: string, baseUrl: string);
|
|
43
|
+
/** Set the workspace this session operates in (null = key default). */
|
|
44
|
+
setActiveWorkspace(workspaceId: string | null): void;
|
|
45
|
+
/** The workspace this session is currently operating in, if any. */
|
|
46
|
+
getActiveWorkspace(): string | null;
|
|
42
47
|
get<T>(path: string, opts?: {
|
|
43
48
|
headers?: Record<string, string>;
|
|
44
49
|
}): Promise<McpV2Response<T>>;
|
package/dist/v2-client.js
CHANGED
|
@@ -50,11 +50,21 @@ export class McpV2Client {
|
|
|
50
50
|
sessionId;
|
|
51
51
|
catalogCache = new Map();
|
|
52
52
|
flowEtags = new Map();
|
|
53
|
+
// Workspace this session operates in (sent as X-Workspace-Id). null = default.
|
|
54
|
+
activeWorkspaceId = null;
|
|
53
55
|
constructor(apiKey, baseUrl) {
|
|
54
56
|
this.apiKey = apiKey;
|
|
55
57
|
this.baseUrl = baseUrl.replace(/\/+$/, '');
|
|
56
58
|
this.sessionId = randomUUID();
|
|
57
59
|
}
|
|
60
|
+
/** Set the workspace this session operates in (null = key default). */
|
|
61
|
+
setActiveWorkspace(workspaceId) {
|
|
62
|
+
this.activeWorkspaceId = workspaceId;
|
|
63
|
+
}
|
|
64
|
+
/** The workspace this session is currently operating in, if any. */
|
|
65
|
+
getActiveWorkspace() {
|
|
66
|
+
return this.activeWorkspaceId;
|
|
67
|
+
}
|
|
58
68
|
get(path, opts = {}) {
|
|
59
69
|
return this.request('GET', path, undefined, opts);
|
|
60
70
|
}
|
|
@@ -95,6 +105,7 @@ export class McpV2Client {
|
|
|
95
105
|
const headers = {
|
|
96
106
|
'Authorization': `Bearer ${this.apiKey}`,
|
|
97
107
|
'Content-Type': 'application/json',
|
|
108
|
+
...(this.activeWorkspaceId ? { 'X-Workspace-Id': this.activeWorkspaceId } : {}),
|
|
98
109
|
...(opts.headers ?? {}),
|
|
99
110
|
};
|
|
100
111
|
// ETag cache for catalog reads
|
package/dist/v2-client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"v2-client.js","sourceRoot":"","sources":["../src/v2-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAOhD,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtB,IAAI,CAAS;IACb,MAAM,CAAS;IACf,OAAO,CAAgB;IACvB,SAAS,CAAgB;IACzB,MAAM,CAAgB;IAEtC,YAAY,IAOX;QACC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpB,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC;QACpC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC;QACxC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC;IACpC,CAAC;IAED,MAAM,CAAC,QAAQ,CAAC,IAAS,EAAE,MAAc;QACvC,MAAM,CAAC,GAAG,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC;QAC5B,OAAO,IAAI,aAAa,CAAC;YACvB,IAAI,EAAE,CAAC,CAAC,IAAI,IAAI,eAAe;YAC/B,OAAO,EAAE,CA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ANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@addai/flows-mcp",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "MCP server for +AI Flows - manage flows, nodes, runs, and more via AI assistants",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "dist/index.js",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
8
|
-
"bin": {
|
|
9
|
-
"flows-mcp": "dist/index.js",
|
|
10
|
-
"flows-mcp-install": "dist/bin/install.js"
|
|
11
|
-
},
|
|
12
|
-
"scripts": {
|
|
13
|
-
"build": "tsc",
|
|
14
|
-
"dev": "tsc --watch",
|
|
15
|
-
"start": "node dist/index.js",
|
|
16
|
-
"test": "tsc -p tsconfig.test.json && node --test 'dist-test/test/**/*.test.js'",
|
|
17
|
-
"gen:cheatsheet": "tsc -p tsconfig.test.json --outDir dist-test && node dist-test/scripts/gen-cheatsheet.js"
|
|
18
|
-
},
|
|
19
|
-
"dependencies": {
|
|
20
|
-
"@modelcontextprotocol/sdk": "^1.12.1",
|
|
21
|
-
"zod": "^3.23.0"
|
|
22
|
-
},
|
|
23
|
-
"devDependencies": {
|
|
24
|
-
"typescript": "^5.7.0",
|
|
25
|
-
"@types/node": "^22.0.0"
|
|
26
|
-
},
|
|
27
|
-
"engines": {
|
|
28
|
-
"node": ">=18"
|
|
29
|
-
},
|
|
30
|
-
"keywords": [
|
|
31
|
-
"mcp",
|
|
32
|
-
"ai-flows",
|
|
33
|
-
"addai",
|
|
34
|
-
"claude",
|
|
35
|
-
"model-context-protocol"
|
|
36
|
-
],
|
|
37
|
-
"license": "MIT",
|
|
38
|
-
"files": [
|
|
39
|
-
"dist",
|
|
40
|
-
"skill"
|
|
41
|
-
]
|
|
42
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@addai/flows-mcp",
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "MCP server for +AI Flows - manage flows, nodes, runs, and more via AI assistants",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"flows-mcp": "dist/index.js",
|
|
10
|
+
"flows-mcp-install": "dist/bin/install.js"
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"dev": "tsc --watch",
|
|
15
|
+
"start": "node dist/index.js",
|
|
16
|
+
"test": "tsc -p tsconfig.test.json && node --test 'dist-test/test/**/*.test.js'",
|
|
17
|
+
"gen:cheatsheet": "tsc -p tsconfig.test.json --outDir dist-test && node dist-test/scripts/gen-cheatsheet.js"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@modelcontextprotocol/sdk": "^1.12.1",
|
|
21
|
+
"zod": "^3.23.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"typescript": "^5.7.0",
|
|
25
|
+
"@types/node": "^22.0.0"
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=18"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"mcp",
|
|
32
|
+
"ai-flows",
|
|
33
|
+
"addai",
|
|
34
|
+
"claude",
|
|
35
|
+
"model-context-protocol"
|
|
36
|
+
],
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"files": [
|
|
39
|
+
"dist",
|
|
40
|
+
"skill"
|
|
41
|
+
]
|
|
42
|
+
}
|
package/skill/SKILL.md
CHANGED
|
@@ -1,89 +1,89 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: building-aiflows
|
|
3
|
-
description: Build, test, and publish +Ai Flows automations. Use whenever the user wants to create or modify a flow. Loaded automatically when the @addai/flows-mcp MCP server is connected.
|
|
4
|
-
version: 2.1.0
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# Building +Ai Flows
|
|
8
|
-
|
|
9
|
-
You have access to the +Ai Flows MCP server. This skill teaches you how to use it to build production-quality flows.
|
|
10
|
-
|
|
11
|
-
## Mental model
|
|
12
|
-
|
|
13
|
-
A flow is a **directed graph**: nodes connected by edges. Execution starts at a trigger node and follows edges until it reaches a terminator (goal or exit) or fails.
|
|
14
|
-
|
|
15
|
-
- **Nodes** do work — trigger an event, make an HTTP call, branch on a condition, send an email.
|
|
16
|
-
- **Edges** define order. Most nodes have one outgoing edge. **Branching nodes** (`if`, `switch`, `loop`, `review`, `splitTest`, `aiSwitch`) have multiple, distinguished by `sourceHandle`.
|
|
17
|
-
- **Variables** carry values between nodes via three distinct templating systems (see `flow-semantics.md`).
|
|
18
|
-
|
|
19
|
-
## The rigid workflow
|
|
20
|
-
|
|
21
|
-
You MUST follow this loop. Each step has a named tool.
|
|
22
|
-
|
|
23
|
-
```
|
|
24
|
-
1. DISCOVER → list_node_types, describe_node_type, list_custom_nodes, describe_custom_node
|
|
25
|
-
2. DESIGN → propose_flow (NL → draft) [optional]
|
|
26
|
-
3. BUILD → create_flow, add_nodes, connect_nodes, set_variable
|
|
27
|
-
4. VALIDATE → validate_flow ← MUST PASS BEFORE TESTING
|
|
28
|
-
5. TEST → test_node (per uncertain node), test_flow / dry_run (end-to-end)
|
|
29
|
-
6. DEBUG → diagnose_run, replay_run, tail_logs [if test fails]
|
|
30
|
-
7. PUBLISH → pre_publish_check, then publish_flow / canary_publish
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
**You have not finished if you did not validate and test before publishing.**
|
|
34
|
-
|
|
35
|
-
## Ten rules you must not break
|
|
36
|
-
|
|
37
|
-
1. **Never guess a node's config schema.** Call `describe_node_type(type)` first if you have not used this type in this session.
|
|
38
|
-
2. **NEVER pass a `position` to `add_nodes`. EVER.** It auto-places horizontally (left → right). If you pass positions you will get a vertical-stacked flow that the user has to manually fix. If positions get messy mid-build, call `autolayout` once at the end.
|
|
39
|
-
3. **A `page` node CAN be the terminator** — set `data.isGoal: true` (or `isExit: true`) with a `goalName`. Do NOT add a trailing `goal` node after a page. The page IS the goal. See `describe_node_type("page")` for the full field list.
|
|
40
|
-
4. **Never reuse `{{}}` syntax inside a code node.** Code nodes use `$("nodeId")`. Custom node code uses `inputs.x`. See `flow-semantics.md`.
|
|
41
|
-
5. **Never insert a `customNode` without `customVersionId`.** Custom nodes do not auto-update on publish — explicit version pinning is required.
|
|
42
|
-
6. **Never publish without `pre_publish_check`.** Even if validation passes.
|
|
43
|
-
7. **The flow MUST be horizontal on the canvas.** Trigger on the far left, terminators on the far right. If `validate_flow` returns `LAYOUT_VERTICAL_DRIFT`, fix it before you continue.
|
|
44
|
-
8. **Every form input MUST have a `label`. Every `page` MUST start with a `textBlock` heading.** Forms with empty labels render as unmarked grey rectangles and are unusable. See AP14. Pick the right element type per field (`email`, `shortText`, `longText`, `dropdown`, etc.) — do not use `longText` for short single-line input.
|
|
45
|
-
9. **Every non-terminal `page` MUST include at least one `button` element with `buttonAction: "submit"`.** No button = no way to advance the flow. The button's text field is `buttonText` (NOT `label`). Action values: `submit` / `link` / `stop` / `restart`. See AP15 and AP16.
|
|
46
|
-
10. **Field-name discipline.** Many node types have non-obvious canonical keys. **Always call `describe_node_type(type)` before authoring a node you have not used in this session** — the catalog spells out the real keys. Known traps:
|
|
47
|
-
- `if`/`switch`: condition logic is `logicOperator` (UPPERCASE), not `conditionLogic`. See AP17.
|
|
48
|
-
- `aiSwitch` routes: `context`, not `contextDescription`. See AP18.
|
|
49
|
-
- Page terminal: `goalId` (FK) + `goalName` (display) — not `goalName` alone. See AP19.
|
|
50
|
-
- `httpRequest.authentication.type`: `credential` is real and is the production default. See AP20.
|
|
51
|
-
- `claudeCode`: `offlineBehavior`, `retryConfig`, `fallbackSteps` for production resiliency. See AP21.
|
|
52
|
-
- The MCP validator now raises `UNKNOWN_DATA_KEY` warnings when you write keys not in the catalog — read them and fix.
|
|
53
|
-
|
|
54
|
-
## Tool-by-step quick reference
|
|
55
|
-
|
|
56
|
-
| Step | Tool | Purpose |
|
|
57
|
-
|---|---|---|
|
|
58
|
-
| Discover types | `list_node_types`, `describe_node_type` | What's available, what each node needs |
|
|
59
|
-
| Discover custom | `list_custom_nodes`, `describe_custom_node` | Workspace-specific reusable nodes |
|
|
60
|
-
| Discover layout | `get_layout_config` | Canonical h_spacing / v_spacing constants |
|
|
61
|
-
| Create flow | `create_flow` | New empty flow with trigger node |
|
|
62
|
-
| Add nodes | `add_nodes` | Insert nodes + edges; auto-positions horizontally |
|
|
63
|
-
| Connect | `connect_nodes`, `disconnect_nodes` | Atomic edge ops |
|
|
64
|
-
| Variables | `set_variable`, `list_variables`, `delete_variable` | Atomic per-name; no full flow rewrite |
|
|
65
|
-
| Lay out | `autolayout` | One-call horizontal cleanup |
|
|
66
|
-
| Validate | `validate_flow` | Server-authoritative; errors[] and warnings[] |
|
|
67
|
-
| Test node | `test_node` | Run one node in isolation |
|
|
68
|
-
| Test code | `test_custom_node_code` | Verify custom node code before save |
|
|
69
|
-
| Test flow | `test_flow`, `dry_run` | End-to-end; dry_run suppresses side effects |
|
|
70
|
-
| Debug | `diagnose_run`, `replay_run` (Phase 2), `tail_logs` (Phase 2) | One-call diagnostics; re-execute |
|
|
71
|
-
| Pre-publish | `pre_publish_check` (Phase 2) | Gate: validation + snapshot tests + secret scan |
|
|
72
|
-
| Publish | `publish_flow`, `canary_publish` (Phase 2) | Production rollout |
|
|
73
|
-
| Undo | `undo_last_operation` | Session-scoped stack |
|
|
74
|
-
| Safety | `confirm_intent` | Two-step destructive ops |
|
|
75
|
-
|
|
76
|
-
## How to handle uncertainty
|
|
77
|
-
|
|
78
|
-
If you don't know:
|
|
79
|
-
- **What a node does** → `describe_node_type(type)`. Don't guess.
|
|
80
|
-
- **What fields a custom node needs** → `describe_custom_node(custom_node_id)`. The schema is authoritative.
|
|
81
|
-
- **What a template reference will resolve to** → test the upstream node with `test_node` first.
|
|
82
|
-
- **Whether your config is valid** → `validate_flow`.
|
|
83
|
-
- **Why a run failed** → `diagnose_run(run_id)` (Phase 2). For now: `get_run` + `list_node_logs` + `get_node_output`.
|
|
84
|
-
|
|
85
|
-
Asking the human costs you a turn. The tools above usually answer the question faster than the human would.
|
|
86
|
-
|
|
87
|
-
## Now go
|
|
88
|
-
|
|
89
|
-
Start with `list_node_types`. Then read `flow-semantics.md` for variable systems and edge handles. Then read `recipes.md` for patterns. Then read `anti-patterns.md` to know what NOT to do.
|
|
1
|
+
---
|
|
2
|
+
name: building-aiflows
|
|
3
|
+
description: Build, test, and publish +Ai Flows automations. Use whenever the user wants to create or modify a flow. Loaded automatically when the @addai/flows-mcp MCP server is connected.
|
|
4
|
+
version: 2.1.0
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Building +Ai Flows
|
|
8
|
+
|
|
9
|
+
You have access to the +Ai Flows MCP server. This skill teaches you how to use it to build production-quality flows.
|
|
10
|
+
|
|
11
|
+
## Mental model
|
|
12
|
+
|
|
13
|
+
A flow is a **directed graph**: nodes connected by edges. Execution starts at a trigger node and follows edges until it reaches a terminator (goal or exit) or fails.
|
|
14
|
+
|
|
15
|
+
- **Nodes** do work — trigger an event, make an HTTP call, branch on a condition, send an email.
|
|
16
|
+
- **Edges** define order. Most nodes have one outgoing edge. **Branching nodes** (`if`, `switch`, `loop`, `review`, `splitTest`, `aiSwitch`) have multiple, distinguished by `sourceHandle`.
|
|
17
|
+
- **Variables** carry values between nodes via three distinct templating systems (see `flow-semantics.md`).
|
|
18
|
+
|
|
19
|
+
## The rigid workflow
|
|
20
|
+
|
|
21
|
+
You MUST follow this loop. Each step has a named tool.
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
1. DISCOVER → list_node_types, describe_node_type, list_custom_nodes, describe_custom_node
|
|
25
|
+
2. DESIGN → propose_flow (NL → draft) [optional]
|
|
26
|
+
3. BUILD → create_flow, add_nodes, connect_nodes, set_variable
|
|
27
|
+
4. VALIDATE → validate_flow ← MUST PASS BEFORE TESTING
|
|
28
|
+
5. TEST → test_node (per uncertain node), test_flow / dry_run (end-to-end)
|
|
29
|
+
6. DEBUG → diagnose_run, replay_run, tail_logs [if test fails]
|
|
30
|
+
7. PUBLISH → pre_publish_check, then publish_flow / canary_publish
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
**You have not finished if you did not validate and test before publishing.**
|
|
34
|
+
|
|
35
|
+
## Ten rules you must not break
|
|
36
|
+
|
|
37
|
+
1. **Never guess a node's config schema.** Call `describe_node_type(type)` first if you have not used this type in this session.
|
|
38
|
+
2. **NEVER pass a `position` to `add_nodes`. EVER.** It auto-places horizontally (left → right). If you pass positions you will get a vertical-stacked flow that the user has to manually fix. If positions get messy mid-build, call `autolayout` once at the end.
|
|
39
|
+
3. **A `page` node CAN be the terminator** — set `data.isGoal: true` (or `isExit: true`) with a `goalName`. Do NOT add a trailing `goal` node after a page. The page IS the goal. See `describe_node_type("page")` for the full field list.
|
|
40
|
+
4. **Never reuse `{{}}` syntax inside a code node.** Code nodes use `$("nodeId")`. Custom node code uses `inputs.x`. See `flow-semantics.md`.
|
|
41
|
+
5. **Never insert a `customNode` without `customVersionId`.** Custom nodes do not auto-update on publish — explicit version pinning is required.
|
|
42
|
+
6. **Never publish without `pre_publish_check`.** Even if validation passes.
|
|
43
|
+
7. **The flow MUST be horizontal on the canvas.** Trigger on the far left, terminators on the far right. If `validate_flow` returns `LAYOUT_VERTICAL_DRIFT`, fix it before you continue.
|
|
44
|
+
8. **Every form input MUST have a `label`. Every `page` MUST start with a `textBlock` heading.** Forms with empty labels render as unmarked grey rectangles and are unusable. See AP14. Pick the right element type per field (`email`, `shortText`, `longText`, `dropdown`, etc.) — do not use `longText` for short single-line input.
|
|
45
|
+
9. **Every non-terminal `page` MUST include at least one `button` element with `buttonAction: "submit"`.** No button = no way to advance the flow. The button's text field is `buttonText` (NOT `label`). Action values: `submit` / `link` / `stop` / `restart`. See AP15 and AP16.
|
|
46
|
+
10. **Field-name discipline.** Many node types have non-obvious canonical keys. **Always call `describe_node_type(type)` before authoring a node you have not used in this session** — the catalog spells out the real keys. Known traps:
|
|
47
|
+
- `if`/`switch`: condition logic is `logicOperator` (UPPERCASE), not `conditionLogic`. See AP17.
|
|
48
|
+
- `aiSwitch` routes: `context`, not `contextDescription`. See AP18.
|
|
49
|
+
- Page terminal: `goalId` (FK) + `goalName` (display) — not `goalName` alone. See AP19.
|
|
50
|
+
- `httpRequest.authentication.type`: `credential` is real and is the production default. See AP20.
|
|
51
|
+
- `claudeCode`: `offlineBehavior`, `retryConfig`, `fallbackSteps` for production resiliency. See AP21.
|
|
52
|
+
- The MCP validator now raises `UNKNOWN_DATA_KEY` warnings when you write keys not in the catalog — read them and fix.
|
|
53
|
+
|
|
54
|
+
## Tool-by-step quick reference
|
|
55
|
+
|
|
56
|
+
| Step | Tool | Purpose |
|
|
57
|
+
|---|---|---|
|
|
58
|
+
| Discover types | `list_node_types`, `describe_node_type` | What's available, what each node needs |
|
|
59
|
+
| Discover custom | `list_custom_nodes`, `describe_custom_node` | Workspace-specific reusable nodes |
|
|
60
|
+
| Discover layout | `get_layout_config` | Canonical h_spacing / v_spacing constants |
|
|
61
|
+
| Create flow | `create_flow` | New empty flow with trigger node |
|
|
62
|
+
| Add nodes | `add_nodes` | Insert nodes + edges; auto-positions horizontally |
|
|
63
|
+
| Connect | `connect_nodes`, `disconnect_nodes` | Atomic edge ops |
|
|
64
|
+
| Variables | `set_variable`, `list_variables`, `delete_variable` | Atomic per-name; no full flow rewrite |
|
|
65
|
+
| Lay out | `autolayout` | One-call horizontal cleanup |
|
|
66
|
+
| Validate | `validate_flow` | Server-authoritative; errors[] and warnings[] |
|
|
67
|
+
| Test node | `test_node` | Run one node in isolation |
|
|
68
|
+
| Test code | `test_custom_node_code` | Verify custom node code before save |
|
|
69
|
+
| Test flow | `test_flow`, `dry_run` | End-to-end; dry_run suppresses side effects |
|
|
70
|
+
| Debug | `diagnose_run`, `replay_run` (Phase 2), `tail_logs` (Phase 2) | One-call diagnostics; re-execute |
|
|
71
|
+
| Pre-publish | `pre_publish_check` (Phase 2) | Gate: validation + snapshot tests + secret scan |
|
|
72
|
+
| Publish | `publish_flow`, `canary_publish` (Phase 2) | Production rollout |
|
|
73
|
+
| Undo | `undo_last_operation` | Session-scoped stack |
|
|
74
|
+
| Safety | `confirm_intent` | Two-step destructive ops |
|
|
75
|
+
|
|
76
|
+
## How to handle uncertainty
|
|
77
|
+
|
|
78
|
+
If you don't know:
|
|
79
|
+
- **What a node does** → `describe_node_type(type)`. Don't guess.
|
|
80
|
+
- **What fields a custom node needs** → `describe_custom_node(custom_node_id)`. The schema is authoritative.
|
|
81
|
+
- **What a template reference will resolve to** → test the upstream node with `test_node` first.
|
|
82
|
+
- **Whether your config is valid** → `validate_flow`.
|
|
83
|
+
- **Why a run failed** → `diagnose_run(run_id)` (Phase 2). For now: `get_run` + `list_node_logs` + `get_node_output`.
|
|
84
|
+
|
|
85
|
+
Asking the human costs you a turn. The tools above usually answer the question faster than the human would.
|
|
86
|
+
|
|
87
|
+
## Now go
|
|
88
|
+
|
|
89
|
+
Start with `list_node_types`. Then read `flow-semantics.md` for variable systems and edge handles. Then read `recipes.md` for patterns. Then read `anti-patterns.md` to know what NOT to do.
|