suppa-mcp-2 1.29.0 → 1.30.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -63,7 +63,7 @@ child process and makes it speak MCP** — `initialize`, then `tools/list`. A
|
|
|
63
63
|
healthy install prints one line:
|
|
64
64
|
|
|
65
65
|
```
|
|
66
|
-
suppa-mcp-2: self-check ok — v1.
|
|
66
|
+
suppa-mcp-2: self-check ok — v1.30.0, 96 tools.
|
|
67
67
|
```
|
|
68
68
|
|
|
69
69
|
A broken one says what is wrong, what the host will show you instead, and the
|
|
@@ -347,7 +347,7 @@ extension table is created outside that check and is not subject to it.
|
|
|
347
347
|
|
|
348
348
|
## Available tools
|
|
349
349
|
|
|
350
|
-
|
|
350
|
+
96 tools across the areas below.
|
|
351
351
|
|
|
352
352
|
### Session & identity
|
|
353
353
|
|
|
@@ -425,6 +425,7 @@ extension table is created outside that check and is not subject to it.
|
|
|
425
425
|
| `suppa_add_custom_field` | Create a custom field in one context (its set is created if missing) |
|
|
426
426
|
| `suppa_add_custom_fields_batch` | Create MANY custom fields in ONE atomic call — one bad entry creates nothing |
|
|
427
427
|
| `suppa_link_custom_field` | Put an existing custom field into another context, take it out, or set `required` there (confirm-gated) |
|
|
428
|
+
| `suppa_apply_custom_fields` | Apply a custom-field declaration FILE from the repo — idempotent, never deletes, dry run by default |
|
|
428
429
|
| `suppa_remove_custom_field` | Soft-remove custom fields; the column is parked, not dropped (confirm-gated) |
|
|
429
430
|
| `suppa_restore_custom_field` | Put a removed custom field and its values back (confirm-gated) |
|
|
430
431
|
| `suppa_set_title_field` | Set the representative/title field |
|
package/dist/server.js
CHANGED
|
@@ -14,6 +14,7 @@ import * as docs from "./tools/docs.js";
|
|
|
14
14
|
import * as entity from "./tools/entity.js";
|
|
15
15
|
import * as customFields from "./tools/customFields.js";
|
|
16
16
|
import * as customFieldSets from "./tools/customFieldSets.js";
|
|
17
|
+
import * as customFieldsAsCode from "./tools/customFieldsAsCode.js";
|
|
17
18
|
import * as entityCode from "./tools/entityCode.js";
|
|
18
19
|
import { houseRulesDigest } from "./tools/entityCode.js";
|
|
19
20
|
import * as files from "./tools/files.js";
|
|
@@ -1518,6 +1519,27 @@ export function buildServer() {
|
|
|
1518
1519
|
contextValue: a.context_value,
|
|
1519
1520
|
setIds: a.set_ids,
|
|
1520
1521
|
})));
|
|
1522
|
+
reg("suppa_apply_custom_fields", {
|
|
1523
|
+
description: "Custom fields DECLARED IN A REPO FILE, applied to a tenant — the file is the source of truth.\n" +
|
|
1524
|
+
" The SDK has no decorator for them, so they are the one part of a schema with no home in git.\n" +
|
|
1525
|
+
' declaration: {"entity","context_field","fields":[{"name","type","title","contexts":["PL"]}]}.\n' +
|
|
1526
|
+
" Idempotent — a second run answers already_converged. Creates per context in ONE atomic\n" +
|
|
1527
|
+
" batch, then links existing fields into their other contexts.\n" +
|
|
1528
|
+
" NEVER deletes (a dropped field is reported as not_declared; removal reserves its name for\n" +
|
|
1529
|
+
" good) and never changes a type (type_drift — that is a data migration).\n" +
|
|
1530
|
+
" Dry run by default; confirm=true applies.",
|
|
1531
|
+
inputSchema: {
|
|
1532
|
+
declaration: z
|
|
1533
|
+
.string()
|
|
1534
|
+
.describe('JSON: {"entity","context_field","fields":[...]}. Every field needs "contexts" — one offered ' +
|
|
1535
|
+
"everywhere is an ordinary field and belongs in the entity class."),
|
|
1536
|
+
confirm: z
|
|
1537
|
+
.boolean()
|
|
1538
|
+
.default(false)
|
|
1539
|
+
.describe("false (default) returns the plan and changes nothing; true applies it."),
|
|
1540
|
+
},
|
|
1541
|
+
annotations: _ADD,
|
|
1542
|
+
}, async (a) => text(await customFieldsAsCode.applyCustomFieldsDeclaration(a.declaration, { confirm: a.confirm })));
|
|
1521
1543
|
reg("suppa_link_custom_field", {
|
|
1522
1544
|
description: "Put EXISTING custom fields into another context, take them out of one, or set required.\n" +
|
|
1523
1545
|
" A field joins a context through a row, so ONE field can be live in several contexts at\n" +
|
|
@@ -102,8 +102,11 @@ export async function resolveTargetSets(entityName, sel) {
|
|
|
102
102
|
return { ids: rows.map((r) => Number(r.id)).filter(Number.isInteger) };
|
|
103
103
|
}
|
|
104
104
|
/** FieldMetadata rows for an extension entity, by field name. */
|
|
105
|
-
async function extensionFields(extension) {
|
|
106
|
-
const rows = asRows(await searchEntity(META_ENTITY, [{ field: "entity.name", value: extension, comparator: "=" }],
|
|
105
|
+
export async function extensionFields(extension) {
|
|
106
|
+
const rows = asRows(await searchEntity(META_ENTITY, [{ field: "entity.name", value: extension, comparator: "=" }],
|
|
107
|
+
// `type` is read so a declaration file can be diffed against the live
|
|
108
|
+
// column: without it every existing field looks like a type change.
|
|
109
|
+
{ id: true, name: true, type: true, deletedAt: true }, 500));
|
|
107
110
|
const out = new Map();
|
|
108
111
|
for (const r of rows) {
|
|
109
112
|
const name = String(r.name ?? "");
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom fields, declared in the repository instead of typed into a chat.
|
|
3
|
+
*
|
|
4
|
+
* THE PROBLEM THIS FIXES. Every other part of a Suppa application is code: an
|
|
5
|
+
* entity class IS its migration, and a seed is a file. Custom fields are the
|
|
6
|
+
* exception — the SDK has no decorator for them, they exist only as runtime
|
|
7
|
+
* rows (CustomFieldSets + CustomFieldSetFields + values under the reserved
|
|
8
|
+
* `customFields` key), and the only way to create one was to call a tool by
|
|
9
|
+
* hand. So the one part of a schema that varies per context was also the one
|
|
10
|
+
* part that lived nowhere in git: not reviewable, not diffable, and not
|
|
11
|
+
* reproducible on a second tenant.
|
|
12
|
+
*
|
|
13
|
+
* The platform will not grow a decorator for us, but nothing forces the
|
|
14
|
+
* DECLARATION to be a chat message. A declaration file in the repo is the
|
|
15
|
+
* source of truth; this converges a tenant to it.
|
|
16
|
+
*
|
|
17
|
+
* { "entity": "ServiceRequests",
|
|
18
|
+
* "context_field": "country",
|
|
19
|
+
* "fields": [
|
|
20
|
+
* { "name": "plTaxId", "type": "text", "title": "NIP", "contexts": ["PL"] }
|
|
21
|
+
* ] }
|
|
22
|
+
*
|
|
23
|
+
* IT NEVER DELETES ANYTHING. A custom field removed from the file is REPORTED,
|
|
24
|
+
* not dropped: removing one parks its column as <name>_<timestamp> and keeps
|
|
25
|
+
* its name reserved forever, so an accidental deletion cannot be undone by
|
|
26
|
+
* putting the line back. Convergence is create-and-link only; taking a field
|
|
27
|
+
* away stays a deliberate act through suppa_remove_custom_field.
|
|
28
|
+
*
|
|
29
|
+
* A TYPE CHANGE IS ALSO ONLY REPORTED. Changing the type of a live column is a
|
|
30
|
+
* migration with data in it, and guessing at one from a diff is how data is
|
|
31
|
+
* lost.
|
|
32
|
+
*/
|
|
33
|
+
import { customFieldsEntity } from "./customFields.js";
|
|
34
|
+
import { addCustomFieldsBatch, extensionFields, linkCustomFields } from "./customFieldSets.js";
|
|
35
|
+
import { jsonResponse, parseJsonParam } from "../utils.js";
|
|
36
|
+
import { makeRequest } from "../httpClient.js";
|
|
37
|
+
/** Read a declaration from JSON, saying plainly what is wrong with a bad one. */
|
|
38
|
+
export function parseDeclaration(input) {
|
|
39
|
+
let raw;
|
|
40
|
+
try {
|
|
41
|
+
raw = parseJsonParam(input, "declaration", "object");
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
return { error: e instanceof Error ? e.message : String(e) };
|
|
45
|
+
}
|
|
46
|
+
const d = raw;
|
|
47
|
+
if (!d || typeof d.entity !== "string" || !d.entity.trim()) {
|
|
48
|
+
return { error: 'Refused: the declaration needs "entity" — the owner entity name. Nothing was sent.' };
|
|
49
|
+
}
|
|
50
|
+
if (typeof d.context_field !== "string" || !d.context_field.trim()) {
|
|
51
|
+
return {
|
|
52
|
+
error: 'Refused: the declaration needs "context_field" — the owner field a set keys on, e.g. "country". ' +
|
|
53
|
+
"A custom field must belong to a context. Nothing was sent.",
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
if (!Array.isArray(d.fields) || !d.fields.length) {
|
|
57
|
+
return { error: 'Refused: the declaration needs a non-empty "fields" array. Nothing was sent.' };
|
|
58
|
+
}
|
|
59
|
+
const fields = [];
|
|
60
|
+
for (const [i, f] of d.fields.entries()) {
|
|
61
|
+
const at = `fields[${i}]`;
|
|
62
|
+
if (!f || typeof f !== "object")
|
|
63
|
+
return { error: `Refused: ${at} is not an object. Nothing was sent.` };
|
|
64
|
+
const spec = f;
|
|
65
|
+
if (typeof spec.name !== "string" || !spec.name.trim()) {
|
|
66
|
+
return { error: `Refused: ${at} has no "name". Nothing was sent.` };
|
|
67
|
+
}
|
|
68
|
+
if (typeof spec.type !== "string" || !spec.type.trim()) {
|
|
69
|
+
return { error: `Refused: ${at} ("${spec.name}") has no "type". Nothing was sent.` };
|
|
70
|
+
}
|
|
71
|
+
const contexts = Array.isArray(spec.contexts) ? spec.contexts.filter((c) => c !== null && c !== "") : [];
|
|
72
|
+
if (!contexts.length) {
|
|
73
|
+
return {
|
|
74
|
+
error: `Refused: ${at} ("${spec.name}") declares no contexts. A field offered everywhere is an ` +
|
|
75
|
+
`ordinary field — put it in the entity class, not here. Nothing was sent.`,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
fields.push({ ...spec, contexts });
|
|
79
|
+
}
|
|
80
|
+
return { decl: { entity: d.entity.trim(), context_field: d.context_field.trim(), fields } };
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The difference between the file and the tenant. Pure: the caller does the
|
|
84
|
+
* reading, so every branch here is testable without a network.
|
|
85
|
+
*
|
|
86
|
+
* @param live every custom field name on the extension entity → its type
|
|
87
|
+
* @param offered context value → the set of field names live in that context
|
|
88
|
+
*/
|
|
89
|
+
export function diffDeclaration(decl, live, offered) {
|
|
90
|
+
const plan = {
|
|
91
|
+
entity: decl.entity,
|
|
92
|
+
extension: customFieldsEntity(decl.entity),
|
|
93
|
+
context_field: decl.context_field,
|
|
94
|
+
create: [],
|
|
95
|
+
link: [],
|
|
96
|
+
unchanged: [],
|
|
97
|
+
type_drift: [],
|
|
98
|
+
not_declared: [],
|
|
99
|
+
};
|
|
100
|
+
const byContext = new Map();
|
|
101
|
+
const declaredAnywhere = new Set();
|
|
102
|
+
for (const f of decl.fields) {
|
|
103
|
+
declaredAnywhere.add(f.name);
|
|
104
|
+
const liveType = live.get(f.name);
|
|
105
|
+
// An unknown live type is not a drift. Claiming one would be worse than
|
|
106
|
+
// saying nothing: it reads as "your schema moved" when nothing moved.
|
|
107
|
+
if (liveType !== undefined && liveType !== "" && liveType !== f.type) {
|
|
108
|
+
plan.type_drift.push({ field: f.name, declared: f.type, live: liveType });
|
|
109
|
+
continue; // a type change is a migration; nothing else about it is safe
|
|
110
|
+
}
|
|
111
|
+
let everywhere = true;
|
|
112
|
+
// Tracked as a local, not re-read from `live`: a field created in THIS run
|
|
113
|
+
// exists from its second context onward, and treating that second context
|
|
114
|
+
// as another create would collide the name with itself.
|
|
115
|
+
let exists = liveType !== undefined;
|
|
116
|
+
for (const ctx of f.contexts) {
|
|
117
|
+
const key = String(ctx);
|
|
118
|
+
if (offered.get(key)?.has(f.name) ?? false)
|
|
119
|
+
continue;
|
|
120
|
+
everywhere = false;
|
|
121
|
+
if (exists) {
|
|
122
|
+
plan.link.push({ context: ctx, field: f.name });
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
// Born in its first declared context; every later one is a link.
|
|
126
|
+
if (!byContext.has(key))
|
|
127
|
+
byContext.set(key, []);
|
|
128
|
+
byContext.get(key).push(f);
|
|
129
|
+
exists = true;
|
|
130
|
+
}
|
|
131
|
+
if (everywhere)
|
|
132
|
+
plan.unchanged.push(f.name);
|
|
133
|
+
}
|
|
134
|
+
for (const [context, fields] of byContext)
|
|
135
|
+
plan.create.push({ context, fields });
|
|
136
|
+
for (const [context, names] of offered) {
|
|
137
|
+
for (const n of names) {
|
|
138
|
+
if (!declaredAnywhere.has(n))
|
|
139
|
+
plan.not_declared.push({ context, field: n });
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return plan;
|
|
143
|
+
}
|
|
144
|
+
/** Is there anything to do? */
|
|
145
|
+
export function planIsEmpty(plan) {
|
|
146
|
+
return !plan.create.length && !plan.link.length;
|
|
147
|
+
}
|
|
148
|
+
/** Read what the tenant currently offers in each declared context. */
|
|
149
|
+
async function readOffered(entity, contextField, contexts) {
|
|
150
|
+
const offered = new Map();
|
|
151
|
+
for (const ctx of contexts) {
|
|
152
|
+
let names = [];
|
|
153
|
+
try {
|
|
154
|
+
const resolved = (await makeRequest("POST", `/api/core/custom-fields/${entity}/resolve`, {
|
|
155
|
+
context: { [contextField]: ctx },
|
|
156
|
+
}));
|
|
157
|
+
names = Array.isArray(resolved?.fields)
|
|
158
|
+
? resolved.fields.map((f) => String(f.fieldName ?? ""))
|
|
159
|
+
: [];
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
// A context with no set yet simply offers nothing.
|
|
163
|
+
names = [];
|
|
164
|
+
}
|
|
165
|
+
offered.set(String(ctx), new Set(names.filter(Boolean)));
|
|
166
|
+
}
|
|
167
|
+
return offered;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Bring a tenant to what the repository declares.
|
|
171
|
+
*
|
|
172
|
+
* Defaults to a dry run, like the migration tool: the plan is the thing worth
|
|
173
|
+
* reading, and it is what a reviewer approves.
|
|
174
|
+
*/
|
|
175
|
+
export async function applyCustomFieldsDeclaration(declaration, opts = {}) {
|
|
176
|
+
const { decl, error } = parseDeclaration(declaration);
|
|
177
|
+
if (error || !decl)
|
|
178
|
+
return jsonResponse({ error });
|
|
179
|
+
const extension = customFieldsEntity(decl.entity);
|
|
180
|
+
const meta = await extensionFields(extension);
|
|
181
|
+
const live = new Map();
|
|
182
|
+
for (const [name, row] of meta) {
|
|
183
|
+
if (!row.deletedAt)
|
|
184
|
+
live.set(name, String(row.type ?? ""));
|
|
185
|
+
}
|
|
186
|
+
const contexts = [...new Set(decl.fields.flatMap((f) => f.contexts.map(String)))];
|
|
187
|
+
const offered = await readOffered(decl.entity, decl.context_field, contexts);
|
|
188
|
+
const plan = diffDeclaration(decl, live, offered);
|
|
189
|
+
if (!opts.confirm) {
|
|
190
|
+
return jsonResponse({
|
|
191
|
+
status: planIsEmpty(plan) ? "already_converged" : "dry_run",
|
|
192
|
+
plan,
|
|
193
|
+
next: planIsEmpty(plan)
|
|
194
|
+
? "Nothing to do — the tenant already matches the file."
|
|
195
|
+
: "Re-call with confirm=true to apply. Nothing has been created yet.",
|
|
196
|
+
note: "A field the file no longer lists is reported under not_declared and never removed: removing " +
|
|
197
|
+
"one parks its column and reserves its name for good. Use suppa_remove_custom_field deliberately.",
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
const applied = { created: [], linked: [] };
|
|
201
|
+
for (const group of plan.create) {
|
|
202
|
+
const out = JSON.parse(await addCustomFieldsBatch(decl.entity, JSON.stringify(group.fields.map((f) => ({
|
|
203
|
+
name: f.name,
|
|
204
|
+
type: f.type,
|
|
205
|
+
...(f.sub_type ? { sub_type: f.sub_type } : {}),
|
|
206
|
+
...(f.title === undefined ? {} : { title: f.title }),
|
|
207
|
+
...(f.options ?? {}),
|
|
208
|
+
}))), { contextField: decl.context_field, contextValue: group.context }));
|
|
209
|
+
if (out.error) {
|
|
210
|
+
return jsonResponse({
|
|
211
|
+
status: "stopped",
|
|
212
|
+
failed_context: group.context,
|
|
213
|
+
error: out.error,
|
|
214
|
+
note: "The batch is atomic, so nothing in THIS context was created. Earlier contexts in this run " +
|
|
215
|
+
"were applied — re-run after fixing; convergence is idempotent.",
|
|
216
|
+
applied,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
applied.created.push({ context: group.context, fields: group.fields.map((f) => f.name) });
|
|
220
|
+
}
|
|
221
|
+
for (const l of plan.link) {
|
|
222
|
+
const out = JSON.parse(await linkCustomFields(decl.entity, [l.field], { contextField: decl.context_field, contextValue: l.context }, { confirm: true }));
|
|
223
|
+
if (out.error) {
|
|
224
|
+
return jsonResponse({ status: "stopped", error: out.error, applied });
|
|
225
|
+
}
|
|
226
|
+
applied.linked.push(l);
|
|
227
|
+
}
|
|
228
|
+
return jsonResponse({
|
|
229
|
+
status: "converged",
|
|
230
|
+
entity: decl.entity,
|
|
231
|
+
extension,
|
|
232
|
+
applied,
|
|
233
|
+
unchanged: plan.unchanged.length,
|
|
234
|
+
type_drift: plan.type_drift,
|
|
235
|
+
not_declared: plan.not_declared,
|
|
236
|
+
});
|
|
237
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "suppa-mcp-2",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.30.1",
|
|
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": {
|
|
@@ -1680,7 +1680,17 @@ function checkExtension(ts, info, findings) {
|
|
|
1680
1680
|
`extension '${info.className}' sets the entity option '${opt}', which extension mode IGNORES — ` +
|
|
1681
1681
|
`title, icon, type, options, representativeFieldName, importKeyFields and the entity's localization ` +
|
|
1682
1682
|
`belong to whoever owns ${target}. Delete it: code the platform discards reads as a promise ` +
|
|
1683
|
-
`it does not keep. Only @Entity({ name: ${named ? `'${info.entityName}'` : "…"} }) and your own columns belong here`
|
|
1683
|
+
`it does not keep. Only @Entity({ name: ${named ? `'${info.entityName}'` : "…"} }) and your own columns belong here` +
|
|
1684
|
+
// Deleting the line is only half an answer when the developer actually
|
|
1685
|
+
// needed the option ON. Ownership makes this a runtime operation, not a
|
|
1686
|
+
// gap in the tooling — say so here rather than leaving them to guess.
|
|
1687
|
+
(opt === "options"
|
|
1688
|
+
? `. If you need an option ENABLED on an entity you do not own — customFields, comments, ` +
|
|
1689
|
+
`trackChangeHistory — that is an owner action and cannot come from a file: call ` +
|
|
1690
|
+
`suppa_update_entity_options(entity_name, options_json) once. It is a schema change ` +
|
|
1691
|
+
`(enabling customFields creates the {Entity}CustomFields side table), so record it in the ` +
|
|
1692
|
+
`plan beside the code that depends on it`
|
|
1693
|
+
: "")));
|
|
1684
1694
|
}
|
|
1685
1695
|
|
|
1686
1696
|
if (info.properties.size === 0) {
|