suppa-mcp-2 1.24.0 → 1.26.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/dist/server.js CHANGED
@@ -21,6 +21,7 @@ import * as automation from "./tools/automation.js";
21
21
  import * as auth from "./auth.js";
22
22
  import * as tenants from "./tenants.js";
23
23
  import { confirmRequired, jsonResponse } from "./utils.js";
24
+ import { installToolsListEconomy } from "./toolsListEconomy.js";
24
25
  import { PACKAGE_NAME, PACKAGE_VERSION, knownLatest, isOutdated, refreshLatestVersion, upgradeNotice, } from "./version.js";
25
26
  export { PACKAGE_VERSION };
26
27
  // ---------------------------------------------------------------------------
@@ -78,6 +79,24 @@ const ProjectionJson = z
78
79
  .string()
79
80
  .describe('JSON projection of fields to return, e.g. {"id": true, "title": true, ' +
80
81
  '"owner": {"id": true, "fullName": true}}. Enums: {"myEnum": {"value": true}}.');
82
+ /**
83
+ * The optional projection on the task/doc read tools. Without it a read answers
84
+ * with the tool's standard field set; with it, only what was named. A model
85
+ * once made seven suppa_get_task calls to collect one shortUID per task — each
86
+ * answered with the whole detail record. This parameter, and task_ids below,
87
+ * make that one call.
88
+ */
89
+ const FieldsJsonOpt = z
90
+ .string()
91
+ .nullable()
92
+ .default(null)
93
+ .describe('Return ONLY these fields: {"id": true, "shortUID": true} or ["id", "shortUID"]; relations as ' +
94
+ 'nested objects ({"assignedTo": {"fullName": true}}). Default: this tool\'s standard field set.');
95
+ const TaskIds = z
96
+ .array(z.number().int())
97
+ .nullable()
98
+ .default(null)
99
+ .describe("Read exactly these task ids in ONE call (combined with the other filters).");
81
100
  // Soft-delete read scoping. Both mirror the platform's own defaults
82
101
  // (captures/api-entity-builder-data.txt:75-76) — this server used to force
83
102
  // includeDeletedRelations=false, which silently hid soft-deleted relations.
@@ -232,51 +251,70 @@ const EntityQuery = z
232
251
  // ---------------------------------------------------------------------------
233
252
  /** Read once, from the one file that states the rules (see houseRulesDigest). */
234
253
  const HOUSE_RULES_DIGEST = houseRulesDigest();
235
- const INSTRUCTIONS = `Suppa Platform MCP Server — manage Tasks, Docs/Pages, Entities, Forms, and file attachments on modern.suppa.me.
254
+ const INSTRUCTIONS = `Suppa Platform MCP Server — Tasks, Docs/Pages, Entities, Forms, Automations and file attachments on Suppa tenants.
236
255
 
237
256
  AUTHENTICATION — RESOLVE THIS BEFORE ANY OTHER SUPPA WORK
