suppa-mcp-2 1.7.0 → 1.7.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
@@ -346,9 +346,11 @@ relation property must carry a TypeScript type that agrees with its decorator
346
346
  (E114/E115/W610; a type naming no class, such as `any`, is the advisory W615),
347
347
  enum member keys are PascalCase (W611), no field option
348
348
  may be written at its platform default (W612), and `@Enum`/`@MultiEnum` take a
349
- global name only when the enum is actually shared (W613). These are **rule
350
- violations**: like errors, they exit 1, because a rule that only warns is a rule
351
- that gets ignored. `--no-strict` demotes them to warnings for a legacy repo.
349
+ global name only when the enum is actually shared (W613). Those four, plus
350
+ `owner` first in a tabular part's `importKeyFields` (W607) and no `inverse` on
351
+ `@ManyToOne`/`@ManyToMany` (W609), are **rule violations**: like errors, they
352
+ exit 1, because a rule that only warns is a rule that gets ignored.
353
+ `--no-strict` demotes them to warnings for a legacy repo.
352
354
  Advisory warnings — W601-W606, W608, W614, W615 — never block; they report what
353
355
  the checker could not see.
354
356
 
package/dist/server.js CHANGED
@@ -6,6 +6,9 @@
6
6
  * server `instructions` string verbatim, and OWNS all confirm-gating (the tool
7
7
  * modules mutate unconditionally, exactly like the Python tool functions).
8
8
  */
9
+ import { readFileSync } from "node:fs";
10
+ import { dirname, join } from "node:path";
11
+ import { fileURLToPath } from "node:url";
9
12
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
10
13
  import { z } from "zod";
11
14
  import * as tasks from "./tools/tasks.js";
@@ -19,6 +22,24 @@ import * as automation from "./tools/automation.js";
19
22
  import * as auth from "./auth.js";
20
23
  import * as tenants from "./tenants.js";
21
24
  import { confirmRequired, jsonResponse } from "./utils.js";
25
+ /**
26
+ * The running package's version, read from its own package.json rather than
27
+ * typed in. A hand-maintained literal here reported 1.6.1 for every release
28
+ * after it, which is exactly the wrong answer to "which version is my client
29
+ * actually running?" — the question you ask when a fix appears not to have
30
+ * landed. Handshake-only, so a failure to read it must never take the server
31
+ * down.
32
+ */
33
+ export const PACKAGE_VERSION = (() => {
34
+ try {
35
+ const here = dirname(fileURLToPath(import.meta.url));
36
+ // dist/server.js -> ../package.json; src/server.ts (tests) -> ../package.json
37
+ return JSON.parse(readFileSync(join(here, "..", "package.json"), "utf-8")).version ?? "unknown";
38
+ }
39
+ catch {
40
+ return "unknown";
41
+ }
42
+ })();
22
43
  // ---------------------------------------------------------------------------
23
44
  // Tool-behavior hints (MCP spec): clients use these for auto-approval policies.
24
45
  // _READ touches nothing; _ADD only creates new data; _MUT changes or removes
@@ -265,6 +286,15 @@ ENTITY BUILDER (create + edit fields; removal is UI-only)
265
286
  - 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.
266
287
  - 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.
267
288
 
