@typeflowus/mcp-server 0.2.2 → 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typeflowus/mcp-server",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "TypeFlow MCP Server - create and manage PDF templates in your TypeFlow library via AI assistants",
5
5
  "type": "module",
6
6
  "bin": {
package/src/api-client.js CHANGED
@@ -7,11 +7,12 @@
7
7
  * startup; the worker passes a key resolved per request from an OAuth token.
8
8
  */
9
9
  export function createApiClient({ apiUrl, headers }) {
10
- async function apiRequest(method, path, body) {
10
+ async function apiRequest(method, path, body, extraHeaders = {}) {
11
11
  const options = {
12
12
  method,
13
13
  headers: {
14
14
  ...headers,
15
+ ...extraHeaders,
15
16
  "Content-Type": "application/json",
16
17
  },
17
18
  };
@@ -24,7 +25,12 @@ export function createApiClient({ apiUrl, headers }) {
24
25
 
25
26
  if (!response.ok) {
26
27
  const error = await response.json().catch(() => ({ error: response.statusText }));
27
- throw new Error(`TypeFlow API error (${response.status}): ${error.error || response.statusText}`);
28
+ // The flow routes explain a refusal in extra fields (which guard, which
29
+ // connections, close field names). Pass them on: the model needs them
30
+ // to fix the call instead of retrying it.
31
+ const { error: message, ...details } = error;
32
+ const extra = Object.keys(details).length ? `\n${JSON.stringify(details, null, 2)}` : "";
33
+ throw new Error(`TypeFlow API error (${response.status}): ${message || response.statusText}${extra}`);
28
34
  }
29
35
 
30
36
  return response.json();
@@ -0,0 +1,250 @@
1
+ import { z } from "zod";
2
+
3
+ /**
4
+ * Flow tools: set up an HTML/CSS flow on an Airtable table, write its
5
+ * template, map it, test it. Step 1 of
6
+ * typeflow-documentation/specification/2026-11-22-mcp-html-flows-step1.md
7
+ *
8
+ * Each tool calls /api/mcp/flows/*, which the worker relays to the app, where
9
+ * the app's own code does the work and refuses what would break a flow. The
10
+ * tools only shape the answers for the model.
11
+ *
12
+ * act_as: TypeFlow staff only (refused for any other key). Builds the flow in
13
+ * a customer's account for Build it for me; every such call is logged.
14
+ */
15
+
16
+ const actAs = z
17
+ .string()
18
+ .optional()
19
+ .describe("TypeFlow staff only: the user id or email to act for. Omit otherwise.");
20
+
21
+ const json = (value) => ({ content: [{ type: "text", text: JSON.stringify(value, null, 2) }] });
22
+
23
+ const failure = (err) => ({ content: [{ type: "text", text: err.message }], isError: true });
24
+
25
+ const PREVIEW_NOTE =
26
+ "Open preview_url in the user's browser and let them check the document. " +
27
+ "Never call activate_flow before they confirm.";
28
+
29
+ export function registerFlowTools(server, apiRequest) {
30
+ const call = (method, path, body, args) =>
31
+ apiRequest(method, path, body, args?.act_as ? { "x-typeflow-act-as": args.act_as } : {});
32
+
33
+ const run = (fn) => async (args) => {
34
+ try {
35
+ return await fn(args);
36
+ } catch (err) {
37
+ return failure(err);
38
+ }
39
+ };
40
+
41
+ server.tool(
42
+ "get_flow",
43
+ "Read a flow: base, table, attachment field, whether it has a template, its variables and which are still unmapped, and whether e-signature is on. Read only. Call it first to see what is missing.",
44
+ { automation_id: z.string().describe("The flow id, as in its URL"), act_as: actAs },
45
+ run(async (args) => json(await call("GET", `/mcp/flows/${encodeURIComponent(args.automation_id)}`, null, args)))
46
+ );
47
+
48
+ server.tool(
49
+ "create_flow",
50
+ `Create an HTML/CSS document flow on an Airtable table. The flow starts without a template: write one with update_flow_template next.
51
+
52
+ Returns the table's fields (names and types): write the template against these exact names.
53
+ If the account has several Airtable connections, the error lists them: ask the user which one and pass connection_id.
54
+ attachment_field is the Airtable attachment field the PDF is saved to; without it, generated PDFs are not written back.`,
55
+ {
56
+ base_id: z.string().describe("Airtable base id (appXXXXXXXXXXXXXX). get_airtable_schema lists them."),
57
+ table_id: z.string().describe("Table id (tblXXX) or exact table name"),
58
+ flow_name: z.string().describe("Name shown in TypeFlow"),
59
+ attachment_field: z.string().optional().describe("Attachment field id or exact name for the generated PDF"),
60
+ connection_id: z.string().optional().describe("Only when the account has several Airtable connections"),
61
+ act_as: actAs,
62
+ },
63
+ run(async (args) => {
64
+ const { act_as, ...body } = args;
65
+ const result = await call("POST", "/mcp/flows", body, { act_as });
66
+ return json({ ...result, next: "Call get_template_guide, then update_flow_template with this automation_id." });
67
+ })
68
+ );
69
+
70
+ server.tool(
71
+ "get_flow_template",
72
+ "The flow's saved template: body html, css, header, footer, page format and variables. Read it before changing anything: update_flow_template is checked against it. Returns update_rules_version: the version of the rules in get_template_guide this server applies.",
73
+ { automation_id: z.string(), act_as: actAs },
74
+ run(async (args) => json(await call("GET", `/mcp/flows/${encodeURIComponent(args.automation_id)}/template`, null, args)))
75
+ );
76
+
77
+ server.tool(
78
+ "update_flow_template",
79
+ `Write the flow's template. Follow get_template_guide, including its "Updating an existing template" rules.
80
+
81
+ - html is the body (a leading <style> block is split into css). header and footer are separate zones with inline styles only: never <header>/<footer> tags in the body. {{page}} and {{total}} work only there.
82
+ - Refused, with nothing written, when the change would: drop a data-tf-node-id or a tf-i-* class, change the TYPEFLOW INSPECTOR OVERRIDES block, put a header or footer in the body, fail validation against the flow's table, or remove a mapped variable (unless replace_mapped_variables is true and the user asked for it).
83
+ - Mappings of variables still in the template are kept. A revision of the previous version is saved.
84
+ - Never activates the flow. ${PREVIEW_NOTE}`,
85
+ {
86
+ automation_id: z.string(),
87
+ html: z.string().describe("Body HTML (may start with a <style> block)"),
88
+ css: z.string().optional().describe("CSS without <style> tags, if not inside html"),
89
+ header: z.string().optional().describe("Header zone HTML, inline styles. Omit to keep the current one, '' to clear it."),
90
+ footer: z.string().optional().describe("Footer zone HTML, inline styles. Omit to keep the current one, '' to clear it."),
91
+ page_format: z.string().optional().describe("Page format id (a4, letter, a4-landscape, label-100x150, ... or custom)"),
92
+ page_width_mm: z.number().optional().describe("With page_format custom"),
93
+ page_height_mm: z.number().optional().describe("With page_format custom"),
94
+ replace_mapped_variables: z.boolean().optional().describe("Allow removing variables that are mapped. Only when the user asked for it."),
95
+ act_as: actAs,
96
+ },
97
+ run(async (args) => {
98
+ const { automation_id, act_as, ...body } = args;
99
+ const result = await call("PUT", `/mcp/flows/${encodeURIComponent(automation_id)}/template`, body, { act_as });
100
+ return json({ ...result, next: `${PREVIEW_NOTE} Then set_mapping.` });
101
+ })
102
+ );
103
+
104
+ server.tool(
105
+ "set_mapping",
106
+ `Bind the template's variables to the flow's Airtable fields.
107
+
108
+ auto (default true) runs TypeFlow's auto-mapping, the same the app runs: exact field names, loop columns through linked records. It never overwrites a variable already mapped.
109
+ overrides maps main-field variables explicitly: { "{{Client}}": { "field": "Client name" } }, with optional barcode_type, width or height (px) for images. An unknown field name returns close matches and saves nothing.
110
+ Returns what is still unmapped: report it to the user, do not guess.`,
111
+ {
112
+ automation_id: z.string(),
113
+ auto: z.boolean().optional(),
114
+ overrides: z.record(z.object({
115
+ field: z.string().describe("Field id or exact name"),
116
+ barcode_type: z.string().optional(),
117
+ width: z.number().optional(),
118
+ height: z.number().optional(),
119
+ })).optional(),
120
+ act_as: actAs,
121
+ },
122
+ run(async (args) => {
123
+ const { automation_id, act_as, ...body } = args;
124
+ return json(await call("POST", `/mcp/flows/${encodeURIComponent(automation_id)}/mapping`, body, { act_as }));
125
+ })
126
+ );
127
+
128
+ server.tool(
129
+ "generate_test",
130
+ `Generate the flow's document for one Airtable record and return the PDF link. Counts as a test, not toward the plan limit.
131
+
132
+ preview_only: true renders the PDF with no side effect (nothing written to Airtable, no email, no signature). Prefer it while the template is being built.
133
+ Without preview_only the PDF is saved to the record's attachment field, as a test from the app would. If e-signature is on, a full test also creates a signature session and emails the first signer: it is refused unless allow_signature_emails is true, which needs the user's explicit agreement.`,
134
+ {
135
+ automation_id: z.string(),
136
+ record_id: z.string().describe("Airtable record id (recXXX)"),
137
+ preview_only: z.boolean().optional(),
138
+ allow_signature_emails: z.boolean().optional(),
139
+ act_as: actAs,
140
+ },
141
+ run(async (args) => {
142
+ const { automation_id, act_as, ...body } = args;
143
+ return json(await call("POST", `/mcp/flows/${encodeURIComponent(automation_id)}/test`, body, { act_as }));
144
+ })
145
+ );
146
+
147
+ server.tool(
148
+ "validate_flow_template",
149
+ "Validate a template against a flow's own Airtable table, without saving. Omit html to validate the saved template. Same validator as validate_template.",
150
+ {
151
+ automation_id: z.string(),
152
+ html: z.string().optional(),
153
+ css: z.string().optional(),
154
+ act_as: actAs,
155
+ },
156
+ run(async (args) => {
157
+ const { automation_id, act_as, ...body } = args;
158
+ return json(await call("POST", `/mcp/flows/${encodeURIComponent(automation_id)}/validate`, body, { act_as }));
159
+ })
160
+ );
161
+
162
+ server.tool(
163
+ "activate_flow",
164
+ "Mark the flow as set up (active). ONLY after the user has opened the flow in their browser and said the document is right. user_confirmation is their exact words; it is logged. Never call it on your own initiative, and never invent the confirmation.",
165
+ {
166
+ automation_id: z.string(),
167
+ user_confirmation: z.string().min(1).describe("The user's exact words confirming the document is right"),
168
+ act_as: actAs,
169
+ },
170
+ run(async (args) => {
171
+ const { automation_id, act_as, user_confirmation } = args;
172
+ return json(await call("POST", `/mcp/flows/${encodeURIComponent(automation_id)}/activate`, { user_confirmation }, { act_as }));
173
+ })
174
+ );
175
+
176
+ server.tool(
177
+ "get_esignature",
178
+ "The flow's e-signature setup: the {{e-signature.*}} tags in the template, the signer numbers they need, the saved config (signers, order, signed PDF field, field updates on completion) and the table's fields. Read only. Call it before configure_esignature.",
179
+ { automation_id: z.string(), act_as: actAs },
180
+ run(async (args) => json(await call("GET", `/mcp/flows/${encodeURIComponent(args.automation_id)}/esignature`, null, args)))
181
+ );
182
+
183
+ server.tool(
184
+ "configure_esignature",
185
+ `Set who signs the flow's document, and turn e-signature on. Writes the same config as the app's e-signature screen; settings not given here are kept as saved in the app.
186
+
187
+ - One signer per signer number of the template ({{e-signature.signature_1}} is signer 1). Every number must be configured, and only those.
188
+ - Each signer takes email_field (+ name_field) from the record, or static_email (+ static_name) for a fixed person, such as the user's own team. Never a {{variable}} in static_email or static_name: it would be sent as written. When the email is on a linked record (e.g. a Client link), give the link field as email_field and the field of the linked table as email_linked_field; same for the name.
189
+ - signed_pdf_field: attachment field the signed PDF is saved to. on_complete: fields set when everyone has signed, e.g. [{ "field": "Status", "value": "Signed" }] (plans with field sync).
190
+ - Sends nothing. Signers are emailed only when a document is generated; generate_test with allow_signature_emails does that, so ask the user first.`,
191
+ {
192
+ automation_id: z.string(),
193
+ signers: z.array(z.object({
194
+ signer_number: z.number().int().min(1),
195
+ email_field: z.string().optional().describe("Field id or exact name holding the signer's email"),
196
+ email_linked_field: z.string().optional().describe("When email_field is a linked record field: the field of the linked table holding the email"),
197
+ name_field: z.string().optional().describe("Field id or exact name holding the signer's name"),
198
+ name_linked_field: z.string().optional().describe("When name_field is a linked record field: the field of the linked table holding the name"),
199
+ static_email: z.string().optional().describe("Fixed email, for a signer who is the same on every document"),
200
+ static_name: z.string().optional().describe("Fixed name, with static_email"),
201
+ role: z.string().optional().describe("Label shown to signers, e.g. Client"),
202
+ optional: z.boolean().optional(),
203
+ })).optional(),
204
+ signing_mode: z.enum(["parallel", "sequential"]).optional().describe("sequential: signer 1 first, then signer 2"),
205
+ signed_pdf_field: z.string().optional().describe("Attachment field id or exact name"),
206
+ on_complete: z.array(z.object({ field: z.string(), value: z.string().optional() })).optional(),
207
+ expiration_days: z.number().int().min(1).max(365).optional(),
208
+ enabled: z.boolean().optional().describe("false turns e-signature off"),
209
+ act_as: actAs,
210
+ },
211
+ run(async (args) => {
212
+ const { automation_id, act_as, ...body } = args;
213
+ return json(await call("PUT", `/mcp/flows/${encodeURIComponent(automation_id)}/esignature`, body, { act_as }));
214
+ })
215
+ );
216
+
217
+ server.tool(
218
+ "list_signatures",
219
+ "The flow's signature requests, newest first: document, record, status, and for each signer whether they viewed or signed, and when they were last reminded. Read only.",
220
+ {
221
+ automation_id: z.string(),
222
+ status: z.enum(["pending", "completed", "declined", "expired", "cancelled"]).optional(),
223
+ record_id: z.string().optional().describe("Only the requests for this Airtable record"),
224
+ limit: z.number().int().min(1).max(100).optional(),
225
+ act_as: actAs,
226
+ },
227
+ run(async (args) => {
228
+ const query = new URLSearchParams();
229
+ for (const key of ["status", "record_id", "limit"]) if (args[key] !== undefined) query.set(key, String(args[key]));
230
+ const qs = query.toString();
231
+ return json(await call("GET", `/mcp/flows/${encodeURIComponent(args.automation_id)}/signatures${qs ? `?${qs}` : ""}`, null, args));
232
+ })
233
+ );
234
+
235
+ server.tool(
236
+ "cancel_signature",
237
+ "Cancel a pending signature request. Every pending signer is emailed that the document was cancelled, so ONLY when the user asked for it: user_confirmation is their exact words; it is logged.",
238
+ {
239
+ automation_id: z.string(),
240
+ request_id: z.string().describe("From list_signatures"),
241
+ user_confirmation: z.string().min(1).describe("The user's exact words asking to cancel"),
242
+ reason: z.string().optional(),
243
+ act_as: actAs,
244
+ },
245
+ run(async (args) => {
246
+ const { automation_id, request_id, act_as, ...body } = args;
247
+ return json(await call("POST", `/mcp/flows/${encodeURIComponent(automation_id)}/signatures/${encodeURIComponent(request_id)}/cancel`, body, { act_as }));
248
+ })
249
+ );
250
+ }
package/src/server.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { z } from "zod";
3
+ import { registerFlowTools } from "./flow-tools.js";
3
4
 
4
5
  /**
5
6
  * What to tell the model about page formats.
@@ -75,7 +76,10 @@ export function createTypeFlowMcpServer({ apiRequest, version }) {
75
76
  "binds to Airtable data, also call get_airtable_schema first: TypeFlow " +
76
77
  "maps variables by exact field name, so a guessed name maps to nothing. " +
77
78
  "Templates are saved to the user's TypeFlow library, where they can be " +
78
- "picked when creating a flow."
79
+ "picked when creating a flow. To set up a flow directly: create_flow, " +
80
+ "update_flow_template, set_mapping, generate_test, then let the user " +
81
+ "check the flow in their browser before activate_flow. For e-signature: " +
82
+ "get_esignature, then configure_esignature; list_signatures follows them up."
79
83
  });
80
84
 
81
85
  // The guide is identical for every user and carries no user data, so one
@@ -451,5 +455,7 @@ If the schema is omitted, only structural HTML/CSS checks are performed (no vari
451
455
  }
452
456
  );
453
457
 
458
+ registerFlowTools(server, apiRequest);
459
+
454
460
  return server;
455
461
  }