suppa-mcp-2 1.8.0 → 1.9.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 CHANGED
@@ -205,7 +205,8 @@ work normally. Erasing data for good is an admin action in the platform's own UI
205
205
  | `suppa_logout` | Remove stored credentials for a tenant |
206
206
  | `suppa_diagnostics` | Validate the whole multi-tenant setup |
207
207
  | `suppa_health_check` | Config + upstream connectivity check (reports `version`) |
208
- | `suppa_version` | Running build vs newest published, and how to upgrade |
208
+ | `suppa_version` | Running build vs newest published, and how to upgrade |
209
+ | `suppa_validate_entity_code` | Run the schema gate over an app repo before calling entity code done |
209
210
 
210
211
  ### Tasks
211
212
 
package/dist/server.js CHANGED
@@ -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 entityCode from "./tools/entityCode.js";
14
15
  import * as files from "./tools/files.js";
15
16
  import * as forms from "./tools/forms.js";
16
17
  import * as migrate from "./tools/migrate.js";
@@ -273,8 +274,7 @@ These four rules are house rules of this platform. They OVERRIDE the platform's
273
274
  2. ENUM MEMBER KEYS ARE PascalCase — \`NotFilled = 'Not filled'\`. The stored value is the string on the right and need not match the key.
274
275
  3. NEVER WRITE A FIELD OPTION AT ITS DEFAULT. canGroup, canSort, showInTable, editFromTable and canFilter are already true; readOnly and searchable are already false. Write one ONLY where the field departs from that (usually just \`searchable: true\`). A field with all seven spelled out is wrong even though it works.
275
276
  4. @Enum/@MultiEnum TAKE THE GLOBAL NAME ONLY WHEN THE ENUM IS GLOBAL — shared by another entity, or referenced from a seed record. Otherwise omit the first argument entirely: \`@Enum(StatusEnum, StatusTitles, { … })\`, and the decorator derives <ClassName>.<propertyName>. A field's own \`key: 'Entity.field'\` is the rename key, NOT a reference, and does not make the enum global.
276
- Before reporting the file done, run the gate — it fails (exit 1) on every one of the four:
277
- node node_modules/suppa-mcp-2/skills/suppa-entity-code/scripts/validate-suppa-schema.mjs <app-root>
277
+ Before reporting the file done, run the gate: call suppa_validate_entity_code(path=<app-root>). It fails on every one of the four and names file:line. passed=false means fix and re-run, not \"note and move on\". (Same checker on the command line: node node_modules/suppa-mcp-2/skills/suppa-entity-code/scripts/validate-suppa-schema.mjs <app-root>.)
278
278
 
279
279
  ATTACHMENTS (files on a record)
280
280
  - 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.
@@ -2167,6 +2167,34 @@ export function buildServer() {
2167
2167
  description: "List known Suppa tenants — which one is active and whether each is authenticated.",
2168
2168
  annotations: _READ,
2169
2169
  }, async () => text(tenants.listTenants()));
2170
+ reg("suppa_validate_entity_code", {
2171
+ description: "Run the schema gate over an application repo's *.entity.ts / *.seed.ts / module files.\n\n" +
2172
+ " CALL THIS BEFORE REPORTING ANY ENTITY OR SEED FILE DONE. It is the same checker the\n" +
2173
+ " bundled suppa-entity-code skill names as its close-out gate, and it catches what tsc\n" +
2174
+ " cannot: an unregistered entity class (no table is ever created for it), a JS value in\n" +
2175
+ " 'default' where a SQL string is required, a relation without a thunk, seed records that\n" +
2176
+ " duplicate on every restart — plus the four house rules, which fail the gate:\n" +
2177
+ " * a relation property must be typed to match its decorator (Target / Target[], and\n" +
2178
+ " optional when the relation is nullable) — never 'any';\n" +
2179
+ " * enum member keys are PascalCase;\n" +
2180
+ " * no field option may be written at its default (canGroup/canSort/showInTable/\n" +
2181
+ " editFromTable/canFilter are already true, readOnly/searchable already false);\n" +
2182
+ " * @Enum/@MultiEnum take a global name ONLY when the enum is shared or seed-referenced.\n" +
2183
+ ' Pass the app ROOT, not one file: several rules read the whole repo ("nothing references\n' +
2184
+ " this enum name\" cannot be judged from a single file).\n" +
2185
+ " passed=false means fix and re-run — it is not advisory.",
2186
+ inputSchema: {
2187
+ path: z
2188
+ .string()
2189
+ .describe("ABSOLUTE path to the application repo root (preferred), or to one *.entity.ts / *.seed.ts file."),
2190
+ strict: z
2191
+ .boolean()
2192
+ .default(true)
2193
+ .describe("true (default): the four house rules fail the gate. false: they are reported as advisory — " +
2194
+ "for a legacy repo you are not cleaning up in this pass, never for a file you just wrote."),
2195
+ },
2196
+ annotations: _READ,
2197
+ }, async (a) => text(await entityCode.validateEntityCode(a.path, a.strict)));
2170
2198
  reg("suppa_version", {
2171
2199
  description: "Which suppa-mcp-2 build this session is actually running, and whether a newer one is\n" +
2172
2200
  " published. Ask this FIRST whenever a fix, tool or behaviour you were told exists is\n" +
@@ -0,0 +1,133 @@
1
+ /**
2
+ * The entity-code gate, as a tool.
3
+ *
4
+ * The rules for writing *.entity.ts live in three places of decreasing reach:
5
+ * the bundled skill (an agent may never open it), the server instructions (read,
6
+ * but advice), and the validator (decisive — and skipped, because running it
7
+ * means shelling out to a path the agent has to work out). Entities kept
8
+ * shipping with every default option restated and a global enum name on a local
9
+ * enum, all of which the validator catches.
10
+ *
11
+ * So the gate becomes a tool call. Same checker as
12
+ * skills/suppa-entity-code/scripts/validate-suppa-schema.mjs — loaded from the
13
+ * installed package, never reimplemented — reporting the same codes.
14
+ */
15
+ import { existsSync, statSync } from "node:fs";
16
+ import { dirname, isAbsolute, join, resolve } from "node:path";
17
+ import { fileURLToPath, pathToFileURL } from "node:url";
18
+ import { jsonResponse } from "../utils.js";
19
+ /** Where the bundled skill sits, from dist/tools/ or src/tools/ alike. */
20
+ function validatorPath() {
21
+ const here = dirname(fileURLToPath(import.meta.url));
22
+ for (const root of [join(here, "..", ".."), join(here, "..", "..", "..")]) {
23
+ const p = join(root, "skills", "suppa-entity-code", "scripts", "validate-suppa-schema.mjs");
24
+ if (existsSync(p))
25
+ return p;
26
+ }
27
+ return null;
28
+ }
29
+ /**
30
+ * Run the schema gate over an application repo (or a single file).
31
+ *
32
+ * `path` is an app root — the whole repo is walked, which is also what lets the
33
+ * unreferenced-enum-name rule speak, since it argues from absence and needs to
34
+ * see every file that could hold a reference.
35
+ */
36
+ export async function validateEntityCode(path, strict = true) {
37
+ const target = String(path ?? "").trim();
38
+ if (!target) {
39
+ return jsonResponse({
40
+ error: "path is required — give the application repo's root (preferred: the whole repo is checked, " +
41
+ "and the enum-name rule needs that) or one *.entity.ts / *.seed.ts file.",
42
+ });
43
+ }
44
+ if (!isAbsolute(target)) {
45
+ return jsonResponse({ error: `path must be absolute, got '${target}'.` });
46
+ }
47
+ if (!existsSync(target)) {
48
+ return jsonResponse({ error: `path not found: ${target}` });
49
+ }
50
+ const script = validatorPath();
51
+ if (!script) {
52
+ return jsonResponse({
53
+ error: "The bundled validator is missing from this installation " +
54
+ "(skills/suppa-entity-code/scripts/validate-suppa-schema.mjs). Reinstall suppa-mcp-2.",
55
+ });
56
+ }
57
+ let mod;
58
+ try {
59
+ mod = await import(pathToFileURL(script).href);
60
+ }
61
+ catch (e) {
62
+ return jsonResponse({
63
+ error: `Could not load the validator: ${e instanceof Error ? e.message : String(e)}`,
64
+ });
65
+ }
66
+ const isDir = (() => {
67
+ try {
68
+ return statSync(target).isDirectory();
69
+ }
70
+ catch {
71
+ return false;
72
+ }
73
+ })();
74
+ let files;
75
+ let rootDir = null;
76
+ if (isDir) {
77
+ rootDir = resolve(target);
78
+ files = mod.discoverFiles(rootDir);
79
+ if (!files.length) {
80
+ return jsonResponse({
81
+ error: `No schema files under ${target}. Expected *.entity.ts, *.seed.ts, or a .ts file ` +
82
+ "containing EntityModule.forFeature — nothing was analyzed, so nothing was verified.",
83
+ });
84
+ }
85
+ }
86
+ else {
87
+ files = [resolve(target)];
88
+ }
89
+ let res;
90
+ try {
91
+ res = mod.validateSchema({ files, rootDir });
92
+ }
93
+ catch (e) {
94
+ // A missing/unusable TypeScript in the target repo is the caller's to fix.
95
+ return jsonResponse({
96
+ error: e?.message ?? String(e),
97
+ hint: e?.code === "SUPPA_VALIDATOR_ENV"
98
+ ? "Run `npm install` in the application repo (the checker parses with ITS typescript), or `npm i -D typescript@5`."
99
+ : undefined,
100
+ });
101
+ }
102
+ // Same split the CLI blocks on: errors always, authoring-rule warnings under
103
+ // strict, and W613 only when the whole repo was walked (it argues from
104
+ // absence). Advisory warnings never block.
105
+ const ruleCodes = mod.RULE_WARNINGS ?? [];
106
+ const needsWholeRepo = mod.RULE_WARNINGS_NEEDING_WHOLE_REPO ?? [];
107
+ const blocks = (f) => strict && ruleCodes.includes(f.code) && (rootDir !== null || !needsWholeRepo.includes(f.code));
108
+ const shape = (f) => ({
109
+ file: f.file,
110
+ line: f.line,
111
+ col: f.col,
112
+ code: f.code,
113
+ message: f.message,
114
+ });
115
+ const violations = res.findings.filter(blocks).map(shape);
116
+ const errors = res.errors.map(shape);
117
+ const advisory = res.warnings.filter((f) => !blocks(f)).map(shape);
118
+ const passed = errors.length + violations.length === 0;
119
+ return jsonResponse({
120
+ passed,
121
+ checked: { path: target, files: files.length, whole_repo: rootDir !== null, strict },
122
+ errors,
123
+ rule_violations: violations,
124
+ advisory_warnings: advisory,
125
+ note: passed
126
+ ? advisory.length
127
+ ? "Gate passed. The advisory warnings say what could NOT be checked (content delivered by reference, a missing tsconfig) — read them before trusting a clean run."
128
+ : "Gate passed."
129
+ : "Gate FAILED — do not report the file done. Fix every entry in errors and rule_violations, then re-run. " +
130
+ "rule_violations are the house rules: relation typing, PascalCase enum keys, no option written at its " +
131
+ "default, and no global enum name on a local enum.",
132
+ });
133
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "suppa-mcp-2",
3
- "version": "1.8.0",
3
+ "version": "1.9.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": {