@typeflowus/mcp-server 0.3.0 → 0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typeflowus/mcp-server",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
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/flow-tools.js CHANGED
@@ -13,6 +13,13 @@ import { z } from "zod";
13
13
  * a customer's account for Build it for me; every such call is logged.
14
14
  */
15
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
+
16
23
  const actAs = z
17
24
  .string()
18
25
  .optional()
@@ -38,27 +45,37 @@ export function registerFlowTools(server, apiRequest) {
38
45
  }
39
46
  };
40
47
 
41
- server.tool(
48
+ server.registerTool(
42
49
  "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 },
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
+ },
45
58
  run(async (args) => json(await call("GET", `/mcp/flows/${encodeURIComponent(args.automation_id)}`, null, args)))
46
59
  );
47
60
 
48
- server.tool(
61
+ server.registerTool(
49
62
  "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.
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.
51
66
 
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.
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.
54
69
  attachment_field is the Airtable attachment field the PDF is saved to; without it, generated PDFs are not written back.`,
55
- {
70
+ inputSchema: {
56
71
  base_id: z.string().describe("Airtable base id (appXXXXXXXXXXXXXX). get_airtable_schema lists them."),
57
72
  table_id: z.string().describe("Table id (tblXXX) or exact table name"),
58
73
  flow_name: z.string().describe("Name shown in TypeFlow"),
59
74
  attachment_field: z.string().optional().describe("Attachment field id or exact name for the generated PDF"),
60
75
  connection_id: z.string().optional().describe("Only when the account has several Airtable connections"),
61
76
  act_as: actAs,
77
+ },
78
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
62
79
  },
63
80
  run(async (args) => {
64
81
  const { act_as, ...body } = args;
@@ -67,23 +84,31 @@ attachment_field is the Airtable attachment field the PDF is saved to; without i
67
84
  })
68
85
  );
69
86
 
70
- server.tool(
87
+ server.registerTool(
71
88
  "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 },
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
+ },
74
97
  run(async (args) => json(await call("GET", `/mcp/flows/${encodeURIComponent(args.automation_id)}/template`, null, args)))
75
98
  );
76
99
 
77
- server.tool(
100
+ server.registerTool(
78
101
  "update_flow_template",
79
- `Write the flow's template. Follow get_template_guide, including its "Updating an existing template" rules.
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".
80
105
 
81
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.
82
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).
83
108
  - 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(),
109
+ - Never activates the flow.`,
110
+ inputSchema: {
111
+ automation_id: automationId,
87
112
  html: z.string().describe("Body HTML (may start with a <style> block)"),
88
113
  css: z.string().optional().describe("CSS without <style> tags, if not inside html"),
89
114
  header: z.string().optional().describe("Header zone HTML, inline styles. Omit to keep the current one, '' to clear it."),
@@ -93,6 +118,8 @@ attachment_field is the Airtable attachment field the PDF is saved to; without i
93
118
  page_height_mm: z.number().optional().describe("With page_format custom"),
94
119
  replace_mapped_variables: z.boolean().optional().describe("Allow removing variables that are mapped. Only when the user asked for it."),
95
120
  act_as: actAs,
121
+ },
122
+ annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false },
96
123
  },
97
124
  run(async (args) => {
98
125
  const { automation_id, act_as, ...body } = args;
@@ -101,23 +128,27 @@ attachment_field is the Airtable attachment field the PDF is saved to; without i
101
128
  })
102
129
  );
103
130
 
104
- server.tool(
131
+ server.registerTool(
105
132
  "set_mapping",
106
- `Bind the template's variables to the flow's Airtable fields.
133
+ {
134
+ title: "Set mapping",
135
+ description: `Bind the template's variables to the flow's Airtable fields.
107
136
 
108
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.
109
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.
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(),
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."),
114
143
  overrides: z.record(z.object({
115
144
  field: z.string().describe("Field id or exact name"),
116
145
  barcode_type: z.string().optional(),
117
146
  width: z.number().optional(),
118
147
  height: z.number().optional(),
119
- })).optional(),
148
+ })).optional().describe("Variable to field, e.g. { \"{{Client}}\": { \"field\": \"Client name\" } }"),
120
149
  act_as: actAs,
150
+ },
151
+ annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false },
121
152
  },
122
153
  run(async (args) => {
123
154
  const { automation_id, act_as, ...body } = args;
@@ -125,18 +156,22 @@ Returns what is still unmapped: report it to the user, do not guess.`,
125
156
  })
