@clipform/mcp-server 5.3.0 → 5.4.1

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 CHANGED
@@ -76,7 +76,7 @@ Your MCP client lists these automatically on connect (via `tools/list`). Full re
76
76
  | `clipform_attach_node_media` | Attach an existing workspace media asset (from clipform_upload_media_asset) to one or more nodes (max 10). |
77
77
  | `clipform_get_node_media` | Get the media attached to a node, including processing status. |
78
78
  | `clipform_delete_node_media` | Remove media from a node by unlinking it; the media asset and its files stay in the workspace library and keep working on any other node or live form that uses them. |
79
- | `clipform_set_logic` | Set the next node for one or more nodes, wiring a linear route (A to B to C). |
79
+ | `clipform_set_logic` | Set where one or more nodes go next. |
80
80
  | `clipform_log_generation` | Internal audit step run by a form-generation workflow. |
81
81
  | `clipform_search_news` | Search recent news articles from NewsAPI and The Guardian and return them as structured results. |
82
82
  | `clipform_generate_tts` | Generate narration audio from text with word-level captions for one question in a Clipform form (max 400 characters). |
@@ -6,7 +6,7 @@ import {
6
6
  recoveryHint,
7
7
  structuredResult,
8
8
  textResult
9
- } from "./chunk-5D3UEINC.js";
9
+ } from "./chunk-IWMRSNMO.js";
10
10
  import "./chunk-ENVV65JX.js";
11
11
  import "./chunk-PBQ5BQWD.js";
12
12
  import "./chunk-PZ5AY32C.js";
@@ -31,7 +31,7 @@ import {
31
31
  union,
32
32
  unknown,
33
33
  url
34
- } from "./chunk-NXNCAGMO.js";
34
+ } from "./chunk-HOKPAJLX.js";
35
35
  import {
36
36
  GUIDE_TYPES,
37
37
  QUIZ_VARIANTS,
@@ -40,7 +40,7 @@ import {
40
40
  getGuideUri,
41
41
  guideFallbackText,
42
42
  registerResources
43
- } from "./chunk-4KXP67SR.js";
43
+ } from "./chunk-QZZFZGY6.js";
44
44
  import {
45
45
  ANON_PREVIEW_LINK_LABEL,
46
46
  ANON_PREVIEW_NOTICE,
@@ -54,16 +54,18 @@ import {
54
54
  isPreviewViewerUrl,
55
55
  previewOnlyNotice,
56
56
  withAdoptedNotice
57
- } from "./chunk-SH53TD4L.js";
57
+ } from "./chunk-NWOLQJ3Z.js";
58
58
  import {
59
59
  ACTIVE_NODE_TYPES,
60
60
  ANON_MCP_BLOCKED_NODE_TYPES,
61
61
  ANON_MCP_LIVE_TTL_DAYS,
62
62
  ANON_MCP_RESPONSE_CAP,
63
+ CHOICE_MAX_OPTIONS,
63
64
  CONTACT_FIELDS,
64
65
  FEATURE_FLAGS,
65
66
  FORM_TYPES_LIST,
66
67
  FORM_TYPE_ALIASES,
68
+ LOGIC_TARGET_TYPES,
67
69
  MAX_CLIP_SECONDS,
68
70
  MAX_NARRATION_CHARS,
69
71
  MCP_TOOL_SECURITY,
@@ -82,13 +84,18 @@ import {
82
84
  gatedEnumValues,
83
85
  isAnonMcpLockedNode,
84
86
  isAnonymousAccountRequired,
87
+ isInactiveOptionEdge,
88
+ isNodeLevelAction,
89
+ isOptionEdge,
90
+ isTerminalType,
85
91
  lettersCapError,
86
92
  normalizeContactFields,
93
+ recallDisplayText,
87
94
  resolveFormType,
88
95
  stripGatedConfigKeys,
89
96
  structuredResult,
90
97
  textResult
91
- } from "./chunk-5D3UEINC.js";
98
+ } from "./chunk-IWMRSNMO.js";
92
99
  import {
93
100
  getMcpAuth,
94
101
  runWithMcpAuth,
@@ -17122,6 +17129,19 @@ function projectNext(node, logicByNode) {
17122
17129
  const target = defaultTarget(logicByNode.get(node.id));
17123
17130
  return target ? { target_id: target.value, target_type: target.type } : void 0;
17124
17131
  }
17132
+ function projectAnswerRoutes(node, logicByNode) {
17133
+ const options = node.node_options ?? node.options ?? [];
17134
+ const targetByOption = /* @__PURE__ */ new Map();
17135
+ for (const action of logicByNode.get(node.id) ?? []) {
17136
+ if (!isOptionEdge(action) || isInactiveOptionEdge(node, action) || !action.details?.to) continue;
17137
+ const optionId = action.option_id ?? action.condition.vars.find((v) => v.type === "option")?.value;
17138
+ if (optionId && !targetByOption.has(optionId)) targetByOption.set(optionId, action.details.to);
17139
+ }
17140
+ return options.flatMap((o) => {
17141
+ const to = targetByOption.get(o.id);
17142
+ return to ? [{ option_id: o.id, option_content: o.content, target_id: to.value, target_type: to.type }] : [];
17143
+ });
17144
+ }
17125
17145
  function projectFormState(data) {
17126
17146
  const { nodes, logicByNode } = orderNodesWithLogic(data);
17127
17147
  const urls = projectUrls(data);
@@ -17192,21 +17212,32 @@ function formatFormState(data) {
17192
17212
  ` Options: ${options.map((o) => o.id ? `${o.content} (id: ${o.id})` : o.content).join(", ")}`
17193
17213
  );
17194
17214
  }
17215
+ const routes = projectAnswerRoutes(q, logicByNode);
17195
17216
  const next = projectNext(q, logicByNode);
17196
- if (next) {
17197
- lines.push(` -> next: ${next.target_id} (${next.target_type})`);
17217
+ if (routes.length === 0) {
17218
+ if (next) lines.push(` -> next: ${next.target_id} (${next.target_type})`);
17219
+ } else {
17220
+ const fallback = (logicByNode.get(q.id) ?? []).find((a) => isNodeLevelAction(a, q.id))?.details?.to;
17221
+ lines.push(` Routes by answer:`);
17222
+ for (const o of options ?? []) {
17223
+ const r = routes.find((route) => route.option_id === o.id);
17224
+ if (r) lines.push(` "${r.option_content}" -> ${r.target_id} (${r.target_type})`);
17225
+ else if (fallback) lines.push(` "${o.content}" -> ${fallback.value} (${fallback.type}, default route)`);
17226
+ else lines.push(` "${o.content}" -> NO ROUTE (add a rule for this answer or a default rule, or publishing fails)`);
17227
+ }
17198
17228
  }
17199
17229
  }
17200
17230
  return lines.join("\n");
17201
17231
  }
