suppa-mcp-2 1.23.0 → 1.24.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.
@@ -8,6 +8,9 @@ import { config } from "./config.js";
8
8
  import { assertMergeLists, elideEchoedResponse, stripAccessMetadata } from "./utils.js";
9
9
  import * as tenants from "./tenants.js";
10
10
  import { lastRefreshError } from "./sessionDiag.js";
11
+ import { isOwnProjection, withoutPaths } from "./projection.js";
12
+ // Re-exported so the transport stays the single import for entity reads.
13
+ export { ownProjection, isOwnProjection } from "./projection.js";
11
14
  // HTTP statuses that signal a transient upstream problem worth one retry.
12
15
  const TRANSIENT_CODES = new Set([429, 502, 503, 504]);
13
16
  function debug(msg) {
@@ -216,6 +219,32 @@ export function permanentDeleteRefusal(pathOrUrl) {
216
219
  "deletedAt and leaves the row in place; tool suppa_delete_record), undone with " +
217
220
  "suppa_restore_record. No flag, confirm=true or other tool lifts this block.");
218
221
  }
222
+ /**
223
+ * A non-2xx answer from the platform, with its body already parsed.
224
+ *
225
+ * The message is byte-for-byte what the plain Error carried before; the fields
226
+ * exist so a caller can act on WHAT the platform objected to — the invalid
227
+ * field paths it names, in particular — instead of matching on prose.
228
+ */
229
+ export class ApiError extends Error {
230
+ status;
231
+ body;
232
+ parsedBody;
233
+ constructor(status, statusText, body) {
234
+ super(`HTTP ${status} ${statusText}: ${body}`);
235
+ this.name = "ApiError";
236
+ this.status = status;
237
+ this.body = body;
238
+ let parsed = null;
239
+ try {
240
+ parsed = body ? JSON.parse(body) : null;
241
+ }
242
+ catch {
243
+ parsed = null; // HTML error page, empty body, truncated JSON
244
+ }
245
+ this.parsedBody = parsed;
246
+ }
247
+ }
219
248
  function noTokenError(ctx) {
220
249
  return new Error(`NOT SIGNED IN to Suppa tenant '${ctx.host}'. This is expected on first use ` +
221
250
  "and is not a failure to report back as 'broken'. ACTION REQUIRED: call the " +
@@ -390,15 +419,20 @@ async function readResponse(res, rc) {
390
419
  // The refresh that failed knows WHY it failed; without this the sentence
391
420
  // was the same whether the session had aged out or the endpoint had
392
421
  // moved — and only the first of those is fixed by signing in again.
422
+ // Each recorded reason already ends with ITS action — sign in again, or
423
+ // install a newer server. Appending the generic "Run suppa_login" to a
424
+ // diagnosis that just said signing in will not help is how a user ends up
425
+ // re-authenticating every fifteen minutes.
393
426
  const why = lastRefreshError(ctx.host);
394
- throw new Error(`HTTP 401 for tenant '${ctx.host}': the session could not be refreshed ` +
427
+ throw new Error(`HTTP 401 for tenant '${ctx.host}': the session could not be refreshed — ` +
395
428
  (why
396
- ? `— ${why}. `
397
- : "(no stored session to refresh, or the platform rejected the refresh). ") +
398
- "Run suppa_login — or, if this tenant is configured through SUPPA_API_KEY, " +
399
- `set a valid key. ${errorBody}`);
429
+ ? why
430
+ : "there is no stored session to refresh, or the platform rejected the " +
431
+ "refresh. Run suppa_login — or, if this tenant is configured through " +
432
+ "SUPPA_API_KEY, set a valid key") +
433
+ `. ${errorBody}`);
400
434
  }
401
- throw new Error(`HTTP ${code} ${safeStatusText(res)}: ${errorBody}`);
435
+ throw new ApiError(code, safeStatusText(res), errorBody);
402
436
  }
403
437
  // A download returns bytes, not JSON — reading it as text would corrupt
404
438
  // anything that is not UTF-8 (every PDF, image and zip). Content-Type comes
@@ -583,6 +617,74 @@ export const DELETED_SCOPES = ["active", "deleted", "all"];
583
617
  /** The platform's own defaults for the two soft-delete read parameters. */
584
618
  export const DEFAULT_DELETED_SCOPE = "active"; // data.txt:76
585
619
  export const DEFAULT_INCLUDE_DELETED_RELATIONS = true; // data.txt:75