126
157
  );
127
158
 
128
- server.tool(
159
+ server.registerTool(
129
160
  "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.
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.
131
164
 
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.
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.
133
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.`,
134
- {
135
- automation_id: z.string(),
167
+ inputSchema: {
168
+ automation_id: automationId,
136
169
  record_id: z.string().describe("Airtable record id (recXXX)"),
137
- preview_only: z.boolean().optional(),
138
- allow_signature_emails: z.boolean().optional(),
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."),
139
172
  act_as: actAs,
173
+ },
174
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true },
140
175
  },
141
176
  run(async (args) => {
142
177
  const { automation_id, act_as, ...body } = args;
@@ -144,14 +179,20 @@ Without preview_only the PDF is saved to the record's attachment field, as a tes
144
179
  })
145
180
  );
146
181
 
147
- server.tool(
182
+ server.registerTool(
148
183
  "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
184
  {
151
- automation_id: z.string(),
152
- html: z.string().optional(),
153
- css: z.string().optional(),
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"),
154
193
  act_as: actAs,
194
+ },
195
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
155
196
  },
156
197
  run(async (args) => {
157
198
  const { automation_id, act_as, ...body } = args;
@@ -159,13 +200,19 @@ Without preview_only the PDF is saved to the record's attachment field, as a tes
159
200
  })
160
201
  );
161
202
 
162
- server.tool(
203
+ server.registerTool(
163
204
  "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
205
  {
166
- automation_id: z.string(),
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,
167
212
  user_confirmation: z.string().min(1).describe("The user's exact words confirming the document is right"),
168
213
  act_as: actAs,
214
+ },
215
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
169
216
  },
170
217
  run(async (args) => {
171
218
  const { automation_id, act_as, user_confirmation } = args;
@@ -173,23 +220,31 @@ Without preview_only the PDF is saved to the record's attachment field, as a tes
173
220
  })
174
221
  );
175
222
 
176
- server.tool(
223
+ server.registerTool(
177
224
  "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 },
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
+ },
180
233
  run(async (args) => json(await call("GET", `/mcp/flows/${encodeURIComponent(args.automation_id)}/esignature`, null, args)))
181
234
  );
182
235
 
183
- server.tool(
236
+ server.registerTool(
184
237
  "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.
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.
186
241
 
187
242
  - One signer per signer number of the template ({{e-signature.signature_1}} is signer 1). Every number must be configured, and only those.
188
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.
189
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).
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(),
245
+ - Sends nothing. Signers are emailed only when a document is generated.`,
246
+ inputSchema: {
247
+ automation_id: automationId,
193
248
  signers: z.array(z.object({
194
249
  signer_number: z.number().int().min(1),
195
250
  email_field: z.string().optional().describe("Field id or exact name holding the signer's email"),
@@ -200,13 +255,15 @@ Without preview_only the PDF is saved to the record's attachment field, as a tes
200
255
  static_name: z.string().optional().describe("Fixed name, with static_email"),
201
256
  role: z.string().optional().describe("Label shown to signers, e.g. Client"),
202
257
  optional: z.boolean().optional(),
203
- })).optional(),
258
+ })).optional().describe("One entry per signer number of the template"),
204
259
  signing_mode: z.enum(["parallel", "sequential"]).optional().describe("sequential: signer 1 first, then signer 2"),
205
260
  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(),
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"),
208
263
  enabled: z.boolean().optional().describe("false turns e-signature off"),
209
264
  act_as: actAs,
265
+ },
266
+ annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false },
210
267
  },
211
268
  run(async (args) => {
212
269
  const { automation_id, act_as, ...body } = args;
@@ -214,15 +271,21 @@ Without preview_only the PDF is saved to the record's attachment field, as a tes
214
271
  })
215
272
  );
216
273
 