17202
17232
 
17203
17233
  // src/tools/get-form.ts
17234
+ var TargetTypeSchema = external_exports.enum(LOGIC_TARGET_TYPES);
17204
17235
  function registerGetFormTool(server) {
17205
17236
  server.registerTool(
17206
17237
  "clipform_get_form",
17207
17238
  {
17208
17239
  title: "Get Clipform",
17209
- description: `Retrieve a form's details including all nodes in sequential order and their routing. Returns title, settings, and every node with its options, config, media status, and next node (from clipform_set_logic).`,
17240
+ description: `Retrieve a form's details including all nodes in sequential order and their routing. Returns title, settings, and every node with its options, config, media status, next node, and - for a node that routes by answer - each answer's route (all set with clipform_set_logic).`,
17210
17241
  inputSchema: external_exports.object({
17211
17242
  form_id: external_exports.string().uuid().describe("The form UUID (returned by clipform_create_form, not the short share_id from the URL)")
17212
17243
  }),
@@ -17235,8 +17266,20 @@ function registerGetFormTool(server) {
17235
17266
  options: external_exports.array(external_exports.object({ id: external_exports.string(), content: external_exports.string() })).optional(),
17236
17267
  next: external_exports.object({
17237
17268
  target_id: external_exports.string().describe("The node/screen ID this node routes to"),
17238
- target_type: external_exports.enum(["node", "end_screen", "redirect", "link_list"]).describe("What kind of target target_id is")
17239
- }).optional().describe("This node's outgoing edge, set via clipform_set_logic. Omitted for a chain tail or terminal node.")
17269
+ target_type: TargetTypeSchema.describe("What kind of target target_id is")
17270
+ }).optional().describe("This node's outgoing edge, set via clipform_set_logic. Omitted for a chain tail or terminal node."),
17271
+ // Declared ahead of emission (#4839): the ChatGPT-approved schema is
17272
+ // additionalProperties:false, so routes stay text-only until a Rescan
17273
+ // approves this field (#4845, SUBMISSION.md). Then emit it from
17274
+ // projectFormState.
17275
+ routes: external_exports.array(
17276
+ external_exports.object({
17277
+ option_id: external_exports.string(),
17278
+ option_content: external_exports.string().describe("The answer's text"),
17279
+ target_id: external_exports.string().describe("The node/screen ID this answer routes to"),
17280
+ target_type: TargetTypeSchema
17281
+ })
17282
+ ).optional().describe("Each answer's own route, for a node that routes by answer")
17240
17283
  })
