suppa-mcp-2 1.18.0 → 1.19.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 +537 -524
- package/dist/httpClient.js +18 -6
- package/dist/server.js +1 -0
- package/dist/utils.js +169 -1
- package/package.json +1 -1
package/dist/httpClient.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* global `fetch` in place of `urllib`, with an AbortController for timeouts.
|
|
6
6
|
*/
|
|
7
7
|
import { config } from "./config.js";
|
|
8
|
-
import { assertMergeLists } from "./utils.js";
|
|
8
|
+
import { assertMergeLists, elideEchoedResponse, stripAccessMetadata } from "./utils.js";
|
|
9
9
|
import * as tenants from "./tenants.js";
|
|
10
10
|
// HTTP statuses that signal a transient upstream problem worth one retry.
|
|
11
11
|
const TRANSIENT_CODES = new Set([429, 502, 503, 504]);
|
|
@@ -356,7 +356,10 @@ async function sendWithReauth(ctx, buildHeaders, method, url, data, timeout, opt
|
|
|
356
356
|
if (!raw || !raw.trim()) {
|
|
357
357
|
return null;
|
|
358
358
|
}
|
|
359
|
-
|
|
359
|
+
// Every JSON response this server ever sees passes through here, which is
|
|
360
|
+
// the only place a backstop can cover the endpoints whose access flag is
|
|
361
|
+
// undocumented as well as the ones where it is set. See stripAccessMetadata.
|
|
362
|
+
const result = stripAccessMetadata(JSON.parse(raw));
|
|
360
363
|
return opts.unwrap ? unwrapEnvelope(result) : result;
|
|
361
364
|
}
|
|
362
365
|
}
|
|
@@ -505,10 +508,15 @@ export async function insertEntity(entity, fieldsList, returning = null) {
|
|
|
505
508
|
body.returning = returning;
|
|
506
509
|
}
|
|
507
510
|
const result = await makeRequest("POST", dataUrl(entity, "insert"), body);
|
|
508
|
-
|
|
509
|
-
|
|
511
|
+
// With no `returning` projection the platform answers with the whole stored
|
|
512
|
+
// record, so a long value just uploaded comes straight back. Only values that
|
|
513
|
+
// are byte-identical to what was sent are replaced — see elideEchoedResponse.
|
|
514
|
+
const sent = fieldsList.length === 1 ? fieldsList[0] : {};
|
|
515
|
+
const lean = elideEchoedResponse(result, sent);
|
|
516
|
+
if (Array.isArray(lean)) {
|
|
517
|
+
return lean;
|
|
510
518
|
}
|
|
511
|
-
return
|
|
519
|
+
return lean ? [lean] : [];
|
|
512
520
|
}
|
|
513
521
|
/**
|
|
514
522
|
* Update one instance.
|
|
@@ -537,7 +545,11 @@ export async function updateEntity(entity, instanceId, fields, merge = null, unm
|
|
|
537
545
|
if (unmerge && unmerge.length > 0) {
|
|
538
546
|
body.unmerge = [...unmerge];
|
|
539
547
|
}
|
|
540
|
-
|
|
548
|
+
const result = await makeRequest("POST", dataUrl(entity, "update") + `/${instanceId}`, body);
|
|
549
|
+
// Same echo as insert, and here there is no documented flag to turn it off at
|
|
550
|
+
// the source — the update endpoint's body (data.txt:588-593) has no
|
|
551
|
+
// getAccessByFields. Only byte-identical values are replaced.
|
|
552
|
+
return elideEchoedResponse(result, fields);
|
|
541
553
|
}
|
|
542
554
|
/**
|
|
543
555
|
* SOFT-delete the matching instances: /remove sets deletedAt and leaves the row
|
package/dist/server.js
CHANGED
|
@@ -243,6 +243,7 @@ APPROVAL GATES (human-in-the-loop)
|
|
|
243
243
|
- Every update/move/close/delete tool returns {"status": "confirmation_required"} when called without confirm=true, and performs NOTHING.
|
|
244
244
|
- On that response: show the user what will change, get explicit approval, then re-call the same tool with confirm=true. Never set confirm=true on the first call without the user's go-ahead.
|
|
245
245
|
- Create/read tools (and comments) need no confirmation.
|
|
246
|
+
- A value shown as <N chars — exactly as sent / unchanged from this call's arguments> is NOT the stored text: it is the long string you yourself supplied in this same call, named instead of repeated. Quote it to the user from your own arguments; never report the marker as the record's content.
|
|
246
247
|
|
|
247
248
|
ENTITY BUILDER (create + edit fields; removal is UI-only) — suppa_add_field's description carries the real field types, the sub_type matrix and the field options; suppa_update_field's carries what may still be changed on a field that exists. Two things those cannot decide for you:
|
|
248
249
|
- OWNED CHILD COLLECTIONS ARE TABULAR PARTS. Repeating rows belonging to ONE parent record (a part's BOM items) go through suppa_create_tabular_part(parent_entity, name), which creates the child's 'owner' relation and the parent link. Never model it by hand — suppa_add_field REFUSES field_type='one-to-many'. 'many-to-many' is for a shared lookup referenced by many records.
|
package/dist/utils.js
CHANGED
|
@@ -586,7 +586,175 @@ export function confirmRequired(action, target, proposedChanges) {
|
|
|
586
586
|
"soft — sets deletedAt, row remains, reversible via suppa_restore_record";
|
|
587
587
|
}
|
|
588
588
|
if (proposedChanges !== undefined) {
|
|
589
|
-
|
|
589
|
+
// The preview was a verbatim copy of this call's own arguments. Long values
|
|
590
|
+
// are named and sized instead of repeated — see elideEchoedArgs.
|
|
591
|
+
body.proposed_changes = elideEchoedArgs(proposedChanges);
|
|
590
592
|
}
|
|
591
593
|
return jsonResponse(body);
|
|
592
594
|
}
|
|
595
|
+
// ---------------------------------------------------------------------------
|
|
596
|
+
// Payload thrift: three things this server was paying for and reading never.
|
|
597
|
+
//
|
|
598
|
+
// A tool result is not paid once. The whole context is re-sent on every turn,
|
|
599
|
+
// so a 12k-char string returned in turn 5 is charged again in turns 6..N and is
|
|
600
|
+
// still occupying the window when compaction fires. The reductions below are
|
|
601
|
+
// therefore worth real money — but each one has to be information-preserving,
|
|
602
|
+
// or it buys tokens with the model's ability to do the job.
|
|
603
|
+
//
|
|
604
|
+
// The test each of these passes: the bytes removed carry NOTHING the caller does
|
|
605
|
+
// not already hold. That is a stronger claim than "probably unimportant", and it
|
|
606
|
+
// is the only claim that justifies removing anything at all.
|
|
607
|
+
// ---------------------------------------------------------------------------
|
|
608
|
+
/**
|
|
609
|
+
* Per-record access metadata the platform attaches to rows.
|
|
610
|
+
*
|
|
611
|
+
* These are lists of FIELD NAMES, identical on every row of an entity, and no
|
|
612
|
+
* code in this server reads any of them. `getAccessByFields: false` suppresses
|
|
613
|
+
* the first two at the source (api-entity-builder-data.txt:72) — this list is
|
|
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.
|
|
617
|
+
*
|
|
618
|
+
* NAMED KEYS ONLY, deliberately. A blanket "drop every key starting with $"
|
|
619
|
+
* would also drop any future `$`-prefixed key the platform introduces to carry
|
|
620
|
+
* something that matters, and it would do so silently.
|
|
621
|
+
*/
|
|
622
|
+
export const ACCESS_METADATA_KEYS = [
|
|
623
|
+
"$readAccess",
|
|
624
|
+
"$updateAccess",
|
|
625
|
+
"$instanceAccess",
|
|
626
|
+
];
|
|
627
|
+
/**
|
|
628
|
+
* Recursively drop ACCESS_METADATA_KEYS from a parsed response.
|
|
629
|
+
*
|
|
630
|
+
* 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.
|
|
633
|
+
*/
|
|
634
|
+
export function stripAccessMetadata(value) {
|
|
635
|
+
if (Array.isArray(value)) {
|
|
636
|
+
let changed = false;
|
|
637
|
+
const out = value.map((item) => {
|
|
638
|
+
const next = stripAccessMetadata(item);
|
|
639
|
+
if (next !== item) {
|
|
640
|
+
changed = true;
|
|
641
|
+
}
|
|
642
|
+
return next;
|
|
643
|
+
});
|
|
644
|
+
return changed ? out : value;
|
|
645
|
+
}
|
|
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;
|
|
669
|
+
}
|
|
670
|
+
/**
|
|
671
|
+
* Below this many characters, a value is cheaper to repeat than to describe.
|
|
672
|
+
*
|
|
673
|
+
* The marker that replaces an elided value costs ~60 characters, so eliding a
|
|
674
|
+
* short title would COST tokens and lose the at-a-glance readability that makes
|
|
675
|
+
* a confirmation preview reviewable. Only values long enough for the saving to
|
|
676
|
+
* dominate are elided.
|
|
677
|
+
*/
|
|
678
|
+
export const ECHO_ELISION_THRESHOLD = 200;
|
|
679
|
+
/** The stand-in for a value the caller already holds verbatim. */
|
|
680
|
+
function echoMarker(chars, why) {
|
|
681
|
+
return `<${chars} chars — ${why}>`;
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* Replace long string values the CALLER SUPPLIED IN THIS CALL with a marker.
|
|
685
|
+
*
|
|
686
|
+
* This is the confirmation-preview half. `proposed_changes` exists so the agent
|
|
687
|
+
* can show the user what is about to change; it was built by copying the tool's
|
|
688
|
+
* own arguments back out. For a task description that is a verbatim second copy
|
|
689
|
+
* of a string sitting in the same assistant turn's tool-call arguments — the
|
|
690
|
+
* model cannot learn anything from reading it twice, and it pays for it on
|
|
691
|
+
* every subsequent turn.
|
|
692
|
+
*
|
|
693
|
+
* What survives: the key (so the user still sees WHICH fields change), every
|
|
694
|
+
* short value in full (titles, ids, deadlines — the things a human actually
|
|
695
|
+
* eyeballs before approving), and the size of what was elided.
|
|
696
|
+
*/
|
|
697
|
+
export function elideEchoedArgs(changes) {
|
|
698
|
+
if (typeof changes === "string") {
|
|
699
|
+
return changes.length > ECHO_ELISION_THRESHOLD
|
|
700
|
+
? echoMarker(changes.length, "unchanged from this call's arguments")
|
|
701
|
+
: changes;
|
|
702
|
+
}
|
|
703
|
+
if (Array.isArray(changes)) {
|
|
704
|
+
return changes.map((item) => elideEchoedArgs(item));
|
|
705
|
+
}
|
|
706
|
+
if (changes === null || typeof changes !== "object") {
|
|
707
|
+
return changes;
|
|
708
|
+
}
|
|
709
|
+
const proto = Object.getPrototypeOf(changes);
|
|
710
|
+
if (proto !== Object.prototype && proto !== null) {
|
|
711
|
+
return changes;
|
|
712
|
+
}
|
|
713
|
+
// Recurses: suppa_update_record nests the real payload one level down, in
|
|
714
|
+
// proposed_changes.fields, and a top-level-only pass walked straight past the
|
|
715
|
+
// one value on that tool big enough to matter.
|
|
716
|
+
const out = {};
|
|
717
|
+
for (const [key, value] of Object.entries(changes)) {
|
|
718
|
+
out[key] = elideEchoedArgs(value);
|
|
719
|
+
}
|
|
720
|
+
return out;
|
|
721
|
+
}
|
|
722
|
+
/**
|
|
723
|
+
* Replace values in a write RESPONSE that came back byte-identical to what was
|
|
724
|
+
* sent, when they are long enough to be worth it.
|
|
725
|
+
*
|
|
726
|
+
* This is the platform-echo half. An insert with no `returning` projection
|
|
727
|
+
* answers with the whole stored record, which means the HTML description just
|
|
728
|
+
* uploaded is billed a second time on the way back.
|
|
729
|
+
*
|
|
730
|
+
* The identity test is what makes this safe, and it is not a heuristic: a value
|
|
731
|
+
* is only replaced when it is EXACTLY the string that was sent. If the platform
|
|
732
|
+
* normalised the markup, filled a default, or rejected part of the input, the
|
|
733
|
+
* stored value differs from the sent one — that difference is real information
|
|
734
|
+
* about what the platform did, and it is returned in full. The key is always
|
|
735
|
+
* kept, so "the field was written" is never in doubt.
|
|
736
|
+
*/
|
|
737
|
+
export function elideEchoedResponse(result, sent) {
|
|
738
|
+
if (Array.isArray(result)) {
|
|
739
|
+
return result.map((row) => elideEchoedResponse(row, sent));
|
|
740
|
+
}
|
|
741
|
+
if (result === null || typeof result !== "object") {
|
|
742
|
+
return result;
|
|
743
|
+
}
|
|
744
|
+
const proto = Object.getPrototypeOf(result);
|
|
745
|
+
if (proto !== Object.prototype && proto !== null) {
|
|
746
|
+
return result;
|
|
747
|
+
}
|
|
748
|
+
const out = {};
|
|
749
|
+
for (const [key, value] of Object.entries(result)) {
|
|
750
|
+
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;
|
|
758
|
+
}
|
|
759
|
+
return out;
|
|
760
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "suppa-mcp-2",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.19.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": {
|