217
- server.tool(
274
+ server.registerTool(
218
275
  "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
276
  {
221
- automation_id: z.string(),
222
- status: z.enum(["pending", "completed", "declined", "expired", "cancelled"]).optional(),
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"),
223
284
  record_id: z.string().optional().describe("Only the requests for this Airtable record"),
224
- limit: z.number().int().min(1).max(100).optional(),
285
+ limit: z.number().int().min(1).max(100).optional().describe("At most this many requests"),
225
286
  act_as: actAs,
287
+ },
288
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
226
289
  },
227
290
  run(async (args) => {
228
291
  const query = new URLSearchParams();
@@ -232,15 +295,21 @@ Without preview_only the PDF is saved to the record's attachment field, as a tes
232
295
  })
233
296
  );
234
297
 
235
- server.tool(
298
+ server.registerTool(
236
299
  "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
300
  {
239
- automation_id: z.string(),
240
- request_id: z.string().describe("From list_signatures"),
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"),
241
308
  user_confirmation: z.string().min(1).describe("The user's exact words asking to cancel"),
242
- reason: z.string().optional(),
309
+ reason: z.string().optional().describe("Why the request is cancelled"),
243
310
  act_as: actAs,
311
+ },
312
+ annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: true },
244
313
  },
245
314
  run(async (args) => {
246
315
  const { automation_id, request_id, act_as, ...body } = args;
@@ -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,6 +1,7 @@
1
1
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { z } from "zod";
3
3
  import { registerFlowTools } from "./flow-tools.js";
4
+ import { registerGenerateTools } from "./generate-tools.js";
4
5
 
5
6
  /**
6
7
  * What to tell the model about page formats.
@@ -105,10 +106,16 @@ export function createTypeFlowMcpServer({ apiRequest, version }) {
105
106
  // Tool: get_template_guide
106
107
  // ============================================================
107
108
 
108
- server.tool(
109
+ server.registerTool(
109
110
  "get_template_guide",
110
- "Returns the COMPLETE TypeFlow template creation guide: HTML/CSS rules, variable syntax, loop structures, image handling, examples, and the decision tree for turning an Airtable schema into TypeFlow variables. You MUST call this before creating or updating any template.",
111
- {},
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
+ },
112
119
  async () => {
113
120
  try {
114
121
  return {
@@ -136,20 +143,24 @@ server.tool(
136
143
  // Tool: get_airtable_schema
137
144
  // ============================================================
138
145
 
139
- server.tool(
146
+ server.registerTool(
140
147
  "get_airtable_schema",
141
- `List the user's Airtable bases, or read the tables and fields of one.
148
+ {
149
+ title: "Get Airtable schema",
150
+ description: `List the user's Airtable bases, or read the tables and fields of one.
142
151
 
143
- Call with no arguments to list the bases this account can reach. Call with a base_id to get its tables, fields and field types.
152
+ With no arguments, lists the bases this account can reach. With a base_id, returns its tables, fields and field types.
144
153
 
145
- Read this BEFORE writing a template that binds to Airtable data. TypeFlow maps variables by name: {{Invoice Number}} binds to a field called exactly "Invoice Number" and to nothing else. A template written against guessed field names maps to nothing, and the user finds out one field at a time in the editor.
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.
146
155
 
147
- Returns structure only - table names, field names, field types. No record data.`,
148
- {
149
- base_id: z
150
- .string()
151
- .optional()
152
- .describe("Airtable base id (appXXXXXXXXXXXXXX). Omit to list the available bases."),
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 },
153
164
  },
154
165
  async (args) => {
155
166
  const path = args.base_id
@@ -199,14 +210,14 @@ Returns structure only - table names, field names, field types. No record data.`
199
210
  // Tool: create_template
200
211
  // ============================================================
201
212
 
202
- server.tool(
213
+ server.registerTool(
203
214
  "create_template",
204
- `Create a new HTML template in the user's TypeFlow template library.
205
-
206
- IMPORTANT: You MUST call get_template_guide first before generating any HTML. The guide contains all the rules you need.
207
-
208
- The template is saved to the library and can later be picked when creating a flow in TypeFlow.`,
209
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: {
210
221
  name: z.string().describe("Template name (e.g. 'Drilling Report Q2')"),
211
222
  html: z.string().describe("HTML content without <style> tags. Must follow the rules from get_template_guide."),
212
223
  css: z.string().describe("CSS content without <style> wrapper"),
@@ -215,6 +226,8 @@ The template is saved to the library and can later be picked when creating a flo
215
226
  page_width_mm: z.number().optional().describe("Page width in millimetres. Required when page_format is 'custom'."),
216
227
  page_height_mm: z.number().optional().describe("Page height in millimetres. Required when page_format is 'custom'."),
217
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 },
218
231
  },
219
232
  async (args) => {
220
233
  const result = await apiRequest("POST", "/mcp/templates", {
@@ -243,11 +256,15 @@ The template is saved to the library and can later be picked when creating a flo
243
256
  // Tool: list_templates
244
257
  // ============================================================
245
258
 
246
- server.tool(
259
+ server.registerTool(
247
260
  "list_templates",
248
- "List all templates in the user's TypeFlow template library.",
249
261
  {
250
- tag: z.string().optional().describe("Filter by tag"),
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 },
251
268
  },
252
269
  async (args) => {
253
270
  const params = new URLSearchParams();
@@ -276,11 +293,15 @@ server.tool(
276
293
  // Tool: get_template
277
294
  // ============================================================
278
295
 
279
- server.tool(
296
+ server.registerTool(
280
297
  "get_template",
281
- "Get full details of a template including HTML, CSS, and the variables and loops it contains.",
282
298
  {
283
- id: z.string().describe("Template UUID"),
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 },
284
305
  },
285
306
  async (args) => {
286
307
  const result = await apiRequest("GET", `/mcp/templates/${args.id}`);
@@ -311,14 +332,14 @@ server.tool(
311
332
  // Tool: update_template
312
333
  // ============================================================
313
334
 
314
- server.tool(
335
+ server.registerTool(
315
336
  "update_template",
316
- `Update an existing template in the user's TypeFlow template library.
317
-
318
- 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.
319
-
320
- YOU MUST FOLLOW THE SAME TEMPLATE RULES as create_template when generating HTML/CSS. Call get_template_guide if you have not already.`,
321
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: {
322
343
  id: z.string().describe("Template UUID to update"),
323
344
  html: z.string().optional().describe("New HTML content (replaces existing)"),
324
345
  css: z.string().optional().describe("New CSS content (replaces existing)"),
@@ -328,6 +349,8 @@ YOU MUST FOLLOW THE SAME TEMPLATE RULES as create_template when generating HTML/
328
349
  page_width_mm: z.number().optional().describe("New page width in millimetres, with page_format 'custom'."),
329
350
  page_height_mm: z.number().optional().describe("New page height in millimetres, with page_format 'custom'."),
330
351
  tags: z.array(z.string()).optional().describe("New tags"),
352
+ },
353
+ annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false },
331
354
  },
332
355
  async (args) => {
333
356
  const { id, ...updates } = args;
@@ -348,11 +371,17 @@ YOU MUST FOLLOW THE SAME TEMPLATE RULES as create_template when generating HTML/
348
371
  // Tool: delete_template
349
372
  // ============================================================
350
373
 
351
- server.tool(
374
+ server.registerTool(
352
375
  "delete_template",
353
- "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.",
354
376
  {
355
- id: z.string().describe("Template UUID to delete"),
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 },
356
385
  },
357
386
  async (args) => {
358
387
  const result = await apiRequest("DELETE", `/mcp/templates/${args.id}`);
@@ -367,15 +396,15 @@ server.tool(
367
396
  // Tool: validate_template
368
397
  // ============================================================
369
398
 
370
- server.tool(
399
+ server.registerTool(
371
400
  "validate_template",
372
- `Validate an HTML template against an Airtable schema before creating it.
373
-
374
- Returns hard errors (template will fail) and warnings (template works but may have issues).
375
- Always call this after generating HTML and before calling create_template.
376
-
377
- If the schema is omitted, only structural HTML/CSS checks are performed (no variable validation).`,
378
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: {
379
408
  html: z.string().describe("The template HTML string to validate"),
380
409
  schema: z.object({
381
410
  mainTable: z.object({
@@ -399,6 +428,8 @@ If the schema is omitted, only structural HTML/CSS checks are performed (no vari
399
428
  })).optional(),
400
429
  })).optional(),
401
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 },
402
433
  },
403
434
  async (args) => {
404
435
  try {
@@ -456,6 +487,7 @@ If the schema is omitted, only structural HTML/CSS checks are performed (no vari
456
487
  );
457
488
 
458
489
  registerFlowTools(server, apiRequest);
490
+ registerGenerateTools(server, apiRequest);
459
491
 
460
492
  return server;
461
493
  }