suppa-mcp-2 1.20.0 → 1.21.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 +2 -16
- package/dist/httpClient.js +1 -24
- package/dist/tools/entity.js +16 -46
- package/dist/utils.js +84 -39
- package/package.json +2 -2
- package/dist/schemaCache.js +0 -112
package/README.md
CHANGED
|
@@ -51,7 +51,6 @@ All variables are optional — the server works out of the box and authenticates
|
|
|
51
51
|
| `SUPPA_MCP_LOGIN_PORT` | `8080` | Local loopback port for the browser login callback |
|
|
52
52
|
| `SUPPA_MCP_HOME` | `~/.suppa-mcp` | Directory for the tenant registry |
|
|
53
53
|
| `SUPPA_HTTP_TIMEOUT` | `60` | Per-request timeout, seconds |
|
|
54
|
-
| `SUPPA_SCHEMA_CACHE_TTL` | `30` | Seconds a schema read stays cached, per tenant. `0` disables the cache. |
|
|
55
54
|
| `SUPPA_MCP_DEBUG` | (off) | `1` logs each request line to stderr |
|
|
56
55
|
|
|
57
56
|
---
|
|
@@ -173,25 +172,12 @@ A tool result is not paid once: the whole conversation is re-sent on every turn,
|
|
|
173
172
|
|
|
174
173
|
| Removed | Why it is safe |
|
|
175
174
|
|---|---|
|
|
176
|
-
| `$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.
|
|
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. |
|
|
177
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. |
|
|
178
|
-
| 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. |
|
|
179
178
|
|
|
180
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.
|
|
181
180
|
|
|
182
|
-
### What the server does not ask twice
|
|
183
|
-
|
|
184
|
-
Every record write reads the schema before it does anything: once to resolve the entity name, once to check the field names against real columns. Those reads are what make the write path safe — the platform silently **drops** unknown keys, so an unvalidated write creates a record quietly missing its data. They are not optional, only repetitive: ten sequential `suppa_create_record` calls fetched the identical schema twenty times.
|
|
185
|
-
|
|
186
|
-
Schema reads are now cached per tenant for `SUPPA_SCHEMA_CACHE_TTL` seconds (default 30). Ten sequential creates: **30 requests → 12**.
|
|
187
|
-
|
|
188
|
-
A stale schema is not a slow answer, it is a wrong one, so three things bound it:
|
|
189
|
-
|
|
190
|
-
- **Anything that changes a schema clears the cache**, from inside `makeRequest`, where every `/api/core/builder/` request must pass. No call site can forget, because no call site does it. Clearing is per-tenant and deliberately coarse: a relation with a back-reference adds a column to an entity nobody named in the URL.
|
|
191
|
-
- **The TTL bounds a change made elsewhere** — another session, the UI, or the platform converging the schema on application start.
|
|
192
|
-
- **The one path where staleness could produce a wrong answer re-reads before it acts.** Refusing a write because a field "does not exist", or an entity name because it "is not on this tenant", costs one fresh read from the platform first. An agent is never told a field is missing because this server was holding an old copy.
|
|
193
|
-
|
|
194
|
-
|
|
195
181
|
|
|
196
182
|
### Deletes are reversible — permanent delete is blocked
|
|
197
183
|
|
package/dist/httpClient.js
CHANGED
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
import { config } from "./config.js";
|
|
8
8
|
import { assertMergeLists, elideEchoedResponse, stripAccessMetadata } from "./utils.js";
|
|
9
9
|
import * as tenants from "./tenants.js";
|
|
10
|
-
import * as schemaCache from "./schemaCache.js";
|
|
11
10
|
// HTTP statuses that signal a transient upstream problem worth one retry.
|
|
12
11
|
const TRANSIENT_CODES = new Set([429, 502, 503, 504]);
|
|
13
12
|
function debug(msg) {
|
|
@@ -269,25 +268,6 @@ async function sendWithReauth(ctx, buildHeaders, method, url, data, timeout, opt
|
|
|
269
268
|
if (isPermanentDeletePath(url)) {
|
|
270
269
|
throw permanentDeleteRefusal(url);
|
|
271
270
|
}
|
|
272
|
-
// A schema read repeated inside one burst of work is the same schema. The
|
|
273
|
-
// lookup sits here rather than at the twelve call sites, so a new caller gets
|
|
274
|
-
// the benefit without knowing the cache exists. See schemaCache.
|
|
275
|
-
// sendWithReauth is handed an absolute URL; the cache is keyed by the path so
|
|
276
|
-
// the same entity on two tenants cannot collide.
|
|
277
|
-
const path = url.startsWith(ctx.baseUrl) ? url.slice(ctx.baseUrl.length) : url;
|
|
278
|
-
const cacheable = schemaCache.isCacheableSchemaRead(method, path);
|
|
279
|
-
if (cacheable && !opts.fresh) {
|
|
280
|
-
const hit = schemaCache.get(ctx.host, path);
|
|
281
|
-
if (hit !== schemaCache.MISS) {
|
|
282
|
-
debug(`${method} ${url} -> schema cache hit`);
|
|
283
|
-
return opts.unwrap ? unwrapEnvelope(hit) : hit;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
// Likewise the invalidation: every builder write passes through here, so no
|
|
287
|
-
// call site can change a schema and forget to say so.
|
|
288
|
-
if (schemaCache.invalidatesSchema(method, path)) {
|
|
289
|
-
schemaCache.invalidate(ctx.host);
|
|
290
|
-
}
|
|
291
271
|
let refreshed = false;
|
|
292
272
|
let transientRetried = false;
|
|
293
273
|
const retriable = isSafeRequest(method, url);
|
|
@@ -380,9 +360,6 @@ async function sendWithReauth(ctx, buildHeaders, method, url, data, timeout, opt
|
|
|
380
360
|
// the only place a backstop can cover the endpoints whose access flag is
|
|
381
361
|
// undocumented as well as the ones where it is set. See stripAccessMetadata.
|
|
382
362
|
const result = stripAccessMetadata(JSON.parse(raw));
|
|
383
|
-
if (cacheable) {
|
|
384
|
-
schemaCache.set(ctx.host, path, result);
|
|
385
|
-
}
|
|
386
363
|
return opts.unwrap ? unwrapEnvelope(result) : result;
|
|
387
364
|
}
|
|
388
365
|
}
|
|
@@ -405,7 +382,7 @@ export async function makeRequest(method, path, body = null, opts = {}) {
|
|
|
405
382
|
data = JSON.stringify(body);
|
|
406
383
|
extra["Content-Type"] = "application/json; charset=UTF-8";
|
|
407
384
|
}
|
|
408
|
-
return sendWithReauth(ctx, (t) => headers(ctx, t, extra), method, url, data, timeout, { unwrap: !opts.raw
|
|
385
|
+
return sendWithReauth(ctx, (t) => headers(ctx, t, extra), method, url, data, timeout, { unwrap: !opts.raw });
|
|
409
386
|
}
|
|
410
387
|
/** Make a raw-bytes request (for multipart uploads). */
|
|
411
388
|
export async function makeRequestRawBytes(method, path, data, contentType, opts = {}) {
|
package/dist/tools/entity.js
CHANGED
|
@@ -1861,9 +1861,9 @@ function _truncJson(val) {
|
|
|
1861
1861
|
return jsonResponse(val).slice(0, 60);
|
|
1862
1862
|
}
|
|
1863
1863
|
/** Live entity names on this tenant, or null if the schema list is unreadable. */
|
|
1864
|
-
async function _liveEntityList(
|
|
1864
|
+
async function _liveEntityList() {
|
|
1865
1865
|
try {
|
|
1866
|
-
const listing = await makeRequest("GET", "/api/core/schema"
|
|
1866
|
+
const listing = await makeRequest("GET", "/api/core/schema");
|
|
1867
1867
|
if (!Array.isArray(listing)) {
|
|
1868
1868
|
return null;
|
|
1869
1869
|
}
|
|
@@ -1884,31 +1884,17 @@ async function _liveEntityList(fresh = false) {
|
|
|
1884
1884
|
* returns an error with near-matches.
|
|
1885
1885
|
*/
|
|
1886
1886
|
async function _resolveEntity(name) {
|
|
1887
|
-
|
|
1887
|
+
const names = await _liveEntityList();
|
|
1888
1888
|
if (names === null || names.length === 0) {
|
|
1889
1889
|
return { name };
|
|
1890
1890
|
}
|
|
1891
1891
|
if (names.includes(name)) {
|
|
1892
1892
|
return { name };
|
|
1893
1893
|
}
|
|
1894
|
-
|
|
1894
|
+
const ci = names.find((n) => n.toLowerCase() === name.toLowerCase());
|
|
1895
1895
|
if (ci) {
|
|
1896
1896
|
return { name: ci };
|
|
1897
1897
|
}
|
|
1898
|
-
// About to refuse a name for not existing. The list may have come from the
|
|
1899
|
-
// cache, and an entity created elsewhere since would be refused wrongly — so
|
|
1900
|
-
// the refusal is only allowed to stand against a list read from the platform.
|
|
1901
|
-
const latest = await _liveEntityList(true);
|
|
1902
|
-
if (latest !== null && latest.length > 0) {
|
|
1903
|
-
names = latest;
|
|
1904
|
-
if (names.includes(name)) {
|
|
1905
|
-
return { name };
|
|
1906
|
-
}
|
|
1907
|
-
ci = names.find((n) => n.toLowerCase() === name.toLowerCase());
|
|
1908
|
-
if (ci) {
|
|
1909
|
-
return { name: ci };
|
|
1910
|
-
}
|
|
1911
|
-
}
|
|
1912
1898
|
const nl = name.toLowerCase();
|
|
1913
1899
|
const near = names
|
|
1914
1900
|
.filter((n) => n.toLowerCase().includes(nl) || nl.includes(n.toLowerCase()))
|
|
@@ -1951,36 +1937,20 @@ async function _validateRecordWrites(entityName, records) {
|
|
|
1951
1937
|
return { entityName, error: ent.error };
|
|
1952
1938
|
}
|
|
1953
1939
|
entityName = ent.name;
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
}
|
|
1962
|
-
const unknownIn = (names) => [
|
|
1963
|
-
...new Set(records.flatMap((r) => Object.keys(r).filter((k) => !names.has(k)))),
|
|
1964
|
-
];
|
|
1965
|
-
const namesOf = (list) => new Set(list.map((f) => f.name).filter((n) => Boolean(n)));
|
|
1966
|
-
let defs = await readDefs(false);
|
|
1940
|
+
let defs;
|
|
1941
|
+
try {
|
|
1942
|
+
const schema = await makeRequest("GET", `/api/core/schema/${entityName}`);
|
|
1943
|
+
defs = _extractFields(schema);
|
|
1944
|
+
}
|
|
1945
|
+
catch {
|
|
1946
|
+
defs = null; // unreadable → can't validate fields; proceed
|
|
1947
|
+
}
|
|
1967
1948
|
if (defs && defs.length > 0) {
|
|
1968
1949
|
const many = records.length > 1;
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
// way a stale schema turns into a WRONG answer rather than a slow one is
|
|
1974
|
-
// right here: refusing a field that somebody added since. Re-read from the
|
|
1975
|
-
// platform before refusing. Costs a request only on the path that was
|
|
1976
|
-
// about to fail anyway.
|
|
1977
|
-
const latest = await readDefs(true);
|
|
1978
|
-
if (latest && latest.length > 0) {
|
|
1979
|
-
defs = latest;
|
|
1980
|
-
fieldNames = namesOf(latest);
|
|
1981
|
-
unknown = unknownIn(fieldNames);
|
|
1982
|
-
}
|
|
1983
|
-
}
|
|
1950
|
+
const fieldNames = new Set(defs.map((f) => f.name).filter((n) => Boolean(n)));
|
|
1951
|
+
const unknown = [
|
|
1952
|
+
...new Set(records.flatMap((r) => Object.keys(r).filter((k) => !fieldNames.has(k)))),
|
|
1953
|
+
];
|
|
1984
1954
|
if (unknown.length > 0) {
|
|
1985
1955
|
const body = {
|
|
1986
1956
|
error: `Refused: field(s) [${unknown.join(", ")}] do not exist on '${entityName}'. ` +
|
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
|
|
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
|
-
*
|
|
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
|
|
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 =
|
|
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
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
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
|
|
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
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "suppa-mcp-2",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.21.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": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"test": "node scripts/check-version-literals.mjs && vitest run",
|
|
27
27
|
"postinstall": "node skills/suppa-entity-code/scripts/postinstall.mjs",
|
|
28
28
|
"test:watch": "vitest",
|
|
29
|
-
"prepublishOnly": "npm run
|
|
29
|
+
"prepublishOnly": "npm run rebuild && npm test",
|
|
30
30
|
"inspect": "npx @modelcontextprotocol/inspector node dist/bin.js",
|
|
31
31
|
"schema:gate": "node skills/suppa-entity-code/scripts/entity-code-guard.mjs --ci .",
|
|
32
32
|
"guards:install": "node skills/suppa-entity-code/scripts/install-entity-code-guards.mjs"
|
package/dist/schemaCache.js
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
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
|
-
}
|