suppa-mcp-2 1.3.0 → 1.3.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.
@@ -69,12 +69,6 @@ const PERMANENT_DELETE_ROUTE = /^(?:api\/)?core\/data\/[^/]+\/delete$/;
69
69
  // "a single-dot path segment must be '.' or '%2e'; a double-dot path segment
70
70
  // must be '..', '.%2e', '%2e.' or '%2e%2e'" (URL Standard) — so `%2e%2e` climbs
71
71
  // a level on the wire exactly like `..` does.
72
- //
73
- // These are tested AFTER one decodeURIComponent pass, where a surviving `%2e`
74
- // can only have come from a double-encoded `%252e`. fetch would leave that one
75
- // encoded, so accepting it here over-matches by exactly one decoding level:
76
- // the safe direction for a block, and the reason no second decode pass is
77
- // needed to be sure the matcher has seen every form the wire can resolve.
78
72
  const SINGLE_DOT_SEGMENT = /^(?:\.|%2e)$/i;
79
73
  const DOUBLE_DOT_SEGMENT = /^(?:\.|%2e){2}$/i;
80
74
  /**
@@ -98,42 +92,75 @@ function resolveDotSegments(path) {
98
92
  }
99
93
  return out.join("/");
100
94
  }
101
- /** Normalize a path or absolute URL down to comparable route segments. */
102
- function routePath(pathOrUrl) {
95
+ /**
96
+ * Strip an input down to its path, undoing the rewrites fetch performs BEFORE
97
+ * it parses.
98
+ *
99
+ * The URL parser inside fetch DELETES every tab, LF and CR from the input and
100
+ * trims leading/trailing C0 controls and spaces, so `de<TAB>lete` and
101
+ * `delete\x00` are the segment `delete` on the wire. It also maps `\` to `/`
102
+ * for http(s). Undoing all three here is what keeps this matcher and the wire
103
+ * looking at the same path — each was a live bypass.
104
+ */
105
+ function rawPath(pathOrUrl) {
103
106
  let p = String(pathOrUrl ?? "");
104
- // The URL parser inside fetch DELETES every tab, LF and CR from the input and
105
- // trims leading/trailing C0 controls and spaces, so `de<TAB>lete` and
106
- // `delete\x00` are the segment `delete` on the wire. It also maps `\` to `/`
107
- // for http(s). Undoing all three here first is what keeps this matcher and
108
- // the wire looking at the same path — each was a live bypass.
109
107
  p = p.replace(/[\t\n\r]/g, "").replace(/^[\x00-\x20]+|[\x00-\x20]+$/g, "").replace(/\\/g, "/");
110
108
  const scheme = p.indexOf("://");
111
109
  if (scheme !== -1) {
112
110
  const slash = p.indexOf("/", scheme + 3);
113
111
  p = slash === -1 ? "" : p.slice(slash);
114
112
  }
115
- p = p.split("?")[0].split("#")[0];
113
+ return p.split("?")[0].split("#")[0];
114
+ }
115
+ /** Collapse, trim and lowercase a resolved path into comparable route segments. */
116
+ function comparable(path) {
117
+ return path
118
+ .replace(/\/+/g, "/")
119
+ .replace(/^\/+|\/+$/g, "")
120
+ .toLowerCase();
121
+ }
122
+ /**
123
+ * Every path this input can be READ as by the time it reaches the platform's
124
+ * router — the block is the OR over all of them, because a single normalization
125
+ * cannot model both ends of the wire at once.
126
+ *
127
+ * Resolving dot segments on a DECODED path was a live bypass:
128
+ * `/core/data/%252e/%2e%2e/Tasks/delete` decodes to `.../%2e/../Tasks/delete`,
129
+ * where the matcher read `%2e` as a dot segment, DROPPED it, and then let the
130
+ * real `..` pop `data` — landing on `core/Tasks/delete`, which is not the
131
+ * blocked shape. fetch never decodes, so on the wire `%252e` stays a literal
132
+ * segment, `%2e%2e` pops THAT instead, and the request left as
133
+ * POST /core/data/Tasks/delete. Treating a decoded escape as a dot segment
134
+ * REMOVES a segment, so it under-matches as readily as it over-matches — the
135
+ * earlier "over-matches by one decoding level, the safe direction" reasoning
136
+ * was simply wrong.
137
+ *
138
+ * So each candidate is derived for one reader, and none of them has to be
139
+ * conservative on its own:
140
+ * 1. what fetch puts on the wire — dot segments resolved, nothing decoded;
141
+ * 2. that path decoded once, for a router that decodes before routing (this
142
+ * is also what keeps %2F from smuggling a separator past the matcher);
143
+ * 3. the decoded path re-resolved, for one that normalizes after decoding.
144
+ */
145
+ function routeCandidates(pathOrUrl) {
146
+ const onWire = resolveDotSegments(rawPath(pathOrUrl));
147
+ const candidates = [comparable(onWire)];
148
+ let decoded = null;
116
149
  try {
117
- // %2F-encoded separators must not smuggle the route past the matcher.
118
- p = decodeURIComponent(p);
150
+ decoded = decodeURIComponent(onWire);
119
151
  }
120
152
  catch {
121
- // Malformed escapes: match the raw form rather than giving up. The dot
122
- // segment patterns below still catch the %2e forms in that raw path.
153
+ // Malformed escapes: the wire form above is the whole answer. A router
154
+ // cannot decode this either, so there is no second reading to model.
123
155
  }
124
- // Decode first, THEN resolve dot segments, THEN collapse and lowercase: the
125
- // matcher and fetch must agree on the path, and fetch resolves '.' / '..'
126
- // while this function used to leave them in place — `Tasks/./delete` reached
127
- // the permanent delete with the block silently looking at a different path.
128
- p = resolveDotSegments(p);
129
- return p
130
- .replace(/\/+/g, "/")
131
- .replace(/^\/+|\/+$/g, "")
132
- .toLowerCase();
156
+ if (decoded !== null && decoded !== onWire) {
157
+ candidates.push(comparable(decoded), comparable(resolveDotSegments(decoded)));
158
+ }
159
+ return candidates;
133
160
  }
134
161
  /** True for POST /core/data/:entityName/delete — and only for that route. */
135
162
  export function isPermanentDeletePath(pathOrUrl) {
136
- return PERMANENT_DELETE_ROUTE.test(routePath(pathOrUrl));
163
+ return routeCandidates(pathOrUrl).some((p) => PERMANENT_DELETE_ROUTE.test(p));
137
164
  }
138
165
  /** The refusal raised in place of a permanent delete. Names the reversible pair. */
139
166
  export function permanentDeleteRefusal(pathOrUrl) {
package/dist/server.js CHANGED
@@ -296,7 +296,7 @@ export function buildServer() {
296
296
  // Reset so repeated buildServer() calls (e.g. in tests) do not double-count.
297
297
  TOOL_NAMES.length = 0;
298
298
  PROMPT_NAMES.length = 0;
299
- const server = new McpServer({ name: "suppa-2.0", version: "1.3.0" }, { instructions: INSTRUCTIONS });
299
+ const server = new McpServer({ name: "suppa-2.0", version: "1.3.1" }, { instructions: INSTRUCTIONS });
300
300
  const reg = (name, cfg, handler) => {
301
301
  server.registerTool(name, {
302
302
  description: cfg.description,
@@ -70,9 +70,17 @@ export const RELATION_LIKE_FIELD_TYPES = [
70
70
  // Where `defaultValue` does NOT apply. builder.txt:43 — "defaultValue | string |
71
71
  // false | Default value. Not applicable to relations, enums, or unique fields."
72
72
  // So: every relation-like type above, plus ANY type when unique is set.
73
- // (`notNull` has its own, narrower exclusion — builder.txt:41: "Not applicable to
74
- // many-to-many / multi-enum" — and is still sent for the rest.)
75
73
  export const NO_DEFAULT_VALUE_FIELD_TYPES = RELATION_LIKE_FIELD_TYPES;
74
+ // Where `notNull` does NOT apply — its own, narrower exclusion. builder.txt:41 —
75
+ // "notNull | boolean | false | Field is required. Not applicable to many-to-many
76
+ // / multi-enum." The comment above used to claim this exclusion was honoured
77
+ // while the wire body set `notNull` unconditionally, so a required=true on these
78
+ // two types was sent to the builder and reported back as applied.
79
+ export const NO_NOT_NULL_FIELD_TYPES = ["many-to-many", "multi-enum"];
80
+ /** True when `notNull` is applicable to this field type (builder.txt:41). */
81
+ export function notNullApplies(fieldType) {
82
+ return !NO_NOT_NULL_FIELD_TYPES.includes(fieldType);
83
+ }
76
84
  /**
77
85
  * True when `defaultValue` is applicable to this field — and therefore when
78
86
  * `notNull` on it also demands one. Recorded evidence for that demand, on the
@@ -1336,9 +1344,30 @@ export async function addField(entityName, fieldName, fieldType, title, opts = {
1336
1344
  name: fieldName,
1337
1345
  type: resolvedType,
1338
1346
  title: await _expandTitle(title, fieldName),
1339
- notNull: required,
1340
- unique,
1341
1347
  };
1348
+ // Applicability is per the builder's own table, and a constraint that does not
1349
+ // apply is DROPPED by the builder without complaint — so sending it would be
1350
+ // reported back to the agent as applied while nothing changed. Each of these
1351
+ // is instead withheld and named in `not_applicable`, so the caller learns the
1352
+ // constraint is not in force.
1353
+ const notApplicable = [];
1354
+ if (notNullApplies(resolvedType)) {
1355
+ fieldDef.notNull = required;
1356
+ }
1357
+ else if (required) {
1358
+ notApplicable.push(`notNull was NOT set: builder.txt:41 — "Not applicable to many-to-many / multi-enum" ` +
1359
+ `(this field is '${resolvedType}'). The field was created WITHOUT the required ` +
1360
+ "constraint; enforce it in application logic if you need it.");
1361
+ }
1362
+ // builder.txt:42 — "unique | boolean | false | Field must be unique. Not
1363
+ // applicable to relations and enums."
1364
+ if (!RELATION_LIKE_FIELD_TYPES.includes(resolvedType)) {
1365
+ fieldDef.unique = unique;
1366
+ }
1367
+ else if (unique) {
1368
+ notApplicable.push(`unique was NOT set: builder.txt:42 — "Not applicable to relations and enums" ` +
1369
+ `(this field is '${resolvedType}'). The field was created WITHOUT the unique constraint.`);
1370
+ }
1342
1371
  // builder.txt:43 — "Not applicable to relations, enums, or unique fields":
1343
1372
  // sending it there is at best ignored, so it is never emitted.
1344
1373
  if (defaultText.trim() !== "" && typeNeedsDefault) {
@@ -1383,7 +1412,12 @@ export async function addField(entityName, fieldName, fieldType, title, opts = {
1383
1412
  const result = await makeRequest("POST", `/api/core/builder/${entityName}/add-fields`, [
1384
1413
  fieldDef,
1385
1414
  ]);
1386
- return jsonResponse(result);
1415
+ // Plain result when everything asked for was applied — the shape callers and
1416
+ // tests already read. The wrapper appears only when something was withheld,
1417
+ // because that is the case a bare success would misreport.
1418
+ return notApplicable.length > 0
1419
+ ? jsonResponse({ result, not_applicable: notApplicable })
1420
+ : jsonResponse(result);
1387
1421
  }
1388
1422
  // builder.txt:391-398 — on a field created by the system (initiator = system)
1389
1423
  // these are the only accepted keys. Note searchPriority is NOT among them.
@@ -1018,6 +1018,13 @@ const _NO_DEFAULT_VALUE_TYPES = new Set([
1018
1018
  "file",
1019
1019
  "multi-file",
1020
1020
  ]);
1021
+ // Where `notNull` does not apply — its own, narrower exclusion.
1022
+ // (api-entity-builder-builder.txt:41 — "notNull ... Not applicable to
1023
+ // many-to-many / multi-enum".) Mirrors NO_NOT_NULL_FIELD_TYPES in
1024
+ // tools/entity.ts, kept local for the same reason as the set above: entity.js is
1025
+ // module-mocked in the migrator's tests. notNullFieldTypesMatch.test.ts fails if
1026
+ // the two copies drift.
1027
+ const _NO_NOT_NULL_TYPES = new Set(["many-to-many", "multi-enum"]);
1021
1028
  const _DOWNGRADE_NOTE = "Some fields that are required in Suppa 1.0 were created NULLABLE here: the 2.0 " +
1022
1029
  "builder refuses NOT NULL without a defaultValue, and this migrator will not " +
1023
1030
  "invent one — the value empty rows should carry is a data decision, not a " +
@@ -1036,7 +1043,23 @@ function _requiredOpts(entity, f, downgrades) {
1036
1043
  if (!(f.required ?? false)) {
1037
1044
  return { required: false };
1038
1045
  }
1039
- if (_NO_DEFAULT_VALUE_TYPES.has(String(f.type ?? ""))) {
1046
+ const planType = String(f.type ?? "");
1047
+ // builder.txt:41 — notNull is "Not applicable to many-to-many / multi-enum".
1048
+ // The builder drops it there, so asking for it would report a constraint that
1049
+ // was never created; record the downgrade instead of claiming success.
1050
+ if (_NO_NOT_NULL_TYPES.has(planType)) {
1051
+ downgrades.push({
1052
+ entity,
1053
+ field: f.name,
1054
+ type: f.type ?? null,
1055
+ v1_required: true,
1056
+ created_as: "nullable",
1057
+ reason: `the 2.0 builder does not apply notNull to '${planType}' fields ` +
1058
+ '(builder.txt:41 — "Not applicable to many-to-many / multi-enum")',
1059
+ });
1060
+ return { required: false };
1061
+ }
1062
+ if (_NO_DEFAULT_VALUE_TYPES.has(planType)) {
1040
1063
  return { required: true }; // defaultValue does not apply — notNull needs none
1041
1064
  }
1042
1065
  // `default_value` is put on every planned field by _planFields (from the v1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "suppa-mcp-2",
3
- "version": "1.3.0",
3
+ "version": "1.3.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": {
@@ -159,7 +159,7 @@ Step 1 exists to catch exactly this: an unregistered class is E301 and the gate
159
159
 
160
160
  `validate-suppa-schema.mjs` exits `0` on a clean run, `1` when errors are found, `2` on a usage error or a missing path. The gate requires exit `0` — warnings alone do not block.
161
161
 
162
- The validator parses with the TypeScript compiler API, read from the app repo you point it at (a Suppa application compiles with `tsc`, so it has one). If it reports `cannot resolve 'typescript'`, run `npm install` in that repo — or `npm i -D typescript` if it genuinely has none.
162
+ The validator parses with the TypeScript compiler API, read from the app repo you point it at (a Suppa application compiles with `tsc`, so it has one). If it reports `cannot resolve 'typescript'`, run `npm install` in that repo — or `npm i -D typescript@5` if it genuinely has none. Pin the major: plain `typescript` now installs 7.x, whose main entry exports only version info and carries no compiler API.
163
163
 
164
164
  ## Troubleshooting
165
165
 
@@ -62,18 +62,39 @@ export function loadTypescript(rootDir) {
62
62
  if (rootDir) froms.push(join(resolve(rootDir), "package.json"));
63
63
  froms.push(join(process.cwd(), "package.json"));
64
64
  froms.push(import.meta.url);
65
+ let sawStub = false;
65
66
  for (const from of froms) {
67
+ let mod;
66
68
  try {
67
- return createRequire(from)("typescript");
69
+ mod = createRequire(from)("typescript");
68
70
  } catch {
69
- /* try next */
71
+ continue; // not resolvable from here — try the next candidate
70
72
  }
73
+ // Resolvability is NOT proof the compiler API is there. TypeScript 7 — what
74
+ // plain `npm i -D typescript` installs today — maps exports["."] to
75
+ // lib/version.cjs, which exports only { version, versionMajorMinor }; the
76
+ // parser moved behind ./unstable/*. That require SUCCEEDS and used to be
77
+ // handed straight to the parser, which then died on `ts.ScriptTarget.Latest`
78
+ // being undefined. Check the two members this validator actually uses, and
79
+ // keep looking: a usable TS 5 further down the list still rescues the run.
80
+ if (typeof mod?.createSourceFile === "function" && mod?.ScriptTarget) {
81
+ return mod;
82
+ }
83
+ sawStub = true;
71
84
  }
72
- throw new Error(
73
- "validate-suppa-schema: cannot resolve 'typescript'. It is read from the app repo " +
74
- "being validated (a Suppa application compiles with tsc, so it normally has it). " +
75
- "Install it there — `npm i -D typescript` — or run this from a directory where it resolves.",
76
- );
85
+ // Tagged so the CLI can report it as an environment problem — one actionable
86
+ // line and exit 2 — instead of an uncaught stack trace.
87
+ throw Object.assign(new Error(
88
+ sawStub
89
+ ? "validate-suppa-schema: the 'typescript' found here is TypeScript 7 (or newer), whose " +
90
+ "main entry exports only version info — it has no createSourceFile/ScriptTarget, so " +
91
+ "this validator cannot parse with it. Install the 5.x line in the app repo being " +
92
+ "validated: `npm i -D typescript@5`."
93
+ : "validate-suppa-schema: cannot resolve 'typescript'. It is read from the app repo " +
94
+ "being validated (a Suppa application compiles with tsc, so it normally has it). " +
95
+ "Install it there — `npm i -D typescript@5` — or run this from a directory where it " +
96
+ "resolves.",
97
+ ), { code: "SUPPA_VALIDATOR_ENV" });
77
98
  }
78
99
 
79
100
  /**
@@ -1240,7 +1261,17 @@ if (isMain) {
1240
1261
  }
1241
1262
  }
1242
1263
  const dedupedFiles = [...new Set(files)];
1243
- const res = validateSchema({ files: dedupedFiles, rootDir });
1264
+ let res;
1265
+ try {
1266
+ res = validateSchema({ files: dedupedFiles, rootDir });
1267
+ } catch (err) {
1268
+ // A missing/unusable toolchain is the caller's to fix: one actionable line,
1269
+ // same exit code as the other argument problems. Anything else is a bug in
1270
+ // this validator and keeps its stack trace.
1271
+ if (err?.code !== "SUPPA_VALIDATOR_ENV") throw err;
1272
+ console.error(err.message);
1273
+ process.exit(2);
1274
+ }
1244
1275
  for (const f of res.findings) {
1245
1276
  console.log(
1246
1277
  `${displayPath(process.cwd(), f.file)}:${f.line}:${f.col} ${f.code} [${f.level}] ${f.message}`,