@addai/flows-mcp 0.2.1 → 0.3.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.
Files changed (65) hide show
  1. package/README.md +13 -0
  2. package/dist/bin/install.js +53 -0
  3. package/dist/bin/install.js.map +1 -1
  4. package/dist/client.d.ts +1 -0
  5. package/dist/client.js +19 -2
  6. package/dist/client.js.map +1 -1
  7. package/dist/healing.d.ts +9 -0
  8. package/dist/healing.js +104 -0
  9. package/dist/healing.js.map +1 -0
  10. package/dist/index.js +2 -0
  11. package/dist/index.js.map +1 -1
  12. package/dist/instructions.js +13 -3
  13. package/dist/instructions.js.map +1 -1
  14. package/dist/node-defaults.js +13 -36
  15. package/dist/node-defaults.js.map +1 -1
  16. package/dist/prompts.js +28 -8
  17. package/dist/prompts.js.map +1 -1
  18. package/dist/tools/flows.js +36 -35
  19. package/dist/tools/flows.js.map +1 -1
  20. package/dist/tools/nodes.js +15 -5
  21. package/dist/tools/nodes.js.map +1 -1
  22. package/dist/tools/preview.d.ts +3 -0
  23. package/dist/tools/preview.js +85 -0
  24. package/dist/tools/preview.js.map +1 -0
  25. package/dist/tools/reference.js +2 -2
  26. package/dist/tools/reference.js.map +1 -1
  27. package/dist/validation/enums.d.ts +20 -0
  28. package/dist/validation/enums.js +36 -0
  29. package/dist/validation/enums.js.map +1 -0
  30. package/dist/validation/handles.d.ts +2 -0
  31. package/dist/validation/handles.js +88 -0
  32. package/dist/validation/handles.js.map +1 -0
  33. package/dist/validation/index.d.ts +3 -0
  34. package/dist/validation/index.js +47 -0
  35. package/dist/validation/index.js.map +1 -0
  36. package/dist/validation/nested-ids.d.ts +2 -0
  37. package/dist/validation/nested-ids.js +55 -0
  38. package/dist/validation/nested-ids.js.map +1 -0
  39. package/dist/validation/reachability.d.ts +2 -0
  40. package/dist/validation/reachability.js +62 -0
  41. package/dist/validation/reachability.js.map +1 -0
  42. package/dist/validation/references.d.ts +2 -0
  43. package/dist/validation/references.js +107 -0
  44. package/dist/validation/references.js.map +1 -0
  45. package/dist/validation/shape-rules.d.ts +7 -0
  46. package/dist/validation/shape-rules.js +284 -0
  47. package/dist/validation/shape-rules.js.map +1 -0
  48. package/dist/validation/shape.d.ts +2 -0
  49. package/dist/validation/shape.js +47 -0
  50. package/dist/validation/shape.js.map +1 -0
  51. package/dist/validation/structure.d.ts +2 -0
  52. package/dist/validation/structure.js +137 -0
  53. package/dist/validation/structure.js.map +1 -0
  54. package/dist/validation/syntax.d.ts +2 -0
  55. package/dist/validation/syntax.js +69 -0
  56. package/dist/validation/syntax.js.map +1 -0
  57. package/dist/validation/types.d.ts +49 -0
  58. package/dist/validation/types.js +2 -0
  59. package/dist/validation/types.js.map +1 -0
  60. package/package.json +6 -3
  61. package/skill/SKILL.md +116 -0
  62. package/skill/anti-patterns.md +207 -0
  63. package/skill/node-cheatsheet.md +37 -0
  64. package/skill/recipes.md +308 -0
  65. package/skill/version.txt +1 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@addai/flows-mcp",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "MCP server for +AI Flows - manage flows, nodes, runs, and more via AI assistants",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -12,7 +12,9 @@
12
12
  "scripts": {
13
13
  "build": "tsc",
14
14
  "dev": "tsc --watch",
15
- "start": "node dist/index.js"
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"
16
18
  },