238
- - Auth is an interactive Google browser sign-in. There is NO API key for an end user to find or paste — so NEVER ask the user for a token, key, or password. If you're tempted to ask for credentials, call suppa_login instead.
239
- - At the start of Suppa work, if you don't already know the user is signed in, call suppa_list_tenants (cheap, read-only). Look at the ACTIVE tenant: if "authenticated": false or "needs_login": true, the user is not signed in.
240
- - Whenever the user is not signed in — OR any tool returns "No Suppa credentials" / HTTP 401 / "session could not be refreshed" / a ReloginRequired error — DO NOT STOP and DO NOT ask for a key. Authenticate yourself:
241
- 1. Call suppa_login (or suppa_login(tenant="<alias|host|url>") to target a specific instance; default is the active tenant). This OPENS A GOOGLE SIGN-IN PAGE in the user's default browser — a local page served at http://localhost:8080.
242
- 2. Tell the user in plain words: "I've opened a Google sign-in page in your browser — pick your account to finish signing in." If the browser didn't open, the tool result carries the URL; give it to them to open manually.
243
- 3. suppa_login blocks until they finish and returns {"status":"ok"}. THEN retry the original action. Tokens are stored in the OS keychain and auto-refresh, so this is a one-time step per tenant — you won't need to repeat it next session.
244
- - A static SUPPA_API_KEY in the client env is supported (CI / single-tenant) and, when present, means no login is needed — but it is optional and most users won't have one.
245
- - Use suppa_diagnostics to validate the whole setup; it reports the login_origin that must be whitelisted. ONE-TIME ORG SETUP: the loopback origin (http://localhost:8080) must be added to the Google OAuth client's "Authorized JavaScript origins". If the sign-in page opens but never completes, that missing whitelist entry is almost always why — surface this to the user so an admin can add it.
246
- - suppa_use_tenant switches the active instance for ALL later calls; suppa_list_tenants shows what's known and authenticated.
257
+ - Sign-in is an interactive Google flow in the browser. There is NO API key for a user to find or paste — NEVER ask for a token, key or password; call suppa_login instead.
258
+ - Unsure whether the user is signed in? Call suppa_list_tenants (cheap, read-only): the ACTIVE tenant shows "authenticated": false or "needs_login": true when not.
259
+ - When not signed in — or any tool answers "No Suppa credentials" / HTTP 401 / "session could not be refreshed" / ReloginRequired — DO NOT STOP and DO NOT ask for a key:
260
+ 1. Call suppa_login (suppa_login(tenant="<alias|host|url>") targets another instance; default is the active tenant). It OPENS A GOOGLE SIGN-IN PAGE in the default browser, served locally at http://localhost:8080.
261
+ 2. Tell the user: "I've opened a Google sign-in page in your browser — pick your account to finish signing in." If the browser did not open, the result carries the URL for them to open by hand.
262
+ 3. It blocks until they finish and returns {"status":"ok"} — THEN retry the original action. Tokens go to the OS keychain and auto-refresh: one login per tenant, not per session.
263
+ - A static SUPPA_API_KEY in the client env (CI / single tenant) means no login is needed; it is optional and most users have none.
264
+ - suppa_diagnostics validates the whole setup and reports the login_origin to whitelist. ONE-TIME ORG SETUP: http://localhost:8080 must be in the Google OAuth client's "Authorized JavaScript origins" — a sign-in page that opens but never completes is almost always this; tell the user so an admin can add it.
265
+ - suppa_use_tenant switches the active instance for ALL later calls; suppa_list_tenants shows what is known and authenticated.
247
266
 
248
267
  DATA BASICS
249
- - IDs are integers (not UUIDs). Dates are ISO-8601 strings; a naive datetime (no offset) is read as UTC, so include an explicit offset (+03:00) or convert local times yourself. Task deadlines also accept 'today', 'tomorrow', '+3d', '+2h', '+30m', '+1w'.
250
- - Every write tool's description carries the shapes it demands — relations and enums as {"id": N}, list fields REPLACED unless merge_json says otherwise, and validation against the live schema before anything is written. Read the one you are about to call; a bare number where a reference belongs returns 201 and stores null.
251
- - DELETE IS A SOFT DELETE — every delete tool here sets deletedAt and leaves the row in place, reversible with suppa_restore_record(entity_name, record_id). Don't tell the user their data was destroyed. It still needs confirm=true, because the record disappears from all normal reads. To find a removed row again, read with deleted_scope='deleted'.
252
- - PERMANENT DELETE IS UNAVAILABLE HERE, BY DESIGN — this server performs REVERSIBLE deletes only. The platform's PERMANENT delete (POST /core/data/:entityName/delete: the rows leave the table and cannot be restored) is BLOCKED in the HTTP client itself, so no tool, no flag, no confirm=true and no direct call can reach it; an attempt is refused before the request is sent. Don't look for a tool, a parameter or a workaround — there is none. If a user asks to erase data for good, say so plainly and offer the soft delete (suppa_delete_record → /remove, undone by suppa_restore_record); permanent removal has to be done by an admin in the platform's own UI.
268
+ - IDs are integers, not UUIDs. Dates are ISO-8601; a naive datetime (no offset) is read as UTC, so pass an explicit offset (+03:00) or convert local times yourself. Task deadlines also accept 'today', 'tomorrow', '+3d', '+2h', '+30m', '+1w'.
269
+ - Each write tool's description states the shapes it demands — relations and enums as {"id": N}, list fields REPLACED unless merge_json says otherwise — and validates against the live schema before writing. Read it before calling: a bare number where a reference belongs returns 201 and stores null.
270
+ - DELETE IS A SOFT DELETE — every delete tool sets deletedAt and leaves the row in place, reversible with suppa_restore_record(entity_name, record_id); never tell the user their data was destroyed. It still needs confirm=true because the row leaves all normal reads; find it again with deleted_scope='deleted'.
271
+ - PERMANENT DELETE IS UNAVAILABLE HERE, BY DESIGN — this server performs REVERSIBLE deletes only. The platform's PERMANENT delete (POST /core/data/:entityName/delete — rows leave the table and cannot be restored) is BLOCKED in the HTTP client itself: no tool, flag, confirm=true or direct call reaches it, and an attempt is refused before any request is sent. Do not look for a tool, a parameter or a workaround — there is none. Asked to erase data for good, say so plainly and offer the soft delete (suppa_delete_record → /remove, undone by suppa_restore_record); permanent removal is an admin action in the platform's own UI.
272
+ - Reads are compact: relation objects omit deletedAt when null (a live row); schema reads omit nulls, false flags and default options and carry a _legend (full=true returns the raw form).
253
273
 
254
274
  SEARCH & FILTERS — suppa_search_records' description carries the comparators, nested AND/OR groups, dotted field paths, "$current-user", paging and the auto-diagnosis of an empty result. Read it before your first search.
255
- - PROJECT ONLY THE FIELDS YOU NEED (fields_json). It is the difference between a 600-character answer and a 50 000-character one, and every answer is re-sent on every later turn of the conversation.
256
- - Discover schema first when unsure: suppa_list_entities → suppa_describe_entity, then suppa_search_records. One record by id needs no filters at all: suppa_get_record / suppa_get_task / suppa_get_doc.
275
+ - PROJECT ONLY THE FIELDS YOU NEED: fields_json is on suppa_search_records AND on every task/doc read (suppa_get_task, suppa_search_tasks — which also takes task_ids, so several tasks are ONE call, never one suppa_get_task each — suppa_get_doc, suppa_list_pages, …). A 600-character answer instead of a 50 000-character one, re-sent on every later turn.
276
+ - Unsure of the schema: suppa_list_entities → suppa_describe_entity → suppa_search_records. One record by id needs no filters: suppa_get_record / suppa_get_task / suppa_get_doc.
257
277
 
258
278
  APPROVAL GATES (human-in-the-loop)
259
- - Every update/move/close/delete tool returns {"status": "confirmation_required"} when called without confirm=true, and performs NOTHING.
260
- - On that response: show the user what will change, get explicit approval, then re-call the same tool with confirm=true. Never set confirm=true on the first call without the user's go-ahead.
261
- - Create/read tools (and comments) need no confirmation.
262
- - A value shown as <N chars — exactly as sent / unchanged from this call's arguments> is NOT the stored text: it is the long string you yourself supplied in this same call, named instead of repeated. Quote it to the user from your own arguments; never report the marker as the record's content.
279
+ - Every update/move/close/delete tool called without confirm=true returns {"status": "confirmation_required"} and performs NOTHING. Show the user what will change, get explicit approval, then re-call the same tool with confirm=true — never set it on the first call without their go-ahead. Create/read tools and comments need no confirmation.
280
+ - A value shown as <N chars — exactly as sent / unchanged from this call's arguments> is NOT the stored text: it names the long string you yourself supplied in this same call. Quote it to the user from your own arguments; never report the marker as the record's content.
263
281
 
264
282
  ENTITY BUILDER (create + edit fields; removal is UI-only) — suppa_add_field's description carries the real field types, the sub_type matrix and the field options; suppa_update_field's carries what may still be changed on a field that exists. Two things those cannot decide for you:
265
- - OWNED CHILD COLLECTIONS ARE TABULAR PARTS. Repeating rows belonging to ONE parent record (a part's BOM items) go through suppa_create_tabular_part(parent_entity, name), which creates the child's 'owner' relation and the parent link. Never model it by hand — suppa_add_field REFUSES field_type='one-to-many'. 'many-to-many' is for a shared lookup referenced by many records.
266
- - An enum value on a RECORD is a reference, not a string: {"id": <Enums row id>}, or an array of those for multi-enum. A bare code like "red" is refused. Read the ids with suppa_search_records on 'Enums' filtered by name.
283
+ - OWNED CHILD COLLECTIONS ARE TABULAR PARTS: repeating rows that belong to ONE parent record (a part's BOM items) go through suppa_create_tabular_part(parent_entity, name), which creates the child's 'owner' relation and the parent link. Never model it by hand — suppa_add_field REFUSES field_type='one-to-many'; 'many-to-many' is for a shared lookup referenced by many records.
284
+ - An enum value on a RECORD is a reference, {"id": <Enums row id>} (an array of those for multi-enum), never a bare code like "red" — that is refused. Read the ids with suppa_search_records on 'Enums' filtered by name.
267
285
 
268
286
  ${HOUSE_RULES_DIGEST}
269
287
 
270
- ATTACHMENTS (files on a record) — an entity can hold files only if it has a 'file' or 'multi-file' field; add one with suppa_add_field. suppa_attach_file_to_record uploads from local disk and returns the file_ids that are the only handle to the bytes; suppa_list_record_files lists what a record carries; suppa_download_file and suppa_download_files_zip fetch them. Those descriptions carry the rest.
288
+ ATTACHMENTS — an entity holds files only through a 'file' or 'multi-file' field (add one with suppa_add_field). suppa_attach_file_to_record uploads from local disk and returns the file_ids that are the only handle to the bytes; suppa_list_record_files lists what a record carries; suppa_download_file and suppa_download_files_zip fetch them. Those descriptions carry the rest.
271
289
 
272
- MIGRATION (Suppa 1.0 → 2.0)
273
- - Always dry-run first: suppa_migrate_entities_from_v1(dry_run=true, output_file="plan.json"), review/edit the plan, then execute with plan_file="plan.json", dry_run=false.
290
+ MIGRATION (Suppa 1.0 → 2.0) — always dry-run first: suppa_migrate_entities_from_v1(dry_run=true, output_file="plan.json"), review/edit the plan, then execute with plan_file="plan.json", dry_run=false.
274
291
  `;
275
292
  // ---------------------------------------------------------------------------
276
293
  // Registered tool + prompt names (tests assert the counts).
277
294
  // ---------------------------------------------------------------------------
278
295
  export const TOOL_NAMES = [];
279
296
  export const PROMPT_NAMES = [];
297
+ /**
298
+ * Tool descriptions were ported from Python docstrings and kept their four-space
299
+ * continuation indent — thousands of characters of leading whitespace across the
300
+ * listing that no reader needs. Stripped at registration; the words are unchanged.
301
+ */
302
+ export function compactDescription(description) {
303
+ const lines = description.split("\n");
304
+ if (lines.length < 2)
305
+ return description;
306
+ let common = Infinity;
307
+ for (const line of lines.slice(1)) {
308
+ if (!line.trim())
309
+ continue;
310
+ const indent = line.length - line.trimStart().length;
311
+ if (indent < common)
312
+ common = indent;
313
+ }
314
+ if (!Number.isFinite(common) || common === 0)
315
+ return description;
316
+ return [lines[0], ...lines.slice(1).map((l) => (l.trim() ? l.slice(common) : ""))].join("\n");
317
+ }
280
318
  /** Wrap a tool-module call result (a JSON string) into an MCP text content. */
281
319
  function text(result) {
282
320
  return { content: [{ type: "text", text: result }] };
@@ -310,7 +348,7 @@ export function buildServer() {
310
348
  const server = new McpServer({ name: "suppa-2.0", version: PACKAGE_VERSION }, { instructions: INSTRUCTIONS + upgradeNotice() });
311
349
  const reg = (name, cfg, handler) => {
312
350
  server.registerTool(name, {
313
- description: cfg.description,
351
+ description: compactDescription(cfg.description),
314
352
  inputSchema: (cfg.inputSchema ?? {}),
315
353
  annotations: cfg.annotations,
316
354
  }, handler);
@@ -324,8 +362,12 @@ export function buildServer() {
324
362
  annotations: _READ,
325
363
  }, async () => text(await tasks.getMe()));
326
364
  reg("suppa_search_tasks", {
327
- description: "Search tasks. Use my=true for your tasks, active=true for open tasks, or search by title substring.",
365
+ description: "Search tasks. Use my=true for your tasks, active=true for open tasks, or search by title substring.\n" +
366
+ " Several known tasks: task_ids=[…] reads them in ONE call. fields_json narrows each row to\n" +
367
+ " what you need — task_ids + fields_json replaces N suppa_get_task calls.",
328
368
  inputSchema: {
369
+ task_ids: TaskIds,
370
+ fields_json: FieldsJsonOpt,
329
371
  search: TaskSearch.default(""),
330
372
  my: MyFlag.default(false),
331
373
  active: ActiveFlag.default(false),
@@ -339,7 +381,7 @@ export function buildServer() {
339
381
  offset: z.number().int().default(0),
340
382
  },
341
383
  annotations: _READ,
342
- }, async (a) => text(await tasks.searchTasks(a.search, a.my, a.active, a.overdue, a.due_today, a.project_id, a.workflow_id, a.stage_id, a.assigned_to_id, a.limit, a.offset)));
384
+ }, async (a) => text(await tasks.searchTasks(a.search, a.my, a.active, a.overdue, a.due_today, a.project_id, a.workflow_id, a.stage_id, a.assigned_to_id, a.limit, a.offset, a.task_ids, a.fields_json)));
343
385
  reg("suppa_count_tasks", {
344
386
  description: "Count tasks matching filters without returning full data.",
345
387
  inputSchema: {
@@ -354,10 +396,13 @@ export function buildServer() {
354
396
  annotations: _READ,
355
397
  }, async (a) => text(await tasks.countTasks(a.my, a.active, a.project_id, a.workflow_id, a.search, a.overdue, a.due_today)));
356
398
  reg("suppa_get_task", {
357
- description: "Get full details of a task by its ID.",
358
- inputSchema: { task_id: z.number().int() },
399
+ description: "Get a task by its ID — full details by default, or only fields_json (e.g. [\"id\", \"shortUID\"]).\n" +
400
+ " For SEVERAL tasks call suppa_search_tasks(task_ids=[…], fields_json=…) once, not this per task.\n" +
401
+ " The description is htmlDescription; plainDescription is included only when it differs\n" +
402
+ " from that HTML with the tags removed.",
403
+ inputSchema: { task_id: z.number().int(), fields_json: FieldsJsonOpt },
359
404
  annotations: _READ,
360
- }, async (a) => text(await tasks.getTask(a.task_id)));
405
+ }, async (a) => text(await tasks.getTask(a.task_id, a.fields_json)));
361
406
  reg("suppa_create_task", {
362
407
  description: "Create a new task. Deadline accepts: 'today', 'tomorrow', '+3d', '+2h', '+30m', '+1w', or ISO datetime.\n" +
363
408
  " HTML: plain text is auto-wrapped in <p>…</p>; to pass raw HTML, start the\n" +
@@ -386,8 +431,7 @@ export function buildServer() {
386
431
  " Any list-valued field written here is REPLACED wholesale — this tool has no\n" +
387
432
  " merge option. To ADD to / REMOVE from a task's list field, use\n" +
388
433
  ' suppa_update_record("Tasks", ...) with merge_json / unmerge_json.\n\n' +
389
- " APPROVAL GATE: without confirm=true this returns a confirmation request and\n" +
390
- " changes nothing. Get the user's approval, then re-call with confirm=true.",
434
+ " APPROVAL GATE: without confirm=true this returns a confirmation request and changes nothing.",
391
435
  inputSchema: {
392
436
  task_id: z.number().int(),
393
437
  title: z.string().nullable().default(null),
@@ -426,14 +470,12 @@ export function buildServer() {
426
470
  });
427
471
  reg("suppa_delete_task", {
428
472
  description: "Soft-delete a task.\n\n" +
429
- " SOFT DELETE: sets deletedAt — the row remains in the database and the delete\n" +
430
- " is reversible: suppa_restore_record('Tasks', task_id) brings it back. The task\n" +
431
- " does drop out of every normal read — find it again with\n" +
432
- " suppa_search_records('Tasks', deleted_scope='deleted').\n\n" +
433
- " NOT the platform's permanent delete (a separate endpoint where the rows leave\n" +
434
- " the table and cannot be restored); that one is deliberately not exposed here.\n\n" +
435
- " APPROVAL GATE: without confirm=true this returns a confirmation request and\n" +
436
- " deletes nothing. Get the user's approval, then re-call with confirm=true.",
473
+ " SOFT DELETE: sets deletedAt — the row remains and the delete is reversible with\n" +
474
+ " suppa_restore_record('Tasks', task_id); it drops out of normal reads, so find it again\n" +
475
+ " with suppa_search_records('Tasks', deleted_scope='deleted'). Not the platform's\n" +
476
+ " permanent delete (rows leave the table and cannot be restored), which this server\n" +
477
+ " does not expose.\n\n" +
478
+ " APPROVAL GATE: without confirm=true this returns a confirmation request and deletes nothing.",
437
479
  inputSchema: { task_id: z.number().int(), confirm: Confirm },
438
480
  annotations: _MUT,
439
481
  }, async (a) => {
@@ -444,8 +486,7 @@ export function buildServer() {
444
486
  });
445
487
  reg("suppa_move_task", {
446
488
  description: "Move a task to a different workflow stage.\n\n" +
447
- " APPROVAL GATE: without confirm=true this returns a confirmation request and\n" +
448
- " changes nothing. Get the user's approval, then re-call with confirm=true.",
489
+ " APPROVAL GATE: without confirm=true this returns a confirmation request and changes nothing.",
449
490
  inputSchema: {
450
491
  task_id: z.number().int(),
451
492
  stage_id: z
@@ -463,8 +504,7 @@ export function buildServer() {
463
504
  });
464
505
  reg("suppa_close_task", {
465
506
  description: "Close a task by moving it to the workflow's completed stage.\n\n" +
466
- " APPROVAL GATE: without confirm=true this returns a confirmation request and\n" +
467
- " changes nothing. Get the user's approval, then re-call with confirm=true.",
507
+ " APPROVAL GATE: without confirm=true this returns a confirmation request and changes nothing.",
468
508
  inputSchema: { task_id: z.number().int(), confirm: Confirm },
469
509
  annotations: _MUT,
470
510
  }, async (a) => {
@@ -509,12 +549,13 @@ export function buildServer() {
509
549
  annotations: _ADD,
510
550
  }, async (a) => text(await tasks.attachFile(a.task_id, a.file_path)));
511
551
  reg("suppa_list_workflows", {
512
- description: "List all workflows. Optionally filter by name.",
552
+ description: "List all workflows with their stages in order. Optionally filter by name. A stage's\n" +
553
+ " status is the enum value ('active', 'completed', …).",
513
554
  inputSchema: { name: z.string().nullable().default(null) },
514
555
  annotations: _READ,
515
556
  }, async (a) => text(await tasks.listWorkflows(a.name)));
516
557
  reg("suppa_list_stages", {
517
- description: "List all stages in a specific workflow.",
558
+ description: "List all stages in a specific workflow, in order. status is the enum value ('active', 'completed', …).",
518
559
  inputSchema: {
519
560
  workflow_id: z
520
561
  .number()
@@ -542,21 +583,22 @@ export function buildServer() {
542
583
  // Docs tools
543
584
  // =========================================================================
544
585
  reg("suppa_list_docs", {
545
- description: "List documents, optionally filtering by title.",
586
+ description: "List documents, optionally filtering by title. fields_json narrows each row.",
546
587
  inputSchema: {
547
588
  search: z
548
589
  .string()
549
590
  .default("")
550
591
  .describe("Case-insensitive substring of the doc title."),
551
592
  limit: z.number().int().default(20),
593
+ fields_json: FieldsJsonOpt,
552
594
  },
553
595
  annotations: _READ,
554
596
  }, async (a) => text(await docs.listDocs(a.search, a.limit)));
555
597
  reg("suppa_get_doc", {
556
- description: "Get a document by ID including its page tree.",
557
- inputSchema: { doc_id: z.number().int() },
598
+ description: "Get a document by ID including its page tree, or only fields_json.",
599
+ inputSchema: { doc_id: z.number().int(), fields_json: FieldsJsonOpt },
558
600
  annotations: _READ,
559
- }, async (a) => text(await docs.getDoc(a.doc_id)));
601
+ }, async (a) => text(await docs.getDoc(a.doc_id, a.fields_json)));
560
602
  reg("suppa_create_doc", {
561
603
  description: "Create a new document.",
562
604
  inputSchema: {
@@ -569,8 +611,7 @@ export function buildServer() {
569
611
  description: "Update a document's title or visibility.\n\n" +
570
612
  " Any list-valued field written here is REPLACED wholesale — this tool has no\n" +
571
613
  ' merge option; use suppa_update_record("Docs", ...) with merge_json to add.\n\n' +
572
- " APPROVAL GATE: without confirm=true this returns a confirmation request and\n" +
573
- " changes nothing. Get the user's approval, then re-call with confirm=true.",
614
+ " APPROVAL GATE: without confirm=true this returns a confirmation request and changes nothing.",
574
615
  inputSchema: {
575
616
  doc_id: z.number().int(),
576
617
  title: z.string().nullable().default(null),
@@ -591,14 +632,12 @@ export function buildServer() {
591
632
  });
592
633
  reg("suppa_delete_doc", {
593
634
  description: "Soft-delete a document (and its pages).\n\n" +
594
- " SOFT DELETE: sets deletedAt — the row remains in the database and the delete\n" +
595
- " is reversible: suppa_restore_record('Docs', doc_id) brings it back. The doc\n" +
596
- " does drop out of every normal read — find it again with\n" +
597
- " suppa_search_records('Docs', deleted_scope='deleted').\n\n" +
598
- " NOT the platform's permanent delete (a separate endpoint where the rows leave\n" +
599
- " the table and cannot be restored); that one is deliberately not exposed here.\n\n" +
600
- " APPROVAL GATE: without confirm=true this returns a confirmation request and\n" +
601
- " deletes nothing. Get the user's approval, then re-call with confirm=true.",
635
+ " SOFT DELETE: sets deletedAt — the row remains and the delete is reversible with\n" +
636
+ " suppa_restore_record('Docs', doc_id); it drops out of normal reads, so find it again\n" +
637
+ " with suppa_search_records('Docs', deleted_scope='deleted'). Not the platform's\n" +
638
+ " permanent delete (rows leave the table and cannot be restored), which this server\n" +
639
+ " does not expose.\n\n" +
640
+ " APPROVAL GATE: without confirm=true this returns a confirmation request and deletes nothing.",
602
641
  inputSchema: { doc_id: z.number().int(), confirm: Confirm },
603
642
  annotations: _MUT,
604
643
  }, async (a) => {
@@ -608,18 +647,19 @@ export function buildServer() {
608
647
  return text(await docs.deleteDoc(a.doc_id));
609
648
  });
610
649
  reg("suppa_list_pages", {
611
- description: "List all pages in a document.",
650
+ description: "List all pages in a document. fields_json narrows each row.",
612
651
  inputSchema: {
613
652
  doc_id: z.number().int(),
614
653
  limit: z.number().int().default(50),
654
+ fields_json: FieldsJsonOpt,
615
655
  },
616
656
  annotations: _READ,
617
- }, async (a) => text(await docs.listPages(a.doc_id, a.limit)));
657
+ }, async (a) => text(await docs.listPages(a.doc_id, a.limit, a.fields_json)));
618
658
  reg("suppa_get_page", {
619
- description: "Get a page's metadata.",
620
- inputSchema: { page_id: z.number().int() },
659
+ description: "Get a page's metadata, or only fields_json.",
660
+ inputSchema: { page_id: z.number().int(), fields_json: FieldsJsonOpt },
621
661
  annotations: _READ,
622
- }, async (a) => text(await docs.getPage(a.page_id)));
662
+ }, async (a) => text(await docs.getPage(a.page_id, a.fields_json)));
623
663
  reg("suppa_create_page", {
624
664
  description: "Create a new page in a document.",
625
665
  inputSchema: {
@@ -644,8 +684,7 @@ export function buildServer() {
644
684
  description: "Update a page's metadata.\n\n" +
645
685
  " Any list-valued field written here is REPLACED wholesale — this tool has no\n" +
646
686
  ' merge option; use suppa_update_record("Pages", ...) with merge_json to add.\n\n' +
647
- " APPROVAL GATE: without confirm=true this returns a confirmation request and\n" +
648
- " changes nothing. Get the user's approval, then re-call with confirm=true.",
687
+ " APPROVAL GATE: without confirm=true this returns a confirmation request and changes nothing.",
649
688
  inputSchema: {
650
689
  page_id: z.number().int(),
651
690
  title: z.string().nullable().default(null),
@@ -675,14 +714,12 @@ export function buildServer() {
675
714
  reg("suppa_delete_page", {
676
715
  description: "Soft-delete a page. The platform refuses to delete a document's LAST page\n" +
677
716
  " (HTTP 400) — delete the whole doc instead (suppa_delete_doc).\n\n" +
678
- " SOFT DELETE: sets deletedAt — the row remains in the database and the delete\n" +
679
- " is reversible: suppa_restore_record('Pages', page_id) brings it back. The page\n" +
680
- " does drop out of every normal read — find it again with\n" +
681
- " suppa_search_records('Pages', deleted_scope='deleted').\n\n" +
682
- " NOT the platform's permanent delete (a separate endpoint where the rows leave\n" +
683
- " the table and cannot be restored); that one is deliberately not exposed here.\n\n" +
684
- " APPROVAL GATE: without confirm=true this returns a confirmation request and\n" +
685
- " deletes nothing. Get the user's approval, then re-call with confirm=true.",
717
+ " SOFT DELETE: sets deletedAt — the row remains and the delete is reversible with\n" +
718
+ " suppa_restore_record('Pages', page_id); it drops out of normal reads, so find it again\n" +
719
+ " with suppa_search_records('Pages', deleted_scope='deleted'). Not the platform's\n" +
720
+ " permanent delete (rows leave the table and cannot be restored), which this server\n" +
721
+ " does not expose.\n\n" +
722
+ " APPROVAL GATE: without confirm=true this returns a confirmation request and deletes nothing.",
686
723
  inputSchema: { page_id: z.number().int(), confirm: Confirm },
687
724
  annotations: _MUT,
688
725
  }, async (a) => {
@@ -737,8 +774,7 @@ export function buildServer() {
737
774
  " properties_json REPLACES the block's properties wholesale (as does any\n" +
738
775
  " list-valued field) — this tool has no merge option; read the current\n" +
739
776
  " properties with suppa_get_blocks first and re-send them in full.\n\n" +
740
- " APPROVAL GATE: without confirm=true this returns a confirmation request and\n" +
741
- " changes nothing. Get the user's approval, then re-call with confirm=true.",
777
+ " APPROVAL GATE: without confirm=true this returns a confirmation request and changes nothing.",
742
778
  inputSchema: {
743
779
  block_id: z.number().int(),
744
780
  title: z
@@ -767,14 +803,12 @@ export function buildServer() {
767
803
  });
768
804
  reg("suppa_delete_block", {
769
805
  description: "Soft-delete a content block.\n\n" +
770
- " SOFT DELETE: sets deletedAt — the row remains in the database and the delete\n" +
771
- " is reversible: suppa_restore_record('PageBlocks', block_id) brings it back. The\n" +
772
- " block does drop out of every normal read — find it again with\n" +
773
- " suppa_search_records('PageBlocks', deleted_scope='deleted').\n\n" +
774
- " NOT the platform's permanent delete (a separate endpoint where the rows leave\n" +
775
- " the table and cannot be restored); that one is deliberately not exposed here.\n\n" +
776
- " APPROVAL GATE: without confirm=true this returns a confirmation request and\n" +
777
- " deletes nothing. Get the user's approval, then re-call with confirm=true.",
806
+ " SOFT DELETE: sets deletedAt — the row remains and the delete is reversible with\n" +
807
+ " suppa_restore_record('PageBlocks', block_id); it drops out of normal reads, so find it again\n" +
808
+ " with suppa_search_records('PageBlocks', deleted_scope='deleted'). Not the platform's\n" +
809
+ " permanent delete (rows leave the table and cannot be restored), which this server\n" +
810
+ " does not expose.\n\n" +
811
+ " APPROVAL GATE: without confirm=true this returns a confirmation request and deletes nothing.",
778
812
  inputSchema: { block_id: z.number().int(), confirm: Confirm },
779
813
  annotations: _MUT,
780
814
  }, async (a) => {
@@ -786,8 +820,7 @@ export function buildServer() {
786
820
  reg("suppa_reorder_blocks", {
787
821
  description: "Reorder blocks on a page. block_ids: comma-separated IDs to move. Provide after_id or before_id as anchor.\n" +
788
822
  "\n" +
789
- " APPROVAL GATE: without confirm=true this returns a confirmation request and\n" +
790
- " changes nothing. Get the user's approval, then re-call with confirm=true.",
823
+ " APPROVAL GATE: without confirm=true this returns a confirmation request and changes nothing.",
791
824
  inputSchema: {
792
825
  page_id: z.number().int(),
793
826
  block_ids: z
@@ -835,15 +868,24 @@ export function buildServer() {
835
868
  full: z
836
869
  .boolean()
837
870
  .default(false)
838
- .describe("true = raw schema rows; default returns a slim summary per entity."),
871
+ .describe("true = raw schema rows; default returns a slim summary per entity (title reduced to its language keys)."),
839
872
  },
840
873
  annotations: _READ,
841
874
  }, async (a) => text(await entity.listEntities(a.search, a.full)));
842
875
  reg("suppa_describe_entity", {
843
- description: "Get the full schema of an entity — all fields, types, relations, and constraints.",
844
- inputSchema: { entity_name: EntityName },
876
+ description: "Get the schema of an entity — all fields, types, relations, and constraints.\n" +
877
+ " Compact by default: a field lists only what departs from the platform defaults, and\n" +
878
+ " the result's _legend says exactly what an absent key means — a quarter of the raw\n" +
879
+ " size. full=true returns the platform's raw schema.",
880
+ inputSchema: {
881
+ entity_name: EntityName,
882
+ full: z
883
+ .boolean()
884
+ .default(false)
885
+ .describe("true = the platform's raw schema (every null, default and localisation record)."),
886
+ },
845
887
  annotations: _READ,
846
- }, async (a) => text(await entity.describeEntity(a.entity_name)));
888
+ }, async (a) => text(await entity.describeEntityCompact(a.entity_name, a.full)));
847
889
  reg("suppa_list_tabular_parts", {
848
890
  description: 'List an entity\'s tabular parts (owned child sub-tables / "таблична частина").\n' +
849
891
  " Each result has type='tabular-part' and a relationEntity pointing back to the parent.",
@@ -985,8 +1027,7 @@ export function buildServer() {
985
1027
  " checklists is forbidden; the docs do not list the suffixes, so that one can only\n" +
986
1028
  " be reported as a warning. The platform answers with the APPLIED options, which\n" +
987
1029
  " may be a subset of the request — anything missing is called out in the result.\n\n" +
988
- " APPROVAL GATE: without confirm=true this returns a confirmation request and\n" +
989
- " changes nothing. Get the user's approval, then re-call with confirm=true.",
1030
+ " APPROVAL GATE: without confirm=true this returns a confirmation request and changes nothing.",
990
1031
  inputSchema: {
991
1032
  entity_name: EntityName,
992
1033
  options_json: z
@@ -1058,18 +1099,12 @@ export function buildServer() {
1058
1099
  " There is NO date/datetime/richtext/email/url/phone type — use timestamp\n" +
1059
1100
  " (+sub_type='date' for date-only) and multi-language for localized text.\n" +
1060
1101
  " 'relation' is accepted as an alias for many-to-one. Provide relation_entity for\n" +
1061
- " relations, enum_name for enums. sub_type matrix: timestamp takes 'date' | 'time' |\n" +
1062
- " 'timestamp', text takes 'encrypted', every other type takes none — for enum and\n" +
1063
- " multi-enum the subtype IS the enum's global name and the platform sets it, so never\n" +
1064
- " pass one. Constraints: max_length/min_length (text),\n" +
1065
- " decimal_places / min_value / max_value / only_positive (numeric).\n" +
1066
- " options_json tunes the field: showInTable, canFilter, canSort, canGroup,\n" +
1067
- " editFromTable, readOnly, searchable + searchPriority (1-4). Omitted, the\n" +
1068
- " platform fills its own defaults in — visible, sortable, groupable, filterable,\n" +
1069
- " editable, not read-only, and NOT searchable. So searchable (+searchPriority) is\n" +
1070
- " the one worth setting: without it the field cannot be found by free-text\n" +
1071
- " search. All of them can be changed later with suppa_update_field; the field's\n" +
1072
- " TYPE never can.\n" +
1102
+ " relations, enum_name for enums. The sub_type matrix and the field options (searchable +\n" +
1103
+ " searchPriority is the one usually worth setting) live on the sub_type and options_json\n" +
1104
+ " parameters — read them; enum/multi-enum take no sub_type (the platform sets it).\n" +
1105
+ " Constraints: max_length/min_length (text),\n" +
1106
+ " decimal_places / min_value / max_value / only_positive (numeric). Options can be\n" +
1107
+ " changed later with suppa_update_field; the field's TYPE never can.\n" +
1073
1108
  " required=true makes the column NOT NULL. Where a defaultValue APPLIES it is\n" +
1074
1109
  " also required, and the call is refused before any request if missing — no\n" +
1075
1110
  " default is ever invented for you. defaultValue does NOT apply to relations,\n" +
@@ -1207,8 +1242,7 @@ export function buildServer() {
1207
1242
  " - A SYSTEM field (initiator='system') accepts only title and options.{canGroup,\n" +
1208
1243
  " canSort, showInTable, editFromTable, canFilter, readOnly, searchable}.\n" +
1209
1244
  " Removing a field is still UI-only — this server has no remove-field call.\n\n" +
1210
- " APPROVAL GATE: without confirm=true this returns a confirmation request and\n" +
1211
- " changes nothing. Get the user's approval, then re-call with confirm=true.",
1245
+ " APPROVAL GATE: without confirm=true this returns a confirmation request and changes nothing.",
1212
1246
  inputSchema: {
1213
1247
  entity_name: EntityName,
1214
1248
  field_name: z
@@ -1337,8 +1371,7 @@ export function buildServer() {
1337
1371
  "\n" +
1338
1372
  " This CHANGES what every existing record of the entity displays as its label,\n" +
1339
1373
  " so it is confirm-gated like any other edit to live data.\n" +
1340
- " APPROVAL GATE: without confirm=true this returns a confirmation request and\n" +
1341
- " changes nothing. Get the user's approval, then re-call with confirm=true.",
1374
+ " APPROVAL GATE: without confirm=true this returns a confirmation request and changes nothing.",
1342
1375
  inputSchema: {
1343
1376
  entity_name: EntityName,
1344
1377
  field_name: z
@@ -1382,8 +1415,7 @@ export function buildServer() {
1382
1415
  ' [{"id": 15}]} makes 15 the ONLY watcher — every other watcher is dropped.\n' +
1383
1416
  ' To ADD the listed items instead, pass merge_json=["watchers"]; to REMOVE\n' +
1384
1417
  ' only the listed items, pass unmerge_json=["watchers"].\n\n' +
1385
- " APPROVAL GATE: without confirm=true this returns a confirmation request and\n" +
1386
- " changes nothing. Get the user's approval, then re-call with confirm=true.",
1418
+ " APPROVAL GATE: without confirm=true this returns a confirmation request and changes nothing.",
1387
1419
  inputSchema: {
1388
1420
  entity_name: EntityName,
1389
1421
  record_id: z.number().int(),
@@ -1427,20 +1459,16 @@ export function buildServer() {
1427
1459
  });
1428
1460
  reg("suppa_delete_record", {
1429
1461
  description: "Soft-delete a record (instance) from any entity.\n\n" +
1430
- " SOFT DELETE: the platform sets deletedAt — the row remains in the database\n" +
1431
- " and the delete is reversible with suppa_restore_record. Nothing is purged.\n" +
1432
- " The record does disappear from every normal read; find it again with\n" +
1433
- " suppa_search_records(deleted_scope='deleted').\n\n" +
1434
- " NOT A PERMANENT DELETE: the platform's permanent delete is a different\n" +
1435
- " endpoint (/core/data/<entity>/delete) where the rows leave the table and\n" +
1436
- " cannot be restored. This server deliberately does not expose it — every\n" +
1437
- " delete tool here is the reversible one.\n\n" +
1462
+ " SOFT DELETE: sets deletedAt — the row remains and the delete is reversible with\n" +
1463
+ " suppa_restore_record; it disappears from normal reads, so find it again with\n" +
1464
+ " suppa_search_records(deleted_scope='deleted'). Not the platform's permanent delete\n" +
1465
+ " (/core/data/<entity>/delete — rows leave the table and cannot be restored), which\n" +
1466
+ " this server does not expose; every delete tool here is the reversible one.\n\n" +
1438
1467
  " Removes a single instance, not the entity/schema. Entities and fields are\n" +
1439
1468
  " created with suppa_create_entity / suppa_add_field and edited with\n" +
1440
1469
  " suppa_update_field (a field's type is never changeable); REMOVING a field is\n" +
1441
1470
  " UI-only — this server has no remove-field call.\n\n" +
1442
- " APPROVAL GATE: without confirm=true this returns a confirmation request and\n" +
1443
- " deletes nothing. Get the user's approval, then re-call with confirm=true.",
1471
+ " APPROVAL GATE: without confirm=true this returns a confirmation request and deletes nothing.",
1444
1472
  inputSchema: {
1445
1473
  entity_name: EntityName,
1446
1474
  record_id: z.number().int(),
@@ -1470,8 +1498,7 @@ export function buildServer() {
1470
1498
  " deletedAt IS NOT NULL, so calling this on a live record changes nothing and\n" +
1471
1499
  " returns restored=false. A record removed with the platform's PERMANENT\n" +
1472
1500
  " delete cannot be restored — but this server never issues that call.\n\n" +
1473
- " APPROVAL GATE: without confirm=true this returns a confirmation request and\n" +
1474
- " restores nothing. Get the user's approval, then re-call with confirm=true.",
1501
+ " APPROVAL GATE: without confirm=true this returns a confirmation request and restores nothing.",
1475
1502
  inputSchema: {
1476
1503
  entity_name: EntityName,
1477
1504
  record_id: z.number().int(),
@@ -1716,8 +1743,7 @@ export function buildServer() {
1716
1743
  " change; settings is merged over the stored value (pinData and untouched keys\n" +
1717
1744
  " preserved); nodes/connections are whole-document replaces. Runs pre-flight\n" +
1718
1745
  " validation on the resulting graph.\n\n" +
1719
- " APPROVAL GATE: without confirm=true this returns a confirmation request and\n" +
1720
- " changes nothing. Get the user's approval, then re-call with confirm=true.",
1746
+ " APPROVAL GATE: without confirm=true this returns a confirmation request and changes nothing.",
1721
1747
  inputSchema: {
1722
1748
  automation_id: AutomationId,
1723
1749
  name: z.string().nullable().default(null).describe("New automation name."),
@@ -1758,16 +1784,13 @@ export function buildServer() {
1758
1784
  });
1759
1785
  reg("suppa_delete_automation", {
1760
1786
  description: "Soft-delete an automation workflow.\n\n" +
1761
- " SOFT DELETE: this goes through the same /remove as every other delete here —\n" +
1762
- " the platform sets deletedAt, the row remains in the database and the delete\n" +
1763
- " is reversible: suppa_restore_record('AutomationWorkflow', automation_id) brings\n" +
1764
- " it back. Nothing is purged. The workflow does disappear from every normal read\n" +
1765
- " and stops running, so treat it as gone for further work; find it again with\n" +
1766
- " suppa_search_records('AutomationWorkflow', deleted_scope='deleted').\n\n" +
1767
- " NOT the platform's permanent delete (a separate endpoint where the rows leave\n" +
1768
- " the table and cannot be restored); that one is deliberately not exposed here.\n\n" +
1769
- " APPROVAL GATE: without confirm=true this returns a confirmation request and\n" +
1770
- " deletes nothing. Get the user's approval, then re-call with confirm=true.",
1787
+ " SOFT DELETE: sets deletedAt — the row remains and the delete is reversible with\n" +
1788
+ " suppa_restore_record('AutomationWorkflow', automation_id). It disappears from normal\n" +
1789
+ " reads and STOPS RUNNING, so treat it as gone for further work; find it again with\n" +
1790
+ " suppa_search_records('AutomationWorkflow', deleted_scope='deleted'). Not the\n" +
1791
+ " platform's permanent delete (rows leave the table and cannot be restored), which this\n" +
1792
+ " server does not expose.\n\n" +
1793
+ " APPROVAL GATE: without confirm=true this returns a confirmation request and deletes nothing.",
1771
1794
  inputSchema: { automation_id: AutomationId, confirm: Confirm },
1772
1795
  annotations: _MUT,
1773
1796
  }, async (a) => {
@@ -1781,8 +1804,7 @@ export function buildServer() {
1781
1804
  " the automation-service. Requires the automation-service deployed on the tenant;\n" +
1782
1805
  " if absent the call 404s and the error is returned (never crashes). A typed 400\n" +
1783
1806
  " returns {published:false, errors, warnings, message}.\n\n" +
1784
- " APPROVAL GATE: without confirm=true this returns a confirmation request and\n" +
1785
- " changes nothing. Get the user's approval, then re-call with confirm=true.",
1807
+ " APPROVAL GATE: without confirm=true this returns a confirmation request and changes nothing.",
1786
1808
  inputSchema: { automation_id: AutomationId, confirm: Confirm },
1787
1809
  annotations: _MUT,
1788
1810
  }, async (a) => {
@@ -1795,8 +1817,7 @@ export function buildServer() {
1795
1817
  description: "Unpublish (deactivate) an automation — clears the live snapshot via the\n" +
1796
1818
  " automation-service. Requires the automation-service deployed (else 404,\n" +
1797
1819
  " returned as an error).\n\n" +
1798
- " APPROVAL GATE: without confirm=true this returns a confirmation request and\n" +
1799
- " changes nothing. Get the user's approval, then re-call with confirm=true.",
1820
+ " APPROVAL GATE: without confirm=true this returns a confirmation request and changes nothing.",
1800
1821
  inputSchema: { automation_id: AutomationId, confirm: Confirm },
1801
1822
  annotations: _MUT,
1802
1823
  }, async (a) => {
@@ -2069,8 +2090,7 @@ export function buildServer() {
2069
2090
  reg("suppa_update_form", {
2070
2091
  description: "Update a form's name, schema (data.formShema), settings, or module code.\n" +
2071
2092
  " Form names are UNIQUE platform-wide — renaming to an existing name fails.\n\n" +
2072
- " APPROVAL GATE: without confirm=true this returns a confirmation request and\n" +
2073
- " changes nothing. Get the user's approval, then re-call with confirm=true.",
2093
+ " APPROVAL GATE: without confirm=true this returns a confirmation request and changes nothing.",
2074
2094
  inputSchema: {
2075
2095
  form_id: z.number().int(),
2076
2096
  name: z.string().nullable().default(null),
@@ -2122,8 +2142,7 @@ export function buildServer() {
2122
2142
  reg("suppa_add_field_to_form", {
2123
2143
  description: "Append a field to a form's schema. Types: text, textarea, richtext, date, select, userSelect, files, toogle, etc.\n\n" +
2124
2144
  " This modifies an existing form (data.formShema). APPROVAL GATE: without\n" +
2125
- " confirm=true this returns a confirmation request and changes nothing. Get\n" +
2126
- " the user's approval, then re-call with confirm=true.",
2145
+ " confirm=true this returns a confirmation request and changes nothing.",
2127
2146
  inputSchema: {
2128
2147
  form_id: z.number().int(),
2129
2148
  field_name: z
@@ -2423,6 +2442,9 @@ export function buildServer() {
2423
2442
  "the gate fails with E301 if anything is unregistered — run it, do not assume.\n" +
2424
2443
  "Porting from Suppa 1.0? Read the schema with suppa_read_v1_entity_props / suppa_read_v1_enum and map per references/v1-mapping.md — " +
2425
2444
  "never invent a mapping; record data stays with suppa_migrate_entities_from_v1.");
2445
+ // Every tools/list goes out without the schema boilerplate no model reads —
2446
+ // see toolsListEconomy.ts. Installed last so it wraps the SDK's own handler.
2447
+ installToolsListEconomy(server);
2426
2448
  return server;
2427
2449
  }
2428
2450
  /**