@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.
@@ -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
- All operations automatically target the workspace tied to your API key. You do NOT need to specify a workspace — it is enforced server-side.
66
- - Use \`list_workspaces\` to see which workspace is active (marked \`is_current: true\`)
67
- - If you see unexpected data, verify you're in the right workspace first
68
-
69
- ## Testing Flows
70
-
71
- After building or modifying a flow, **always test it** using the \`test_flow\` tool:
72
- - \`test_flow(flow_id)\` triggers a run, waits for completion, and returns all node outputs
73
- - Review the outputs to verify each node executed correctly
74
- - If a node failed, check the error and fix the flow configuration
75
- - Use \`input_data\` to provide test trigger data if the flow expects it
76
-
77
- ## Flow Building Patterns
78
-
79
- 1. **Every flow needs a trigger node** — webhook, schedule, email, table trigger, or a page node with \`data.isStartForm: true\` (public form trigger).
80
- 2. **Use \`add_nodes\` with \`temp_id\` + \`edges\`** to create connected node chains in a single call
81
- 3. **Use \`get_node_type_info(type)\`** to see the full guide, output shape, handles, and tips for any node before building it
82
- 4. **Use \`list_page_elements\`** before building Page nodes (including start-form pages) to see available element types
83
- 5. **Validate with \`validate_flow\`** before publishing to catch disconnected nodes, missing triggers, etc.
84
- 6. **Flow variables** are created via \`set_variable\` tool and accessed as \`{{Variables.varName}}\` in config fields
85
- 7. **Always test after building** — use \`test_flow\` to run the flow and verify all nodes work correctly
86
-
87
- ## Common Mistakes to Avoid
88
-
89
- - Using \`$("nodeId")\` in config fields — that's code-node-only syntax. Use \`{{nodeId.field}}\` instead.
90
- - Using \`{{}}\` template syntax inside Code node code — use \`$("nodeId")\` instead.
91
- - Using \`$("nodeId")\` in Custom Node code — use \`inputs.keyName\` instead.
92
- - Forgetting \`source_handle\` when connecting branching nodes (if, switch, loop, review, page, splitTest).
93
- - Not returning an object from Code/Custom Node code — always \`return { key: value }\`.
94
- - Referencing form submission data by element ID instead of label — use \`{{pageNodeId.submissionData.Element Label}}\`.
95
-
96
- ## If/Switch Condition Structure
97
-
98
- Conditions use this format:
99
- \`\`\`json
100
- {
101
- "id": "crypto.randomUUID()",
102
- "leftValue": "{{nodeId.field}}",
103
- "operator": "equals",
104
- "rightValue": "some value",
105
- "dataType": "string",
106
- "range": {"min": "", "max": ""},
107
- "expression": ""
108
- }
109
- \`\`\`
110
- 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.
111
- 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.
112
-
113
- ## Map Node Mapping Format
114
- Each mapping: {id: "<uuid>", inputExpression: "{{nodeId.field}}", outputName: "myKey", transformType: "direct", enabled: true}
115
- 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).
116
-
117
- ## HTTP Request Authentication
118
- 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.
119
-
120
- ## Custom Node Input Schema Format
121
-
122
- \`\`\`json
123
- [{
124
- "key": "fieldName",
125
- "label": "Display Label",
126
- "type": "string | number | boolean | object | array | select | code | textarea",
127
- "required": true,
128
- "default": "",
129
- "description": "Help text shown in the editor",
130
- "options": [{ "label": "Option", "value": "val" }],
131
- "condition": { "field": "otherKey", "value": "someValue", "operator": "equals" }
132
- }]
133
- \`\`\`
134
- The \`condition\` field makes an input conditionally visible based on another input's value.
135
-
136
- ## Custom Node Output Schema Format
137
-
138
- \`\`\`json
139
- [{
140
- "key": "fieldName",
141
- "label": "Display Label",
142
- "type": "string | number | boolean | object | array",
143
- "description": "What this output contains"
144
- }]
145
- \`\`\`
146
-
147
- ## Recommended Workflow Tools (v0.3+)
148
-
149
- Three tools that make flow authoring reliable. **Use them in this order.**
150
-
151
- - \`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.
152
- - \`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.
153
- - \`describe_flow(flow_id)\` — Compact graph summary (nodes, edges, variables, validation headline). Much cheaper than get_flow for sanity checks.
154
-
155
- **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.
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
@@ -1 +1 @@
1
- {"version":3,"file":"instructions.js","sourceRoot":"","sources":["../src/instructions.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsJlC,CAAC,IAAI,EAAE,CAAC"}
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
  }