suppa-mcp-2 1.36.0 → 1.37.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 +31 -5
- package/dist/tools/customFields.js +97 -18
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -162,6 +162,26 @@ const BlocksJson = z
|
|
|
162
162
|
const EntityName = z
|
|
163
163
|
.string()
|
|
164
164
|
.describe("Exact entity name, e.g. 'Tasks' — discover via suppa_list_entities.");
|
|
165
|
+
/**
|
|
166
|
+
* A field label: a plain string, or the LOCALIZATION OBJECT the builder doc
|
|
167
|
+
* prescribes (`title | object | Localization object`, builder.txt:56).
|
|
168
|
+
*
|
|
169
|
+
* It was typed `string` here while buildFieldDef had accepted either for two
|
|
170
|
+
* releases, so the documented shape was rejected by input validation before it
|
|
171
|
+
* could reach the platform at all — `{ en, uk }` came back as "Expected string,
|
|
172
|
+
* received object" and never left this process.
|
|
173
|
+
*/
|
|
174
|
+
const FieldTitle = z
|
|
175
|
+
.union([z.string(), z.record(z.string())])
|
|
176
|
+
// OPTIONAL, not nullable: a two-branch union plus a null branch is an `anyOf`
|
|
177
|
+
// the listing's compaction cannot collapse into a type list (the object
|
|
178
|
+
// branch carries additionalProperties, which a type list cannot say), and
|
|
179
|
+
// toolsListEconomy refuses a nullable spelled as anyOf. Omitting the
|
|
180
|
+
// parameter and passing null mean the same thing downstream — buildFieldDef
|
|
181
|
+
// tests for both — so the null branch bought nothing and cost the collapse.
|
|
182
|
+
.optional()
|
|
183
|
+
.describe('Label users see: "Budget", or {"en": "Budget", "uk": "Бюджет"}. Omitted: no title, and ' +
|
|
184
|
+
"none is invented from the name.");
|
|
165
185
|
// Entity Options (captures/api-entity-builder-builder.txt:74-90) — the platform's
|
|
166
186
|
// 15 per-entity features, plus customFields (newer than that capture, verified live). The TIP at :91-92 is quoted in full: enabling one is a
|
|
167
187
|
// schema change (it creates the backing side table), not a preference toggle.
|
|
@@ -1134,7 +1154,7 @@ export function buildServer() {
|
|
|
1134
1154
|
field_type: z
|
|
1135
1155
|
.string()
|
|
1136
1156
|
.describe("A real Suppa 2.0 type (see suppa_list_field_types). NO date/richtext/email type exists — use 'timestamp' (+sub_type='date') or 'multi-language'. 'one-to-many' is refused — use suppa_create_tabular_part for owned children, 'many-to-many' for shared lookups."),
|
|
1137
|
-
title:
|
|
1157
|
+
title: FieldTitle,
|
|
1138
1158
|
required: z.boolean().default(false),
|
|
1139
1159
|
default_value: z
|
|
1140
1160
|
.string()
|
|
@@ -1429,9 +1449,9 @@ export function buildServer() {
|
|
|
1429
1449
|
" Needs context_field + context_value (the set for that context is created if it has\n" +
|
|
1430
1450
|
" none) or set_ids — a custom field belonging to neither is refused. The entity needs\n" +
|
|
1431
1451
|
" options.customFields on (suppa_update_entity_options).\n" +
|
|
1432
|
-
" Types, sub_type and options are suppa_add_field's.
|
|
1433
|
-
"
|
|
1434
|
-
"
|
|
1452
|
+
" Types, sub_type and options are suppa_add_field's. required=true marks it mandatory in\n" +
|
|
1453
|
+
" THIS context (its CustomFieldSetFields row), binding when the values row is written;\n" +
|
|
1454
|
+
" column-level notNull is a different thing this build cannot create.\n" +
|
|
1435
1455
|
" Enum values come after: suppa_add_enum_values(entity_name='<Entity>CustomFields',\n" +
|
|
1436
1456
|
" field_name='<field>') — both, or it cannot read the group off the field.",
|
|
1437
1457
|
inputSchema: {
|
|
@@ -1441,7 +1461,7 @@ export function buildServer() {
|
|
|
1441
1461
|
.describe("camelCase, letters/numbers/underscores, 1-50 — and the English MEANING of the title, " +
|
|
1442
1462
|
"never the title in Latin letters (opysPrychyny is refused; reasonDescription is the name)."),
|
|
1443
1463
|
field_type: z.string().describe("As suppa_add_field (see suppa_list_field_types)."),
|
|
1444
|
-
title:
|
|
1464
|
+
title: FieldTitle,
|
|
1445
1465
|
context_field: z
|
|
1446
1466
|
.string()
|
|
1447
1467
|
.nullable()
|
|
@@ -1457,6 +1477,11 @@ export function buildServer() {
|
|
|
1457
1477
|
.nullable()
|
|
1458
1478
|
.default(null)
|
|
1459
1479
|
.describe("Existing CustomFieldSets ids, instead of a context."),
|
|
1480
|
+
required: z
|
|
1481
|
+
.boolean()
|
|
1482
|
+
.default(false)
|
|
1483
|
+
.describe("Mandatory in THIS context — set on the field's CustomFieldSetFields row. An insert " +
|
|
1484
|
+
"naming it null is refused; one with no customFields key still passes."),
|
|
1460
1485
|
relation_entity: z.string().nullable().default(null),
|
|
1461
1486
|
options_json: z.string().nullable().default(null),
|
|
1462
1487
|
sub_type: z.string().nullable().default(null),
|
|
@@ -1469,6 +1494,7 @@ export function buildServer() {
|
|
|
1469
1494
|
contextField: a.context_field,
|
|
1470
1495
|
contextValue: a.context_value,
|
|
1471
1496
|
setIds: a.set_ids,
|
|
1497
|
+
required: a.required,
|
|
1472
1498
|
relationEntity: a.relation_entity,
|
|
1473
1499
|
options: a.options_json,
|
|
1474
1500
|
subType: a.sub_type,
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
* field mandatory is `required` on the CustomFieldSetFields link row, which
|
|
43
43
|
* the platform enforces when the values row is created.
|
|
44
44
|
*/
|
|
45
|
-
import { makeRequest, searchEntity } from "../httpClient.js";
|
|
45
|
+
import { makeRequest, searchEntity, updateEntity } from "../httpClient.js";
|
|
46
46
|
import { customFieldsHint } from "../customFieldHints.js";
|
|
47
|
-
import { jsonResponse, confirmRequired } from "../utils.js";
|
|
47
|
+
import { jsonResponse, confirmRequired, makeFilter } from "../utils.js";
|
|
48
48
|
import { buildFieldDef, CUSTOM_FIELDS_EXTENSION_SUFFIX, CUSTOM_FIELDS_KEY, CUSTOM_FIELDS_OPTION, } from "./entity.js";
|
|
49
49
|
/**
|
|
50
50
|
* Re-exported from ./entity.ts, where the option lives beside the rest of the
|
|
@@ -235,22 +235,23 @@ export async function addCustomField(entityName, fieldName, fieldType, title, op
|
|
|
235
235
|
"ways to name the same thing and the builder reads only one of them. Nothing was sent.",
|
|
236
236
|
});
|
|
237
237
|
}
|
|
238
|
-
//
|
|
239
|
-
//
|
|
240
|
-
//
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
238
|
+
// `required` is NOT notNull. Column-level notNull is refused by this build
|
|
239
|
+
// (without a default the builder answers "`defaultValue` is required when
|
|
240
|
+
// creating a field with `notNull: true`"; with one it answers "Field x is not
|
|
241
|
+
// available for this record's context", even for a context holding no values).
|
|
242
|
+
// Per-CONTEXT obligation is a different mechanism and it works: it lives on
|
|
243
|
+
// the CustomFieldSetFields link row, resolve reports it, and the platform
|
|
244
|
+
// enforces it when the values row is created — an insert naming the field as
|
|
245
|
+
// null is refused with "is required for this record's context" (verified on
|
|
246
|
+
// dev 2026-09-15, traceId 70caccc643d55bdf3f021331510c1c89).
|
|
247
|
+
//
|
|
248
|
+
// This used to be a refusal telling the caller to go and set that row by
|
|
249
|
+
// hand — and the refusal was unreachable, because the tool exposed no
|
|
250
|
+
// `required` parameter at all and `options_json` rejects notNull as an
|
|
251
|
+
// unknown option. So a caller who asked for a mandatory field got an optional
|
|
252
|
+
// one and no warning. Do the two steps instead of describing them.
|
|
253
|
+
const wantRequired = Boolean(fieldOpts.required);
|
|
254
|
+
delete fieldOpts.required; // never forwarded to the builder as notNull
|
|
254
255
|
// An enum custom field is bound through relationTarget, exactly like a normal
|
|
255
256
|
// one; the tenant convention (every enum field already on the tenant) is the
|
|
256
257
|
// qualified '<ExtensionEntity>.<field>' name, and the variants are ordinary
|
|
@@ -290,6 +291,8 @@ export async function addCustomField(entityName, fieldName, fieldType, title, op
|
|
|
290
291
|
return errorResponse(e, { sent: { customFields: envelope } });
|
|
291
292
|
}
|
|
292
293
|
const out = { result };
|
|
294
|
+
if (wantRequired)
|
|
295
|
+
out.required = await _markRequiredInSets(entityName, fieldName, result);
|
|
293
296
|
if (usage)
|
|
294
297
|
Object.assign(out, quotaNote(usage, 1));
|
|
295
298
|
if (built.notApplicable && built.notApplicable.length > 0) {
|
|
@@ -336,6 +339,82 @@ export async function addCustomField(entityName, fieldName, fieldType, title, op
|
|
|
336
339
|
`{"${fieldName}": <value>}}')`;
|
|
337
340
|
return jsonResponse(out);
|
|
338
341
|
}
|
|
342
|
+
/**
|
|
343
|
+
* Turn on per-context obligation for a custom field that was just created.
|
|
344
|
+
*
|
|
345
|
+
* `required` is a property of the LINK between a field and a set
|
|
346
|
+
* (`CustomFieldSetFields`), not of the column — one field can be mandatory in
|
|
347
|
+
* one context and optional in another, which is the whole point of sets. The
|
|
348
|
+
* builder has no way to set it, so this is a second call by design.
|
|
349
|
+
*
|
|
350
|
+
* NEVER turns a successful creation into a failure: the field exists either
|
|
351
|
+
* way, and the caller has to be told exactly which half happened rather than
|
|
352
|
+
* being handed an error for a column that is sitting on the tenant.
|
|
353
|
+
*/
|
|
354
|
+
async function _markRequiredInSets(entityName, fieldName, result) {
|
|
355
|
+
const manual = `suppa_search_records("CustomFieldSetFields", filters on field.name="${fieldName}") to find ` +
|
|
356
|
+
'the link row, then suppa_update_record on it with {"required": true}.';
|
|
357
|
+
const created = result?.[CUSTOM_FIELDS_KEY];
|
|
358
|
+
const fieldId = Array.isArray(created)
|
|
359
|
+
? created.find((f) => f?.name === fieldName)?.id
|
|
360
|
+
: undefined;
|
|
361
|
+
if (typeof fieldId !== "number") {
|
|
362
|
+
return {
|
|
363
|
+
applied: false,
|
|
364
|
+
field_is_optional: true,
|
|
365
|
+
reason: "the builder's answer carried no id for this field, so its set link could not be found",
|
|
366
|
+
do_this: manual,
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
let links;
|
|
370
|
+
try {
|
|
371
|
+
links = await searchEntity("CustomFieldSetFields", [makeFilter("field.id", fieldId)], { id: true, set: { id: true } }, 50);
|
|
372
|
+
}
|
|
373
|
+
catch (e) {
|
|
374
|
+
return {
|
|
375
|
+
applied: false,
|
|
376
|
+
field_is_optional: true,
|
|
377
|
+
reason: `the field was created, but its set links could not be read: ${e instanceof Error ? e.message : String(e)}`,
|
|
378
|
+
do_this: manual,
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
const ids = links
|
|
382
|
+
.map((l) => l?.id)
|
|
383
|
+
.filter((id) => typeof id === "number");
|
|
384
|
+
if (ids.length === 0) {
|
|
385
|
+
return {
|
|
386
|
+
applied: false,
|
|
387
|
+
field_is_optional: true,
|
|
388
|
+
reason: "the field was created but is linked to no set, so there is no context to be required in",
|
|
389
|
+
do_this: manual,
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
const done = [];
|
|
393
|
+
const failed = {};
|
|
394
|
+
for (const id of ids) {
|
|
395
|
+
try {
|
|
396
|
+
await updateEntity("CustomFieldSetFields", id, { required: true });
|
|
397
|
+
done.push(id);
|
|
398
|
+
}
|
|
399
|
+
catch (e) {
|
|
400
|
+
failed[String(id)] = e instanceof Error ? e.message : String(e);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
return {
|
|
404
|
+
applied: done.length > 0 && Object.keys(failed).length === 0,
|
|
405
|
+
link_rows_marked: done,
|
|
406
|
+
...(Object.keys(failed).length > 0 ? { link_rows_that_failed: failed, do_this: manual } : {}),
|
|
407
|
+
// Obligation binds when the values row is created, not on every insert —
|
|
408
|
+
// an insert that never mentions customFields at all still passes (verified
|
|
409
|
+
// on dev 2026-09-15: record 120 went in with no customFields key).
|
|
410
|
+
means: `'${fieldName}' is now mandatory in this context: an insert or update that names it as ` +
|
|
411
|
+
`null is refused with "is required for this record's context". An insert that carries no ` +
|
|
412
|
+
`customFields key at all still passes — the obligation binds when the values row is written.`,
|
|
413
|
+
undo: `suppa_update_record("CustomFieldSetFields", <link row id>, '{"required": false}') — the ` +
|
|
414
|
+
`rows are listed above. suppa_resolve_custom_fields("${entityName}", …) shows each field's ` +
|
|
415
|
+
`current required flag.`,
|
|
416
|
+
};
|
|
417
|
+
}
|
|
339
418
|
// ---------------------------------------------------------------------------
|
|
340
419
|
// Remove / restore
|
|
341
420
|
// ---------------------------------------------------------------------------
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "suppa-mcp-2",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.37.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": {
|