17
19
  "dependencies": {
18
20
  "@modelcontextprotocol/sdk": "^1.12.1",
@@ -34,6 +36,7 @@
34
36
  ],
35
37
  "license": "MIT",
36
38
  "files": [
37
- "dist"
39
+ "dist",
40
+ "skill"
38
41
  ]
39
42
  }
package/skill/SKILL.md ADDED
@@ -0,0 +1,116 @@
1
+ ---
2
+ name: building-aiflows
3
+ description: Use when creating, modifying, or debugging +Ai Flows via the addai-flows MCP — enforces the discover→study→build→preview→validate→test workflow and prevents silent flow breakage
4
+ ---
5
+
6
+ # Building +Ai Flows with the MCP
7
+
8
+ ## When to use
9
+
10
+ Any time you're about to call `mcp__addai-flows__create_flow`, `add_nodes`, `update_node`, `update_flow`, or `publish_flow`. Also use when debugging a flow that isn't producing the output you expect.
11
+
12
+ **If the user says "build me a flow that..." or "add a node for..." or "why is my flow broken", you are in scope.**
13
+
14
+ ## The rigid workflow (do not skip steps)
15
+
16
+ Create a TodoWrite todo per numbered step below, complete in order, mark each done as you finish it.
17
+
18
+ ### 1. Discover (once per session)
19
+ Call `list_node_types()` once. Scan the returned `types` array to see what's available. Note which categories are relevant to the flow you're building.
20
+
21
+ ### 2. Study each node type you'll use
22
+ For EVERY unique node type you plan to add, call `get_node_type_info(node_type)` FIRST. Read carefully:
23
+ - `defaultData` — the exact fields you need to set
24
+ - `handles.source` — for branching nodes, the allowed `source_handle` values
25
+ - `outputShape` — the fields you can reference downstream via `{{nodeId.field}}`
26
+ - `tips` — gotchas the registry has seen before
27
+
28
+ If it's a `page` node, also call `list_page_elements` and `get_page_element_info(element_type)` for each form element you'll use.
29
+
30
+ ### 3. Scaffold the flow
31
+ ```
32
+ create_flow({ name, description, trigger_type }) → { id }
33
+ get_flow({ flow_id }) → capture the trigger node's id
34
+ ```
35
+
36
+ ### 4. Preview before you add
37
+ For the first batch of nodes, call `preview_flow(flow_id, nodes, edges)` — same signature as `add_nodes` but no save. Read the `validation` report. Fix any errors BEFORE calling `add_nodes`. Zero canvas churn while you iterate.
38
+
39
+ ### 5. Add in small chunks
40
+ Use `add_nodes(flow_id, nodes, edges)` with `temp_id` for cross-references. **Every nested item needs an id** (the server auto-heals, but set them explicitly when you can):
41
+ - `if.conditions[].id`
42
+ - `switch.cases[].id` AND `switch.cases[].conditions[].id`
43
+ - `map.mappings[].id`
44
+ - `review.options[].id` AND `review.fields[].id`
45
+ - `page.elements[].id` AND `page.abandonments[].id`
46
+ - `splitTest.variants[].id`
47
+
48
+ Use the temp_id → real_id mapping from the response when adding more nodes that reference these.
49
+
50
+ ### 6. Wire branching edges with correct handles
51
+ For any edge from a branching node, `source_handle` is **mandatory**:
52
+
53
+ | Type | Required source_handle values |
54
+ |------|-------------------------------|
55
+ | `if` | `"true"` or `"false"` |
56
+ | `switch` | each case's `outputLabel`, plus `"default"` if `hasDefault` |
57
+ | `loop` | `"loop"` (per iteration), `"done"` (after), `"fail"` (only if enableFailRoute) |
58
+ | `review` | option ids: `"option_0"`, `"option_1"`, ... |
59
+ | `page` | `"right"` (submission) or an abandonment id |
60
+ | `splitTest` | variant label strings: `"Variant A"`, `"Variant B"`, ... |
61
+
62
+ ### 7. Validate
63
+ Call `validate_flow(flow_id)`. Read EVERY diagnostic. Fix every `severity: "error"` entry before moving on — each includes `node_id` and `path` pointing exactly at what to fix. Warnings are worth reading but not blocking.
64
+
65
+ ### 8. Describe (sanity check)
66
+ Call `describe_flow(flow_id)` to see the graph shape in compact form. Confirm the trigger, node set, and edges with handles are what you intended.
67
+
68
+ ### 9. Test
69
+ Call `test_flow(flow_id, input_data)` with a realistic payload matching the trigger's expected input. The tool polls until the run completes and returns every node's output.
70
+
71
+ Read each node's output:
72
+ - Did the expected number of nodes run?
73
+ - Does each node's output match its `outputShape` from step 2?
74
+ - If a node failed, its output contains an `error` field — use that + the node's config to diagnose.
75
+
76
+ ### 10. Debug loop (if test fails)
77
+ - Failed node's output → compare against its `outputShape`
78
+ - Trace variable references: for each `{{nodeId.path}}`, confirm the upstream node ran and produced that path
79
+ - Fix with `update_node(flow_id, node_id, data)` — data is merged, not replaced
80
+ - Re-run step 7 (validate) then step 9 (test). Never skip straight back to publish.
81
+
82
+ ### 11. Publish
83
+ Only after step 9 returns `status: "completed"` with every node succeeding, call `publish_flow(flow_id)`.
84
+
85
+ ---
86
+
87
+ ## Red-flag thoughts (stop and course-correct)
88
+
89
+ | Thought | Reality |
90
+ |---------|---------|
91
+ | "I know this node type, skip `get_node_type_info`" | The registry has required fields and handle names you don't remember exactly. Call it. |
92
+ | "Simple flow, skip `validate_flow`" | Simple flows have silent handle mismatches and missing IDs. Validate every time. |
93
+ | "Tests take too long, user can test" | You own correctness. Test before claiming done. |
94
+ | "I'll use `{{trigger.body.x}}` in this code node, it's cleaner" | Code sandboxes don't expand templates. You'll get the literal string. Use `$("nodeId")`. |
95
+ | "preview_flow is redundant with add_nodes" | Preview catches errors without churning the canvas. Use it for the first batch at minimum. |
96
+ | "I'll fix the warnings later" | Warnings often point at real bugs (unknown variable, unreachable goal). Read them. |
97
+
98
+ ---
99
+
100
+ ## Three-system variable cheat sheet
101
+
102
+ | Where | Syntax | Example |
103
+ |-------|--------|---------|
104
+ | **Config fields** (URL, body, headers, conditions, element defaults) | `{{nodeId.field}}` or `{{Variables.varName}}` | `url: "https://api.x/{{abc-123.body.id}}"` |
105
+ | **Code node `code`** | `$("nodeId")` — returns that node's full output object | `const t = $("abc-123"); return { id: t.body.id }` |
106
+ | **Custom node code** | `inputs.keyName` (pre-resolved), `secrets.keyName` | `const key = secrets.api_key` |
107
+
108
+ **Never mix:** `$()` in a config field is an error. `{{}}` in code is a warning (it's a literal string, won't resolve).
109
+
110
+ ---
111
+
112
+ ## See also
113
+
114
+ - `recipes.md` — 8 copy-paste working patterns
115
+ - `anti-patterns.md` — the specific wrong/right examples for the four failure modes
116
+ - `node-cheatsheet.md` — one-row-per-type quick reference
@@ -0,0 +1,207 @@
1
+ # Anti-Patterns — Four Failure Modes
2
+
3
+ For each mode: a wrong example, why it breaks, the correct version.
4
+
5
+ ---
6
+
7
+ ## 1. Wrong config shape
8
+
9
+ **Wrong:**
10
+ ```
11
+ add_nodes({
12
+ flow_id: "...",
13
+ nodes: [{
14
+ type: "httpRequest",
15
+ data: {
16
+ url: "https://api.example.com/data",
17
+ method: "get", // ← lowercase — will be healed but illegal if healing fails
18
+ bodyType: "JSON", // ← uppercase — illegal
19
+ body: "not json", // ← invalid JSON when bodyType is "json"
20
+ authentication: { type: "Bearer", token: "x" } // ← "Bearer" not in enum
21
+ }
22
+ }]
23
+ })
24
+ ```
25
+
26
+ **Why it breaks:** the enum values `method`, `bodyType`, `authentication.type` are case-sensitive and constrained. `validate_flow` catches all three. The body will silently stringify "not json" and the downstream API call will fail.
27
+
28
+ **Right:**
29
+ ```
30
+ // Step 2 of workflow: study first
31
+ get_node_type_info("httpRequest") // See exact enum values
32
+
33
+ // Step 5: correct shape
34
+ add_nodes({
35
+ flow_id: "...",
36
+ nodes: [{
37
+ type: "httpRequest",
38
+ data: {
39
+ url: "https://api.example.com/data",
40
+ method: "GET",
41
+ bodyType: "none",
42
+ authentication: { type: "bearer", token: "{{Variables.apiKey}}" }
43
+ }
44
+ }]
45
+ })
46
+ ```
47
+
48
+ ---
49
+
50
+ ## 2. Missing IDs on nested items
51
+
52
+ **Wrong:**
53
+ ```
54
+ add_nodes({
55
+ flow_id: "...",
56
+ nodes: [{
57
+ type: "if",
58
+ data: {
59
+ conditions: [
60
+ { leftValue: "{{trigger.body.status}}", operator: "equals", rightValue: "active" }
61
+ // ← no id — UI evaluation order becomes non-deterministic, editor breaks
62
+ ],
63
+ conditionLogic: "and"
64
+ }
65
+ }]
66
+ })
67
+ ```
68
+
69
+ **Why it breaks:** conditions without `id` confuse the evaluation engine and the canvas editor can't render them. The server auto-heals now, but you'll see the `_healed` entry in the response — that's a hint your caller pattern is wrong.
70
+
71
+ **Right:**
72
+ ```
73
+ add_nodes({
74
+ flow_id: "...",
75
+ nodes: [{
76
+ type: "if",
77
+ data: {
78
+ conditions: [{
79
+ id: crypto.randomUUID(),
80
+ leftValue: "{{trigger.body.status}}",
81
+ operator: "equals",
82
+ rightValue: "active",
83
+ dataType: "string"
84
+ }],
85
+ conditionLogic: "and"
86
+ }
87
+ }]
88
+ })
89
+ ```
90
+
91
+ Every nested item — conditions, cases (+ their conditions), mappings, options, elements, abandonments, variants, fields — needs an explicit `id`.
92
+
93
+ ---
94
+
95
+ ## 3. Broken edge handles
96
+
97
+ **Wrong:**
98
+ ```
99
+ add_nodes({
100
+ flow_id: "...",
101
+ nodes: [
102
+ { type: "if", temp_id: "check" },
103
+ { type: "goal", temp_id: "ok" },
104
+ { type: "exit", temp_id: "fail" }
105
+ ],
106
+ edges: [
107
+ { source: "check", target: "ok" }, // ← no source_handle — error
108
+ { source: "check", target: "fail" } // ← no source_handle — error
109
+ ]
110
+ })
111
+ ```
112
+
113
+ **Why it breaks:** `if` nodes branch on `true`/`false`. Without a `source_handle`, the engine doesn't know which branch this edge belongs to. `validate_flow` returns `missing_handle` for both.
114
+
115
+ **Right:**
116
+ ```
117
+ add_nodes({
118
+ flow_id: "...",
119
+ nodes: [
120
+ { type: "if", temp_id: "check", data: { conditions: [...], conditionLogic: "and" } },
121
+ { type: "goal", temp_id: "ok", data: { goalName: "approved" } },
122
+ { type: "exit", temp_id: "fail", data: { exitName: "rejected" } }
123
+ ],
124
+ edges: [
125
+ { source: "check", target: "ok", source_handle: "true" },
126
+ { source: "check", target: "fail", source_handle: "false" }
127
+ ]
128
+ })
129
+ ```
130
+
131
+ For switch: `source_handle` must match a case's `outputLabel` (or `"default"`).
132
+ For loop: `"loop"`, `"done"`, or `"fail"` (only if `enableFailRoute: true`).
133
+ For review: the option's `id` (e.g. `"option_0"`).
134
+ For page: `"right"` or an abandonment id.
135
+ For splitTest: the variant's `label` string.
136
+
137
+ ---
138
+
139
+ ## 4. Bad variable references
140
+
141
+ **Wrong:**
142
+ ```
143
+ add_nodes({
144
+ flow_id: "...",
145
+ nodes: [
146
+ {
147
+ type: "httpRequest",
148
+ temp_id: "api",
149
+ data: {
150
+ url: "https://api.x/$(\"trigger\").body.id", // ← $() in config field
151
+ method: "GET"
152
+ }
153
+ },
154
+ {
155
+ type: "code",
156
+ temp_id: "process",
157
+ data: {
158
+ code: "return { result: \"{{trigger.body.id}}\" }", // ← {{}} in code body
159
+ mode: "runOnce"
160
+ }
161
+ },
162
+ {
163
+ type: "httpRequest",
164
+ temp_id: "api2",
165
+ data: {
166
+ url: "https://api.x/{{ghostNodeId.data}}", // ← nodeId doesn't exist
167
+ method: "GET"
168
+ }
169
+ }
170
+ ]
171
+ })
172
+ ```
173
+
174
+ **Why it breaks:**
175
+ - `$()` in a config field is a literal string — templates use `{{}}`. `validate_flow` flags `dollar_in_config`.
176
+ - `{{}}` in a code body is a literal string inside JS — code nodes resolve fields via `$("nodeId")`. `validate_flow` warns `template_in_code`.
177
+ - `ghostNodeId` references a node that doesn't exist. `validate_flow` errors `unknown_node_reference`.
178
+
179
+ **Right:**
180
+ ```
181
+ add_nodes({
182
+ flow_id: "...",
183
+ nodes: [
184
+ {
185
+ type: "httpRequest",
186
+ temp_id: "api",
187
+ data: {
188
+ url: "https://api.x/{{trigger-real-id.body.id}}", // config: {{}}
189
+ method: "GET"
190
+ }
191
+ },
192
+ {
193
+ type: "code",
194
+ temp_id: "process",
195
+ data: {
196
+ code: `
197
+ const t = $("trigger-real-id"); // code: $()
198
+ return { result: t.body.id };
199
+ `,
200
+ mode: "runOnce"
201
+ }
202
+ }
203
+ ]
204
+ })
205
+ ```
206
+
207
+ For custom nodes, use `inputs.keyName` inside the code body (inputs are pre-resolved from `{{}}` by the engine).
@@ -0,0 +1,37 @@
1
+ # Node Cheatsheet — Auto-Generated
2
+
3
+ > Generated from NODE_TYPES at build time. Do NOT edit by hand — changes will be overwritten.
4
+
5
+ | Type | Category | Required fields | Source handles | Key output fields | Gotcha |
6
+ |------|----------|-----------------|----------------|-------------------|--------|
7
+ | `trigger` | triggers | — | (default) | `body`, `headers`, `query`, `method` | The webhook URL is auto-generated after the flow is published |
8
+ | `scheduleTrigger` | triggers | — | (default) | `scheduledTime`, `scheduleType` | intervalUnit options: seconds, minutes, hours, days |
9
+ | `tablesSchedule` | triggers | — | (default) | `scheduledTime`, `databaseId`, `tableId` | — |
10
+ | `tableButton` | triggers | — | (default) | `row`, `rowId`, `tableId`, `columnId` | — |
11
+ | `tableActionTrigger` | triggers | — | (default) | `row`, `rowId`, `buttonId`, `databaseId` | — |
12
+ | `batchActionTrigger` | triggers | — | (default) | `row`, `rowId`, `actionId`, `databaseId` | — |
13
+ | `tableTrigger` | triggers | — | (default) | `event`, `row`, `oldRow`, `rowId` | — |
14
+ | `emailTrigger` | triggers | — | (default) | `from`, `to`, `subject`, `text` | — |
15
+ | `httpRequest` | processing | url, method | (default) | `status`, `body`, `headers`, `success` | URL supports {{nodeId.field}} templates, e.g. "https://api.example.com/users/... |
16
+ | `respondToWebhook` | processing | — | (default) | `success`, `statusCode`, `responseBody`, `skipped` | Must be used in a flow that starts with a Webhook Trigger |
17
+ | `code` | processing | code, mode | `right` | `<user-defined>` | Always return an object: return { result: data } |
18
+ | `map` | processing | mappings | (default) | `<outputName>`, `_metadata`, `transformMode` | inputExpression supports {{nodeId.field}} template syntax |
19
+ | `if` | logic | conditions, conditionLogic | `true`, `false` | `conditionMet`, `evaluatedConditions`, `logicOperator` | leftValue and rightValue support {{nodeId.field}} templates |
20
+ | `switch` | logic | cases | `<case.outputLabel>`, `default` | `matchedHandles`, `matchedCaseLabels`, `hasDefault`, `mode` | source_handle must match the case's outputLabel value (e.g. "case-0") |
21
+ | `wait` | logic | waitType | (default) | `type`, `duration`, `completedAt`, `pauseInDatabase` | durationUnit options: seconds, minutes, hours, days |
22
+ | `flow` | logic | flowId | (default) | `flowId`, `flowName`, `runId`, `waitedForCompletion` | body supports {{}} templates for passing dynamic data to the child flow |
23
+ | `goal` | logic | — | (default) | `goalName`, `isEndNode`, `endType`, `success` | Goal nodes have no output handles — they terminate the flow path |
24
+ | `exit` | logic | — | (default) | `exitName`, `isEndNode`, `endType`, `success` | Exit nodes have no output handles — they terminate the flow path |
25
+ | `review` | logic | options | `option_0`, `option_1`, `option_N` | `selectedOption`, `selectedOptionLabel`, `reviewData`, `respondedBy` | source_handle must match the option's id (e.g. "option_0" for Approve) |
26
+ | `page` | logic | — | `right`, `<abandonment.id>` | `submissionData`, `submittedDate`, `status`, `activeHandle` | Use source_handle "right" for the submission path |
27
+ | `loop` | logic | arraySources | `loop`, `done`, `fail` | `items`, `totalItems`, `currentItem`, `currentIndex` | arraySources uses {{nodeId.field}} syntax, e.g. ["{{httpRequestId.body.data}}"] |
28
+ | `subflow` | logic | — | (default) | — | Subflows are purely visual — they don't change execution behavior |
29
+ | `variable` | logic | action | (default) | `action`, `variableName`, `previousValue`, `newValue` | Reference variables in other node config fields as {{Variables.varName}} |
30
+ | `splitTest` | logic | variants | `Variant A`, `Variant B` | `selectedHandle`, `selectedLabel`, `selectedVariantId` | source_handle must match the variant's label string (e.g. "Variant A") |
31
+ | `customNode` | custom | — | (default) | `<defined by output_schema>` | Custom node code uses inputs.keyName, NOT $("nodeId") — $() is only for inlin... |
32
+ | `note` | utility | — | (default) | — | Notes are not connected to the flow — they are visual only |
33
+
34
+ ---
35
+
36
+ For full per-type detail (defaultData, tips, guide), call `get_node_type_info(type)` at runtime.
37
+ For form element types, call `list_page_elements` and `get_page_element_info(element_type)`.