620
+ /** `host::entity` -> field paths this tenant has rejected, for this process. */
621
+ const rejectedFields = new Map();
622
+ function rejectKey(ctx, entity) {
623
+ return `${ctx.host}::${entity}`;
624
+ }
625
+ /**
626
+ * The field paths the platform rejected — and ONLY those from the projection.
627
+ *
628
+ * A field named in a filter or an order is part of the question being asked;
629
+ * dropping it would answer a different one, so those are left to fail loudly
630
+ * (data.txt:145-148 — path / location / kind / reason).
631
+ */
632
+ function invalidProjectionPaths(e) {
633
+ if (!(e instanceof ApiError) || e.status !== 400) {
634
+ return [];
635
+ }
636
+ const list = e.parsedBody?.invalidFields;
637
+ if (!Array.isArray(list)) {
638
+ return [];
639
+ }
640
+ return list
641
+ .filter((f) => Boolean(f) &&
642
+ typeof f.path === "string" &&
643
+ f.location === "fields")
644
+ .map((f) => f.path);
645
+ }
646
+ /**
647
+ * POST an entity read, trimming this server's own projection to fit the tenant.
648
+ *
649
+ * The platform names the offending paths in its own 400, so the fix is to
650
+ * believe it: drop them, retry once, and remember for the rest of the process
651
+ * so the wasted round trip is paid once per tenant and entity, not per call.
652
+ */
653
+ async function postEntityRead(entity, path, body, fields, opts = {}) {
654
+ const ctx = opts.ctx ?? tenants.current();
655
+ const own = fields !== null && isOwnProjection(fields);
656
+ let payload = body;
657
+ if (own) {
658
+ const known = rejectedFields.get(rejectKey(ctx, entity));
659
+ if (known && known.size > 0) {
660
+ payload = { ...body, fields: withoutPaths(fields, known) };
661
+ }
662
+ }
663
+ try {
664
+ return await makeRequest("POST", path, payload, opts);
665
+ }
666
+ catch (e) {
667
+ if (!own) {
668
+ throw e;
669
+ }
670
+ const bad = invalidProjectionPaths(e);
671
+ if (bad.length === 0) {
672
+ throw e;
673
+ }
674
+ const key = rejectKey(ctx, entity);
675
+ const known = rejectedFields.get(key) ?? new Set();
676
+ const before = known.size;
677
+ for (const p of bad) {
678
+ known.add(p);
679
+ }
680
+ rejectedFields.set(key, known);
681
+ if (known.size === before) {
682
+ throw e; // the retry named the same fields — the problem is elsewhere
683
+ }
684
+ debug(`${entity}: this tenant has no ${bad.join(", ")} — retrying without them`);
685
+ return await makeRequest("POST", path, { ...body, fields: withoutPaths(fields, known) }, opts);
686
+ }
687
+ }
586
688
  export async function searchEntity(entity, filters = null, fields = null, limit = 50, offset = 0, orderBy = null, searchValue = "", operator = "and", deletedScope = DEFAULT_DELETED_SCOPE, includeDeletedRelations = DEFAULT_INCLUDE_DELETED_RELATIONS) {
587
689
  const body = {
588
690
  conditions: { operator, filters: filters !== null ? filters : [] },
@@ -609,7 +711,7 @@ export async function searchEntity(entity, filters = null, fields = null, limit
609
711
  // callers can page over removed rows (search body = Select body, data.txt:226).
610
712
  deletedScope,
611
713
  };
612
- const result = await makeRequest("POST", dataUrl(entity, "search"), body);
714
+ const result = await postEntityRead(entity, dataUrl(entity, "search"), body, fields);
613
715
  return Array.isArray(result) ? result : [];
614
716
  }
615
717
  export async function selectEntity(entity, filters, fields = null, deletedScope = DEFAULT_DELETED_SCOPE, includeDeletedRelations = DEFAULT_INCLUDE_DELETED_RELATIONS) {
@@ -620,7 +722,7 @@ export async function selectEntity(entity, filters, fields = null, deletedScope
620
722
  includeDeletedRelations, // data.txt:75 (platform default true; was hard-coded false)
621
723
  deletedScope, // data.txt:76
622
724
  };
623
- const result = await makeRequest("POST", dataUrl(entity, "select"), body, {
725
+ const result = await postEntityRead(entity, dataUrl(entity, "select"), body, fields, {
624
726
  query: { markAsView: false },
625
727
  });
626
728
  // The select endpoint returns a list of matching rows; return the first.
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Which field projections belong to THIS SERVER, and how to trim one.
3
+ *
4
+ * A tenant's entities are editable, so a field this server names may simply not
5
+ * be there — `Tasks.author` is absent on tenants that renamed it `createdBy`,
6
+ * and that one field failed every task read with an opaque 400 about a
7
+ * projection the user never chose and could not change.
8
+ *
9
+ * A projection tagged here may be trimmed to fit the tenant. One a caller
10
+ * supplied never is: quietly returning everything except what someone asked for
11
+ * is a wrong answer, where the error is at least the truth.
12
+ *
13
+ * Kept in its own dependency-free module so the tool modules can tag their
14
+ * constants without importing the transport — a tool module that imports
15
+ * httpClient for this alone breaks every test that mocks httpClient partially.
16
+ */
17
+ const OWN_PROJECTIONS = new WeakSet();
18
+ /** Mark `fields` as this server's own, so it can be pruned to fit a tenant. */
19
+ export function ownProjection(fields) {
20
+ OWN_PROJECTIONS.add(fields);
21
+ return fields;
22
+ }
23
+ /** True when `fields` is a projection this server owns. */
24
+ export function isOwnProjection(fields) {
25
+ return OWN_PROJECTIONS.has(fields);
26
+ }
27
+ /** A copy of `fields` with each dotted path removed. The original is untouched. */
28
+ export function withoutPaths(fields, paths) {
29
+ const clone = JSON.parse(JSON.stringify(fields));
30
+ for (const path of paths) {
31
+ const segments = path.split(".");
32
+ let node = clone;
33
+ for (let i = 0; i < segments.length - 1 && node; i++) {
34
+ const next = node[segments[i]];
35
+ node = next !== null && typeof next === "object" ? next : null;
36
+ }
37
+ if (node) {
38
+ delete node[segments[segments.length - 1]];
39
+ }
40
+ }
41
+ return clone;
42
+ }
@@ -9,6 +9,7 @@
9
9
  * present, and is otherwise DERIVED from the `nodes` JSON of live workflows.
10
10
  */
11
11
  import { makeRequest, searchEntity, selectEntity, insertEntity, updateEntity, removeEntity, } from "../httpClient.js";
12
+ import { ownProjection } from "../projection.js";
12
13
  import { makeFilter, jsonResponse, parseJsonParam, ACCESS_METADATA_KEYS } from "../utils.js";
13
14
  export const WORKFLOW_ENTITY = "AutomationWorkflow";
14
15
  export const EXECUTE_ENTITY = "AutomationWorkflowExecute";
@@ -19,7 +20,7 @@ export const COUNT_CAP = 1000;
19
20
  const SCAN_PAGE = 200;
20
21
  // Authoritative node-type catalog (newer builds; older ones 404 -> graph fallback).
21
22
  const NODE_CATALOG_PATH = "/api/automation/nodes";
22
- const _LIST_FIELDS = {
23
+ const _LIST_FIELDS = ownProjection({
23
24
  id: true,
24
25
  name: true,
25
26
  description: true,
@@ -28,8 +29,8 @@ const _LIST_FIELDS = {
28
29
  priority: true,
29
30
  publishedAt: true,
30
31
  updatedAt: true,
31
- };
32
- const _GRAPH_FIELDS = {
32
+ });
33
+ const _GRAPH_FIELDS = ownProjection({
33
34
  id: true,
34
35
  name: true,
35
36
  description: true,
@@ -43,8 +44,8 @@ const _GRAPH_FIELDS = {
43
44
  activeNodes: true,
44
45
  activeConnections: true,
45
46
  activeSettings: true,
46
- };
47
- const _RUN_FIELDS = {
47
+ });
48
+ const _RUN_FIELDS = ownProjection({
48
49
  id: true,
49
50
  status: true,
50
51
  mode: true,
@@ -55,7 +56,7 @@ const _RUN_FIELDS = {
55
56
  triggerEvent: true,
56
57
  triggerEntityName: true,
57
58
  error: true,
58
- };
59
+ });
59
60
  function isPlainObject(v) {
60
61
  return typeof v === "object" && v !== null && !Array.isArray(v);
61
62
  }
@@ -8,13 +8,14 @@
8
8
  * `formShema` / `formModul` is intentional and must be preserved.
9
9
  */
10
10
  import { randomUUID } from "node:crypto";
11
- import { makeRequest, searchEntity, selectEntity, insertEntity } from "../httpClient.js";
11
+ import { makeRequest, searchEntity, selectEntity, insertEntity, } from "../httpClient.js";
12
+ import { ownProjection } from "../projection.js";
12
13
  import { makeFilter, jsonResponse, parseJsonParam } from "../utils.js";
13
14
  // ---------------------------------------------------------------------------
14
15
  // Constants
15
16
  // ---------------------------------------------------------------------------
16
17
  export const ENTITY_FORMS = "Forms";
17
- export const FORM_LIST_FIELDS = {
18
+ export const FORM_LIST_FIELDS = ownProjection({
18
19
  id: true,
19
20
  name: true,
20
21
  type: true,
@@ -24,8 +25,11 @@ export const FORM_LIST_FIELDS = {
24
25
  lockedBy: { id: true, firstName: true, lastName: true },
25
26
  createdAt: true,
26
27
  updatedAt: true,
27
- };
28
- export const FORM_DETAIL_FIELDS = { ...FORM_LIST_FIELDS, data: true };
28
+ });
29
+ export const FORM_DETAIL_FIELDS = ownProjection({
30
+ ...FORM_LIST_FIELDS,
31
+ data: true,
32
+ });
29
33
  export const DEFAULT_FORM_SETTINGS = {
30
34
  id: 0,
31
35
  size: "md",
@@ -8,13 +8,19 @@
8
8
  * mutations lives one layer up (server.ts, mirroring server.py) — NOT here.
9
9
  */
10
10
  import { searchEntity, selectEntity, insertEntity, updateEntity, removeEntity, } from "../httpClient.js";
11
+ import { ownProjection } from "../projection.js";
11
12
  import { makeFilter, parseDeadline, wrapHtml, jsonResponse, localDayRange } from "../utils.js";
12
13
  import * as tenants from "../tenants.js";
13
14
  import { config } from "../config.js";
14
15
  // ---------------------------------------------------------------------------
15
16
  // Field projections
16
17
  // ---------------------------------------------------------------------------
17
- export const TASK_LIST_FIELDS = {
18
+ // `ownProjection` marks these as THIS SERVER's, not the caller's: a tenant
19
+ // that does not have one of these fields gets it pruned on first use instead of
20
+ // failing every task read. Both spellings of the person who filed the task are
21
+ // listed on purpose — tenants renamed `author` to `createdBy`, and whichever is
22
+ // absent here is dropped once, per tenant.
23
+ export const TASK_LIST_FIELDS = ownProjection({
18
24
  id: true,
19
25
  title: true,
20
26
  shortID: true,
@@ -24,6 +30,7 @@ export const TASK_LIST_FIELDS = {
24
30
  estimatedDuration: true,
25
31
  assignedTo: { id: true, firstName: true, lastName: true, fullName: true },
26
32
  author: { id: true, fullName: true },
33
+ createdBy: { id: true, fullName: true },
27
34
  project: { id: true, title: true },
28
35
  parent: { id: true, title: true },
29
36
  stage: {
@@ -37,8 +44,8 @@ export const TASK_LIST_FIELDS = {
37
44
  priority: { id: true, title: true, name: true, value: true },
38
45
  type: { id: true, title: true, color: true },
39
46
  tags: { id: true, name: true },
40
- };
41
- export const TASK_DETAIL_FIELDS = {
47
+ });
48
+ export const TASK_DETAIL_FIELDS = ownProjection({
42
49
  ...TASK_LIST_FIELDS,
43
50
  htmlDescription: true,
44
51
  plainDescription: true,
@@ -48,7 +55,7 @@ export const TASK_DETAIL_FIELDS = {
48
55
  watchers: { id: true, fullName: true },
49
56
  children: { id: true, title: true },
50
57
  attachments: { id: true, fileName: true, filePath: true },
51
- };
58
+ });
52
59
  const _ACTIVE_STATES = ["active", "inprogress"];
53
60
  /** Build the Tasks filter list shared by searchTasks and countTasks. */
54
61
  function _taskFilters(my = false, active = false, overdue = false, dueToday = false, projectId = null, workflowId = null, stageId = null, assignedToId = null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "suppa-mcp-2",
3
- "version": "1.23.0",
3
+ "version": "1.24.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": {