suppa-mcp-2 1.4.1 → 1.6.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/README.md +422 -419
- package/dist/bin.js +1 -1
- package/dist/httpClient.js +73 -13
- package/dist/server.js +94 -13
- package/dist/tools/entity.js +84 -8
- package/dist/tools/files.js +192 -0
- package/dist/tools/v1Fields.js +0 -0
- package/package.json +1 -1
- package/skills/suppa-entity-code/SKILL.md +22 -6
- package/skills/suppa-entity-code/references/v1-mapping.md +18 -6
- package/skills/suppa-entity-code/scripts/validate-suppa-schema.mjs +1626 -1550
- package/skills/suppa-entity-code/templates/tabular-part.template.ts +1 -0
package/dist/bin.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* stdio entrypoint for the Suppa MCP server (npm `suppa-mcp-2`).
|
|
4
4
|
*
|
|
5
|
-
* Builds the server (all
|
|
5
|
+
* Builds the server (all 87 tools) and connects it to stdio, exactly like the
|
|
6
6
|
* Python package's console script. Faithful 1:1 port.
|
|
7
7
|
*/
|
|
8
8
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
package/dist/httpClient.js
CHANGED
|
@@ -107,11 +107,34 @@ function rawPath(pathOrUrl) {
|
|
|
107
107
|
p = p.replace(/[\t\n\r]/g, "").replace(/^[\x00-\x20]+|[\x00-\x20]+$/g, "").replace(/\\/g, "/");
|
|
108
108
|
const scheme = p.indexOf("://");
|
|
109
109
|
if (scheme !== -1) {
|
|
110
|
-
|
|
110
|
+
// Skip the WHOLE run of slashes after the scheme, then the authority. The
|
|
111
|
+
// old code took the first '/' after '://', so `https:///host/core/data/X/delete`
|
|
112
|
+
// kept `host` as a path segment and the route no longer matched — while the
|
|
113
|
+
// URL parser consumed the run and made `host` the host. Eight inputs
|
|
114
|
+
// bypassed the block that way.
|
|
115
|
+
let i = scheme + 1;
|
|
116
|
+
while (i < p.length && p[i] === "/")
|
|
117
|
+
i += 1;
|
|
118
|
+
const slash = p.indexOf("/", i);
|
|
111
119
|
p = slash === -1 ? "" : p.slice(slash);
|
|
112
120
|
}
|
|
113
121
|
return p.split("?")[0].split("#")[0];
|
|
114
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* The path the request will actually carry, as computed by the SAME parser
|
|
125
|
+
* fetch uses. Hand-rolled normalisation has now been wrong six times — tabs,
|
|
126
|
+
* NULs, backslashes, dot segments, double-encoded dots, and slash runs — so the
|
|
127
|
+
* authoritative reading comes from the platform's URL parser, and the manual
|
|
128
|
+
* one below is kept only as a second opinion for inputs it refuses.
|
|
129
|
+
*/
|
|
130
|
+
function parsedPath(pathOrUrl) {
|
|
131
|
+
try {
|
|
132
|
+
return new URL(String(pathOrUrl ?? ""), "https://blocked.invalid/").pathname;
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
115
138
|
/** Collapse, trim and lowercase a resolved path into comparable route segments. */
|
|
116
139
|
function comparable(path) {
|
|
117
140
|
return path
|
|
@@ -143,18 +166,26 @@ function comparable(path) {
|
|
|
143
166
|
* 3. the decoded path re-resolved, for one that normalizes after decoding.
|
|
144
167
|
*/
|
|
145
168
|
function routeCandidates(pathOrUrl) {
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
169
|
+
const candidates = [];
|
|
170
|
+
// Two readings of the wire: the platform's own URL parser (authoritative) and
|
|
171
|
+
// the manual normalisation (for inputs it rejects). Both feed the same decode
|
|
172
|
+
// variants below, so a divergence between them can only ADD a blocked form.
|
|
173
|
+
const wireForms = [parsedPath(pathOrUrl), resolveDotSegments(rawPath(pathOrUrl))];
|
|
174
|
+
for (const onWire of wireForms) {
|
|
175
|
+
if (onWire === null)
|
|
176
|
+
continue;
|
|
177
|
+
candidates.push(comparable(onWire));
|
|
178
|
+
let decoded = null;
|
|
179
|
+
try {
|
|
180
|
+
decoded = decodeURIComponent(onWire);
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
// Malformed escapes: the wire form is the whole answer. A router cannot
|
|
184
|
+
// decode this either, so there is no second reading to model.
|
|
185
|
+
}
|
|
186
|
+
if (decoded !== null && decoded !== onWire) {
|
|
187
|
+
candidates.push(comparable(decoded), comparable(resolveDotSegments(decoded)));
|
|
188
|
+
}
|
|
158
189
|
}
|
|
159
190
|
return candidates;
|
|
160
191
|
}
|
|
@@ -304,6 +335,20 @@ async function sendWithReauth(ctx, buildHeaders, method, url, data, timeout, opt
|
|
|
304
335
|
}
|
|
305
336
|
throw new Error(`HTTP ${code} ${safeStatusText(res)}: ${errorBody}`);
|
|
306
337
|
}
|
|
338
|
+
// A download returns bytes, not JSON — reading it as text would corrupt
|
|
339
|
+
// anything that is not UTF-8 (every PDF, image and zip). Content-Type comes
|
|
340
|
+
// back with it so the caller can name the file sensibly.
|
|
341
|
+
if (opts.binary) {
|
|
342
|
+
const buf = Buffer.from(await res.arrayBuffer());
|
|
343
|
+
if (config.DEBUG) {
|
|
344
|
+
debug(`${method} ${url} -> ${code} ${buf.length}B (${((Date.now() - started) / 1000).toFixed(2)}s)`);
|
|
345
|
+
}
|
|
346
|
+
return {
|
|
347
|
+
bytes: buf,
|
|
348
|
+
contentType: res.headers.get("content-type") ?? "",
|
|
349
|
+
contentDisposition: res.headers.get("content-disposition") ?? "",
|
|
350
|
+
};
|
|
351
|
+
}
|
|
307
352
|
const raw = await res.text();
|
|
308
353
|
if (config.DEBUG) {
|
|
309
354
|
debug(`${method} ${url} -> ${code} (${((Date.now() - started) / 1000).toFixed(2)}s)`);
|
|
@@ -344,6 +389,21 @@ export async function makeRequestRawBytes(method, path, data, contentType, opts
|
|
|
344
389
|
const url = path.startsWith("/") ? `${ctx.baseUrl}${path}` : path;
|
|
345
390
|
return sendWithReauth(ctx, (t) => headers(ctx, t, { "Content-Type": contentType }), method, url, data, timeout, { unwrap: false });
|
|
346
391
|
}
|
|
392
|
+
/**
|
|
393
|
+
* Fetch a response as BYTES rather than JSON — downloads
|
|
394
|
+
* (api-entity-builder-files.txt:80 "Buffer", :100 "ZIP (stream)").
|
|
395
|
+
*
|
|
396
|
+
* Goes through the same choke point as every other request, so the
|
|
397
|
+
* permanent-delete refusal covers it too.
|
|
398
|
+
*/
|
|
399
|
+
export async function makeRequestBinary(method, path, body = null, opts = {}) {
|
|
400
|
+
const ctx = tenants.current();
|
|
401
|
+
await tenants.ensureValid(ctx);
|
|
402
|
+
const timeout = opts.timeout ?? Math.max(120, config.HTTP_TIMEOUT); // downloads need headroom
|
|
403
|
+
const url = path.startsWith("/") ? `${ctx.baseUrl}${path}` : path;
|
|
404
|
+
const payload = body === null || body === undefined ? null : JSON.stringify(body);
|
|
405
|
+
return (await sendWithReauth(ctx, (t) => headers(ctx, t, payload === null ? null : { "Content-Type": "application/json" }), method, url, payload, timeout, { unwrap: false, binary: true }));
|
|
406
|
+
}
|
|
347
407
|
// ---------------------------------------------------------------------------
|
|
348
408
|
// High-level entity helpers
|
|
349
409
|
// ---------------------------------------------------------------------------
|
package/dist/server.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Suppa MCP Server — unified gateway to the Suppa platform.
|
|
3
3
|
*
|
|
4
|
-
* Faithful 1:1 port of the Python `suppa_mcp/server.py`. Wires all
|
|
4
|
+
* Faithful 1:1 port of the Python `suppa_mcp/server.py`. Wires all 87 tools,
|
|
5
5
|
* mirrors the tool-behavior annotations (_READ/_ADD/_MUT), reproduces the
|
|
6
6
|
* server `instructions` string verbatim, and OWNS all confirm-gating (the tool
|
|
7
7
|
* modules mutate unconditionally, exactly like the Python tool functions).
|
|
@@ -11,6 +11,7 @@ import { z } from "zod";
|
|
|
11
11
|
import * as tasks from "./tools/tasks.js";
|
|
12
12
|
import * as docs from "./tools/docs.js";
|
|
13
13
|
import * as entity from "./tools/entity.js";
|
|
14
|
+
import * as files from "./tools/files.js";
|
|
14
15
|
import * as forms from "./tools/forms.js";
|
|
15
16
|
import * as migrate from "./tools/migrate.js";
|
|
16
17
|
import * as workspace from "./tools/workspace.js";
|
|
@@ -258,12 +259,19 @@ APPROVAL GATES (human-in-the-loop)
|
|
|
258
259
|
ENTITY BUILDER (create + edit fields; removal is UI-only)
|
|
259
260
|
- Real field types only: text, numeric, integer, serial, boolean, timestamp, json, uuid, multi-language, bytea, tsvector, multi-type, icon, enum, multi-enum, file, multi-file, many-to-one, many-to-many, many-to-many-backref. There is NO date/datetime/richtext/email/url/phone type — use timestamp (+sub_type='date') or multi-language.
|
|
260
261
|
- sub_type matrix: timestamp → 'date' | 'time' | 'timestamp'; text → 'encrypted'; enum/multi-enum → the enum's global name, set by the platform (never pass it); every other type takes none. Anything else is refused before the request.
|
|
261
|
-
- FIELD OPTIONS
|
|
262
|
+
- FIELD OPTIONS: searchable, searchPriority (1-4), readOnly, canGroup, canSort, showInTable, editFromTable, canFilter. Omit options_json and the platform fills in its own defaults — visible, sortable, groupable, filterable, editable, not read-only, and NOT searchable. So the one worth passing is searchable (+searchPriority): suppa_search_records' free-text search only covers fields marked searchable. Turn any of them on later with suppa_update_field.
|
|
262
263
|
- OWNED CHILD COLLECTIONS ARE TABULAR PARTS. Repeating rows that belong to one parent record (e.g. a part's BOM items) → suppa_create_tabular_part(parent_entity, name), which auto-creates the child's 'owner' relation and the parent link. NEVER model this by hand as parent.one-to-many + child.owner: suppa_add_field REFUSES field_type='one-to-many'. Use 'many-to-many' only for a shared lookup referenced by many records.
|
|
263
264
|
- Relations need relation_entity; enums need enum_name (the enum's global name, conventionally 'Entity.field'). Add the values FIRST with suppa_add_enum_values, then create the field with the same enum_name — the field is bound to the enum by that name.
|
|
264
265
|
- An enum value on a RECORD is a reference, not a string: write {"id": <Enums row id>} for enum and [{"id": ...}, ...] for multi-enum. A bare code like "red" is refused with 'field must contain id for many-to-one relationship'. Read the ids with suppa_search_records on 'Enums' filtered by name = the enum name.
|
|
265
266
|
- Existing fields CAN be edited with suppa_update_field (name, title, notNull/unique/default, relation target, and the options above), within the platform's own limits: a field's TYPE can never be changed, its SUBTYPE only toggles 'encrypted' on/off (text fields only), and a system field takes just title + the options keys. Removing a field is still UI-only — this server has no remove-field call.
|
|
266
267
|
|
|
268
|
+
ATTACHMENTS (files on a record)
|
|
269
|
+
- A record can carry files only if its entity has a 'file' or 'multi-file' field; check with suppa_describe_entity and add one with suppa_add_field if it has none.
|
|
270
|
+
- WRITE: suppa_attach_file_to_record(entity, record_id, absolute_path) uploads from the local disk and returns file_ids — keep them, they are the only handle that gets the bytes back.
|
|
271
|
+
- READ: suppa_list_record_files(entity, record_id) lists fileName/size/mimeType/paths for one record. It does NOT return ids; get those from the attach response, or with suppa_search_records on the 'Files' entity.
|
|
272
|
+
- GET THE BYTES: suppa_download_file(file_id, absolute_dest_path) writes one file to disk — file_type='file' (original), 'preview' or 'pdf'. suppa_download_files_zip(file_ids, dest) fetches several as one archive. Nothing is overwritten unless overwrite=true.
|
|
273
|
+
- To duplicate a record's attachments onto a copy, use suppa_copy_record(copy_files=true) — there is no local path for a file that already lives on the platform.
|
|
274
|
+
|
|
267
275
|
MIGRATION (Suppa 1.0 → 2.0)
|
|
268
276
|
- 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.
|
|
269
277
|
`;
|
|
@@ -297,7 +305,7 @@ export function buildServer() {
|
|
|
297
305
|
// Reset so repeated buildServer() calls (e.g. in tests) do not double-count.
|
|
298
306
|
TOOL_NAMES.length = 0;
|
|
299
307
|
PROMPT_NAMES.length = 0;
|
|
300
|
-
const server = new McpServer({ name: "suppa-2.0", version: "1.
|
|
308
|
+
const server = new McpServer({ name: "suppa-2.0", version: "1.6.0" }, { instructions: INSTRUCTIONS });
|
|
301
309
|
const reg = (name, cfg, handler) => {
|
|
302
310
|
server.registerTool(name, {
|
|
303
311
|
description: cfg.description,
|
|
@@ -1038,15 +1046,20 @@ export function buildServer() {
|
|
|
1038
1046
|
" 'relation' is accepted as an alias for many-to-one. Provide relation_entity for\n" +
|
|
1039
1047
|
" relations, enum_name for enums. Constraints: max_length/min_length (text),\n" +
|
|
1040
1048
|
" decimal_places / min_value / max_value / only_positive (numeric).\n" +
|
|
1041
|
-
" options_json
|
|
1042
|
-
"
|
|
1043
|
-
"
|
|
1044
|
-
"
|
|
1045
|
-
"
|
|
1046
|
-
"
|
|
1047
|
-
"
|
|
1048
|
-
"
|
|
1049
|
-
"
|
|
1049
|
+
" options_json tunes the field: showInTable, canFilter, canSort, canGroup,\n" +
|
|
1050
|
+
" editFromTable, readOnly, searchable + searchPriority (1-4). Omitted, the\n" +
|
|
1051
|
+
" platform fills its own defaults in — visible, sortable, groupable, filterable,\n" +
|
|
1052
|
+
" editable, not read-only, and NOT searchable. So searchable (+searchPriority) is\n" +
|
|
1053
|
+
" the one worth setting: without it the field cannot be found by free-text\n" +
|
|
1054
|
+
" search. All of them can be changed later with suppa_update_field; the field's\n" +
|
|
1055
|
+
" TYPE never can.\n" +
|
|
1056
|
+
" required=true makes the column NOT NULL. Where a defaultValue APPLIES it is\n" +
|
|
1057
|
+
" also required, and the call is refused before any request if missing — no\n" +
|
|
1058
|
+
" default is ever invented for you. defaultValue does NOT apply to relations,\n" +
|
|
1059
|
+
" enums, files or unique fields (builder.txt:43): there it is dropped, and the\n" +
|
|
1060
|
+
" result says so under not_applicable. notNull itself does not apply to\n" +
|
|
1061
|
+
" many-to-many / multi-enum, nor unique to relations and enums (builder.txt:41-42)\n" +
|
|
1062
|
+
" — those are withheld and reported the same way.\n" +
|
|
1050
1063
|
" 'one-to-many' is REFUSED: an owned child collection is a TABULAR PART\n" +
|
|
1051
1064
|
" (suppa_create_tabular_part, which auto-creates the child's 'owner' and the\n" +
|
|
1052
1065
|
" parent link); never hand-build parent.one-to-many + child.owner. Use\n" +
|
|
@@ -1076,7 +1089,10 @@ export function buildServer() {
|
|
|
1076
1089
|
.string()
|
|
1077
1090
|
.nullable()
|
|
1078
1091
|
.default(null)
|
|
1079
|
-
.describe("
|
|
1092
|
+
.describe("The enum's global name — REQUIRED for enum/multi-enum. Conventionally " +
|
|
1093
|
+
"'Entity.field' (e.g. 'Receipts.type'), but it need not match the field " +
|
|
1094
|
+
"name: one enum can back several fields. Create its values first with " +
|
|
1095
|
+
"suppa_add_enum_values under this same name."),
|
|
1080
1096
|
sub_type: z
|
|
1081
1097
|
.string()
|
|
1082
1098
|
.nullable()
|
|
@@ -1458,6 +1474,71 @@ export function buildServer() {
|
|
|
1458
1474
|
},
|
|
1459
1475
|
annotations: _ADD,
|
|
1460
1476
|
}, async (a) => text(await entity.copyRecord(a.entity_name, a.record_id, a.fields_json, a.copy_files, a.copy_related_entities)));
|
|
1477
|
+
reg("suppa_list_record_files", {
|
|
1478
|
+
description: "List the files attached to one record of any entity.\n" +
|
|
1479
|
+
"\n" +
|
|
1480
|
+
" Returns fileName, filePath, pdfPath, previewPath, size, mimeType and type\n" +
|
|
1481
|
+
" for each attachment. It does NOT return the file id, and\n" +
|
|
1482
|
+
" suppa_download_file needs one — read ids from the 'Files' entity with\n" +
|
|
1483
|
+
" suppa_search_records, or keep the id suppa_attach_file_to_record returns.\n" +
|
|
1484
|
+
" An empty list can also mean the entity has no file field at all; check it\n" +
|
|
1485
|
+
" with suppa_describe_entity.\n",
|
|
1486
|
+
inputSchema: {
|
|
1487
|
+
entity_name: EntityName,
|
|
1488
|
+
record_id: z.number().int().describe("Id of the record whose attachments to list."),
|
|
1489
|
+
limit: z.number().int().default(50).describe("Page size, 1-500."),
|
|
1490
|
+
offset: z.number().int().default(0).describe("Rows to skip (paging)."),
|
|
1491
|
+
},
|
|
1492
|
+
annotations: _READ,
|
|
1493
|
+
}, async (a) => text(await files.listRecordFiles(a.entity_name, a.record_id, a.limit, a.offset)));
|
|
1494
|
+
reg("suppa_download_file", {
|
|
1495
|
+
description: "Download one attached file to a local path.\n" +
|
|
1496
|
+
"\n" +
|
|
1497
|
+
" file_id is the id of the row in the 'Files' entity — from\n" +
|
|
1498
|
+
" suppa_search_records on 'Files', or from what suppa_attach_file_to_record\n" +
|
|
1499
|
+
" returned. file_type picks the variant: the original ('file'), its image\n" +
|
|
1500
|
+
" preview ('preview'), or the generated PDF ('pdf').\n" +
|
|
1501
|
+
"\n" +
|
|
1502
|
+
" dest_path must be ABSOLUTE. Point it at a directory to keep the platform's\n" +
|
|
1503
|
+
" own file name. An existing file is never overwritten unless overwrite=true\n" +
|
|
1504
|
+
" — the bytes are discarded instead.\n",
|
|
1505
|
+
inputSchema: {
|
|
1506
|
+
file_id: z.number().int().describe("Id of the row in the 'Files' entity."),
|
|
1507
|
+
dest_path: z
|
|
1508
|
+
.string()
|
|
1509
|
+
.describe("Absolute path to write to — a file, or a directory to keep the sent name."),
|
|
1510
|
+
file_type: z
|
|
1511
|
+
.enum(["file", "preview", "pdf"])
|
|
1512
|
+
.default("file")
|
|
1513
|
+
.describe("Which variant to fetch: the original, its preview, or the generated PDF."),
|
|
1514
|
+
overwrite: z
|
|
1515
|
+
.boolean()
|
|
1516
|
+
.default(false)
|
|
1517
|
+
.describe("Allow replacing an existing file at dest_path."),
|
|
1518
|
+
},
|
|
1519
|
+
annotations: _READ,
|
|
1520
|
+
}, async (a) => text(await files.downloadFile(a.file_id, a.dest_path, a.file_type, a.overwrite)));
|
|
1521
|
+
reg("suppa_download_files_zip", {
|
|
1522
|
+
description: "Download several attached files at once as a ZIP archive.\n" +
|
|
1523
|
+
"\n" +
|
|
1524
|
+
" file_ids are ids of rows in the 'Files' entity. dest_path must be ABSOLUTE;\n" +
|
|
1525
|
+
" point it at a directory to keep the archive name the platform sends.\n" +
|
|
1526
|
+
" Nothing is overwritten unless overwrite=true.\n",
|
|
1527
|
+
inputSchema: {
|
|
1528
|
+
file_ids: z
|
|
1529
|
+
.array(z.number().int())
|
|
1530
|
+
.min(1)
|
|
1531
|
+
.describe("Ids of the rows in the 'Files' entity to include."),
|
|
1532
|
+
dest_path: z
|
|
1533
|
+
.string()
|
|
1534
|
+
.describe("Absolute path to write the .zip to — a file, or a directory."),
|
|
1535
|
+
overwrite: z
|
|
1536
|
+
.boolean()
|
|
1537
|
+
.default(false)
|
|
1538
|
+
.describe("Allow replacing an existing archive at dest_path."),
|
|
1539
|
+
},
|
|
1540
|
+
annotations: _READ,
|
|
1541
|
+
}, async (a) => text(await files.downloadFilesZip(a.file_ids, a.dest_path, a.overwrite)));
|
|
1461
1542
|
reg("suppa_attach_file_to_record", {
|
|
1462
1543
|
description: "Attach a local file to a record (instance) of any entity.\n\n" +
|
|
1463
1544
|
" Auto-detects the entity's file/attachment field from its schema; pass\n" +
|
package/dist/tools/entity.js
CHANGED
|
@@ -97,10 +97,19 @@ export function defaultValueApplies(fieldType, unique = false) {
|
|
|
97
97
|
// ---------------------------------------------------------------------------
|
|
98
98
|
//
|
|
99
99
|
// builder.txt:60 — "options | object | false | Field options configuration."
|
|
100
|
-
// Its keys are builder.txt:66-73.
|
|
101
|
-
//
|
|
102
|
-
//
|
|
103
|
-
//
|
|
100
|
+
// Its keys are builder.txt:66-73.
|
|
101
|
+
//
|
|
102
|
+
// The platform FILLS THEM IN when the body omits them. Read back from a live
|
|
103
|
+
// 2.0 tenant (modern-expo.dev.suppa.me, 2026-08-05) on a field this server
|
|
104
|
+
// created with no options object at all:
|
|
105
|
+
// canGroup:true canSort:true showInTable:true editFromTable:true
|
|
106
|
+
// canFilter:true readOnly:false searchable:false
|
|
107
|
+
// So an omitted options object leaves a field visible, sortable, groupable and
|
|
108
|
+
// filterable — but NOT searchable: the free-text search of suppa_search_records
|
|
109
|
+
// only covers fields carrying `searchable` (data.txt:218 — "Only fields with
|
|
110
|
+
// the searchable option participate."). `searchable` (and searchPriority) are
|
|
111
|
+
// therefore the ones worth setting deliberately; the rest already hold the
|
|
112
|
+
// value most fields want.
|
|
104
113
|
/** Boolean members of the Field Options object. */
|
|
105
114
|
export const FIELD_OPTION_BOOLEAN_KEYS = [
|
|
106
115
|
"searchable", // builder.txt:66 — "Available for search."
|
|
@@ -1369,10 +1378,17 @@ export async function addField(entityName, fieldName, fieldType, title, opts = {
|
|
|
1369
1378
|
`(this field is '${resolvedType}'). The field was created WITHOUT the unique constraint.`);
|
|
1370
1379
|
}
|
|
1371
1380
|
// builder.txt:43 — "Not applicable to relations, enums, or unique fields":
|
|
1372
|
-
// sending it there is at best ignored, so it is never emitted.
|
|
1381
|
+
// sending it there is at best ignored, so it is never emitted. A default the
|
|
1382
|
+
// caller ASKED for and did not get is reported, like the other two — dropping
|
|
1383
|
+
// it silently was the same defect notNull and unique already had fixed.
|
|
1373
1384
|
if (defaultText.trim() !== "" && typeNeedsDefault) {
|
|
1374
1385
|
fieldDef.defaultValue = defaultText;
|
|
1375
1386
|
}
|
|
1387
|
+
else if (defaultText.trim() !== "") {
|
|
1388
|
+
notApplicable.push(`defaultValue was NOT set: builder.txt:43 — "Not applicable to relations, enums, or unique ` +
|
|
1389
|
+
`fields" (this field is '${resolvedType}'${unique ? " and unique" : ""}). The field was ` +
|
|
1390
|
+
"created WITHOUT a default.");
|
|
1391
|
+
}
|
|
1376
1392
|
if (subType) {
|
|
1377
1393
|
fieldDef.subType = subType;
|
|
1378
1394
|
}
|
|
@@ -1626,6 +1642,40 @@ export async function updateField(entityName, fieldName, opts = {}) {
|
|
|
1626
1642
|
});
|
|
1627
1643
|
}
|
|
1628
1644
|
}
|
|
1645
|
+
// Applicability is a property of the field TYPE, not of the endpoint
|
|
1646
|
+
// (builder.txt:41-43), so update-field has to withhold exactly what add-fields
|
|
1647
|
+
// withholds. It used to send all three unconditionally and report them as
|
|
1648
|
+
// applied — the 1.3.1 fix, never carried across to this path. The live type
|
|
1649
|
+
// read above is what makes the decision possible; without it nothing is
|
|
1650
|
+
// withheld, because guessing would be worse than sending.
|
|
1651
|
+
const notApplicable = [];
|
|
1652
|
+
const liveType = String(meta?.type ?? "");
|
|
1653
|
+
if (liveType) {
|
|
1654
|
+
if ("notNull" in body && body.notNull === true && !notNullApplies(liveType)) {
|
|
1655
|
+
delete body.notNull;
|
|
1656
|
+
notApplicable.push(`notNull was NOT sent: builder.txt:41 — "Not applicable to many-to-many / multi-enum" ` +
|
|
1657
|
+
`('${fieldName}' is '${liveType}'). The required constraint is unchanged.`);
|
|
1658
|
+
}
|
|
1659
|
+
if ("unique" in body &&
|
|
1660
|
+
body.unique === true &&
|
|
1661
|
+
RELATION_LIKE_FIELD_TYPES.includes(liveType)) {
|
|
1662
|
+
delete body.unique;
|
|
1663
|
+
notApplicable.push(`unique was NOT sent: builder.txt:42 — "Not applicable to relations and enums" ` +
|
|
1664
|
+
`('${fieldName}' is '${liveType}'). The unique constraint is unchanged.`);
|
|
1665
|
+
}
|
|
1666
|
+
if ("defaultValue" in body && !defaultValueApplies(liveType, body.unique === true)) {
|
|
1667
|
+
delete body.defaultValue;
|
|
1668
|
+
notApplicable.push(`defaultValue was NOT sent: builder.txt:43 — "Not applicable to relations, enums, or ` +
|
|
1669
|
+
`unique fields" ('${fieldName}' is '${liveType}'). The default is unchanged.`);
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
if (Object.keys(body).length === 0) {
|
|
1673
|
+
return jsonResponse({
|
|
1674
|
+
error: `Refused: every change requested for '${entityName}.${fieldName}' is inapplicable to a ` +
|
|
1675
|
+
`'${liveType}' field, so nothing was sent.`,
|
|
1676
|
+
not_applicable: notApplicable,
|
|
1677
|
+
});
|
|
1678
|
+
}
|
|
1629
1679
|
const result = await makeRequest("POST", `/api/core/builder/${entityName}/${fieldName}/update-field`, body);
|
|
1630
1680
|
const out = {
|
|
1631
1681
|
entity: entityName,
|
|
@@ -1633,6 +1683,9 @@ export async function updateField(entityName, fieldName, opts = {}) {
|
|
|
1633
1683
|
sent: body,
|
|
1634
1684
|
result,
|
|
1635
1685
|
};
|
|
1686
|
+
if (notApplicable.length > 0) {
|
|
1687
|
+
out.not_applicable = notApplicable;
|
|
1688
|
+
}
|
|
1636
1689
|
if (subTypeValue === "encrypted") {
|
|
1637
1690
|
// migrations.txt:244-247 — what the platform does to the field and its rows.
|
|
1638
1691
|
out.encryption_note =
|
|
@@ -2264,6 +2317,11 @@ export async function attachFileToRecord(entityName, recordId, filePath, fieldNa
|
|
|
2264
2317
|
if (entityId === null) {
|
|
2265
2318
|
return jsonResponse({ error: `Could not resolve numeric id for entity '${entityName}'.` });
|
|
2266
2319
|
}
|
|
2320
|
+
// files.txt:14-19 documents exactly three required meta keys — entityId,
|
|
2321
|
+
// recordId, entityFieldName — plus optional pdfPath/previewPath. `entityName`
|
|
2322
|
+
// and `type` are NOT in that table; they are inherited from the Python server
|
|
2323
|
+
// and the platform drops unknown keys, so they are harmless extras rather
|
|
2324
|
+
// than doc-backed fields. The documented three are what makes the upload land.
|
|
2267
2325
|
const meta = {
|
|
2268
2326
|
entityId,
|
|
2269
2327
|
recordId: Math.trunc(recordId),
|
|
@@ -2277,14 +2335,32 @@ export async function attachFileToRecord(entityName, recordId, filePath, fieldNa
|
|
|
2277
2335
|
try {
|
|
2278
2336
|
const { body, contentType } = buildFileUpload(meta, filePath);
|
|
2279
2337
|
const result = await makeRequestRawBytes("POST", "/api/core/files/upload", body, contentType);
|
|
2280
|
-
|
|
2281
|
-
|
|
2338
|
+
// files.txt:36-46 — the response is {summary, success[], errors[]}, and
|
|
2339
|
+
// success[].id is the Files record id, the ONLY handle that gets the bytes
|
|
2340
|
+
// back later (suppa_download_file). Lifted out of the raw payload so a
|
|
2341
|
+
// caller does not have to know that shape to keep it.
|
|
2342
|
+
const uploaded = isPlainObject(result) ? result.success : null;
|
|
2343
|
+
const fileIds = Array.isArray(uploaded)
|
|
2344
|
+
? uploaded
|
|
2345
|
+
.filter((f) => f !== null && typeof f === "object")
|
|
2346
|
+
.map((f) => f.id)
|
|
2347
|
+
.filter((id) => typeof id === "number")
|
|
2348
|
+
: [];
|
|
2349
|
+
const failures = isPlainObject(result) ? result.errors : null;
|
|
2350
|
+
const out = {
|
|
2351
|
+
status: Array.isArray(failures) && failures.length > 0 ? "partial" : "ok",
|
|
2282
2352
|
entity: entityName,
|
|
2283
2353
|
record_id: Math.trunc(recordId),
|
|
2284
2354
|
field: fieldName,
|
|
2285
2355
|
file: basename(filePath),
|
|
2356
|
+
file_ids: fileIds,
|
|
2286
2357
|
result,
|
|
2287
|
-
}
|
|
2358
|
+
};
|
|
2359
|
+
if (fileIds.length > 0) {
|
|
2360
|
+
out.next = `Read it back with suppa_download_file(file_id=${fileIds[0]}), or list this ` +
|
|
2361
|
+
`record's attachments with suppa_list_record_files.`;
|
|
2362
|
+
}
|
|
2363
|
+
return jsonResponse(out);
|
|
2288
2364
|
}
|
|
2289
2365
|
catch (e) {
|
|
2290
2366
|
return jsonResponse({
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attachments: reading what is attached to a record, and getting the bytes.
|
|
3
|
+
*
|
|
4
|
+
* Endpoints and shapes are
|
|
5
|
+
* docs/superpowers/specs/captures/api-entity-builder-files.txt:
|
|
6
|
+
* :157 POST core/files/:table — every file attached to one record
|
|
7
|
+
* :68 GET core/files/download — one file's bytes (fileId, fileType)
|
|
8
|
+
* :83 POST core/files/download-all — several files as a ZIP stream
|
|
9
|
+
* Uploading already lives in tools/entity.ts (attachFileToRecord, :2760).
|
|
10
|
+
*
|
|
11
|
+
* NOTE on that capture's "shellAuthorization" header rows: the doc renders a
|
|
12
|
+
* fenced block whose language tag ("shell") is glued to the first line by the
|
|
13
|
+
* text extraction — the header is plain `Authorization`, which httpClient
|
|
14
|
+
* already sends. The same artefact produces "Request examplejson{" elsewhere in
|
|
15
|
+
* the file. Do not "fix" the client to send shellAuthorization.
|
|
16
|
+
*/
|
|
17
|
+
import { existsSync, mkdirSync, statSync, writeFileSync } from "node:fs";
|
|
18
|
+
import { dirname, isAbsolute, join } from "node:path";
|
|
19
|
+
import { makeRequest, makeRequestBinary } from "../httpClient.js";
|
|
20
|
+
import { jsonResponse } from "../utils.js";
|
|
21
|
+
/** files.txt:76 — "Which variant to download: file, preview or pdf." */
|
|
22
|
+
export const FILE_TYPES = ["file", "preview", "pdf"];
|
|
23
|
+
/** The platform caps a page of results; keep the tool from asking for absurd ones. */
|
|
24
|
+
const MAX_LIMIT = 500;
|
|
25
|
+
/**
|
|
26
|
+
* Every file attached to one record — POST core/files/:table (files.txt:157).
|
|
27
|
+
*
|
|
28
|
+
* Body is {recordId, limit, offset} (files.txt:164-167; limit is REQUIRED).
|
|
29
|
+
* The response rows carry fileName/filePath/pdfPath/previewPath/size/mimeType/
|
|
30
|
+
* type (files.txt:176-183) — and, notably, NO id, while the download endpoint
|
|
31
|
+
* is keyed on one. That gap is surfaced in the result rather than papered over.
|
|
32
|
+
*/
|
|
33
|
+
export async function listRecordFiles(entityName, recordId, limit = 50, offset = 0) {
|
|
34
|
+
const name = String(entityName ?? "").trim();
|
|
35
|
+
if (!name) {
|
|
36
|
+
return jsonResponse({ error: "entity_name is required." });
|
|
37
|
+
}
|
|
38
|
+
if (!Number.isFinite(recordId)) {
|
|
39
|
+
return jsonResponse({ error: "record_id must be a number." });
|
|
40
|
+
}
|
|
41
|
+
const body = {
|
|
42
|
+
recordId: Math.trunc(recordId),
|
|
43
|
+
limit: Math.max(1, Math.min(Math.trunc(limit), MAX_LIMIT)),
|
|
44
|
+
offset: Math.max(0, Math.trunc(offset)),
|
|
45
|
+
};
|
|
46
|
+
const result = await makeRequest("POST", `/api/core/files/${name}`, body);
|
|
47
|
+
const rows = Array.isArray(result) ? result : [];
|
|
48
|
+
return jsonResponse({
|
|
49
|
+
entity: name,
|
|
50
|
+
record_id: body.recordId,
|
|
51
|
+
count: rows.length,
|
|
52
|
+
files: rows,
|
|
53
|
+
// Honest about the shape rather than inventing an id: the caller needs one
|
|
54
|
+
// to download, and this endpoint does not return it.
|
|
55
|
+
note: rows.length > 0
|
|
56
|
+
? "This endpoint returns no file id (files.txt:176-183), and suppa_download_file needs " +
|
|
57
|
+
"one. Get ids from suppa_search_records on the 'Files' entity, or from the response of " +
|
|
58
|
+
"suppa_attach_file_to_record, which returns success[].id."
|
|
59
|
+
: "No files attached to this record — or the entity has no file field at all " +
|
|
60
|
+
"(check with suppa_describe_entity).",
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/** Where a download may be written, and under what name. */
|
|
64
|
+
function resolveDestination(destPath, fallbackName, overwrite) {
|
|
65
|
+
const dest = String(destPath ?? "").trim();
|
|
66
|
+
if (!dest) {
|
|
67
|
+
return { error: "dest_path is required — give an absolute file or directory path." };
|
|
68
|
+
}
|
|
69
|
+
if (!isAbsolute(dest)) {
|
|
70
|
+
return { error: `dest_path must be absolute, got '${dest}'.` };
|
|
71
|
+
}
|
|
72
|
+
// A directory target keeps the platform's own file name.
|
|
73
|
+
let target = dest;
|
|
74
|
+
if (existsSync(dest) && statSync(dest).isDirectory()) {
|
|
75
|
+
target = join(dest, fallbackName);
|
|
76
|
+
}
|
|
77
|
+
if (existsSync(target) && !overwrite) {
|
|
78
|
+
return {
|
|
79
|
+
error: `Refused: '${target}' already exists and overwrite=false, so nothing was written. ` +
|
|
80
|
+
"Pass overwrite=true or choose another dest_path.",
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const parent = dirname(target);
|
|
84
|
+
if (!existsSync(parent)) {
|
|
85
|
+
try {
|
|
86
|
+
mkdirSync(parent, { recursive: true });
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
return { error: `Cannot create directory '${parent}': ${e instanceof Error ? e.message : e}` };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return { path: target };
|
|
93
|
+
}
|
|
94
|
+
/** The filename the platform suggests, if it sent one. */
|
|
95
|
+
export function filenameFromDisposition(disposition) {
|
|
96
|
+
if (!disposition)
|
|
97
|
+
return null;
|
|
98
|
+
// RFC 5987 form first — that is what the doc's example uses
|
|
99
|
+
// (files.txt:108: filename*=UTF-8''download_2026-02-25.zip).
|
|
100
|
+
const star = /filename\*\s*=\s*[^']*'[^']*'([^;]+)/i.exec(disposition);
|
|
101
|
+
if (star) {
|
|
102
|
+
try {
|
|
103
|
+
return decodeURIComponent(star[1].trim().replace(/^"|"$/g, "")) || null;
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return star[1].trim().replace(/^"|"$/g, "") || null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const plain = /filename\s*=\s*("([^"]*)"|[^;]+)/i.exec(disposition);
|
|
110
|
+
if (plain) {
|
|
111
|
+
return (plain[2] ?? plain[1]).trim() || null;
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* One file's bytes — GET core/files/download?fileId&fileType (files.txt:68-77).
|
|
117
|
+
*
|
|
118
|
+
* `fileType` picks the variant: the original, its preview, or the generated PDF
|
|
119
|
+
* (files.txt:76). Writes to disk rather than returning bytes, because an MCP
|
|
120
|
+
* result is text and a binary blob would have to be base64'd through the model's
|
|
121
|
+
* context for no benefit.
|
|
122
|
+
*/
|
|
123
|
+
export async function downloadFile(fileId, destPath, fileType = "file", overwrite = false) {
|
|
124
|
+
if (!Number.isFinite(fileId)) {
|
|
125
|
+
return jsonResponse({ error: "file_id must be a number (the Files record id)." });
|
|
126
|
+
}
|
|
127
|
+
if (!FILE_TYPES.includes(fileType)) {
|
|
128
|
+
return jsonResponse({
|
|
129
|
+
error: `file_type must be one of ${FILE_TYPES.join(", ")} (files.txt:76), got '${fileType}'.`,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
const id = Math.trunc(fileId);
|
|
133
|
+
let res;
|
|
134
|
+
try {
|
|
135
|
+
res = await makeRequestBinary("GET", `/api/core/files/download?fileId=${id}&fileType=${fileType}`);
|
|
136
|
+
}
|
|
137
|
+
catch (e) {
|
|
138
|
+
return jsonResponse({
|
|
139
|
+
error: `Download of file ${id} failed: ${e instanceof Error ? e.message : String(e)}`,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
const suggested = filenameFromDisposition(res.contentDisposition) ?? `file-${id}`;
|
|
143
|
+
const dest = resolveDestination(destPath, suggested, overwrite);
|
|
144
|
+
if ("error" in dest) {
|
|
145
|
+
return jsonResponse({ ...dest, bytes_received: res.bytes.length, not_written: true });
|
|
146
|
+
}
|
|
147
|
+
writeFileSync(dest.path, res.bytes);
|
|
148
|
+
return jsonResponse({
|
|
149
|
+
file_id: id,
|
|
150
|
+
file_type: fileType,
|
|
151
|
+
saved_to: dest.path,
|
|
152
|
+
bytes: res.bytes.length,
|
|
153
|
+
content_type: res.contentType,
|
|
154
|
+
suggested_name: suggested,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Several files at once, as a ZIP — POST core/files/download-all (files.txt:83).
|
|
159
|
+
*
|
|
160
|
+
* Body is {instanceIds: number[]} (files.txt:91) and the response is a zip
|
|
161
|
+
* stream (files.txt:100).
|
|
162
|
+
*/
|
|
163
|
+
export async function downloadFilesZip(fileIds, destPath, overwrite = false) {
|
|
164
|
+
const ids = (fileIds ?? []).map((n) => Math.trunc(Number(n))).filter((n) => Number.isFinite(n));
|
|
165
|
+
if (ids.length === 0) {
|
|
166
|
+
return jsonResponse({
|
|
167
|
+
error: "file_ids must hold at least one Files record id (files.txt:91 — instanceIds).",
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
let res;
|
|
171
|
+
try {
|
|
172
|
+
res = await makeRequestBinary("POST", "/api/core/files/download-all", { instanceIds: ids });
|
|
173
|
+
}
|
|
174
|
+
catch (e) {
|
|
175
|
+
return jsonResponse({
|
|
176
|
+
error: `Download of ${ids.length} file(s) failed: ${e instanceof Error ? e.message : String(e)}`,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
const suggested = filenameFromDisposition(res.contentDisposition) ?? "download.zip";
|
|
180
|
+
const dest = resolveDestination(destPath, suggested, overwrite);
|
|
181
|
+
if ("error" in dest) {
|
|
182
|
+
return jsonResponse({ ...dest, bytes_received: res.bytes.length, not_written: true });
|
|
183
|
+
}
|
|
184
|
+
writeFileSync(dest.path, res.bytes);
|
|
185
|
+
return jsonResponse({
|
|
186
|
+
file_ids: ids,
|
|
187
|
+
saved_to: dest.path,
|
|
188
|
+
bytes: res.bytes.length,
|
|
189
|
+
content_type: res.contentType,
|
|
190
|
+
suggested_name: suggested,
|
|
191
|
+
});
|
|
192
|
+
}
|
package/dist/tools/v1Fields.js
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "suppa-mcp-2",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "MCP server for the Suppa platform (modern.suppa.me) — Tasks, Docs/Pages, Entities & Schema, Forms, Automations, and file attachments, with multi-tenant Google auth. Node port of PyPI suppa-mcp.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|