289
+ WRITING ENTITY CODE (*.entity.ts in an application repo — NOT the API tools above)
290
+ These four rules are house rules of this platform. They OVERRIDE the platform's own migrations doc, which contradicts two of them, and they override the style of the entities already in the repo you are editing — an existing file that breaks them is the habit these rules exist to stop, not a convention to match. The full skill is skills/suppa-entity-code/SKILL.md inside the installed suppa-mcp-2 package; these four bind whether or not you open it.
291
+ 1. TYPE EVERY RELATION PROPERTY to match its decorator: @ManyToOne -> \`owner: Target;\` (\`owner?: Target\` when the relation is nullable), @ManyToMany/@OneToMany/@ManyToManyBackRef -> \`peers: Target[];\`. Never \`any\`.
292
+ 2. ENUM MEMBER KEYS ARE PascalCase — \`NotFilled = 'Not filled'\`. The stored value is the string on the right and need not match the key.
293
+ 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.
294
+ 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.
295
+ Before reporting the file done, run the gate — it fails (exit 1) on every one of the four:
296
+ node node_modules/suppa-mcp-2/skills/suppa-entity-code/scripts/validate-suppa-schema.mjs <app-root>
297
+
268
298
  ATTACHMENTS (files on a record)
269
299
  - 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
300
  - 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.
@@ -305,7 +335,7 @@ export function buildServer() {
305
335
  // Reset so repeated buildServer() calls (e.g. in tests) do not double-count.
306
336
  TOOL_NAMES.length = 0;
307
337
  PROMPT_NAMES.length = 0;
308
- const server = new McpServer({ name: "suppa-2.0", version: "1.6.1" }, { instructions: INSTRUCTIONS });
338
+ const server = new McpServer({ name: "suppa-2.0", version: PACKAGE_VERSION }, { instructions: INSTRUCTIONS });
309
339
  const reg = (name, cfg, handler) => {
310
340
  server.registerTool(name, {
311
341
  description: cfg.description,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "suppa-mcp-2",
3
- "version": "1.7.0",
3
+ "version": "1.7.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": {
@@ -60,6 +60,7 @@ export const RULE_WARNINGS = [
60
60
  "W611", // enum member key is not PascalCase
61
61
  "W612", // field option written at its platform default
62
62
  "W613", // enum global name passed for an enum nothing references
63
+ "W615", // relation typed with a shape that names no class ('any', a union, …)
63
64
  ];
64
65
  /**
65
66
  * W613 argues from ABSENCE — "nothing references this name". That only holds
@@ -234,6 +235,20 @@ function objectMap(ts, node) {
234
235
  }
235
236
  return map;
236
237
  }
238
+ /**
239
+ * Computed keys objectMap could NOT resolve — `{ [KEY]: true }`, where KEY is a
240
+ * const. The key exists but its name is unknowable here, so every option rule
241
+ * silently stops applying to it; callers report that rather than fall quiet.
242
+ */
243
+ function unreadableComputedKeys(ts, node) {
244
+ if (!node || !ts.isObjectLiteralExpression(node)) return [];
245
+ return node.properties.filter(
246
+ (p) =>
247
+ ts.isPropertyAssignment(p) &&
248
+ ts.isComputedPropertyName(p.name) &&
249
+ stringValue(ts, unwrapExpr(ts, p.name.expression)) === null,
250
+ );
251
+ }
237
252
  function stringValue(ts, node) {
238
253
  return node && (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node))
239
254
  ? node.text
@@ -396,6 +411,17 @@ function analyzeImports(ts, sf) {
396
411
  }
397
412
  }
398
413
  }
414
+ // A local `type Customer = Customers;` names the same class as the thunk
415
+ // returns, so a property typed with it is correct — reading only the written
416
+ // identifier made E115 (an ERROR) fire on code that is right.
417
+ for (const st of sf.statements) {
418
+ if (!ts.isTypeAliasDeclaration(st)) continue;
419
+ let t = st.type;
420
+ while (t && ts.isParenthesizedTypeNode(t)) t = t.type;
421
+ if (t && ts.isTypeReferenceNode(t) && ts.isIdentifier(t.typeName) && !t.typeArguments) {
422
+ alias.set(st.name.text, alias.get(t.typeName.text) ?? t.typeName.text);
423
+ }
424
+ }
399
425
  sf.suppaImports = { alias, namespaces };
400
426
  }
401
427
  function importsOf(sf) {
@@ -508,10 +534,24 @@ function analyzeEntities(ts, sf, model) {
508
534
  const last = d.args[d.args.length - 1];
509
535
  const enumOptionsNode =
510
536
  d.args.length >= 2 && last && ts.isObjectLiteralExpression(last) ? last : null;
537
+ // Argument 0 is EITHER the global name (a string) or the enum
538
+ // itself (an identifier / namespace access). Anything else — a
539
+ // concatenation, a substituting template — is a name being passed
540
+ // that this checker cannot read, and reading it as "no name given"
541
+ // turned one token into a bypass of W613 AND of E206's seed
542
+ // cross-check.
543
+ const first = d.args[0] ? unwrapExpr(ts, d.args[0]) : null;
544
+ const nameIsUnreadable =
545
+ !!first &&
546
+ stringValue(ts, first) === null &&
547
+ !ts.isIdentifier(first) &&
548
+ !ts.isPropertyAccessExpression(first);
511
549
  info.properties.set(propName, {
512
550
  kind: d.name === "Enum" ? "enum" : "multi-enum",
513
551
  node: member, decorator: d,
514
- enumGlobalName: stringValue(ts, d.args[0]),
552
+ enumGlobalName: stringValue(ts, first),
553
+ enumGlobalNameUnreadable: nameIsUnreadable,
554
+ enumGlobalNameNode: d.args[0] ?? null,
515
555
  optionsNode: enumOptionsNode,
516
556
  enumOptions: objectMap(ts, enumOptionsNode),
517
557
  });
@@ -846,6 +886,18 @@ function checkDefaultFieldOptions(ts, sf, propName, prop, findings) {
846
886
  const unwrapped = nested && unwrapExpr(ts, nested);
847
887
  if (unwrapped && ts.isObjectLiteralExpression(unwrapped)) scopes.push(unwrapped);
848
888
  }
889
+ // Not for @Enum/@MultiEnum: their options slot is ambiguous with an inline
890
+ // TITLES map (see the extractor), and a titles map is BUILT from computed
891
+ // keys — `{ [StatusEnum.Active]: { title } }`. Reporting those would be noise
892
+ // on correct code. Enum options are only ever read for `subType` (E113), so
893
+ // nothing is lost.
894
+ const enumKind = prop.kind === "enum" || prop.kind === "multi-enum";
895
+ for (const scope of enumKind ? [] : scopes) {
896
+ for (const keyNode of unreadableComputedKeys(ts, scope)) {
897
+ findings.push(finding(ts, sf, keyNode, "W606",
898
+ `'${propName}' has an option under a computed key whose name cannot be read statically — the default-option check (W612) and the unknown-option checks (E501/E502) are skipped for it. Write the key literally.`));
899
+ }
900
+ }
849
901
  for (const scope of scopes) {
850
902
  for (const [key, valNode] of objectMap(ts, scope)) {
851
903
  if (!(key in DEFAULT_FIELD_OPTIONS)) continue;
@@ -871,7 +923,13 @@ function checkDefaultFieldOptions(ts, sf, propName, prop, findings) {
871
923
  */
872
924
  function checkEnumGlobalName(ts, sf, propName, prop, model, findings) {
873
925
  const name = prop.enumGlobalName;
874
- if (!name) return; // local enum — the default, and nothing to check
926
+ if (!name) {
927
+ if (prop.enumGlobalNameUnreadable) {
928
+ findings.push(finding(ts, sf, prop.enumGlobalNameNode, "W606",
929
+ `'${propName}' (@${prop.decorator.name}) passes a global enum name this checker cannot read (it is built at runtime, not written as a literal) — the local-vs-global rule (W613) and the seed cross-check (E206) are both skipped for this field. Write the name as a plain string, or omit it if the enum is local.`));
930
+ }
931
+ return; // local enum — the default, and nothing to check
932
+ }
875
933
  // A REFERENCE is an occurrence of the name somewhere other than the property
876
934
  // that declares it. Occurrences inside this property do not count, however
877
935
  // they are spelled: `key: 'Entity.field'` (the rename key, which by convention
@@ -884,7 +942,12 @@ function checkEnumGlobalName(ts, sf, propName, prop, model, findings) {
884
942
  const references = sites.filter(
885
943
  (s) => !(s.file === sf.fileName && s.start >= declStart && s.end <= declEnd),
886
944
  ).length;
887
- if (references === 0) {
945
+ // …and application code outside the schema files counts too: a query that
946
+ // filters by { name: 'Orders.status', value: … } lives in a service, which is
947
+ // never parsed here.
948
+ const referencedElsewhere =
949
+ references === 0 && model.externalTexts.some((text) => text.includes(name));
950
+ if (references === 0 && !referencedElsewhere) {
888
951
  findings.push(finding(ts, sf, prop.decorator.args[0], "W613",
889
952
  `'${propName}' (@${prop.decorator.name}) declares the global enum name '${name}', but nothing outside this ` +
890
953
  `field references it (its own 'key'/'subType' option does not count as a reference). A global name is for ` +
@@ -1621,6 +1684,7 @@ export function validateSchema({ files = [], rootDir = null } = {}) {
1621
1684
  entities: new Map(), entityByName: new Map(),
1622
1685
  seeds: [], modules: [], stringEnums: new Map(),
1623
1686
  enumDeclarations: [], stringLiteralCounts: new Map(), stringLiteralSites: new Map(),
1687
+ externalTexts: [],
1624
1688
  };
1625
1689
  const findings = [];
1626
1690
  // the CLI deduped; the exported API did not, and duplicated seeds duplicated findings
@@ -1628,6 +1692,7 @@ export function validateSchema({ files = [], rootDir = null } = {}) {
1628
1692
  const sources = uniqueFiles.map((f) =>
1629
1693
  ts.createSourceFile(f, readFileSync(f, "utf-8"), ts.ScriptTarget.Latest, true),
1630
1694
  );
1695
+ model.externalTexts = collectExternalTexts(rootDir, uniqueFiles);
1631
1696
  for (const sf of sources) analyzeImports(ts, sf);
1632
1697
  for (const sf of sources) analyzeEnums(ts, sf, model);
1633
1698
  for (const sf of sources) {
@@ -1661,6 +1726,58 @@ export function validateSchema({ files = [], rootDir = null } = {}) {
1661
1726
  };
1662
1727
  }
1663
1728
 
1729
+ /**
1730
+ * Raw text of every OTHER TypeScript file under the app root — the ones that
1731
+ * carry no schema and so are never parsed: services, controllers, DTOs.
1732
+ *
1733
+ * W613 argues that nothing references an enum's global name. The analyzed set is
1734
+ * entities, seeds and modules only, but an application legitimately names an
1735
+ * enum outside all three — `{ name: 'Orders.status', value: 'new' }` in a query
1736
+ * lives in a service. Without this the check called a genuinely global enum
1737
+ * unreferenced and, now that it blocks, stopped a correct repo from shipping.
1738
+ * A substring scan is enough: the question is only "does this name appear
1739
+ * anywhere else at all", so no parsing is needed.
1740
+ *
1741
+ * The trade is deliberate and one-sided. A mention inside a COMMENT counts as a
1742
+ * reference, so a name that only a comment uses escapes W613 — a false negative.
1743
+ * The alternative, parsing every file in the repo to be exact, buys precision in
1744
+ * a check that BLOCKS the gate, where a false positive costs far more than a
1745
+ * missed warning.
1746
+ */
1747
+ function collectExternalTexts(rootDir, analyzed) {
1748
+ if (!rootDir) return [];
1749
+ const skip = new Set(analyzed.map((f) => resolve(f)));
1750
+ const texts = [];
1751
+ (function walk(dir) {
1752
+ let entries;
1753
+ try {
1754
+ entries = readdirSync(dir);
1755
+ } catch {
1756
+ return; // unreadable directory: absence of evidence, not evidence of absence
1757
+ }
1758
+ for (const name of entries) {
1759
+ if (name === "node_modules" || name === "dist" || name.startsWith(".")) continue;
1760
+ const p = join(dir, name);
1761
+ let st;
1762
+ try {
1763
+ st = statSync(p);
1764
+ } catch {
1765
+ continue;
1766
+ }
1767
+ if (st.isDirectory()) {
1768
+ walk(p);
1769
+ } else if ((name.endsWith(".ts") || name.endsWith(".tsx")) && !skip.has(resolve(p))) {
1770
+ try {
1771
+ texts.push(readFileSync(p, "utf-8"));
1772
+ } catch {
1773
+ /* unreadable file — skip */
1774
+ }
1775
+ }
1776
+ }
1777
+ })(resolve(rootDir));
1778
+ return texts;
1779
+ }
1780
+
1664
1781
  // ── discovery ──
1665
1782
  export function discoverFiles(rootDir) {
1666
1783
  const files = [];