suppa-mcp-2 1.42.3 → 1.42.5
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 +1 -1
- package/dist/auth.js +115 -21
- package/dist/cli/flags.js +21 -0
- package/dist/server.js +38 -1
- package/dist/tools/entity.js +67 -38
- package/dist/utils.js +24 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -89,7 +89,7 @@ All variables are optional — the server works out of the box and authenticates
|
|
|
89
89
|
| `SUPPA_LANG` | `en` | Language (`en` / `uk`) |
|
|
90
90
|
| `SUPPA_LANGS` | (auto) | Languages a multi-language title/Name is written into. When unset, resolved from the platform: the languages the tenant has enabled (`SystemPreferences.availableLanguages`, what the builder UI reads), else the language keys of existing entity titles, falling back to `en,uk`. Only the 24 `Localizations` language columns are kept, and `en` is always included. Set e.g. `en,uk` to force it. |
|
|
91
91
|
| `SUPPA_TZ` | `Europe/Kyiv` | Timezone, sent as `X-Timezone`. Must be an IANA name (`Europe/Kyiv`, `UTC`): the platform refuses an offset such as `+03:00` on every request, so an invalid value falls back to the default with a warning on stderr. |
|
|
92
|
-
| `SUPPA_MCP_LOGIN_PORT` | `8080` | Local
|
|
92
|
+
| `SUPPA_MCP_LOGIN_PORT` | `8080` | Local port of the sign-in page (listens on 127.0.0.1 and [::1]). Another port works only once `http://localhost:<port>` is in the Google OAuth client's Authorized JavaScript origins — ask an admin first |
|
|
93
93
|
| `SUPPA_MCP_HOME` | `~/.suppa-mcp` | Directory for the tenant registry |
|
|
94
94
|
| `SUPPA_HTTP_TIMEOUT` | `60` | Per-request timeout, seconds |
|
|
95
95
|
| `SUPPA_MCP_DEBUG` | (off) | `1` logs each request line to stderr |
|
package/dist/auth.js
CHANGED
|
@@ -124,16 +124,19 @@ export function extractCredentials(body, setCookies) {
|
|
|
124
124
|
(typeof b.refresh_token === "string" ? b.refresh_token : "") ||
|
|
125
125
|
"";
|
|
126
126
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
127
|
+
// The auth service answers with more than the two token cookies, in this order: an emptied
|
|
128
|
+
// `accessToken` and `refreshToken` (Max-Age=0 — it expires the other SameSite variant, BSU-3077),
|
|
129
|
+
// the device cookie `suppa_did`, and only then the real `accessToken` and `refreshToken`. So the
|
|
130
|
+
// first cookie of a name is not the token: take the first one that has a value and is not expired.
|
|
131
|
+
for (const { name, value, expired } of setCookies.flatMap(splitSetCookieHeader).map(parseSetCookie)) {
|
|
132
|
+
if (!value || expired) {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
132
135
|
if (name === "accessToken" && !access) {
|
|
133
|
-
access =
|
|
136
|
+
access = value;
|
|
134
137
|
}
|
|
135
138
|
else if (name === "refreshToken" && !refresh) {
|
|
136
|
-
refresh =
|
|
139
|
+
refresh = value;
|
|
137
140
|
}
|
|
138
141
|
}
|
|
139
142
|
if (access && !aExp) {
|
|
@@ -149,6 +152,48 @@ export function extractCredentials(body, setCookies) {
|
|
|
149
152
|
refreshExp: rExp,
|
|
150
153
|
};
|
|
151
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Split a Set-Cookie value that holds several cookies joined with ", " — what `headers.get()`
|
|
157
|
+
* gives on a runtime without `getSetCookie`, or behind a proxy that folds the header — back into
|
|
158
|
+
* one cookie each. A comma starts a new cookie only when a `name=` follows it, so the comma inside
|
|
159
|
+
* `Expires=Thu, 01 Jan 1970 …` stays where it is.
|
|
160
|
+
*/
|
|
161
|
+
export function splitSetCookieHeader(value) {
|
|
162
|
+
return value
|
|
163
|
+
.split(/,(?=\s*[!#$%&'*+\-.^_`|~0-9A-Za-z]+=)/)
|
|
164
|
+
.map((part) => part.trim())
|
|
165
|
+
.filter(Boolean);
|
|
166
|
+
}
|
|
167
|
+
/** One Set-Cookie line: its name, its value, and whether it deletes the cookie instead of setting it. */
|
|
168
|
+
function parseSetCookie(line) {
|
|
169
|
+
const [pair, ...attributes] = line.split(";");
|
|
170
|
+
const eq = pair.indexOf("=");
|
|
171
|
+
const name = (eq === -1 ? pair : pair.slice(0, eq)).trim();
|
|
172
|
+
const value = eq === -1 ? "" : pair.slice(eq + 1).trim();
|
|
173
|
+
let expired = false;
|
|
174
|
+
for (const attribute of attributes) {
|
|
175
|
+
const at = attribute.indexOf("=");
|
|
176
|
+
const key = (at === -1 ? attribute : attribute.slice(0, at)).trim().toLowerCase();
|
|
177
|
+
const arg = at === -1 ? "" : attribute.slice(at + 1).trim();
|
|
178
|
+
if (key === "max-age" && Number(arg) <= 0) {
|
|
179
|
+
expired = true;
|
|
180
|
+
}
|
|
181
|
+
else if (key === "expires" && Date.parse(arg) <= Date.now()) {
|
|
182
|
+
expired = true;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return { name, value, expired };
|
|
186
|
+
}
|
|
187
|
+
/** The cookies a response set, by name only — never a value — for an error that has to say what came. */
|
|
188
|
+
export function describeSetCookies(setCookies) {
|
|
189
|
+
const cookies = setCookies.flatMap(splitSetCookieHeader).map(parseSetCookie);
|
|
190
|
+
if (cookies.length === 0) {
|
|
191
|
+
return "no Set-Cookie at all";
|
|
192
|
+
}
|
|
193
|
+
return cookies
|
|
194
|
+
.map(({ name, value, expired }) => `${name}${!value ? " (empty)" : expired ? " (expired)" : ""}`)
|
|
195
|
+
.join(", ");
|
|
196
|
+
}
|
|
152
197
|
// ---------------------------------------------------------------------------
|
|
153
198
|
// Low-level network (auth endpoints only — no tenant auth headers)
|
|
154
199
|
// ---------------------------------------------------------------------------
|
|
@@ -171,9 +216,10 @@ function readSetCookies(headers) {
|
|
|
171
216
|
}
|
|
172
217
|
try {
|
|
173
218
|
if (typeof h.get === "function") {
|
|
219
|
+
// Without getSetCookie every Set-Cookie line comes back joined into one value.
|
|
174
220
|
const single = h.get("set-cookie");
|
|
175
221
|
if (single) {
|
|
176
|
-
return
|
|
222
|
+
return splitSetCookieHeader(single);
|
|
177
223
|
}
|
|
178
224
|
}
|
|
179
225
|
}
|
|
@@ -527,7 +573,8 @@ export async function doRefresh(baseUrl, host, creds) {
|
|
|
527
573
|
}
|
|
528
574
|
const fresh = extractCredentials(body, cookies);
|
|
529
575
|
if (!fresh.accessToken) {
|
|
530
|
-
recordRefreshFailure(host, `the refresh endpoint returned HTTP 200 with no access token in it (${REFRESH_PATH}
|
|
576
|
+
recordRefreshFailure(host, `the refresh endpoint returned HTTP 200 with no access token in it (${REFRESH_PATH}; ` +
|
|
577
|
+
`cookies set: ${describeSetCookies(cookies)})`);
|
|
531
578
|
throw new ReloginRequired(host);
|
|
532
579
|
}
|
|
533
580
|
if (!fresh.refreshToken) {
|
|
@@ -629,7 +676,7 @@ export function browserGoogleLogin(host, timeout = 180) {
|
|
|
629
676
|
/* socket already gone — ignore */
|
|
630
677
|
}
|
|
631
678
|
};
|
|
632
|
-
const
|
|
679
|
+
const handle = (req, res) => {
|
|
633
680
|
// A client that aborts mid-request makes `req` emit 'error'; with no
|
|
634
681
|
// listener Node re-throws it as an uncaughtException. Swallow it.
|
|
635
682
|
req.on("error", () => {
|
|
@@ -688,7 +735,17 @@ export function browserGoogleLogin(host, timeout = 180) {
|
|
|
688
735
|
// Contain any synchronous throw in the request handler.
|
|
689
736
|
finish(e instanceof Error ? e.message : String(e), null);
|
|
690
737
|
}
|
|
691
|
-
}
|
|
738
|
+
};
|
|
739
|
+
// The browser opens http://localhost:<port>, and localhost is [::1] before 127.0.0.1. Listening
|
|
740
|
+
// on 127.0.0.1 alone, a dev server on [::1]:<port> (the platform's pnpm run dev takes 8080) got
|
|
741
|
+
// the browser while both started without an error, and the sign-in hung until its timeout.
|
|
742
|
+
// So the page listens on both, and a [::1] that is taken is said at once.
|
|
743
|
+
const servers = [createServer(handle), createServer(handle)];
|
|
744
|
+
const closeAll = () => {
|
|
745
|
+
for (const s of servers) {
|
|
746
|
+
s.close();
|
|
747
|
+
}
|
|
748
|
+
};
|
|
692
749
|
const finish = (error, idToken) => {
|
|
693
750
|
if (settled) {
|
|
694
751
|
return;
|
|
@@ -697,7 +754,7 @@ export function browserGoogleLogin(host, timeout = 180) {
|
|
|
697
754
|
if (timer) {
|
|
698
755
|
clearTimeout(timer);
|
|
699
756
|
}
|
|
700
|
-
|
|
757
|
+
closeAll();
|
|
701
758
|
if (error) {
|
|
702
759
|
reject(new Error(`Google sign-in failed: ${error}`));
|
|
703
760
|
}
|
|
@@ -708,18 +765,52 @@ export function browserGoogleLogin(host, timeout = 180) {
|
|
|
708
765
|
reject(new Error("Google sign-in failed: no credential returned by Google"));
|
|
709
766
|
}
|
|
710
767
|
};
|
|
711
|
-
|
|
768
|
+
const otherPort = "or set SUPPA_MCP_LOGIN_PORT to another port — its origin http://localhost:<port> must " +
|
|
769
|
+
"also be in the Google OAuth client's Authorized JavaScript origins, or Google refuses the page.";
|
|
770
|
+
const refuse = (message) => {
|
|
712
771
|
if (settled) {
|
|
713
772
|
return;
|
|
714
773
|
}
|
|
715
774
|
settled = true;
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
775
|
+
closeAll();
|
|
776
|
+
reject(new Error(message));
|
|
777
|
+
};
|
|
778
|
+
const listenOn = (s, host) => new Promise((ok, fail) => {
|
|
779
|
+
s.once("error", fail);
|
|
780
|
+
s.listen(port, host, () => {
|
|
781
|
+
s.off("error", fail);
|
|
782
|
+
// An error after listening ends the sign-in, never the process (an EventEmitter
|
|
783
|
+
// 'error' with no listener is thrown).
|
|
784
|
+
s.on("error", (e) => finish(e.message, null));
|
|
785
|
+
ok();
|
|
786
|
+
});
|
|
721
787
|
});
|
|
722
|
-
|
|
788
|
+
void (async () => {
|
|
789
|
+
try {
|
|
790
|
+
await listenOn(servers[0], "127.0.0.1");
|
|
791
|
+
}
|
|
792
|
+
catch (e) {
|
|
793
|
+
const err = e;
|
|
794
|
+
return refuse(`Could not start the login server on port ${port} (${err.message}). ` +
|
|
795
|
+
`Close whatever is using it, ${otherPort}`);
|
|
796
|
+
}
|
|
797
|
+
try {
|
|
798
|
+
await listenOn(servers[1], "::1");
|
|
799
|
+
}
|
|
800
|
+
catch (e) {
|
|
801
|
+
const err = e;
|
|
802
|
+
if (err.code !== "EADDRNOTAVAIL" && err.code !== "EAFNOSUPPORT") {
|
|
803
|
+
return refuse(`Could not start the sign-in page: [::1]:${port} is already held by another server ` +
|
|
804
|
+
`(${err.code ?? err.message}) — most likely a local dev server; the platform's ` +
|
|
805
|
+
`pnpm run dev listens on 8080. The browser opens http://localhost:${port}, which ` +
|
|
806
|
+
"reaches [::1] first, so it would show that server instead of the sign-in page. " +
|
|
807
|
+
`Stop it for the minute the sign-in takes, ${otherPort}`);
|
|
808
|
+
}
|
|
809
|
+
servers.pop(); // no IPv6 loopback on this machine: nothing can shadow 127.0.0.1 there
|
|
810
|
+
}
|
|
811
|
+
if (settled) {
|
|
812
|
+
return;
|
|
813
|
+
}
|
|
723
814
|
const url = `http://localhost:${port}/`;
|
|
724
815
|
const opened = openBrowser(url);
|
|
725
816
|
timer = setTimeout(() => {
|
|
@@ -727,11 +818,11 @@ export function browserGoogleLogin(host, timeout = 180) {
|
|
|
727
818
|
return;
|
|
728
819
|
}
|
|
729
820
|
settled = true;
|
|
730
|
-
|
|
821
|
+
closeAll();
|
|
731
822
|
reject(new Error(`Login timed out after ${timeout}s. ` +
|
|
732
823
|
(opened ? "" : `Open ${url} manually and sign in.`)));
|
|
733
824
|
}, timeout * 1000);
|
|
734
|
-
});
|
|
825
|
+
})();
|
|
735
826
|
});
|
|
736
827
|
}
|
|
737
828
|
/** Authenticate to a tenant via Google and store the tokens. Returns JSON status. */
|
|
@@ -784,6 +875,9 @@ export async function login(tenant = "") {
|
|
|
784
875
|
if (!creds.accessToken) {
|
|
785
876
|
return JSON.stringify({
|
|
786
877
|
error: "Login exchange returned no access token.",
|
|
878
|
+
// Names only, never values: what the platform set tells whether it sent the token at all.
|
|
879
|
+
cookies_set: describeSetCookies(result.cookies),
|
|
880
|
+
node: process.version,
|
|
787
881
|
host,
|
|
788
882
|
});
|
|
789
883
|
}
|
package/dist/cli/flags.js
CHANGED
|
@@ -281,6 +281,27 @@ export function nearestName(target, candidates) {
|
|
|
281
281
|
return null;
|
|
282
282
|
return best.name;
|
|
283
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* `nearestName`, then one more way to be close: an abbreviation — the same first letter and every
|
|
286
|
+
* letter of `target` in order inside exactly one candidate. A typo is what `nearestName` catches;
|
|
287
|
+
* `filters` for `filters_json` or `cmp` for `comparator` is a short form, and scores below the
|
|
288
|
+
* threshold (0.58, 0.3). Two candidates that both contain it is a guess, so null.
|
|
289
|
+
*/
|
|
290
|
+
export function suggestName(target, candidates) {
|
|
291
|
+
const near = nearestName(target, candidates);
|
|
292
|
+
if (near !== null)
|
|
293
|
+
return near;
|
|
294
|
+
const t = target.toLowerCase();
|
|
295
|
+
const inOrder = (name) => {
|
|
296
|
+
let i = 0;
|
|
297
|
+
for (const c of name.toLowerCase())
|
|
298
|
+
if (c === t[i])
|
|
299
|
+
i++;
|
|
300
|
+
return i === t.length;
|
|
301
|
+
};
|
|
302
|
+
const hits = candidates.filter((name) => t.length > 1 && name[0]?.toLowerCase() === t[0] && inOrder(name));
|
|
303
|
+
return hits.length === 1 ? hits[0] : null;
|
|
304
|
+
}
|
|
284
305
|
/**
|
|
285
306
|
* Optimal-string-alignment distance: Levenshtein (insert / delete / substitute,
|
|
286
307
|
* each cost 1) plus one more move — swapping two adjacent characters counts as
|
package/dist/server.js
CHANGED
|
@@ -29,6 +29,7 @@ import * as query from "./tools/query.js";
|
|
|
29
29
|
import * as auth from "./auth.js";
|
|
30
30
|
import * as tenants from "./tenants.js";
|
|
31
31
|
import { confirmRequired, jsonResponse } from "./utils.js";
|
|
32
|
+
import { suggestName } from "./cli/flags.js";
|
|
32
33
|
import { installToolsListEconomy } from "./toolsListEconomy.js";
|
|
33
34
|
import { PACKAGE_NAME, PACKAGE_VERSION, knownLatest, isOutdated, refreshLatestVersion, upgradeNotice, } from "./version.js";
|
|
34
35
|
export { PACKAGE_VERSION };
|
|
@@ -1770,6 +1771,11 @@ export function buildToolTable() {
|
|
|
1770
1771
|
annotations: _MUT,
|
|
1771
1772
|
}, async (a) => {
|
|
1772
1773
|
if (!a.confirm) {
|
|
1774
|
+
// The checks first: a human asked to approve a write that is then refused approved nothing.
|
|
1775
|
+
const refused = await entity.refusedRecordUpdate(a.entity_name, a.fields_json, a.merge_json, a.unmerge_json);
|
|
1776
|
+
if (refused) {
|
|
1777
|
+
return text(refused);
|
|
1778
|
+
}
|
|
1773
1779
|
let proposed;
|
|
1774
1780
|
try {
|
|
1775
1781
|
proposed = JSON.parse(a.fields_json);
|
|
@@ -1821,6 +1827,10 @@ export function buildToolTable() {
|
|
|
1821
1827
|
annotations: _MUT,
|
|
1822
1828
|
}, async (a) => {
|
|
1823
1829
|
if (!a.confirm) {
|
|
1830
|
+
const refused = await entity.refusedRecordDelete(a.entity_name);
|
|
1831
|
+
if (refused) {
|
|
1832
|
+
return text(refused);
|
|
1833
|
+
}
|
|
1824
1834
|
return text(confirmRequired("delete record", {
|
|
1825
1835
|
entity: a.entity_name,
|
|
1826
1836
|
record_id: a.record_id,
|
|
@@ -2820,6 +2830,33 @@ export function buildToolTable() {
|
|
|
2820
2830
|
}, async (a) => text(await healthCheck(a.deep)));
|
|
2821
2831
|
return table;
|
|
2822
2832
|
}
|
|
2833
|
+
/**
|
|
2834
|
+
* A tool's input schema that REFUSES an argument the tool does not declare. The SDK builds a plain
|
|
2835
|
+
* z.object from a raw shape, and that strips unknown keys: `filters` written for `filters_json`
|
|
2836
|
+
* vanished, the default "[]" stood in, and the search ran unfiltered — answered as if filtered
|
|
2837
|
+
* (09.10.2026, on every tool). The CLI refused this from the start (cli/run.ts); this is the same
|
|
2838
|
+
* refusal on the MCP side, with the same suggestion. In tools/list every tool with arguments
|
|
2839
|
+
* already said `additionalProperties: false`; the six without now say it too.
|
|
2840
|
+
*/
|
|
2841
|
+
export function strictArguments(tool, shape) {
|
|
2842
|
+
const names = Object.keys(shape);
|
|
2843
|
+
return z
|
|
2844
|
+
.object(shape, {
|
|
2845
|
+
errorMap: (issue, ctx) => {
|
|
2846
|
+
if (issue.code !== "unrecognized_keys")
|
|
2847
|
+
return { message: ctx.defaultError };
|
|
2848
|
+
const unknown = issue.keys.map((key) => {
|
|
2849
|
+
const near = suggestName(key, names);
|
|
2850
|
+
return `unknown argument '${key}'${near ? ` — did you mean '${near}'?` : ""}`;
|
|
2851
|
+
});
|
|
2852
|
+
return {
|
|
2853
|
+
message: `${unknown.join("; ")}. ${tool} takes: ${names.join(", ") || "no arguments"}. ` +
|
|
2854
|
+
"Nothing was sent — an undeclared argument is never dropped, because the call would run without it.",
|
|
2855
|
+
};
|
|
2856
|
+
},
|
|
2857
|
+
})
|
|
2858
|
+
.strict();
|
|
2859
|
+
}
|
|
2823
2860
|
export function buildServer() {
|
|
2824
2861
|
// Reset so repeated buildServer() calls (e.g. in tests) do not double-count.
|
|
2825
2862
|
TOOL_NAMES.length = 0;
|
|
@@ -2839,7 +2876,7 @@ export function buildServer() {
|
|
|
2839
2876
|
for (const spec of buildToolTable()) {
|
|
2840
2877
|
server.registerTool(spec.name, {
|
|
2841
2878
|
description: compactDescription(spec.description),
|
|
2842
|
-
inputSchema: (spec.inputSchema ?? {}),
|
|
2879
|
+
inputSchema: strictArguments(spec.name, spec.inputSchema ?? {}),
|
|
2843
2880
|
annotations: spec.annotations,
|
|
2844
2881
|
}, spec.handler);
|
|
2845
2882
|
TOOL_NAMES.push(spec.name);
|
package/dist/tools/entity.js
CHANGED
|
@@ -3079,23 +3079,27 @@ async function _resolveEntity(name) {
|
|
|
3079
3079
|
if (ci) {
|
|
3080
3080
|
return { name: ci, names };
|
|
3081
3081
|
}
|
|
3082
|
-
// The
|
|
3083
|
-
//
|
|
3084
|
-
//
|
|
3085
|
-
//
|
|
3086
|
-
//
|
|
3087
|
-
//
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3082
|
+
// The listing is not the tenant. It leaves out the extension tables
|
|
3083
|
+
// ('<Entity>CustomFields', api/entity-builder/custom-fields.html §6B) and an
|
|
3084
|
+
// application's own tables (LeadsSales, CRM migration 06.10.2026), and both
|
|
3085
|
+
// are served by name — describe and query read them while this refused a
|
|
3086
|
+
// write as "does not exist". So a miss is asked by name before it is refused:
|
|
3087
|
+
// a schema that comes back with fields IS the entity, spelled as it answers.
|
|
3088
|
+
try {
|
|
3089
|
+
const schema = await makeRequest("GET", `/api/core/schema/${encodeURIComponent(name)}`);
|
|
3090
|
+
const fields = _extractFields(schema);
|
|
3091
|
+
// An extension table is one only with its `owner` column, as before.
|
|
3092
|
+
const isEntity = name.endsWith(CUSTOM_FIELDS_EXTENSION_SUFFIX)
|
|
3093
|
+
? fields.some((f) => f.name === "owner")
|
|
3094
|
+
: fields.length > 0;
|
|
3095
|
+
if (isEntity) {
|
|
3096
|
+
const served = isPlainObject(schema) && typeof schema.name === "string" && schema.name ? schema.name : name;
|
|
3097
|
+
return { name: served, names };
|
|
3097
3098
|
}
|
|
3098
3099
|
}
|
|
3100
|
+
catch {
|
|
3101
|
+
// fall through to the refusal below — a failed read is not an entity
|
|
3102
|
+
}
|
|
3099
3103
|
const nl = name.toLowerCase();
|
|
3100
3104
|
const near = names
|
|
3101
3105
|
.filter((n) => n.toLowerCase().includes(nl) || nl.includes(n.toLowerCase()))
|
|
@@ -3507,6 +3511,35 @@ function _parseNameList(raw, param) {
|
|
|
3507
3511
|
* change.
|
|
3508
3512
|
*/
|
|
3509
3513
|
export async function updateRecord(entityName, recordId, fieldsJson, mergeJson = null, unmergeJson = null) {
|
|
3514
|
+
const checked = await _checkRecordUpdate(entityName, fieldsJson, mergeJson, unmergeJson);
|
|
3515
|
+
if ("error" in checked) {
|
|
3516
|
+
return checked.error;
|
|
3517
|
+
}
|
|
3518
|
+
const { fields, merge, unmerge } = checked;
|
|
3519
|
+
entityName = checked.entityName;
|
|
3520
|
+
let result;
|
|
3521
|
+
try {
|
|
3522
|
+
result = await updateEntity(entityName, recordId, fields, merge, unmerge);
|
|
3523
|
+
}
|
|
3524
|
+
catch (e) {
|
|
3525
|
+
const hinted = _writeErrorWithHint(e, [fields]);
|
|
3526
|
+
if (hinted) {
|
|
3527
|
+
return hinted;
|
|
3528
|
+
}
|
|
3529
|
+
throw e;
|
|
3530
|
+
}
|
|
3531
|
+
return _updateResult(entityName, recordId, fields, merge, unmerge, result, checked.v);
|
|
3532
|
+
}
|
|
3533
|
+
/**
|
|
3534
|
+
* The refusal `updateRecord` would answer, or null — every check it makes before the write, and
|
|
3535
|
+
* nothing sent. The confirm gate runs this FIRST: it used to ask a human to approve a write and
|
|
3536
|
+
* only then find the entity missing or a field misspelt (CRM migration, 06.10.2026).
|
|
3537
|
+
*/
|
|
3538
|
+
export async function refusedRecordUpdate(entityName, fieldsJson, mergeJson = null, unmergeJson = null) {
|
|
3539
|
+
const checked = await _checkRecordUpdate(entityName, fieldsJson, mergeJson, unmergeJson);
|
|
3540
|
+
return "error" in checked ? checked.error : null;
|
|
3541
|
+
}
|
|
3542
|
+
async function _checkRecordUpdate(entityName, fieldsJson, mergeJson, unmergeJson) {
|
|
3510
3543
|
let fields;
|
|
3511
3544
|
let merge;
|
|
3512
3545
|
let unmerge;
|
|
@@ -3516,36 +3549,28 @@ export async function updateRecord(entityName, recordId, fieldsJson, mergeJson =
|
|
|
3516
3549
|
unmerge = _parseNameList(unmergeJson, "unmerge_json");
|
|
3517
3550
|
}
|
|
3518
3551
|
catch (e) {
|
|
3519
|
-
return jsonResponse({ error: e instanceof Error ? e.message : String(e) });
|
|
3552
|
+
return { error: jsonResponse({ error: e instanceof Error ? e.message : String(e) }) };
|
|
3520
3553
|
}
|
|
3521
3554
|
const mergeProblems = mergeListProblems(fields, merge, unmerge);
|
|
3522
3555
|
if (mergeProblems.length > 0) {
|
|
3523
|
-
return jsonResponse({
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3556
|
+
return { error: jsonResponse({
|
|
3557
|
+
error: "Refused: the merge/unmerge lists do not line up with fields_json. Nothing " +
|
|
3558
|
+
"was written — sending this would have REPLACED the list instead of " +
|
|
3559
|
+
"adding to it, and reported success.",
|
|
3560
|
+
problems: mergeProblems,
|
|
3561
|
+
hint: 'merge_json/unmerge_json take field NAMES (e.g. ["watchers"]); each name ' +
|
|
3562
|
+
'must also appear in fields_json with an array value (e.g. {"watchers": ' +
|
|
3563
|
+
'[{"id": 15}]}), and no name may be in both lists.',
|
|
3564
|
+
}) };
|
|
3532
3565
|
}
|
|
3533
3566
|
const v = await _validateRecordWrite(entityName, fields);
|
|
3534
3567
|
if (v.error) {
|
|
3535
|
-
return v.error;
|
|
3536
|
-
}
|
|
3537
|
-
entityName = v.entityName;
|
|
3538
|
-
let result;
|
|
3539
|
-
try {
|
|
3540
|
-
result = await updateEntity(entityName, recordId, fields, merge, unmerge);
|
|
3541
|
-
}
|
|
3542
|
-
catch (e) {
|
|
3543
|
-
const hinted = _writeErrorWithHint(e, [fields]);
|
|
3544
|
-
if (hinted) {
|
|
3545
|
-
return hinted;
|
|
3546
|
-
}
|
|
3547
|
-
throw e;
|
|
3568
|
+
return { error: v.error };
|
|
3548
3569
|
}
|
|
3570
|
+
return { entityName: v.entityName, fields, merge, unmerge, v };
|
|
3571
|
+
}
|
|
3572
|
+
/** The answer to an update that was sent: whether a row moved, what it replaced, what to warn about. */
|
|
3573
|
+
function _updateResult(entityName, recordId, fields, merge, unmerge, result, v) {
|
|
3549
3574
|
// Not "is the body falsy" but "did a row move": {"affected": 0} and [{}] are
|
|
3550
3575
|
// the platform saying it matched nothing just as surely as [], and this was
|
|
3551
3576
|
// the last writer still reading them as a completed update.
|
|
@@ -3862,6 +3887,10 @@ export async function attachFileToRecord(entityName, recordId, filePath, fieldNa
|
|
|
3862
3887
|
* column is RENAMED to <name>_<timestamp> rather than dropped — so restore-fields
|
|
3863
3888
|
* brings the field and every value back. Verified end-to-end on a live tenant.
|
|
3864
3889
|
*/
|
|
3890
|
+
/** The refusal `deleteRecord` would answer before sending anything, or null — for the confirm gate. */
|
|
3891
|
+
export async function refusedRecordDelete(entityName) {
|
|
3892
|
+
return (await _resolveEntity(entityName)).error ?? null;
|
|
3893
|
+
}
|
|
3865
3894
|
export async function deleteRecord(entityName, recordId) {
|
|
3866
3895
|
// Verify the entity exists (best-effort) so a typo'd name gives a clear error
|
|
3867
3896
|
// rather than an opaque platform failure.
|
package/dist/utils.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { randomUUID } from "node:crypto";
|
|
7
7
|
import { config } from "./config.js";
|
|
8
|
+
import { suggestName } from "./cli/flags.js";
|
|
8
9
|
import { statSync, readFileSync } from "node:fs";
|
|
9
10
|
import { extname, basename } from "node:path";
|
|
10
11
|
export function makeFilter(field, value, comparator = "=") {
|
|
@@ -48,6 +49,22 @@ export function isConditionNode(node) {
|
|
|
48
49
|
function isPlainObj(v) {
|
|
49
50
|
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
50
51
|
}
|
|
52
|
+
// The platform's Filter and Condition have these keys and no others (data.txt:33-42).
|
|
53
|
+
const FILTER_KEYS = ["field", "value", "comparator", "function"];
|
|
54
|
+
const CONDITION_KEYS = ["operator", "filters"];
|
|
55
|
+
/**
|
|
56
|
+
* A key the node does not have is refused, not dropped. Dropped, `{"cmp": "like"}` sent the
|
|
57
|
+
* default "=" and `{"match": "any"}` an AND — a different query, answered as if it were this one.
|
|
58
|
+
*/
|
|
59
|
+
function refuseUnknownKeys(node, allowed, path, what) {
|
|
60
|
+
for (const key of Object.keys(node)) {
|
|
61
|
+
if (allowed.includes(key))
|
|
62
|
+
continue;
|
|
63
|
+
const near = suggestName(key, allowed);
|
|
64
|
+
throw new Error(`${path}: unknown key '${key}'${near ? ` — did you mean '${near}'?` : ""} A ${what} takes ` +
|
|
65
|
+
`${allowed.map((k) => `"${k}"`).join(", ")} and nothing else (data.txt:33-42).`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
51
68
|
/**
|
|
52
69
|
* Validate + normalize ONE node: either a flat filter or a nested condition
|
|
53
70
|
* group. Flat "f=v" filters (what makeFilter produces, used across the tasks /
|
|
@@ -65,10 +82,16 @@ export function normalizeConditionNode(node, path = "filters_json") {
|
|
|
65
82
|
// Shorthand: {"or": [...]} / {"and": [...]}.
|
|
66
83
|
for (const op of CONDITION_OPERATORS) {
|
|
67
84
|
if (op in node && !("operator" in node)) {
|
|
85
|
+
refuseUnknownKeys(node, [op], path, `{"${op}": [...]} group`);
|
|
68
86
|
return normalizeConditionNode({ operator: op, filters: node[op] }, path);
|
|
69
87
|
}
|
|
70
88
|
}
|
|
71
89
|
if ("operator" in node || "filters" in node) {
|
|
90
|
+
if ("field" in node && !("filters" in node)) {
|
|
91
|
+
throw new Error(`${path}: a filter compares with "comparator", not "operator" — "operator" ("and"|"or") ` +
|
|
92
|
+
'belongs to a condition group {"operator", "filters"} (data.txt:35-40).');
|
|
93
|
+
}
|
|
94
|
+
refuseUnknownKeys(node, CONDITION_KEYS, path, "condition group");
|
|
72
95
|
const rawOp = node.operator;
|
|
73
96
|
const operator = typeof rawOp === "string" ? rawOp.trim().toLowerCase() : "";
|
|
74
97
|
if (!CONDITION_OPERATORS.includes(operator)) {
|
|
@@ -86,6 +109,7 @@ export function normalizeConditionNode(node, path = "filters_json") {
|
|
|
86
109
|
};
|
|
87
110
|
}
|
|
88
111
|
// Leaf filter.
|
|
112
|
+
refuseUnknownKeys(node, FILTER_KEYS, path, "filter");
|
|
89
113
|
const field = node.field;
|
|
90
114
|
if (typeof field !== "string" || !field.trim()) {
|
|
91
115
|
throw new Error(`${path}: a filter needs "field" — a field name or dotted path such as ` +
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "suppa-mcp-2",
|
|
3
|
-
"version": "1.42.
|
|
3
|
+
"version": "1.42.5",
|
|
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": {
|