suppa-mcp-2 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server.js +13 -6
- package/dist/tools/entity.js +47 -11
- package/package.json +1 -1
- package/skills/suppa-entity-code/SKILL.md +48 -7
- package/skills/suppa-entity-code/scripts/validate-suppa-schema.mjs +1527 -1284
- package/skills/suppa-entity-code/templates/entity.template.ts +29 -1
- package/skills/suppa-entity-code/templates/tabular-part.template.ts +99 -94
package/dist/server.js
CHANGED
|
@@ -260,7 +260,8 @@ ENTITY BUILDER (create + edit fields; removal is UI-only)
|
|
|
260
260
|
- 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
261
|
- FIELD OPTIONS decide whether a field is usable: searchable, searchPriority (1-4), readOnly, canGroup, canSort, showInTable, editFromTable, canFilter. Pass options_json on suppa_add_field — a field created without them is missing from table views, and suppa_search_records' free-text search only covers fields marked searchable. Turn them on later with suppa_update_field.
|
|
262
262
|
- 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
|
-
- Relations need relation_entity; enums need enum_name (
|
|
263
|
+
- 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
|
+
- 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.
|
|
264
265
|
- 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.
|
|
265
266
|
|
|
266
267
|
MIGRATION (Suppa 1.0 → 2.0)
|
|
@@ -296,7 +297,7 @@ export function buildServer() {
|
|
|
296
297
|
// Reset so repeated buildServer() calls (e.g. in tests) do not double-count.
|
|
297
298
|
TOOL_NAMES.length = 0;
|
|
298
299
|
PROMPT_NAMES.length = 0;
|
|
299
|
-
const server = new McpServer({ name: "suppa-2.0", version: "1.
|
|
300
|
+
const server = new McpServer({ name: "suppa-2.0", version: "1.4.0" }, { instructions: INSTRUCTIONS });
|
|
300
301
|
const reg = (name, cfg, handler) => {
|
|
301
302
|
server.registerTool(name, {
|
|
302
303
|
description: cfg.description,
|
|
@@ -1272,15 +1273,21 @@ export function buildServer() {
|
|
|
1272
1273
|
}));
|
|
1273
1274
|
});
|
|
1274
1275
|
reg("suppa_add_enum_values", {
|
|
1275
|
-
description: "Add values to an enum (lookup table). enum_name:
|
|
1276
|
-
"
|
|
1276
|
+
description: "Add values to an enum (lookup table). enum_name: the enum's global name,\n" +
|
|
1277
|
+
" conventionally 'Entity.field' (e.g. 'Receipts.type'). values:\n" +
|
|
1278
|
+
" comma-separated 'code' or 'code:Label' — a value with no label is\n" +
|
|
1279
|
+
" stored with the code as its label, never blank.\n" +
|
|
1280
|
+
" Call this BEFORE creating the enum field, then pass the same\n" +
|
|
1281
|
+
" enum_name to suppa_add_field.",
|
|
1277
1282
|
inputSchema: {
|
|
1278
1283
|
enum_name: z
|
|
1279
1284
|
.string()
|
|
1280
|
-
.describe("
|
|
1285
|
+
.describe("The enum's global name, conventionally 'Entity.field' (e.g. 'Receipts.type'). " +
|
|
1286
|
+
"It need not match the field name — one enum can back several fields."),
|
|
1281
1287
|
values: z
|
|
1282
1288
|
.string()
|
|
1283
|
-
.describe("Comma-separated
|
|
1289
|
+
.describe("Comma-separated 'code' or 'code:Label' (e.g. \"new:New request,done:Done\"). " +
|
|
1290
|
+
"The label is what users see in the picker. Existing codes are skipped."),
|
|
1284
1291
|
},
|
|
1285
1292
|
annotations: _ADD,
|
|
1286
1293
|
}, async (a) => text(await entity.addEnumValues(a.enum_name, a.values)));
|
package/dist/tools/entity.js
CHANGED
|
@@ -1398,8 +1398,21 @@ export async function addField(entityName, fieldName, fieldType, title, opts = {
|
|
|
1398
1398
|
if (relTarget) {
|
|
1399
1399
|
fieldDef.relationTarget = relTarget;
|
|
1400
1400
|
}
|
|
1401
|
-
|
|
1402
|
-
|
|
1401
|
+
// An enum field is bound to its enum through `relationTarget`, exactly like a
|
|
1402
|
+
// relation — builder.txt:63 groups enum/multi-enum under "Relation types" and
|
|
1403
|
+
// :44 types relationTarget as "Related entity", which for these is the enum's
|
|
1404
|
+
// global name.
|
|
1405
|
+
//
|
|
1406
|
+
// This server used to send `enumName` instead. That key is in no doc capture,
|
|
1407
|
+
// and it is INERT: verified on a live 2.0 tenant (modern-expo.dev.suppa.me,
|
|
1408
|
+
// 2026-08-05) by creating the same field both ways and reading the schema
|
|
1409
|
+
// back — `enumName` produced subType=null, relationTarget=null (an unbound
|
|
1410
|
+
// field with no values behind it), while `relationTarget` produced
|
|
1411
|
+
// subType=relationTarget=<enum name>, matching every working enum field on
|
|
1412
|
+
// that tenant. The add-fields response echoes `enumName` back, which is why
|
|
1413
|
+
// the failure looked like success for so long.
|
|
1414
|
+
if (enumName && (resolvedType === "enum" || resolvedType === "multi-enum")) {
|
|
1415
|
+
fieldDef.relationTarget = enumName;
|
|
1403
1416
|
}
|
|
1404
1417
|
// builder.txt:60 — "options | object | false | Field options configuration."
|
|
1405
1418
|
// (example body: builder.txt:127-132).
|
|
@@ -1638,27 +1651,50 @@ export async function updateField(entityName, fieldName, opts = {}) {
|
|
|
1638
1651
|
* create duplicate rows.
|
|
1639
1652
|
*/
|
|
1640
1653
|
export async function addEnumValues(enumName, values) {
|
|
1641
|
-
|
|
1654
|
+
// "code" or "code:Label". The label is what a user sees in the picker; the
|
|
1655
|
+
// code is what the row stores. Every working enum on a live tenant carries a
|
|
1656
|
+
// title, and a row inserted without one reads back title:null — an option
|
|
1657
|
+
// that shows up blank. This server used to insert {name, value} only, so
|
|
1658
|
+
// every enum it created had untitled options.
|
|
1659
|
+
const parsed = values
|
|
1642
1660
|
.split(",")
|
|
1643
|
-
.map((
|
|
1644
|
-
.filter((
|
|
1645
|
-
|
|
1646
|
-
|
|
1661
|
+
.map((raw) => raw.trim())
|
|
1662
|
+
.filter((raw) => raw)
|
|
1663
|
+
.map((raw) => {
|
|
1664
|
+
const sep = raw.indexOf(":");
|
|
1665
|
+
const value = (sep === -1 ? raw : raw.slice(0, sep)).trim();
|
|
1666
|
+
const title = (sep === -1 ? "" : raw.slice(sep + 1).trim()) || value;
|
|
1667
|
+
return { value, title };
|
|
1668
|
+
})
|
|
1669
|
+
.filter((v) => v.value);
|
|
1670
|
+
if (parsed.length === 0) {
|
|
1671
|
+
return jsonResponse({
|
|
1672
|
+
error: "No values provided — pass a comma-separated list, e.g. \"new,inProgress\" or " +
|
|
1673
|
+
'"new:New request,inProgress:In progress" to set the labels users see.',
|
|
1674
|
+
});
|
|
1647
1675
|
}
|
|
1648
1676
|
const existingRows = await searchEntity("Enums", [makeFilter("name", enumName)], { id: true, value: true }, 1000);
|
|
1649
1677
|
const existing = new Set(existingRows
|
|
1650
1678
|
.filter((r) => r !== null && typeof r === "object")
|
|
1651
1679
|
.map((r) => String(r.value)));
|
|
1652
|
-
const newValues =
|
|
1653
|
-
const skipped =
|
|
1680
|
+
const newValues = parsed.filter((v) => !existing.has(v.value));
|
|
1681
|
+
const skipped = parsed.filter((v) => existing.has(v.value)).map((v) => v.value);
|
|
1654
1682
|
let result = [];
|
|
1655
1683
|
if (newValues.length > 0) {
|
|
1656
1684
|
// The /api/core/data-bulk/{entity} endpoint returns 201 but silently
|
|
1657
1685
|
// persists nothing; the regular insert action actually stores the batch.
|
|
1658
|
-
|
|
1686
|
+
// `title` goes as a plain string: that is the shape the platform's own enum
|
|
1687
|
+
// rows read back as, while a localization object read back as raw JSON.
|
|
1688
|
+
result = await insertEntity("Enums", newValues.map((v, i) => ({
|
|
1689
|
+
name: enumName,
|
|
1690
|
+
value: v.value,
|
|
1691
|
+
title: v.title,
|
|
1692
|
+
order: existing.size + i,
|
|
1693
|
+
})));
|
|
1659
1694
|
}
|
|
1660
1695
|
return jsonResponse({
|
|
1661
|
-
added: newValues,
|
|
1696
|
+
added: newValues.map((v) => v.value),
|
|
1697
|
+
titles: Object.fromEntries(newValues.map((v) => [v.value, v.title])),
|
|
1662
1698
|
skipped_existing: skipped,
|
|
1663
1699
|
result,
|
|
1664
1700
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "suppa-mcp-2",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.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": {
|
|
@@ -52,7 +52,11 @@ Confirm all 5 before writing anything:
|
|
|
52
52
|
11. Renames need `key` set on `@Entity()`/`@Column()` BEFORE the rename ships — otherwise it's a drop-and-create, not a rename.
|
|
53
53
|
12. `subType` refines `type` and means three unrelated things depending on the base type — `Timestamp` → `'date' | 'time' | 'timestamp'`, `Text` → `'encrypted'`, `Enum`/`MultiEnum` → the enum's global name. Never pass `subType` by hand on an `@Enum`/`@MultiEnum` field: the decorator fills it from its first argument (or derives `<ClassName>.<propertyName>`), and a hand-written one either duplicates that or silently disagrees with the value that resolves `{ value: 'active' }` on insert. Any other `(type, subType)` pair does not exist.
|
|
54
54
|
13. `subType` is **immutable after creation**, with one exception: toggling `'encrypted'` on or off. The Builder API answers `Field subType cannot be changed.` to anything else — so choosing `Timestamp` where you needed `subType: 'date'` is not a conversion you can ship later, it is a NEW field plus a removal of the old one (see `references/registration.md` for what removal leaves behind). Get date-vs-timestamp right the first time. To CLEAR a subtype you must write `subType: null` explicitly — deleting the line does nothing, because an omitted key is dropped from the sync payload and the stored subtype survives.
|
|
55
|
-
14.
|
|
55
|
+
14. **Every relation property carries its TypeScript type, and the type says what the decorator says.** `@ManyToOne` holds ONE row — `owner: ProductMatrixEntity;` — while `@ManyToMany`, `@OneToMany` and `@ManyToManyBackRef` hold many — `envs: ApplicationEnvsEntity[];`. Type it optional (`owner?: Target`) unless the relation is `nullable: false`. An untyped relation property is `any` to every consumer of the entity. E114/E115/W610.
|
|
56
|
+
15. **Enum member keys are PascalCase** — `NotFilled = 'Not filled'`. The key is the identifier the code reads; the string on the right is what the platform stores, and the two need not match. W611.
|
|
57
|
+
16. **Never write an option that already holds its default value.** The platform applies `canGroup: true`, `canSort: true`, `showInTable: true`, `editFromTable: true`, `canFilter: true`, `readOnly: false`, `searchable: false` on its own. Declare one of these ONLY where the field departs from it; repeating defaults on every field buries the one option that actually differs. W612.
|
|
58
|
+
17. **`@Enum`/`@MultiEnum` take the global name only when the enum is global.** Default is local: `@Enum(StageStatusEnum, StageStatus, { nullable: false })` — the decorator derives `<ClassName>.<propertyName>`. Pass the name as the FIRST argument only when the value set is shared across entities or referenced from a seed: `@Enum('StageWorkflows.status', StageStatusEnum, StageStatus, { … })`. W613.
|
|
59
|
+
18. Repeating rows owned by one parent record are a **tabular part**, never a plain entity: `type: 'tabular-part'` + `relationEntityName` (the parent's `@Entity()` name) + a `@ManyToOne` field named exactly `owner` pointing at the parent class — all three required, the platform infers none of them. Put `owner` FIRST in `importKeyFields` — it scopes the business key to the parent, or rows collide across different parents.
|
|
56
60
|
|
|
57
61
|
## Decorator decision table
|
|
58
62
|
|
|
@@ -64,17 +68,47 @@ Confirm all 5 before writing anything:
|
|
|
64
68
|
| Time-only column | `@Column({ type: FieldTypeEnum.Timestamp, subType: 'time' })` — there is **no** `FieldTypeEnum.Time` |
|
|
65
69
|
| Date **and** time | `@Column({ type: FieldTypeEnum.Timestamp })` — omitted `subType` already means `timestamp` |
|
|
66
70
|
| Text encrypted at rest | `@Column({ type: FieldTypeEnum.Text, subType: 'encrypted' })` — Text only; see rule 13 for what it costs |
|
|
67
|
-
| Fixed single-select value set | `@Enum(
|
|
68
|
-
|
|
|
69
|
-
|
|
|
70
|
-
|
|
|
71
|
-
|
|
|
72
|
-
| Reverse side of a `@
|
|
71
|
+
| Fixed single-select value set, used by this field only | `@Enum(<Field>Enum, <Field>Titles?, options?)` → `field: <Field>Enum;` |
|
|
72
|
+
| …the same, but shared across entities or referenced from a seed | `@Enum('<Entity>.<field>', <Field>Enum, <Field>Titles?, options?)` |
|
|
73
|
+
| Fixed multi-select value set | `@MultiEnum(...)` — same signatures as `@Enum` |
|
|
74
|
+
| Foreign key on this entity | `@ManyToOne(() => Target, options?)` → `prop: Target;` — **no inverse** |
|
|
75
|
+
| Pivot table between two entities | `@ManyToMany(() => Target, options?)` → `prop: Target[];` — **no inverse** |
|
|
76
|
+
| Reverse side of a `@ManyToMany` | `@ManyToManyBackRef(() => Target, (t) => t.<thisRelationProp>, options?)` → `prop: Target[];` |
|
|
77
|
+
| Reverse side of a `@ManyToOne` | `@OneToMany(() => Target, (t) => t.<thisRelationProp>, options?)` → `prop: Target[];` |
|
|
73
78
|
| Single attachment | `@File({ title })` |
|
|
74
79
|
| Multiple attachments | `@MultiFile({ title })` |
|
|
75
80
|
|
|
76
81
|
`target` is always a thunk, `() => Target`. The `inverse` selector is REQUIRED on `@OneToMany`/`@ManyToManyBackRef` and OPTIONAL on `@ManyToOne`/`@ManyToMany` — omit it there by default. When you do write one, it must select the property on the TARGET class that holds the other side of this relation (e.g. `(task) => task.project`) — never `.id`, never a scalar column.
|
|
77
82
|
|
|
83
|
+
**Typing the property (rule 14).** The decorator declares the relation; the TypeScript type declares its shape, and the two must agree:
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
@ManyToOne(() => ProductMatrixEntity, {
|
|
87
|
+
name: 'owner',
|
|
88
|
+
key: 'ProductMatrixItem.owner',
|
|
89
|
+
nullable: false,
|
|
90
|
+
title: { en: 'Owner' },
|
|
91
|
+
})
|
|
92
|
+
owner: ProductMatrixEntity; // ONE row; no '?' because nullable: false
|
|
93
|
+
|
|
94
|
+
@ManyToMany(() => ProductMatrixEntity, { name: 'peers', title: { en: 'Peers' } })
|
|
95
|
+
peers: ProductMatrixEntity[]; // MANY rows
|
|
96
|
+
|
|
97
|
+
@OneToMany(() => ApplicationEnvsEntity, (entity) => entity.owner, {
|
|
98
|
+
title: getFieldTitle(EntityNamesEnum.Applications, 'envs'),
|
|
99
|
+
})
|
|
100
|
+
envs: ApplicationEnvsEntity[]; // MANY rows, inverse REQUIRED
|
|
101
|
+
|
|
102
|
+
@ManyToManyBackRef(() => ApplicationEnvsEntity, (entity) => entity.owner, {
|
|
103
|
+
title: getFieldTitle(EntityNamesEnum.Applications, 'envs'),
|
|
104
|
+
})
|
|
105
|
+
envs: ApplicationEnvsEntity[]; // MANY rows, inverse REQUIRED
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
A `@ManyToOne` without `nullable: false` is written `owner?: ProductMatrixEntity` — the column may be empty and callers must handle it.
|
|
109
|
+
|
|
110
|
+
**Field options (rule 16).** `canGroup`, `canSort`, `showInTable`, `editFromTable` and `canFilter` default to `true`; `readOnly` and `searchable` default to `false`. Write one only to depart from that — `searchable: true` on the field users actually search, and nothing on the rest.
|
|
111
|
+
|
|
78
112
|
**What `subType: 'encrypted'` costs.** The platform forces the column's `unique`, `searchable`, `canFilter`, `canSort` and `canGroup` to `false` and clears `maxLength`, `minLength` and `mask`, whatever you declared — the ciphertext envelope can't satisfy a plaintext constraint or be read by an index. So an encrypted column cannot be searched, filtered, sorted or grouped: if users need any of that, split the field and keep the searchable part in a separate plaintext column. It is also rejected inside a `MultiType` field and on any non-Text type.
|
|
79
113
|
|
|
80
114
|
## Naming conventions
|
|
@@ -85,6 +119,7 @@ Confirm all 5 before writing anything:
|
|
|
85
119
|
| Entity class | PascalCase, plural = `@Entity()`'s `name` | `StageWorkflows` |
|
|
86
120
|
| Seed export | camelCase plural + `Seed` | `stageWorkflowsSeed` |
|
|
87
121
|
| Enum | PascalCase + `Enum` | `StageStatusEnum` |
|
|
122
|
+
| Enum member key | PascalCase — the stored value is the string on the right and need not match | `NotFilled = 'Not filled'` |
|
|
88
123
|
| Titles map | PascalCase + `Titles` suffix — this doc's own worked examples drop the suffix (`StageStatus`); either is acceptable if used consistently within a repo | `StageStatusTitles` (or `StageStatus`) |
|
|
89
124
|
| Enum global name | `'<EntityName>.<field>'` | `'StageWorkflows.status'` |
|
|
90
125
|
| Index name | `idx_<table>_<cols>` | `idx_tasks_project` |
|
|
@@ -173,6 +208,12 @@ The validator parses with the TypeScript compiler API, read from the app repo yo
|
|
|
173
208
|
| A renamed entity or field appears as a new one | No `key` option was set | W602 |
|
|
174
209
|
| `default` value is rejected | A JavaScript value was passed instead of a SQL expression string | E103 |
|
|
175
210
|
| Generated relation has an inverse selector that fails to typecheck | An `inverse` was passed to `@ManyToOne`/`@ManyToMany`, where it's optional and usually omitted | W609/E111 — drop the selector, write `@ManyToOne(() => Target, { … })` |
|
|
211
|
+
| A relation reads as `any`; nothing catches using it as the wrong shape | The property has no TypeScript type | E114 — write `owner: Target;` (`Target[]` for the to-many decorators) |
|
|
212
|
+
| A to-many relation is used as a single record (or the reverse) | The property's type contradicts the decorator's arity, or names a different class than the thunk | E115 — `@ManyToOne` → `Target`; `@ManyToMany`/`@OneToMany`/`@ManyToManyBackRef` → `Target[]` |
|
|
213
|
+
| Callers never null-check a relation that can be empty | A nullable `@ManyToOne` is typed as always present (or a `nullable: false` one as optional) | W610 — `owner?: Target` when nullable, `owner: Target` when `nullable: false` |
|
|
214
|
+
| Enum members read as data rather than identifiers | Member keys are not PascalCase | W611 — `NotFilled = 'Not filled'` |
|
|
215
|
+
| Every field repeats the same five option lines | Options were written at their default values | W612 — delete them; declare an option only where it departs from the default |
|
|
216
|
+
| An enum name is invented for a field nothing else references | The optional global name was passed to `@Enum`/`@MultiEnum` when the enum is local | W613 — omit the first argument; the decorator derives `<ClassName>.<propertyName>` |
|
|
176
217
|
| Migration rejects the column, or a date field ships as a full `timestamp` | The `(type, subType)` pair isn't one the doc allows — `Timestamp` takes `'date'`/`'time'`/`'timestamp'`, `Text` takes `'encrypted'`, nothing else | E112 |
|
|
177
218
|
| `Encrypted subtype is only allowed on text fields` | `subType: 'encrypted'` on a non-Text column | E112 |
|
|
178
219
|
| An enum field resolves to the wrong enum, or its values fail to insert | `subType` was written by hand on `@Enum`/`@MultiEnum` instead of being left to the decorator | E113 |
|