@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/instructions.js
CHANGED
|
@@ -3,155 +3,156 @@
|
|
|
3
3
|
* Sent to the AI client on initialization to provide always-on context
|
|
4
4
|
* about how the flow system works.
|
|
5
5
|
*/
|
|
6
|
-
export const SYSTEM_INSTRUCTIONS = `
|
|
7
|
-
# +Ai Flows — MCP Server Guide
|
|
8
|
-
|
|
9
|
-
You are connected to the +Ai Flows MCP server. This guide explains how to build and manage automation flows correctly.
|
|
10
|
-
|
|
11
|
-
## Variable Syntax — Three Distinct Systems
|
|
12
|
-
|
|
13
|
-
### 1. Config Fields (node data properties like URL, body, conditions, etc.)
|
|
14
|
-
Use double-brace template syntax to reference upstream node outputs or flow variables:
|
|
15
|
-
- \`{{nodeId.fieldName}}\` — reference a specific field from a node's output
|
|
16
|
-
- \`{{nodeId.nested.path}}\` — dot notation for nested data
|
|
17
|
-
- \`{{nodeId.array[0]}}\` — array index access
|
|
18
|
-
- \`{{Variables.myVar}}\` — reference a flow variable
|
|
19
|
-
|
|
20
|
-
### 2. Code Nodes (inline JavaScript in the "code" node type)
|
|
21
|
-
Code runs in a sandbox with these globals — do NOT use \`{{}}\` template syntax in code:
|
|
22
|
-
- \`$("nodeId")\` — lookup any upstream node's output by its node ID. This is the primary way to access data in code nodes.
|
|
23
|
-
- \`console.log()\` — standard logging
|
|
24
|
-
- \`fetch(url, options)\` — HTTP requests (localhost and private IPs are blocked)
|
|
25
|
-
- Code must \`return { key: value }\` — the returned object's keys become the node's output fields
|
|
26
|
-
- In \`runForEachItem\` mode: \`item\` (current array element) and \`index\` (current index) are available
|
|
27
|
-
|
|
28
|
-
### 3. Custom Nodes (user-created reusable nodes)
|
|
29
|
-
Custom node code runs in a separate sandbox — do NOT use \`$()\`:
|
|
30
|
-
- \`inputs.keyName\` — pre-resolved values from input_schema (the flow editor resolves \`{{}}\` templates before execution)
|
|
31
|
-
- \`secrets.keyName\` — secrets from secret_requirements
|
|
32
|
-
- \`fetch(url, options)\` — HTTP requests (restricted to configured domains)
|
|
33
|
-
- Code must \`return { key: value }\` matching the output_schema
|
|
34
|
-
|
|
35
|
-
## Edge Handles — Connecting Branching Nodes
|
|
36
|
-
|
|
37
|
-
Most nodes have a single default output (no source_handle needed). Branching nodes require specific \`source_handle\` values:
|
|
38
|
-
|
|
39
|
-
| Node Type | Source Handles | Notes |
|
|
40
|
-
|-----------|---------------|-------|
|
|
41
|
-
| \`if\` | \`"true"\`, \`"false"\` | Based on condition evaluation |
|
|
42
|
-
| \`switch\` | Case \`outputLabel\` values, \`"default"\` | outputLabel is defined per case in the switch config |
|
|
43
|
-
| \`loop\` | \`"loop"\`, \`"done"\`, \`"fail"\` | "fail" only if \`enableFailRoute: true\` |
|
|
44
|
-
| \`review\` | Option IDs: \`"option_0"\`, \`"option_1"\`, ... | One handle per review option |
|
|
45
|
-
| \`page\` | \`"right"\` (submission), abandonment IDs | Abandonment handles defined in \`abandonments\` array |
|
|
46
|
-
| \`splitTest\` | Variant labels: \`"Variant A"\`, \`"Variant B"\`, ... | Match the variant label strings |
|
|
47
|
-
|
|
48
|
-
### Target Handles
|
|
49
|
-
|
|
50
|
-
Most nodes have a single default \`target_handle\` (no value needed — omit or pass \`null\`). One node type uses a non-default target handle:
|
|
51
|
-
|
|
52
|
-
| Node Type | Target Handles | Notes |
|
|
53
|
-
|-----------|----------------|-------|
|
|
54
|
-
| \`page\` (start form) | \`"return"\` | Top handle on page nodes with \`isStartForm: true\`. Used for loop-back edges that re-enter the start form as an interactive page. Must not originate from a trigger node. |
|
|
55
|
-
|
|
56
|
-
## Referencing Node Outputs Downstream
|
|
57
|
-
|
|
58
|
-
After a node executes, downstream nodes can access its output:
|
|
59
|
-
- In config fields: \`{{nodeId.fieldName}}\` where nodeId is the UUID of the upstream node
|
|
60
|
-
- The available fields depend on the node type — use \`get_node_type_info\` to see the \`outputShape\` for any node type
|
|
61
|
-
- For Page nodes (including isStartForm pages), submission data is at: \`{{nodeId.submissionData.Element Label}}\` (label-keyed). Start-form pages additionally expose \`{{nodeId.formData.<elementId>}}\` (id-keyed raw) and \`{{nodeId.urlParams.foo}}\` (querystring at landing).
|
|
62
|
-
|
|
63
|
-
## Workspace Context
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
- Use \`list_workspaces\` to see
|
|
67
|
-
- If
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
-
|
|
74
|
-
-
|
|
75
|
-
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
- Using \`
|
|
91
|
-
- Using
|
|
92
|
-
-
|
|
93
|
-
-
|
|
94
|
-
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
"
|
|
103
|
-
"
|
|
104
|
-
"
|
|
105
|
-
"
|
|
106
|
-
"
|
|
107
|
-
"
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
"
|
|
126
|
-
"
|
|
127
|
-
"
|
|
128
|
-
"
|
|
129
|
-
"
|
|
130
|
-
"
|
|
131
|
-
"
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
"
|
|
142
|
-
"
|
|
143
|
-
"
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
- \`
|
|
153
|
-
- \`
|
|
154
|
-
|
|
155
|
-
|
|
6
|
+
export const SYSTEM_INSTRUCTIONS = `
|
|
7
|
+
# +Ai Flows — MCP Server Guide
|
|
8
|
+
|
|
9
|
+
You are connected to the +Ai Flows MCP server. This guide explains how to build and manage automation flows correctly.
|
|
10
|
+
|
|
11
|
+
## Variable Syntax — Three Distinct Systems
|
|
12
|
+
|
|
13
|
+
### 1. Config Fields (node data properties like URL, body, conditions, etc.)
|
|
14
|
+
Use double-brace template syntax to reference upstream node outputs or flow variables:
|
|
15
|
+
- \`{{nodeId.fieldName}}\` — reference a specific field from a node's output
|
|
16
|
+
- \`{{nodeId.nested.path}}\` — dot notation for nested data
|
|
17
|
+
- \`{{nodeId.array[0]}}\` — array index access
|
|
18
|
+
- \`{{Variables.myVar}}\` — reference a flow variable
|
|
19
|
+
|
|
20
|
+
### 2. Code Nodes (inline JavaScript in the "code" node type)
|
|
21
|
+
Code runs in a sandbox with these globals — do NOT use \`{{}}\` template syntax in code:
|
|
22
|
+
- \`$("nodeId")\` — lookup any upstream node's output by its node ID. This is the primary way to access data in code nodes.
|
|
23
|
+
- \`console.log()\` — standard logging
|
|
24
|
+
- \`fetch(url, options)\` — HTTP requests (localhost and private IPs are blocked)
|
|
25
|
+
- Code must \`return { key: value }\` — the returned object's keys become the node's output fields
|
|
26
|
+
- In \`runForEachItem\` mode: \`item\` (current array element) and \`index\` (current index) are available
|
|
27
|
+
|
|
28
|
+
### 3. Custom Nodes (user-created reusable nodes)
|
|
29
|
+
Custom node code runs in a separate sandbox — do NOT use \`$()\`:
|
|
30
|
+
- \`inputs.keyName\` — pre-resolved values from input_schema (the flow editor resolves \`{{}}\` templates before execution)
|
|
31
|
+
- \`secrets.keyName\` — secrets from secret_requirements
|
|
32
|
+
- \`fetch(url, options)\` — HTTP requests (restricted to configured domains)
|
|
33
|
+
- Code must \`return { key: value }\` matching the output_schema
|
|
34
|
+
|
|
35
|
+
## Edge Handles — Connecting Branching Nodes
|
|
36
|
+
|
|
37
|
+
Most nodes have a single default output (no source_handle needed). Branching nodes require specific \`source_handle\` values:
|
|
38
|
+
|
|
39
|
+
| Node Type | Source Handles | Notes |
|
|
40
|
+
|-----------|---------------|-------|
|
|
41
|
+
| \`if\` | \`"true"\`, \`"false"\` | Based on condition evaluation |
|
|
42
|
+
| \`switch\` | Case \`outputLabel\` values, \`"default"\` | outputLabel is defined per case in the switch config |
|
|
43
|
+
| \`loop\` | \`"loop"\`, \`"done"\`, \`"fail"\` | "fail" only if \`enableFailRoute: true\` |
|
|
44
|
+
| \`review\` | Option IDs: \`"option_0"\`, \`"option_1"\`, ... | One handle per review option |
|
|
45
|
+
| \`page\` | \`"right"\` (submission), abandonment IDs | Abandonment handles defined in \`abandonments\` array |
|
|
46
|
+
| \`splitTest\` | Variant labels: \`"Variant A"\`, \`"Variant B"\`, ... | Match the variant label strings |
|
|
47
|
+
|
|
48
|
+
### Target Handles
|
|
49
|
+
|
|
50
|
+
Most nodes have a single default \`target_handle\` (no value needed — omit or pass \`null\`). One node type uses a non-default target handle:
|
|
51
|
+
|
|
52
|
+
| Node Type | Target Handles | Notes |
|
|
53
|
+
|-----------|----------------|-------|
|
|
54
|
+
| \`page\` (start form) | \`"return"\` | Top handle on page nodes with \`isStartForm: true\`. Used for loop-back edges that re-enter the start form as an interactive page. Must not originate from a trigger node. |
|
|
55
|
+
|
|
56
|
+
## Referencing Node Outputs Downstream
|
|
57
|
+
|
|
58
|
+
After a node executes, downstream nodes can access its output:
|
|
59
|
+
- In config fields: \`{{nodeId.fieldName}}\` where nodeId is the UUID of the upstream node
|
|
60
|
+
- The available fields depend on the node type — use \`get_node_type_info\` to see the \`outputShape\` for any node type
|
|
61
|
+
- For Page nodes (including isStartForm pages), submission data is at: \`{{nodeId.submissionData.Element Label}}\` (label-keyed). Start-form pages additionally expose \`{{nodeId.formData.<elementId>}}\` (id-keyed raw) and \`{{nodeId.urlParams.foo}}\` (querystring at landing).
|
|
62
|
+
|
|
63
|
+
## Workspace Context
|
|
64
|
+
|
|
65
|
+
Operations run in ONE workspace at a time. By default that's the key's home workspace, but a key may be authorized for several.
|
|
66
|
+
- Use \`list_workspaces\` to see the workspaces this key can use. Each is marked \`is_current: true\` (the active one) and \`is_default: true\` (the key's home).
|
|
67
|
+
- If the key is authorized for more than one workspace, use \`set_active_workspace(workspace_id)\` to switch which workspace subsequent operations act in (\`get_active_workspace\` reports the current one). The switch applies to every later tool call this session, and the id must be one \`list_workspaces\` returned.
|
|
68
|
+
- If you see unexpected data — e.g. a flow you expected is missing — you may be in the wrong workspace. Check \`list_workspaces\` and switch before creating anything.
|
|
69
|
+
|
|
70
|
+
## Testing Flows
|
|
71
|
+
|
|
72
|
+
After building or modifying a flow, **always test it** using the \`test_flow\` tool:
|
|
73
|
+
- \`test_flow(flow_id)\` triggers a run, waits for completion, and returns all node outputs
|
|
74
|
+
- Review the outputs to verify each node executed correctly
|
|
75
|
+
- If a node failed, check the error and fix the flow configuration
|
|
76
|
+
- Use \`input_data\` to provide test trigger data if the flow expects it
|
|
77
|
+
|
|
78
|
+
## Flow Building Patterns
|
|
79
|
+
|
|
80
|
+
1. **Every flow needs a trigger node** — webhook, schedule, email, table trigger, or a page node with \`data.isStartForm: true\` (public form trigger).
|
|
81
|
+
2. **Use \`add_nodes\` with \`temp_id\` + \`edges\`** to create connected node chains in a single call
|
|
82
|
+
3. **Use \`get_node_type_info(type)\`** to see the full guide, output shape, handles, and tips for any node before building it
|
|
83
|
+
4. **Use \`list_page_elements\`** before building Page nodes (including start-form pages) to see available element types
|
|
84
|
+
5. **Validate with \`validate_flow\`** before publishing to catch disconnected nodes, missing triggers, etc.
|
|
85
|
+
6. **Flow variables** are created via \`set_variable\` tool and accessed as \`{{Variables.varName}}\` in config fields
|
|
86
|
+
7. **Always test after building** — use \`test_flow\` to run the flow and verify all nodes work correctly
|
|
87
|
+
|
|
88
|
+
## Common Mistakes to Avoid
|
|
89
|
+
|
|
90
|
+
- Using \`$("nodeId")\` in config fields — that's code-node-only syntax. Use \`{{nodeId.field}}\` instead.
|
|
91
|
+
- Using \`{{}}\` template syntax inside Code node code — use \`$("nodeId")\` instead.
|
|
92
|
+
- Using \`$("nodeId")\` in Custom Node code — use \`inputs.keyName\` instead.
|
|
93
|
+
- Forgetting \`source_handle\` when connecting branching nodes (if, switch, loop, review, page, splitTest).
|
|
94
|
+
- Not returning an object from Code/Custom Node code — always \`return { key: value }\`.
|
|
95
|
+
- Referencing form submission data by element ID instead of label — use \`{{pageNodeId.submissionData.Element Label}}\`.
|
|
96
|
+
|
|
97
|
+
## If/Switch Condition Structure
|
|
98
|
+
|
|
99
|
+
Conditions use this format:
|
|
100
|
+
\`\`\`json
|
|
101
|
+
{
|
|
102
|
+
"id": "crypto.randomUUID()",
|
|
103
|
+
"leftValue": "{{nodeId.field}}",
|
|
104
|
+
"operator": "equals",
|
|
105
|
+
"rightValue": "some value",
|
|
106
|
+
"dataType": "string",
|
|
107
|
+
"range": {"min": "", "max": ""},
|
|
108
|
+
"expression": ""
|
|
109
|
+
}
|
|
110
|
+
\`\`\`
|
|
111
|
+
Operators: equals, not_equals, greater_than, greater_than_or_equal, less_than, less_than_or_equal, contains, not_contains, starts_with, ends_with, matches_regex, is_empty, is_not_empty, is_null, is_not_null, is_true, is_false, in_array, not_in_array, array_contains, array_length, between, custom_expression.
|
|
112
|
+
dataType options: auto, string, number, boolean, array, object, date. The range field is only for the 'between' operator. The expression field is only for the 'custom_expression' operator.
|
|
113
|
+
|
|
114
|
+
## Map Node Mapping Format
|
|
115
|
+
Each mapping: {id: "<uuid>", inputExpression: "{{nodeId.field}}", outputName: "myKey", transformType: "direct", enabled: true}
|
|
116
|
+
Transform types: direct, toString, toNumber, toBoolean, toJson, stringify, lowercase, uppercase, trim, length, split (set delimiter), join (set separator), extract (set pattern as regex), replace (set find + replaceWith), template (set template with {field} syntax), calculate (set expression), custom (set customCode as JavaScript).
|
|
117
|
+
|
|
118
|
+
## HTTP Request Authentication
|
|
119
|
+
Set data.authentication: {type: "none"|"bearer"|"basic"|"apikey", token?, username?, password?, apiKeyHeader?, apiKeyValue?}. For bodyType "form", use data.formFields: [{key, value, type: "text"|"file", enabled}]. For bodyType "file", use data.fileBody (variable reference) + data.fileContentType.
|
|
120
|
+
|
|
121
|
+
## Custom Node Input Schema Format
|
|
122
|
+
|
|
123
|
+
\`\`\`json
|
|
124
|
+
[{
|
|
125
|
+
"key": "fieldName",
|
|
126
|
+
"label": "Display Label",
|
|
127
|
+
"type": "string | number | boolean | object | array | select | code | textarea",
|
|
128
|
+
"required": true,
|
|
129
|
+
"default": "",
|
|
130
|
+
"description": "Help text shown in the editor",
|
|
131
|
+
"options": [{ "label": "Option", "value": "val" }],
|
|
132
|
+
"condition": { "field": "otherKey", "value": "someValue", "operator": "equals" }
|
|
133
|
+
}]
|
|
134
|
+
\`\`\`
|
|
135
|
+
The \`condition\` field makes an input conditionally visible based on another input's value.
|
|
136
|
+
|
|
137
|
+
## Custom Node Output Schema Format
|
|
138
|
+
|
|
139
|
+
\`\`\`json
|
|
140
|
+
[{
|
|
141
|
+
"key": "fieldName",
|
|
142
|
+
"label": "Display Label",
|
|
143
|
+
"type": "string | number | boolean | object | array",
|
|
144
|
+
"description": "What this output contains"
|
|
145
|
+
}]
|
|
146
|
+
\`\`\`
|
|
147
|
+
|
|
148
|
+
## Recommended Workflow Tools (v0.3+)
|
|
149
|
+
|
|
150
|
+
Three tools that make flow authoring reliable. **Use them in this order.**
|
|
151
|
+
|
|
152
|
+
- \`preview_flow(flow_id, nodes, edges)\` — Same inputs as add_nodes, but does NOT save. Returns { would_add, healed, validation }. Use before add_nodes to iterate without churning the canvas.
|
|
153
|
+
- \`validate_flow(flow_id)\` — Structured diagnostics across 7 phases: structure, nested IDs, shape (required fields + enums), handles, references, syntax, reachability. Each error has node_id and path. Fix all errors before publish.
|
|
154
|
+
- \`describe_flow(flow_id)\` — Compact graph summary (nodes, edges, variables, validation headline). Much cheaper than get_flow for sanity checks.
|
|
155
|
+
|
|
156
|
+
**Auto-heal in add_nodes / update_node:** the server auto-injects missing UUIDs on conditions/cases/mappings/options/elements/abandonments/variants/fields. The response includes a \`_healed\` array listing what was patched — treat that as feedback that your call was missing structure.
|
|
156
157
|
`.trim();
|
|
157
158
|
//# sourceMappingURL=instructions.js.map
|
package/dist/instructions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instructions.js","sourceRoot":"","sources":["../src/instructions.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG
|
|
1
|
+
{"version":3,"file":"instructions.js","sourceRoot":"","sources":["../src/instructions.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuJlC,CAAC,IAAI,EAAE,CAAC"}
|
package/dist/oauth.js
CHANGED
|
@@ -102,9 +102,9 @@ function startLoopback(expectedState) {
|
|
|
102
102
|
rejectWait(new Error('State mismatch (possible CSRF)'));
|
|
103
103
|
return;
|
|
104
104
|
}
|
|
105
|
-
res.writeHead(200, { 'Content-Type': 'text/html' }).end(`<html><body style="font-family:system-ui;padding:48px;text-align:center">
|
|
106
|
-
<h2>You're signed in to +Ai Flows.</h2>
|
|
107
|
-
<p>You can close this tab and return to your terminal.</p>
|
|
105
|
+
res.writeHead(200, { 'Content-Type': 'text/html' }).end(`<html><body style="font-family:system-ui;padding:48px;text-align:center">
|
|
106
|
+
<h2>You're signed in to +Ai Flows.</h2>
|
|
107
|
+
<p>You can close this tab and return to your terminal.</p>
|
|
108
108
|
</body></html>`);
|
|
109
109
|
resolveWait({ code, state });
|
|
110
110
|
}
|