17241
17284
  ).describe("Nodes in sequential order - IDs for update_node / attach_node_media")
17242
17285
  }),
@@ -17770,8 +17813,11 @@ function registerGetResponsesTool(server) {
17770
17813
  return errorResult(`Could not fetch responses: ${subsResult.error}`);
17771
17814
  }
17772
17815
  const nodeById = /* @__PURE__ */ new Map();
17816
+ let nodeList = [];
17773
17817
  if (formResult.ok) {
17774
- const nodes = formResult.data?.nodes ?? [];
17818
+ const data = formResult.data;
17819
+ const nodes = data?.node ?? data?.nodes ?? [];
17820
+ nodeList = nodes;
17775
17821
  for (const n of nodes) nodeById.set(n.id, n);
17776
17822
  }
17777
17823
  const rows = subsResult.data ?? [];
@@ -17794,7 +17840,7 @@ function registerGetResponsesTool(server) {
17794
17840
  for (const [nodeId, resp] of Object.entries(row.node_responses ?? {})) {
17795
17841
  const node = nodeById.get(nodeId);
17796
17842
  const type = node?.type ?? (typeof resp?.type === "string" ? resp.type : "unknown");
17797
- const question = truncate(node?.prompt || type, 120);
17843
+ const question = truncate(recallDisplayText(node?.prompt || type, { variables: [], nodes: nodeList }), 120);
17798
17844
  if (type === "payment") {
17799
17845
  const summary = paymentSummary(resp?.value);
17800
17846
  answers.push({
@@ -17958,12 +18004,15 @@ function registerAddNodeTool(server) {
17958
18004
  "clipform_add_node",
17959
18005
  {
17960
18006
  title: "Add Node",
17961
- description: `Add a new node to an existing form. Inserted before the end screen by default; after_node_id controls insertion position. Inserting into a linear flow automatically re-links the chain (the node before the insertion point points to the new node, which points to what followed) - you do not need clipform_set_logic for a simple insert. Branching still needs an explicit logic write. Node types and config schemas match clipform_create_form.`,
18007
+ description: `Add a new node to an existing form. Inserted before the end screen by default; after_node_id controls insertion position. Inserting into a linear flow automatically re-links the chain (the node before the insertion point points to the new node, which points to what followed) - you do not need clipform_set_logic for a simple insert. For a second ending that only some answers reach (an end screen or redirect), pass unlinked: true and then route to it with clipform_set_logic. Node types and config schemas match clipform_create_form.`,
17962
18008
  inputSchema: external_exports.object({
17963
18009
  form_id: external_exports.string().uuid().describe("The form UUID (returned by clipform_create_form, not the short share_id from the URL)"),
17964
18010
  node: NodeSchema.describe("The node to add"),
17965
18011
  after_node_id: external_exports.string().optional().describe(
17966
- "Insert after this node ID. Omit to append before the end screen."
18012
+ "Insert after this node ID. Omit to append before the end screen. Not used with unlinked."
18013
+ ),
18014
+ unlinked: external_exports.boolean().optional().describe(
18015
+ "Create an ending (end_screen or redirect) outside the flow, so nothing routes to it until you point an answer at it with clipform_set_logic. Only for ending types: a question added this way would sit outside the flow."
17967
18016
  )
17968
18017
  }),
17969
18018
  outputSchema: external_exports.object({
@@ -17977,11 +18026,20 @@ function registerAddNodeTool(server) {
17977
18026
  openWorldHint: false
17978
18027
  }
17979
18028
  },
17980
- async ({ form_id, node, after_node_id }) => {
18029
+ async ({ form_id, node, after_node_id, unlinked }) => {
18030
+ if (unlinked && after_node_id) {
18031
+ return errorResult("Pass either after_node_id (insert into the flow) or unlinked: true (outside the flow), not both.");
18032
+ }
18033
+ if (unlinked && !isTerminalType(node.type)) {
18034
+ return errorResult(
18035
+ `unlinked is only for an ending (end_screen or redirect), not ${node.type}. To give one answer its own question, insert it into the flow with after_node_id, then route answers with clipform_set_logic.`
18036
+ );
18037
+ }
17981
18038
  applyNodeDefaults(node);
17982
18039
  const droppedKeys = stripGatedNodeConfig(node);
17983
18040
  const body = { node };
17984
18041
  if (after_node_id) body.after_node_id = after_node_id;
18042
+ if (unlinked) body.auto_arrange = false;
17985
18043
  const result = await callApi(`/forms/${form_id}/nodes`, {
17986
18044
  method: "POST",
17987
18045
  body
@@ -17991,7 +18049,7 @@ function registerAddNodeTool(server) {
17991
18049
  }
17992
18050
  const nodeId = result.data.node_id;
17993
18051
  const warnings = result.data.warnings ?? [];
17994
- const relinkNote = warnings.length > 0 ? ` ${warnings.join(" ")}` : " The logic chain was automatically re-linked - no clipform_set_logic call is needed for this insert.";
18052
+ const relinkNote = unlinked ? " It is not linked into the flow: route an answer to it with clipform_set_logic (option_content)." : warnings.length > 0 ? ` ${warnings.join(" ")}` : " The logic chain was automatically re-linked - no clipform_set_logic call is needed for this insert.";
17995
18053
  return structuredResult(
17996
18054
  `Node added. ID: ${nodeId} | Type: ${node.type}.${relinkNote}${droppedKeys.length > 0 ? ` ${ignoredConfigNote(droppedKeys)}` : ""}`,
17997
18055
  { node_id: nodeId, type: node.type }
@@ -18002,7 +18060,7 @@ function registerAddNodeTool(server) {
18002
18060
 
18003
18061
  // src/tools/update-node.ts
18004
18062
  var UpdateOptionSchema = OptionSchema.extend({
18005
- id: external_exports.string().uuid().optional().describe("The option's id from clipform_get_form. Include it to keep this option with its routes, answer key and results; omit it to add a new option.")
18063
+ id: external_exports.string().uuid().optional().describe("The option's id from clipform_get_form. Include it to keep this option with its routes, answer key and results; omit it to add a new option (if no option in the list has an id, options are matched to the existing ones instead).")
18006
18064
  });
18007
18065
  var NodeUpdateSchema = external_exports.object({
18008
18066
  node_id: external_exports.string().describe("The node ID to update"),
@@ -18014,7 +18072,7 @@ var NodeUpdateSchema = external_exports.object({
18014
18072
  `${CONFIG_FIELD_DESCRIPTION} Merged shallowly into the stored config - only the keys you pass are changed. Set a key to null to delete it; nested objects are replaced wholesale. When type is changed in the same call, config replaces the stored configuration instead of merging.`
18015
18073
  ),
18016
18074
  options: external_exports.array(UpdateOptionSchema).optional().describe(
18017
- "The full option list (for choice nodes). Include each option's id from clipform_get_form to keep that option and its routes, answer key and results. Options without an id are added as new. Options left out are removed together with their routes. Omit to keep existing options."
18075
+ "The full option list (for choice nodes). Include each option's id from clipform_get_form to keep that option and its routes, answer key and results. Options without an id are added as new, except that if no option has an id, options are matched to the existing ones by text, then by position, so their routes are kept. Options left out are removed together with their routes. Omit to keep existing options."
18018
18076
  )
18019
18077
  }).superRefine((update, ctx) => {
18020
18078
  if (update.type && update.options !== void 0) {
@@ -18643,25 +18701,51 @@ function registerDeleteNodeMediaTool(server) {
18643
18701
 
18644
18702
  // src/tools/set-node-logic.ts
18645
18703
  var LogicRuleSchema = external_exports.object({
18646
- target_node_id: external_exports.string().describe("The node ID this node routes to")
18704
+ target_node_id: external_exports.string().describe("The node ID this route goes to: any other node, including an end screen"),
18705
+ option_content: external_exports.string().optional().describe(
18706
+ "Route only this answer: the option's text exactly as clipform_get_form lists it, without the (id: ...) suffix. Omit for the node's default route, which covers every current answer without a rule of its own."
18707
+ )
18647
18708
  });
18648
18709
  var NodeLogicSchema = external_exports.object({
18649
18710
  node_id: external_exports.string().describe("The node ID to set routing on"),
18650
- rules: external_exports.array(LogicRuleSchema).min(1).max(1).describe("Exactly one rule: the single node this node routes to")
18711
+ rules: external_exports.array(LogicRuleSchema).min(1).max(CHOICE_MAX_OPTIONS + 1).describe(
18712
+ "One rule without option_content for a single next node, or one rule per answer (option_content) plus an optional default rule"
18713
+ )
18651
18714
  });
18715
+ function ruleSetError(rules) {
18716
+ const defaults = rules.filter((r) => !r.option_content).length;
18717
+ if (defaults > 1) return "more than one rule without option_content - give one default route at most";
18718
+ const seen = /* @__PURE__ */ new Set();
18719
+ for (const r of rules) {
18720
+ if (!r.option_content) continue;
18721
+ if (seen.has(r.option_content)) return `two rules for the answer "${r.option_content}" - give each answer one route`;
18722
+ seen.add(r.option_content);
18723
+ }
18724
+ return null;
18725
+ }
18652
18726
  function registerSetNodeLogicTool(server) {
18653
18727
  server.registerTool(
18654
18728
  "clipform_set_logic",
18655
18729
  {
18656
18730
  title: "Set Node Logic",
18657
- description: `Set the next node for one or more nodes, wiring a linear route (A to B to C). Pass multiple nodes in one call instead of separate tool calls. Each node routes to exactly one target node. Branching by which option a respondent picks is not configured here; it is set up in the form's Build tab in the dashboard (the builder URL returned by clipform_get_form / clipform_create_form).
18731
+ description: `Set where one or more nodes go next. Pass multiple nodes in one call instead of separate tool calls.
18732
+
18733
+ - Linear: one rule with only target_node_id (A to B to C).
18734
+ - By answer: on a single-select choice node with branching on, give one rule per answer with option_content set to the option's text, plus an optional default rule without option_content. Every answer needs a route: one with no rule of its own and no default has nowhere to go, and publishing fails. Different answers can go to different nodes or end screens. A multi-select choice has one route out, so answer rules are refused there.
18658
18735
 
18659
- A call replaces that node's routing entirely - it does not merge with any prior target.
18736
+ Turning branching on: set config.choice.enable_branching: true in clipform_create_form, or with clipform_update_node. update_node replaces the whole choice object, so send the node's full current choice config from clipform_get_form with enable_branching added - a choice object with only enable_branching drops quiz settings such as record_scores.
18737
+
18738
+ A second ending that only some answers reach is added with clipform_add_node and unlinked: true.
18739
+
18740
+ A call replaces that node's routing entirely - it does not merge with any prior target. A default rule covers the answers that exist now; an answer added later needs its own rule. clipform_get_form shows each answer's route afterwards, and flags any answer with no route.
18660
18741
 
18661
18742
  Example:
18662
18743
  nodes: [
18663
18744
  { node_id: "q1-id", rules: [{ target_node_id: "q2-id" }] },
18664
- { node_id: "q2-id", rules: [{ target_node_id: "q3-id" }] }
18745
+ { node_id: "country-id", rules: [
18746
+ { option_content: "United Kingdom", target_node_id: "video-id" },
18747
+ { option_content: "Somewhere else", target_node_id: "sorry-end-id" }
18748
+ ] }
18665
18749
  ]`,
18666
18750
  inputSchema: external_exports.object({
18667
18751
  form_id: external_exports.string().uuid().describe("The form UUID (returned by clipform_create_form, not the short share_id from the URL)"),
@@ -18690,6 +18774,12 @@ Example:
18690
18774
  const allLines = [];
18691
18775
  const results = [];
18692
18776
  for (const { node_id, rules } of nodes) {
18777
+ const invalid = ruleSetError(rules);
18778
+ if (invalid) {
18779
+ allLines.push(`Node ${node_id}: FAILED - ${invalid}`);
18780
+ results.push({ node_id, ok: false, error: invalid });
18781
+ continue;
18782
+ }
18693
18783
  const result = await callApi(
18694
18784
  `/forms/${form_id}/nodes/${node_id}/logic/rules`,
18695
18785
  {
@@ -18706,10 +18796,13 @@ Example:
18706
18796
  allLines.push(`Node ${node_id}: logic set (${rulesCount} rules)`);
18707
18797
  results.push({ node_id, ok: true, rules_count: rulesCount });
18708
18798
  }
18709
- if (results.some((r) => r.ok)) {
18799
+ const routedByAnswer = nodes.some(
18800
+ (n, i) => results[i]?.ok && n.rules.some((r) => r.option_content)
18801
+ );
18802
+ if (routedByAnswer) {
18710
18803
  allLines.push(
18711
18804
  `
18712
- To branch by which option a respondent picks (not yet supported here), open the form's Build tab in the dashboard - use the builder URL from clipform_get_form or clipform_create_form.`
18805
+ Routes by answer are set. Call clipform_get_form to check each answer's route; it also says whether a live form needs republishing.`
18713
18806
  );
18714
18807
  }
18715
18808
  return structuredResult(allLines.join("\n"), { results });
@@ -20517,4 +20610,4 @@ export {
20517
20610
  * MIT Licensed
20518
20611
  *)
20519
20612
  */
20520
- //# sourceMappingURL=chunk-H7MHP72Z.js.map
20613
+ //# sourceMappingURL=chunk-3YKZSC7H.js.map