@typeflowus/mcp-server 0.2.2 → 0.4.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 +1 -1
- package/src/api-client.js +8 -2
- package/src/flow-tools.js +319 -0
- package/src/generate-tools.js +113 -0
- package/src/server.js +80 -42
package/package.json
CHANGED
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
|
-
|
|
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,319 @@
|
|
|
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
|
+
// Descriptions say what a tool does, when it is useful, its limits and side
|
|
17
|
+
// effects. They never order other calls: the directories reject descriptions
|
|
18
|
+
// that steer the model. The order lives in the server instructions and in each
|
|
19
|
+
// answer's `next`.
|
|
20
|
+
|
|
21
|
+
const automationId = z.string().describe("The flow id (automation_id), as in its URL");
|
|
22
|
+
|
|
23
|
+
const actAs = z
|
|
24
|
+
.string()
|
|
25
|
+
.optional()
|
|
26
|
+
.describe("TypeFlow staff only: the user id or email to act for. Omit otherwise.");
|
|
27
|
+
|
|
28
|
+
const json = (value) => ({ content: [{ type: "text", text: JSON.stringify(value, null, 2) }] });
|
|
29
|
+
|
|
30
|
+
const failure = (err) => ({ content: [{ type: "text", text: err.message }], isError: true });
|
|
31
|
+
|
|
32
|
+
const PREVIEW_NOTE =
|
|
33
|
+
"Open preview_url in the user's browser and let them check the document. " +
|
|
34
|
+
"Never call activate_flow before they confirm.";
|
|
35
|
+
|
|
36
|
+
export function registerFlowTools(server, apiRequest) {
|
|
37
|
+
const call = (method, path, body, args) =>
|
|
38
|
+
apiRequest(method, path, body, args?.act_as ? { "x-typeflow-act-as": args.act_as } : {});
|
|
39
|
+
|
|
40
|
+
const run = (fn) => async (args) => {
|
|
41
|
+
try {
|
|
42
|
+
return await fn(args);
|
|
43
|
+
} catch (err) {
|
|
44
|
+
return failure(err);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
server.registerTool(
|
|
49
|
+
"get_flow",
|
|
50
|
+
{
|
|
51
|
+
title: "Get flow",
|
|
52
|
+
description:
|
|
53
|
+
"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. " +
|
|
54
|
+
"Useful to see what a flow still needs. Read only.",
|
|
55
|
+
inputSchema: { automation_id: automationId, act_as: actAs },
|
|
56
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
57
|
+
},
|
|
58
|
+
run(async (args) => json(await call("GET", `/mcp/flows/${encodeURIComponent(args.automation_id)}`, null, args)))
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
server.registerTool(
|
|
62
|
+
"create_flow",
|
|
63
|
+
{
|
|
64
|
+
title: "Create flow",
|
|
65
|
+
description: `Create an HTML/CSS document flow on an Airtable table. The flow starts without a template and inactive.
|
|
66
|
+
|
|
67
|
+
Returns the table's fields (names and types), which template variables must match exactly.
|
|
68
|
+
If the account has several Airtable connections, the error lists them, and connection_id picks one.
|
|
69
|
+
attachment_field is the Airtable attachment field the PDF is saved to; without it, generated PDFs are not written back.`,
|
|
70
|
+
inputSchema: {
|
|
71
|
+
base_id: z.string().describe("Airtable base id (appXXXXXXXXXXXXXX). get_airtable_schema lists them."),
|
|
72
|
+
table_id: z.string().describe("Table id (tblXXX) or exact table name"),
|
|
73
|
+
flow_name: z.string().describe("Name shown in TypeFlow"),
|
|
74
|
+
attachment_field: z.string().optional().describe("Attachment field id or exact name for the generated PDF"),
|
|
75
|
+
connection_id: z.string().optional().describe("Only when the account has several Airtable connections"),
|
|
76
|
+
act_as: actAs,
|
|
77
|
+
},
|
|
78
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
|
|
79
|
+
},
|
|
80
|
+
run(async (args) => {
|
|
81
|
+
const { act_as, ...body } = args;
|
|
82
|
+
const result = await call("POST", "/mcp/flows", body, { act_as });
|
|
83
|
+
return json({ ...result, next: "Call get_template_guide, then update_flow_template with this automation_id." });
|
|
84
|
+
})
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
server.registerTool(
|
|
88
|
+
"get_flow_template",
|
|
89
|
+
{
|
|
90
|
+
title: "Get flow template",
|
|
91
|
+
description:
|
|
92
|
+
"The flow's saved template: body html, css, header, footer, page format and variables. " +
|
|
93
|
+
"update_flow_template is checked against this saved version. Returns update_rules_version, the version of the template rules this server applies. Read only.",
|
|
94
|
+
inputSchema: { automation_id: automationId, act_as: actAs },
|
|
95
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
96
|
+
},
|
|
97
|
+
run(async (args) => json(await call("GET", `/mcp/flows/${encodeURIComponent(args.automation_id)}/template`, null, args)))
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
server.registerTool(
|
|
101
|
+
"update_flow_template",
|
|
102
|
+
{
|
|
103
|
+
title: "Update flow template",
|
|
104
|
+
description: `Write the flow's template, under the rules get_template_guide returns, including "Updating an existing template".
|
|
105
|
+
|
|
106
|
+
- 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.
|
|
107
|
+
- 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).
|
|
108
|
+
- Mappings of variables still in the template are kept. A revision of the previous version is saved.
|
|
109
|
+
- Never activates the flow.`,
|
|
110
|
+
inputSchema: {
|
|
111
|
+
automation_id: automationId,
|
|
112
|
+
html: z.string().describe("Body HTML (may start with a <style> block)"),
|
|
113
|
+
css: z.string().optional().describe("CSS without <style> tags, if not inside html"),
|
|
114
|
+
header: z.string().optional().describe("Header zone HTML, inline styles. Omit to keep the current one, '' to clear it."),
|
|
115
|
+
footer: z.string().optional().describe("Footer zone HTML, inline styles. Omit to keep the current one, '' to clear it."),
|
|
116
|
+
page_format: z.string().optional().describe("Page format id (a4, letter, a4-landscape, label-100x150, ... or custom)"),
|
|
117
|
+
page_width_mm: z.number().optional().describe("With page_format custom"),
|
|
118
|
+
page_height_mm: z.number().optional().describe("With page_format custom"),
|
|
119
|
+
replace_mapped_variables: z.boolean().optional().describe("Allow removing variables that are mapped. Only when the user asked for it."),
|
|
120
|
+
act_as: actAs,
|
|
121
|
+
},
|
|
122
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
123
|
+
},
|
|
124
|
+
run(async (args) => {
|
|
125
|
+
const { automation_id, act_as, ...body } = args;
|
|
126
|
+
const result = await call("PUT", `/mcp/flows/${encodeURIComponent(automation_id)}/template`, body, { act_as });
|
|
127
|
+
return json({ ...result, next: `${PREVIEW_NOTE} Then set_mapping.` });
|
|
128
|
+
})
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
server.registerTool(
|
|
132
|
+
"set_mapping",
|
|
133
|
+
{
|
|
134
|
+
title: "Set mapping",
|
|
135
|
+
description: `Bind the template's variables to the flow's Airtable fields.
|
|
136
|
+
|
|
137
|
+
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.
|
|
138
|
+
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.
|
|
139
|
+
Returns what is still unmapped, which only the user can resolve.`,
|
|
140
|
+
inputSchema: {
|
|
141
|
+
automation_id: automationId,
|
|
142
|
+
auto: z.boolean().optional().describe("Run the auto-mapping. Default true."),
|
|
143
|
+
overrides: z.record(z.object({
|
|
144
|
+
field: z.string().describe("Field id or exact name"),
|
|
145
|
+
barcode_type: z.string().optional(),
|
|
146
|
+
width: z.number().optional(),
|
|
147
|
+
height: z.number().optional(),
|
|
148
|
+
})).optional().describe("Variable to field, e.g. { \"{{Client}}\": { \"field\": \"Client name\" } }"),
|
|
149
|
+
act_as: actAs,
|
|
150
|
+
},
|
|
151
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
152
|
+
},
|
|
153
|
+
run(async (args) => {
|
|
154
|
+
const { automation_id, act_as, ...body } = args;
|
|
155
|
+
return json(await call("POST", `/mcp/flows/${encodeURIComponent(automation_id)}/mapping`, body, { act_as }));
|
|
156
|
+
})
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
server.registerTool(
|
|
160
|
+
"generate_test",
|
|
161
|
+
{
|
|
162
|
+
title: "Generate test document",
|
|
163
|
+
description: `Generate the flow's document for one Airtable record and return the PDF link. Counts as a test, not toward the plan limit.
|
|
164
|
+
|
|
165
|
+
preview_only: true renders the PDF with no side effect (nothing written to Airtable, no email, no signature), which suits a template still being built.
|
|
166
|
+
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.`,
|
|
167
|
+
inputSchema: {
|
|
168
|
+
automation_id: automationId,
|
|
169
|
+
record_id: z.string().describe("Airtable record id (recXXX)"),
|
|
170
|
+
preview_only: z.boolean().optional().describe("Render only: nothing written, nothing sent"),
|
|
171
|
+
allow_signature_emails: z.boolean().optional().describe("Allow the signature email of a full test. Only with the user's agreement."),
|
|
172
|
+
act_as: actAs,
|
|
173
|
+
},
|
|
174
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true },
|
|
175
|
+
},
|
|
176
|
+
run(async (args) => {
|
|
177
|
+
const { automation_id, act_as, ...body } = args;
|
|
178
|
+
return json(await call("POST", `/mcp/flows/${encodeURIComponent(automation_id)}/test`, body, { act_as }));
|
|
179
|
+
})
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
server.registerTool(
|
|
183
|
+
"validate_flow_template",
|
|
184
|
+
{
|
|
185
|
+
title: "Validate flow template",
|
|
186
|
+
description:
|
|
187
|
+
"Validate a template against a flow's own Airtable table, without saving. Omit html to validate the saved template. " +
|
|
188
|
+
"Same validator as validate_template. Read only.",
|
|
189
|
+
inputSchema: {
|
|
190
|
+
automation_id: automationId,
|
|
191
|
+
html: z.string().optional().describe("Body HTML to check. Omit to check the saved template."),
|
|
192
|
+
css: z.string().optional().describe("CSS without <style> tags"),
|
|
193
|
+
act_as: actAs,
|
|
194
|
+
},
|
|
195
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
196
|
+
},
|
|
197
|
+
run(async (args) => {
|
|
198
|
+
const { automation_id, act_as, ...body } = args;
|
|
199
|
+
return json(await call("POST", `/mcp/flows/${encodeURIComponent(automation_id)}/validate`, body, { act_as }));
|
|
200
|
+
})
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
server.registerTool(
|
|
204
|
+
"activate_flow",
|
|
205
|
+
{
|
|
206
|
+
title: "Activate flow",
|
|
207
|
+
description:
|
|
208
|
+
"Mark the flow as set up (active). For use once the user has checked the document in their browser and said it is right: " +
|
|
209
|
+
"user_confirmation holds their exact words, and is logged.",
|
|
210
|
+
inputSchema: {
|
|
211
|
+
automation_id: automationId,
|
|
212
|
+
user_confirmation: z.string().min(1).describe("The user's exact words confirming the document is right"),
|
|
213
|
+
act_as: actAs,
|
|
214
|
+
},
|
|
215
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
216
|
+
},
|
|
217
|
+
run(async (args) => {
|
|
218
|
+
const { automation_id, act_as, user_confirmation } = args;
|
|
219
|
+
return json(await call("POST", `/mcp/flows/${encodeURIComponent(automation_id)}/activate`, { user_confirmation }, { act_as }));
|
|
220
|
+
})
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
server.registerTool(
|
|
224
|
+
"get_esignature",
|
|
225
|
+
{
|
|
226
|
+
title: "Get e-signature setup",
|
|
227
|
+
description:
|
|
228
|
+
"The flow's e-signature setup: the {{e-signature.*}} tags in the template, the signer numbers they need, the saved config " +
|
|
229
|
+
"(signers, order, signed PDF field, field updates on completion) and the table's fields. Read only.",
|
|
230
|
+
inputSchema: { automation_id: automationId, act_as: actAs },
|
|
231
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
232
|
+
},
|
|
233
|
+
run(async (args) => json(await call("GET", `/mcp/flows/${encodeURIComponent(args.automation_id)}/esignature`, null, args)))
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
server.registerTool(
|
|
237
|
+
"configure_esignature",
|
|
238
|
+
{
|
|
239
|
+
title: "Configure e-signature",
|
|
240
|
+
description: `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.
|
|
241
|
+
|
|
242
|
+
- One signer per signer number of the template ({{e-signature.signature_1}} is signer 1). Every number must be configured, and only those.
|
|
243
|
+
- 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.
|
|
244
|
+
- 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).
|
|
245
|
+
- Sends nothing. Signers are emailed only when a document is generated.`,
|
|
246
|
+
inputSchema: {
|
|
247
|
+
automation_id: automationId,
|
|
248
|
+
signers: z.array(z.object({
|
|
249
|
+
signer_number: z.number().int().min(1),
|
|
250
|
+
email_field: z.string().optional().describe("Field id or exact name holding the signer's email"),
|
|
251
|
+
email_linked_field: z.string().optional().describe("When email_field is a linked record field: the field of the linked table holding the email"),
|
|
252
|
+
name_field: z.string().optional().describe("Field id or exact name holding the signer's name"),
|
|
253
|
+
name_linked_field: z.string().optional().describe("When name_field is a linked record field: the field of the linked table holding the name"),
|
|
254
|
+
static_email: z.string().optional().describe("Fixed email, for a signer who is the same on every document"),
|
|
255
|
+
static_name: z.string().optional().describe("Fixed name, with static_email"),
|
|
256
|
+
role: z.string().optional().describe("Label shown to signers, e.g. Client"),
|
|
257
|
+
optional: z.boolean().optional(),
|
|
258
|
+
})).optional().describe("One entry per signer number of the template"),
|
|
259
|
+
signing_mode: z.enum(["parallel", "sequential"]).optional().describe("sequential: signer 1 first, then signer 2"),
|
|
260
|
+
signed_pdf_field: z.string().optional().describe("Attachment field id or exact name"),
|
|
261
|
+
on_complete: z.array(z.object({ field: z.string(), value: z.string().optional() })).optional().describe("Fields set when everyone has signed"),
|
|
262
|
+
expiration_days: z.number().int().min(1).max(365).optional().describe("Days before an unsigned request expires"),
|
|
263
|
+
enabled: z.boolean().optional().describe("false turns e-signature off"),
|
|
264
|
+
act_as: actAs,
|
|
265
|
+
},
|
|
266
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
267
|
+
},
|
|
268
|
+
run(async (args) => {
|
|
269
|
+
const { automation_id, act_as, ...body } = args;
|
|
270
|
+
return json(await call("PUT", `/mcp/flows/${encodeURIComponent(automation_id)}/esignature`, body, { act_as }));
|
|
271
|
+
})
|
|
272
|
+
);
|
|
273
|
+
|
|
274
|
+
server.registerTool(
|
|
275
|
+
"list_signatures",
|
|
276
|
+
{
|
|
277
|
+
title: "List signature requests",
|
|
278
|
+
description:
|
|
279
|
+
"The flow's signature requests, newest first: document, record, status, and for each signer whether they viewed or signed, " +
|
|
280
|
+
"and when they were last reminded. Read only.",
|
|
281
|
+
inputSchema: {
|
|
282
|
+
automation_id: automationId,
|
|
283
|
+
status: z.enum(["pending", "completed", "declined", "expired", "cancelled"]).optional().describe("Only the requests in this status"),
|
|
284
|
+
record_id: z.string().optional().describe("Only the requests for this Airtable record"),
|
|
285
|
+
limit: z.number().int().min(1).max(100).optional().describe("At most this many requests"),
|
|
286
|
+
act_as: actAs,
|
|
287
|
+
},
|
|
288
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
289
|
+
},
|
|
290
|
+
run(async (args) => {
|
|
291
|
+
const query = new URLSearchParams();
|
|
292
|
+
for (const key of ["status", "record_id", "limit"]) if (args[key] !== undefined) query.set(key, String(args[key]));
|
|
293
|
+
const qs = query.toString();
|
|
294
|
+
return json(await call("GET", `/mcp/flows/${encodeURIComponent(args.automation_id)}/signatures${qs ? `?${qs}` : ""}`, null, args));
|
|
295
|
+
})
|
|
296
|
+
);
|
|
297
|
+
|
|
298
|
+
server.registerTool(
|
|
299
|
+
"cancel_signature",
|
|
300
|
+
{
|
|
301
|
+
title: "Cancel signature request",
|
|
302
|
+
description:
|
|
303
|
+
"Cancel a pending signature request. Cannot be undone, and every pending signer is emailed that the document was cancelled. " +
|
|
304
|
+
"For use when the user asked for it: user_confirmation holds their exact words, and is logged.",
|
|
305
|
+
inputSchema: {
|
|
306
|
+
automation_id: automationId,
|
|
307
|
+
request_id: z.string().describe("The request id, as list_signatures returns it"),
|
|
308
|
+
user_confirmation: z.string().min(1).describe("The user's exact words asking to cancel"),
|
|
309
|
+
reason: z.string().optional().describe("Why the request is cancelled"),
|
|
310
|
+
act_as: actAs,
|
|
311
|
+
},
|
|
312
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: true },
|
|
313
|
+
},
|
|
314
|
+
run(async (args) => {
|
|
315
|
+
const { automation_id, request_id, act_as, ...body } = args;
|
|
316
|
+
return json(await call("POST", `/mcp/flows/${encodeURIComponent(automation_id)}/signatures/${encodeURIComponent(request_id)}/cancel`, body, { act_as }));
|
|
317
|
+
})
|
|
318
|
+
);
|
|
319
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Generation tools: from a connected Airtable table to a real document. Step 3
|
|
5
|
+
* of typeflow-documentation/specification/2026-12-03-mcp-generate-and-sign.md
|
|
6
|
+
*
|
|
7
|
+
* Like the flow tools, each one calls an /api/mcp/* route in the app, which
|
|
8
|
+
* owns the rules. A refusal carries a `code` and a `next_action`; they reach
|
|
9
|
+
* the model in the error text.
|
|
10
|
+
*
|
|
11
|
+
* Descriptions say what a tool does, when it is useful, its limits and side
|
|
12
|
+
* effects. They never order other calls: the directories reject descriptions
|
|
13
|
+
* that steer the model, so the order lives in the errors' next_action.
|
|
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
|
+
export function registerGenerateTools(server, apiRequest) {
|
|
26
|
+
const call = (method, path, body, args) =>
|
|
27
|
+
apiRequest(method, path, body, args?.act_as ? { "x-typeflow-act-as": args.act_as } : {});
|
|
28
|
+
|
|
29
|
+
const run = (fn) => async (args) => {
|
|
30
|
+
try {
|
|
31
|
+
return await fn(args);
|
|
32
|
+
} catch (err) {
|
|
33
|
+
return failure(err);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
server.registerTool(
|
|
38
|
+
"get_connection_status",
|
|
39
|
+
{
|
|
40
|
+
title: "Get connection status",
|
|
41
|
+
description:
|
|
42
|
+
"Which data sources the user has connected to TypeFlow (Airtable, Google), with each connection's name and date. " +
|
|
43
|
+
"Useful with a user whose setup is unknown, and to check whether a connection the user just made went through. " +
|
|
44
|
+
"Read only. Never returns credentials.",
|
|
45
|
+
inputSchema: { act_as: actAs },
|
|
46
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
47
|
+
},
|
|
48
|
+
run(async (args) => json(await call("GET", "/mcp/connections", null, args)))
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
server.registerTool(
|
|
52
|
+
"get_connect_url",
|
|
53
|
+
{
|
|
54
|
+
title: "Get connection link",
|
|
55
|
+
description:
|
|
56
|
+
"Returns a single-use link, valid 15 minutes, to TypeFlow's own page for connecting a data source. Airtable only. " +
|
|
57
|
+
"The user opens it in a browser where they are logged in to TypeFlow with this account; get_connection_status then shows the connection. " +
|
|
58
|
+
"Refused when Airtable is already connected. TypeFlow never needs the user to paste a token.",
|
|
59
|
+
inputSchema: {
|
|
60
|
+
provider: z.enum(["airtable"]).describe("The data source to connect"),
|
|
61
|
+
act_as: actAs,
|
|
62
|
+
},
|
|
63
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
|
|
64
|
+
},
|
|
65
|
+
run(async (args) => json(await call("POST", "/mcp/connect-url", { provider: args.provider }, args)))
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
server.registerTool(
|
|
69
|
+
"find_records",
|
|
70
|
+
{
|
|
71
|
+
title: "Find records",
|
|
72
|
+
description:
|
|
73
|
+
"Searches the flow's Airtable table by text in its primary field. Returns at most 10 records, each with its record_id and primary field value only, and truncated: true when there were more. " +
|
|
74
|
+
"Useful when the user names a record (a client, a quote number) instead of giving its id. When several match, the user picks one. " +
|
|
75
|
+
"Read only. Works on active HTML flows on Airtable.",
|
|
76
|
+
inputSchema: {
|
|
77
|
+
flow_id: z.string().describe("The flow id (automation_id), as in its URL"),
|
|
78
|
+
query: z.string().min(1).describe("Text to look for in the primary field"),
|
|
79
|
+
act_as: actAs,
|
|
80
|
+
},
|
|
81
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
82
|
+
},
|
|
83
|
+
run(async (args) =>
|
|
84
|
+
json(await call("POST", `/mcp/flows/${encodeURIComponent(args.flow_id)}/records`, { query: args.query }, args))
|
|
85
|
+
)
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
server.registerTool(
|
|
89
|
+
"generate_document",
|
|
90
|
+
{
|
|
91
|
+
title: "Generate document",
|
|
92
|
+
description:
|
|
93
|
+
"Generates the real document for one record of an active flow and writes the PDF to the record's attachment field in Airtable. " +
|
|
94
|
+
"It counts toward the user's plan, unlike generate_test, and may replace the PDF already in that field. " +
|
|
95
|
+
"record is a record_id, or an Airtable record URL from the flow's table. " +
|
|
96
|
+
"On a flow with e-signature, the document is generated and held: no signer is emailed.",
|
|
97
|
+
inputSchema: {
|
|
98
|
+
flow_id: z.string().describe("The flow id (automation_id), as in its URL"),
|
|
99
|
+
record: z.string().min(1).describe("Record id (recXXXXXXXXXXXXXX) or Airtable record URL"),
|
|
100
|
+
idempotency_key: z
|
|
101
|
+
.string()
|
|
102
|
+
.max(200)
|
|
103
|
+
.optional()
|
|
104
|
+
.describe("One value per user request. Retrying with the same key within 24 hours returns the first result instead of generating again."),
|
|
105
|
+
act_as: actAs,
|
|
106
|
+
},
|
|
107
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
|
|
108
|
+
},
|
|
109
|
+
run(async (args) =>
|
|
110
|
+
json(await call("POST", `/mcp/flows/${encodeURIComponent(args.flow_id)}/generate`, { record: args.record, idempotency_key: args.idempotency_key }, args))
|
|
111
|
+
)
|
|
112
|
+
);
|
|
113
|
+
}
|
package/src/server.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import { registerFlowTools } from "./flow-tools.js";
|
|
4
|
+
import { registerGenerateTools } from "./generate-tools.js";
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* What to tell the model about page formats.
|
|
@@ -75,7 +77,10 @@ export function createTypeFlowMcpServer({ apiRequest, version }) {
|
|
|
75
77
|
"binds to Airtable data, also call get_airtable_schema first: TypeFlow " +
|
|
76
78
|
"maps variables by exact field name, so a guessed name maps to nothing. " +
|
|
77
79
|
"Templates are saved to the user's TypeFlow library, where they can be " +
|
|
78
|
-
"picked when creating a flow."
|
|
80
|
+
"picked when creating a flow. To set up a flow directly: create_flow, " +
|
|
81
|
+
"update_flow_template, set_mapping, generate_test, then let the user " +
|
|
82
|
+
"check the flow in their browser before activate_flow. For e-signature: " +
|
|
83
|
+
"get_esignature, then configure_esignature; list_signatures follows them up."
|
|
79
84
|
});
|
|
80
85
|
|
|
81
86
|
// The guide is identical for every user and carries no user data, so one
|
|
@@ -101,10 +106,16 @@ export function createTypeFlowMcpServer({ apiRequest, version }) {
|
|
|
101
106
|
// Tool: get_template_guide
|
|
102
107
|
// ============================================================
|
|
103
108
|
|
|
104
|
-
server.
|
|
109
|
+
server.registerTool(
|
|
105
110
|
"get_template_guide",
|
|
106
|
-
|
|
107
|
-
|
|
111
|
+
{
|
|
112
|
+
title: "Get template guide",
|
|
113
|
+
description:
|
|
114
|
+
"Returns the complete TypeFlow template guide: HTML/CSS rules, variable syntax, loop structures, image handling, examples, " +
|
|
115
|
+
"and the decision tree for turning an Airtable schema into TypeFlow variables. Templates written without it usually fail to render. Read only.",
|
|
116
|
+
inputSchema: {},
|
|
117
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
118
|
+
},
|
|
108
119
|
async () => {
|
|
109
120
|
try {
|
|
110
121
|
return {
|
|
@@ -132,20 +143,24 @@ server.tool(
|
|
|
132
143
|
// Tool: get_airtable_schema
|
|
133
144
|
// ============================================================
|
|
134
145
|
|
|
135
|
-
server.
|
|
146
|
+
server.registerTool(
|
|
136
147
|
"get_airtable_schema",
|
|
137
|
-
|
|
148
|
+
{
|
|
149
|
+
title: "Get Airtable schema",
|
|
150
|
+
description: `List the user's Airtable bases, or read the tables and fields of one.
|
|
138
151
|
|
|
139
|
-
|
|
152
|
+
With no arguments, lists the bases this account can reach. With a base_id, returns its tables, fields and field types.
|
|
140
153
|
|
|
141
|
-
|
|
154
|
+
TypeFlow maps variables by name: {{Invoice Number}} binds to a field called exactly "Invoice Number" and to nothing else, so a template written against guessed field names maps to nothing.
|
|
142
155
|
|
|
143
|
-
Returns structure only - table names, field names, field types. No record data.`,
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
156
|
+
Returns structure only - table names, field names, field types. No record data. Read only.`,
|
|
157
|
+
inputSchema: {
|
|
158
|
+
base_id: z
|
|
159
|
+
.string()
|
|
160
|
+
.optional()
|
|
161
|
+
.describe("Airtable base id (appXXXXXXXXXXXXXX). Omit to list the available bases."),
|
|
162
|
+
},
|
|
163
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
149
164
|
},
|
|
150
165
|
async (args) => {
|
|
151
166
|
const path = args.base_id
|
|
@@ -195,14 +210,14 @@ Returns structure only - table names, field names, field types. No record data.`
|
|
|
195
210
|
// Tool: create_template
|
|
196
211
|
// ============================================================
|
|
197
212
|
|
|
198
|
-
server.
|
|
213
|
+
server.registerTool(
|
|
199
214
|
"create_template",
|
|
200
|
-
`Create a new HTML template in the user's TypeFlow template library.
|
|
201
|
-
|
|
202
|
-
IMPORTANT: You MUST call get_template_guide first before generating any HTML. The guide contains all the rules you need.
|
|
203
|
-
|
|
204
|
-
The template is saved to the library and can later be picked when creating a flow in TypeFlow.`,
|
|
205
215
|
{
|
|
216
|
+
title: "Create template",
|
|
217
|
+
description: `Create a new HTML template in the user's TypeFlow template library, under the rules get_template_guide returns.
|
|
218
|
+
|
|
219
|
+
The template is saved to the library and can later be picked when creating a flow in TypeFlow. No flow is created or changed.`,
|
|
220
|
+
inputSchema: {
|
|
206
221
|
name: z.string().describe("Template name (e.g. 'Drilling Report Q2')"),
|
|
207
222
|
html: z.string().describe("HTML content without <style> tags. Must follow the rules from get_template_guide."),
|
|
208
223
|
css: z.string().describe("CSS content without <style> wrapper"),
|
|
@@ -211,6 +226,8 @@ The template is saved to the library and can later be picked when creating a flo
|
|
|
211
226
|
page_width_mm: z.number().optional().describe("Page width in millimetres. Required when page_format is 'custom'."),
|
|
212
227
|
page_height_mm: z.number().optional().describe("Page height in millimetres. Required when page_format is 'custom'."),
|
|
213
228
|
tags: z.array(z.string()).optional().describe("Tags for organization (e.g. ['drilling', 'report'])"),
|
|
229
|
+
},
|
|
230
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
|
|
214
231
|
},
|
|
215
232
|
async (args) => {
|
|
216
233
|
const result = await apiRequest("POST", "/mcp/templates", {
|
|
@@ -239,11 +256,15 @@ The template is saved to the library and can later be picked when creating a flo
|
|
|
239
256
|
// Tool: list_templates
|
|
240
257
|
// ============================================================
|
|
241
258
|
|
|
242
|
-
server.
|
|
259
|
+
server.registerTool(
|
|
243
260
|
"list_templates",
|
|
244
|
-
"List all templates in the user's TypeFlow template library.",
|
|
245
261
|
{
|
|
246
|
-
|
|
262
|
+
title: "List templates",
|
|
263
|
+
description: "List the templates in the user's TypeFlow template library, with their id, page format, description and tags. Read only.",
|
|
264
|
+
inputSchema: {
|
|
265
|
+
tag: z.string().optional().describe("Filter by tag"),
|
|
266
|
+
},
|
|
267
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
247
268
|
},
|
|
248
269
|
async (args) => {
|
|
249
270
|
const params = new URLSearchParams();
|
|
@@ -272,11 +293,15 @@ server.tool(
|
|
|
272
293
|
// Tool: get_template
|
|
273
294
|
// ============================================================
|
|
274
295
|
|
|
275
|
-
server.
|
|
296
|
+
server.registerTool(
|
|
276
297
|
"get_template",
|
|
277
|
-
"Get full details of a template including HTML, CSS, and the variables and loops it contains.",
|
|
278
298
|
{
|
|
279
|
-
|
|
299
|
+
title: "Get template",
|
|
300
|
+
description: "Full details of a library template: HTML, CSS, page format, and the variables and loops it contains. Read only.",
|
|
301
|
+
inputSchema: {
|
|
302
|
+
id: z.string().describe("Template UUID"),
|
|
303
|
+
},
|
|
304
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
280
305
|
},
|
|
281
306
|
async (args) => {
|
|
282
307
|
const result = await apiRequest("GET", `/mcp/templates/${args.id}`);
|
|
@@ -307,14 +332,14 @@ server.tool(
|
|
|
307
332
|
// Tool: update_template
|
|
308
333
|
// ============================================================
|
|
309
334
|
|
|
310
|
-
server.
|
|
335
|
+
server.registerTool(
|
|
311
336
|
"update_template",
|
|
312
|
-
`Update an existing template in the user's TypeFlow template library.
|
|
313
|
-
|
|
314
|
-
Use this to iterate on a template - change the HTML, CSS, name, description, or page format. Fetch the template first with get_template to see the current state, then update what needs to change.
|
|
315
|
-
|
|
316
|
-
YOU MUST FOLLOW THE SAME TEMPLATE RULES as create_template when generating HTML/CSS. Call get_template_guide if you have not already.`,
|
|
317
337
|
{
|
|
338
|
+
title: "Update template",
|
|
339
|
+
description: `Update a template in the user's TypeFlow template library: HTML, CSS, name, description, page format or tags.
|
|
340
|
+
|
|
341
|
+
The fields given replace the saved ones, with no earlier version kept; get_template returns the current state. The same template rules as create_template apply. Flows already created from the template keep their own copy.`,
|
|
342
|
+
inputSchema: {
|
|
318
343
|
id: z.string().describe("Template UUID to update"),
|
|
319
344
|
html: z.string().optional().describe("New HTML content (replaces existing)"),
|
|
320
345
|
css: z.string().optional().describe("New CSS content (replaces existing)"),
|
|
@@ -324,6 +349,8 @@ YOU MUST FOLLOW THE SAME TEMPLATE RULES as create_template when generating HTML/
|
|
|
324
349
|
page_width_mm: z.number().optional().describe("New page width in millimetres, with page_format 'custom'."),
|
|
325
350
|
page_height_mm: z.number().optional().describe("New page height in millimetres, with page_format 'custom'."),
|
|
326
351
|
tags: z.array(z.string()).optional().describe("New tags"),
|
|
352
|
+
},
|
|
353
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false },
|
|
327
354
|
},
|
|
328
355
|
async (args) => {
|
|
329
356
|
const { id, ...updates } = args;
|
|
@@ -344,11 +371,17 @@ YOU MUST FOLLOW THE SAME TEMPLATE RULES as create_template when generating HTML/
|
|
|
344
371
|
// Tool: delete_template
|
|
345
372
|
// ============================================================
|
|
346
373
|
|
|
347
|
-
server.
|
|
374
|
+
server.registerTool(
|
|
348
375
|
"delete_template",
|
|
349
|
-
"Delete a template from the user's TypeFlow library. Flows already created from it are not affected - they hold their own copy of the HTML.",
|
|
350
376
|
{
|
|
351
|
-
|
|
377
|
+
title: "Delete template",
|
|
378
|
+
description:
|
|
379
|
+
"Delete a template from the user's TypeFlow library. Cannot be undone. " +
|
|
380
|
+
"Flows already created from it are not affected - they hold their own copy of the HTML.",
|
|
381
|
+
inputSchema: {
|
|
382
|
+
id: z.string().describe("Template UUID to delete"),
|
|
383
|
+
},
|
|
384
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false },
|
|
352
385
|
},
|
|
353
386
|
async (args) => {
|
|
354
387
|
const result = await apiRequest("DELETE", `/mcp/templates/${args.id}`);
|
|
@@ -363,15 +396,15 @@ server.tool(
|
|
|
363
396
|
// Tool: validate_template
|
|
364
397
|
// ============================================================
|
|
365
398
|
|
|
366
|
-
server.
|
|
399
|
+
server.registerTool(
|
|
367
400
|
"validate_template",
|
|
368
|
-
`Validate an HTML template against an Airtable schema before creating it.
|
|
369
|
-
|
|
370
|
-
Returns hard errors (template will fail) and warnings (template works but may have issues).
|
|
371
|
-
Always call this after generating HTML and before calling create_template.
|
|
372
|
-
|
|
373
|
-
If the schema is omitted, only structural HTML/CSS checks are performed (no variable validation).`,
|
|
374
401
|
{
|
|
402
|
+
title: "Validate template",
|
|
403
|
+
description: `Validate an HTML template against an Airtable schema, without saving it.
|
|
404
|
+
|
|
405
|
+
Returns hard errors (the template will fail) and warnings (it works but may have issues).
|
|
406
|
+
If the schema is omitted, only structural HTML/CSS checks are performed (no variable validation). Read only.`,
|
|
407
|
+
inputSchema: {
|
|
375
408
|
html: z.string().describe("The template HTML string to validate"),
|
|
376
409
|
schema: z.object({
|
|
377
410
|
mainTable: z.object({
|
|
@@ -395,6 +428,8 @@ If the schema is omitted, only structural HTML/CSS checks are performed (no vari
|
|
|
395
428
|
})).optional(),
|
|
396
429
|
})).optional(),
|
|
397
430
|
}).optional().describe("Airtable schema for semantic validation. If omitted, only structural checks run."),
|
|
431
|
+
},
|
|
432
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
398
433
|
},
|
|
399
434
|
async (args) => {
|
|
400
435
|
try {
|
|
@@ -451,5 +486,8 @@ If the schema is omitted, only structural HTML/CSS checks are performed (no vari
|
|
|
451
486
|
}
|
|
452
487
|
);
|
|
453
488
|
|
|
489
|
+
registerFlowTools(server, apiRequest);
|
|
490
|
+
registerGenerateTools(server, apiRequest);
|
|
491
|
+
|
|
454
492
|
return server;
|
|
455
493
|
}
|