suppa-mcp-2 1.19.0 → 1.21.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
@@ -172,9 +172,9 @@ A tool result is not paid once: the whole conversation is re-sent on every turn,
172
172
 
173
173
  | Removed | Why it is safe |
174
174
  |---|---|
175
- | `$readAccess`, `$updateAccess`, `$instanceAccess` | Lists of field names, identical on every row of an entity, read by nothing in this server. Suppressed at the source with `getAccessByFields: false` where the endpoint documents the flag, and stripped by name in `makeRequest` everywhere else. Only these three keys — never a blanket `$`-prefix rule, which would silently eat a future key that matters. |
175
+ | `$readAccess`, `$updateAccess`, `$instanceAccess` | Lists of field names, identical on every row of an entity, read by nothing in this server. Suppressed at the source with `getAccessByFields: false` where the endpoint documents the flag, and stripped by name in `makeRequest` everywhere else. Two bounds, both deliberate: only these three key names (never a blanket `$`-prefix rule, which would silently eat a future key that matters), and only at **record level** — the response object, and each row of a returned array. The strip never descends into a value, so a `json`-typed field holding data that happens to use these names is left exactly as stored. |
176
176
  | Long values in a **confirmation preview** | `proposed_changes` was built by copying the tool's own arguments back out. The value is verbatim in the same tool call, so it is named and sized instead: `<4231 chars — unchanged from this call's arguments>`. Short values stay verbatim, and `target` — the half that says *what* is about to change — is never touched. |
177
- | Long values a **write echoed back** | An insert with no `returning` projection answers with the whole stored record, so the HTML just uploaded returns with it. Replaced only when byte-identical to what was sent. If the platform normalised the markup or filled a default, the stored value differs — that difference is real information and comes back in full. |
177
+ | Long values a **write echoed back** | An insert with no `returning` projection answers with the whole stored record, so the HTML just uploaded returns with it. Replaced only when byte-identical to what was sent, and the marker says what was checked — `<4231 chars — identical to the value this call wrote>`, not a claim about what you typed (a task description passes through `wrapHtml()` on the way out). If the platform normalised the markup or filled a default, the stored value differs — that difference is real information and comes back in full. |
178
178
 
179
179
  The key is always kept, so "the field was written" is never in doubt. A marker is not the stored text: quote the value to the user from your own arguments.
180
180
 
@@ -0,0 +1,112 @@
1
+ /**
2
+ * A short-lived, per-tenant cache for entity schema reads.
3
+ *
4
+ * WHY THIS EXISTS
5
+ *
6
+ * Every record write pays for the schema twice before it does any work:
7
+ * `GET /api/core/schema` to resolve the entity name, then
8
+ * `GET /api/core/schema/<entity>` to check the field names against the real
9
+ * columns. Measured on suppa_create_record and suppa_update_record, that is two
10
+ * of three requests — and the second one averages ~24 KB. An agent creating ten
11
+ * records in a row fetched the identical schema twenty times.
12
+ *
13
+ * Those two reads are what make the write path SAFE (the platform silently drops
14
+ * unknown keys, so a write that skipped validation would create a record quietly
15
+ * missing its data). They are not optional. They are just repetitive.
16
+ *
17
+ * WHY IT IS SAFE
18
+ *
19
+ * A cache trades freshness for speed, and a stale schema is not a harmless
20
+ * slowdown — it is a wrong answer. Three things bound that:
21
+ *
22
+ * 1. Anything this server does that CHANGES a schema clears the tenant's cache,
23
+ * and the clearing happens in makeRequest, where every builder request must
24
+ * pass. No call site can forget to invalidate, because no call site does it.
25
+ * 2. A short TTL bounds a change made ELSEWHERE — another session, the UI, or
26
+ * the platform's own convergence on application start.
27
+ * 3. The one place staleness could produce a wrong ANSWER rather than a slow
28
+ * one — refusing a write because a field looks unknown — re-reads with
29
+ * `fresh` before it refuses. See _validateRecordWrites.
30
+ *
31
+ * Set SUPPA_SCHEMA_CACHE_TTL=0 to switch it off entirely.
32
+ */
33
+ /** Seconds a cached schema read stays usable. 0 disables the cache. */
34
+ export const SCHEMA_CACHE_TTL = (() => {
35
+ const raw = process.env.SUPPA_SCHEMA_CACHE_TTL;
36
+ if (raw === undefined || raw === "") {
37
+ return 30;
38
+ }
39
+ const n = Number.parseInt(raw, 10);
40
+ return Number.isFinite(n) && n >= 0 ? n : 30;
41
+ })();
42
+ /** host → (path → entry). Keyed by tenant, because suppa_use_tenant switches. */
43
+ const store = new Map();
44
+ /**
45
+ * Schema READS, and only reads.
46
+ *
47
+ * `/api/core/schema`, `/api/core/schema/<entity>` and the tabular-parts listing
48
+ * hanging off it. Deliberately not `/api/core/builder/...`: those are writes,
49
+ * and a write is what invalidates.
50
+ */
51
+ export function isCacheableSchemaRead(method, path) {
52
+ if (method.toUpperCase() !== "GET") {
53
+ return false;
54
+ }
55
+ return /^\/api\/core\/schema(\/|$|\?)/.test(path);
56
+ }
57
+ /**
58
+ * Does this request change what a schema read would return?
59
+ *
60
+ * The entity builder is the whole surface: add-fields, update-field,
61
+ * create-entity, update-options, remove. Data writes (`/api/core/data/...`) move
62
+ * rows, not columns, and leave the schema alone.
63
+ */
64
+ export function invalidatesSchema(method, path) {
65
+ if (method.toUpperCase() === "GET") {
66
+ return false;
67
+ }
68
+ return path.includes("/api/core/builder/");
69
+ }
70
+ /** A cached value, or MISS. `undefined` is a legal cached value, so use MISS. */
71
+ export const MISS = Symbol("schema-cache-miss");
72
+ export function get(host, path) {
73
+ if (SCHEMA_CACHE_TTL <= 0) {
74
+ return MISS;
75
+ }
76
+ const byPath = store.get(host);
77
+ const entry = byPath?.get(path);
78
+ if (!entry) {
79
+ return MISS;
80
+ }
81
+ if (Date.now() >= entry.expires) {
82
+ byPath.delete(path);
83
+ return MISS;
84
+ }
85
+ return entry.value;
86
+ }
87
+ export function set(host, path, value) {
88
+ if (SCHEMA_CACHE_TTL <= 0) {
89
+ return;
90
+ }
91
+ let byPath = store.get(host);
92
+ if (!byPath) {
93
+ byPath = new Map();
94
+ store.set(host, byPath);
95
+ }
96
+ byPath.set(path, { value, expires: Date.now() + SCHEMA_CACHE_TTL * 1000 });
97
+ }
98
+ /**
99
+ * Drop everything cached for one tenant — or, with no argument, for all of them.
100
+ *
101
+ * Coarse on purpose. A builder call can change an entity this server never named
102
+ * (a back-reference lands a column on the OTHER side of a relation), so clearing
103
+ * only the entity in the URL would leave a stale entry behind that nothing would
104
+ * ever correct. The cache refills in one request.
105
+ */
106
+ export function invalidate(host) {
107
+ if (host === undefined) {
108
+ store.clear();
109
+ return;
110
+ }
111
+ store.delete(host);
112
+ }
package/dist/utils.js CHANGED
@@ -612,8 +612,7 @@ export function confirmRequired(action, target, proposedChanges) {
612
612
  * code in this server reads any of them. `getAccessByFields: false` suppresses
613
613
  * the first two at the source (api-entity-builder-data.txt:72) — this list is
614
614
  * the backstop for the rest: `$instanceAccess` appears in no documented flag,
615
- * and the update endpoint documents no flag at all, so an endpoint that ignores
616
- * the request would otherwise put them back without anyone noticing.
615
+ * and the update endpoint documents no flag at all.
617
616
  *
618
617
  * NAMED KEYS ONLY, deliberately. A blanket "drop every key starting with $"
619
618
  * would also drop any future `$`-prefixed key the platform introduces to carry
@@ -625,17 +624,57 @@ export const ACCESS_METADATA_KEYS = [
625
624
  "$instanceAccess",
626
625
  ];
627
626
  /**
628
- * Recursively drop ACCESS_METADATA_KEYS from a parsed response.
627
+ * Drop ACCESS_METADATA_KEYS from a parsed response — AT RECORD LEVEL ONLY.
628
+ *
629
+ * The depth bound is the whole safety argument, and it was learned the hard way:
630
+ * an earlier version of this walked the response to any depth, which meant a
631
+ * `json`-typed field (entity.ts documents the type as "JSON object/array", so a
632
+ * column can hold arbitrary caller data) had ITS OWN contents rewritten if they
633
+ * happened to use one of these key names. An agent would then read a record it
634
+ * had not been given, and an edit-and-write-back would persist the loss into the
635
+ * tenant's real row. Saving tokens is not worth silently editing someone's data.
636
+ *
637
+ * So this strips exactly where the platform documents putting the metadata —
638
+ * "Adds $readAccess and $updateAccess to each record"
639
+ * (api-entity-builder-data.txt:72) — and nowhere else:
640
+ *
641
+ * - the response object's own keys, when the response IS a record;
642
+ * - each element's own keys, when the response is an array of records.
643
+ *
644
+ * It never descends into a value. A relation expanded inside a row keeps its
645
+ * own copy: that is the flag's job, and the flag is set on every endpoint that
646
+ * documents one. A backstop that cannot prove what it is touching should touch
647
+ * as little as possible.
629
648
  *
630
649
  * Returns the input unchanged — the same reference — when there is nothing to
631
- * strip, so the common case (schema reads, error bodies, anything without ACL)
632
- * costs a walk and no allocation.
650
+ * strip, so callers may rely on identity to detect a no-op.
633
651
  */
652
+ function stripRecordAccessKeys(record) {
653
+ if (record === null || typeof record !== "object" || Array.isArray(record)) {
654
+ return record;
655
+ }
656
+ const proto = Object.getPrototypeOf(record);
657
+ if (proto !== Object.prototype && proto !== null) {
658
+ return record;
659
+ }
660
+ const source = record;
661
+ if (!ACCESS_METADATA_KEYS.some((k) => Object.prototype.hasOwnProperty.call(source, k))) {
662
+ return record;
663
+ }
664
+ const out = {};
665
+ for (const [key, value] of Object.entries(source)) {
666
+ if (ACCESS_METADATA_KEYS.includes(key)) {
667
+ continue;
668
+ }
669
+ defineOwn(out, key, value);
670
+ }
671
+ return out;
672
+ }
634
673
  export function stripAccessMetadata(value) {
635
674
  if (Array.isArray(value)) {
636
675
  let changed = false;
637
676
  const out = value.map((item) => {
638
- const next = stripAccessMetadata(item);
677
+ const next = stripRecordAccessKeys(item);
639
678
  if (next !== item) {
640
679
  changed = true;
641
680
  }
@@ -643,29 +682,24 @@ export function stripAccessMetadata(value) {
643
682
  });
644
683
  return changed ? out : value;
645
684
  }
646
- if (value === null || typeof value !== "object") {
647
- return value;
648
- }
649
- // Only plain objects: a Buffer, Date or class instance is left alone.
650
- const proto = Object.getPrototypeOf(value);
651
- if (proto !== Object.prototype && proto !== null) {
652
- return value;
653
- }
654
- const entries = Object.entries(value);
655
- let changed = false;
656
- const out = {};
657
- for (const [key, item] of entries) {
658
- if (ACCESS_METADATA_KEYS.includes(key)) {
659
- changed = true;
660
- continue;
661
- }
662
- const next = stripAccessMetadata(item);
663
- if (next !== item) {
664
- changed = true;
665
- }
666
- out[key] = next;
667
- }
668
- return changed ? out : value;
685
+ return stripRecordAccessKeys(value);
686
+ }
687
+ /**
688
+ * Assign a key as a plain OWN property.
689
+ *
690
+ * `out[key] = v` is not safe for arbitrary key names read off a JSON payload:
691
+ * for the literal key "__proto__" it sets the object's prototype instead of
692
+ * creating a property, so the key vanishes from the result. A field named that
693
+ * is absurd, but silently dropping data because a name was unusual is the kind
694
+ * of bug that is never found once it ships.
695
+ */
696
+ function defineOwn(target, key, value) {
697
+ Object.defineProperty(target, key, {
698
+ value,
699
+ writable: true,
700
+ enumerable: true,
701
+ configurable: true,
702
+ });
669
703
  }
670
704
  /**
671
705
  * Below this many characters, a value is cheaper to repeat than to describe.
@@ -676,6 +710,8 @@ export function stripAccessMetadata(value) {
676
710
  * dominate are elided.
677
711
  */
678
712
  export const ECHO_ELISION_THRESHOLD = 200;
713
+ /** Deeper than any real confirmation preview; the guard is against a crash. */
714
+ const MAX_ELISION_DEPTH = 64;
679
715
  /** The stand-in for a value the caller already holds verbatim. */
680
716
  function echoMarker(chars, why) {
681
717
  return `<${chars} chars — ${why}>`;
@@ -694,14 +730,21 @@ function echoMarker(chars, why) {
694
730
  * short value in full (titles, ids, deadlines — the things a human actually
695
731
  * eyeballs before approving), and the size of what was elided.
696
732
  */
697
- export function elideEchoedArgs(changes) {
733
+ export function elideEchoedArgs(changes, depth = 0) {
734
+ // A preview is two or three levels deep. `fields_json` is caller-supplied JSON
735
+ // though, so the depth is not actually bounded by anything but this line — and
736
+ // an unbounded recursive walk turns a deep payload into a RangeError, i.e. a
737
+ // crash where the old code merely returned something long.
738
+ if (depth > MAX_ELISION_DEPTH) {
739
+ return changes;
740
+ }
698
741
  if (typeof changes === "string") {
699
742
  return changes.length > ECHO_ELISION_THRESHOLD
700
743
  ? echoMarker(changes.length, "unchanged from this call's arguments")
701
744
  : changes;
702
745
  }
703
746
  if (Array.isArray(changes)) {
704
- return changes.map((item) => elideEchoedArgs(item));
747
+ return changes.map((item) => elideEchoedArgs(item, depth + 1));
705
748
  }
706
749
  if (changes === null || typeof changes !== "object") {
707
750
  return changes;
@@ -715,7 +758,7 @@ export function elideEchoedArgs(changes) {
715
758
  // one value on that tool big enough to matter.
716
759
  const out = {};
717
760
  for (const [key, value] of Object.entries(changes)) {
718
- out[key] = elideEchoedArgs(value);
761
+ defineOwn(out, key, elideEchoedArgs(value, depth + 1));
719
762
  }
720
763
  return out;
721
764
  }
@@ -748,13 +791,15 @@ export function elideEchoedResponse(result, sent) {
748
791
  const out = {};
749
792
  for (const [key, value] of Object.entries(result)) {
750
793
  const supplied = sent[key];
751
- out[key] =
752
- typeof value === "string" &&
753
- value.length > ECHO_ELISION_THRESHOLD &&
754
- typeof supplied === "string" &&
755
- supplied === value
756
- ? echoMarker(value.length, "exactly as sent in this call")
757
- : value;
794
+ const echoed = typeof value === "string" &&
795
+ value.length > ECHO_ELISION_THRESHOLD &&
796
+ typeof supplied === "string" &&
797
+ supplied === value;
798
+ // "what this call wrote", not "what you typed": the comparison is against
799
+ // the payload this server SENT, which is not always the caller's argument
800
+ // verbatim — a task description goes through wrapHtml() on the way out. The
801
+ // marker must not claim an identity it did not check.
802
+ defineOwn(out, key, echoed ? echoMarker(value.length, "identical to the value this call wrote") : value);
758
803
  }
759
804
  return out;
760
805
  }
package/package.json CHANGED
@@ -1,63 +1,63 @@
1
- {
2
- "name": "suppa-mcp-2",
3
- "version": "1.19.0",
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
- "type": "module",
6
- "bin": {
7
- "suppa-mcp": "dist/bin.js",
8
- "suppa-entity-guards": "skills/suppa-entity-code/scripts/install-entity-code-guards.mjs"
9
- },
10
- "main": "dist/bin.js",
11
- "files": [
12
- "dist",
13
- "skills",
14
- "README.md",
15
- "LICENSE"
16
- ],
17
- "engines": {
18
- "node": ">=18"
19
- },
20
- "scripts": {
21
- "build": "tsc",
22
- "clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
23
- "rebuild": "npm run clean && npm run build",
24
- "start": "node dist/bin.js",
25
- "dev": "tsc --watch",
26
- "test": "node scripts/check-version-literals.mjs && vitest run",
27
- "postinstall": "node skills/suppa-entity-code/scripts/postinstall.mjs",
28
- "test:watch": "vitest",
29
- "prepublishOnly": "npm run build && npm test",
30
- "inspect": "npx @modelcontextprotocol/inspector node dist/bin.js",
31
- "schema:gate": "node skills/suppa-entity-code/scripts/entity-code-guard.mjs --ci .",
32
- "guards:install": "node skills/suppa-entity-code/scripts/install-entity-code-guards.mjs"
33
- },
34
- "keywords": [
35
- "mcp",
36
- "model-context-protocol",
37
- "suppa",
38
- "modern-expo",
39
- "ai",
40
- "llm",
41
- "tools",
42
- "claude",
43
- "copilot",
44
- "cursor"
45
- ],
46
- "license": "MIT",
47
- "repository": {
48
- "type": "git",
49
- "url": "https://git.modern-expo.com/asu/me-development/skills.git",
50
- "directory": "suppa-mcp-node"
51
- },
52
- "homepage": "https://modern.suppa.me",
53
- "dependencies": {
54
- "@modelcontextprotocol/sdk": "^1.18.0",
55
- "@napi-rs/keyring": "^1.1.0",
56
- "zod": "^3.23.8"
57
- },
58
- "devDependencies": {
59
- "@types/node": "^20.0.0",
60
- "typescript": "^5.6.0",
61
- "vitest": "^2.1.0"
62
- }
63
- }
1
+ {
2
+ "name": "suppa-mcp-2",
3
+ "version": "1.21.0",
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
+ "type": "module",
6
+ "bin": {
7
+ "suppa-mcp": "dist/bin.js",
8
+ "suppa-entity-guards": "skills/suppa-entity-code/scripts/install-entity-code-guards.mjs"
9
+ },
10
+ "main": "dist/bin.js",
11
+ "files": [
12
+ "dist",
13
+ "skills",
14
+ "README.md",
15
+ "LICENSE"
16
+ ],
17
+ "engines": {
18
+ "node": ">=18"
19
+ },
20
+ "scripts": {
21
+ "build": "tsc",
22
+ "clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
23
+ "rebuild": "npm run clean && npm run build",
24
+ "start": "node dist/bin.js",
25
+ "dev": "tsc --watch",
26
+ "test": "node scripts/check-version-literals.mjs && vitest run",
27
+ "postinstall": "node skills/suppa-entity-code/scripts/postinstall.mjs",
28
+ "test:watch": "vitest",
29
+ "prepublishOnly": "npm run build && npm test",
30
+ "inspect": "npx @modelcontextprotocol/inspector node dist/bin.js",
31
+ "schema:gate": "node skills/suppa-entity-code/scripts/entity-code-guard.mjs --ci .",
32
+ "guards:install": "node skills/suppa-entity-code/scripts/install-entity-code-guards.mjs"
33
+ },
34
+ "keywords": [
35
+ "mcp",
36
+ "model-context-protocol",
37
+ "suppa",
38
+ "modern-expo",
39
+ "ai",
40
+ "llm",
41
+ "tools",
42
+ "claude",
43
+ "copilot",
44
+ "cursor"
45
+ ],
46
+ "license": "MIT",
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "https://git.modern-expo.com/asu/me-development/skills.git",
50
+ "directory": "suppa-mcp-node"
51
+ },
52
+ "homepage": "https://modern.suppa.me",
53
+ "dependencies": {
54
+ "@modelcontextprotocol/sdk": "^1.18.0",
55
+ "@napi-rs/keyring": "^1.1.0",
56
+ "zod": "^3.23.8"
57
+ },
58
+ "devDependencies": {
59
+ "@types/node": "^20.0.0",
60
+ "typescript": "^5.6.0",
61
+ "vitest": "^2.1.0"
62
+ }
63
+ }