suppa-mcp-2 1.25.0 → 1.26.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
@@ -232,9 +232,9 @@ work normally. Erasing data for good is an admin action in the platform's own UI
232
232
 
233
233
  | Tool | Description |
234
234
  |---|---|
235
- | `suppa_search_tasks` | Search tasks (my / active / overdue / due-today filters, paginated) |
235
+ | `suppa_search_tasks` | Search tasks (my / active / overdue / due-today filters, paginated); `task_ids` reads several known tasks in one call; `fields_json` narrows each row |
236
236
  | `suppa_count_tasks` | Count tasks matching filters |
237
- | `suppa_get_task` | Get a single task |
237
+ | `suppa_get_task` | Get a single task (full details, or only `fields_json`) |
238
238
  | `suppa_create_task` | Create a task |
239
239
  | `suppa_update_task` | Update a task (confirm-gated) |
240
240
  | `suppa_delete_task` | Delete a task (confirm-gated) |
@@ -252,13 +252,13 @@ work normally. Erasing data for good is an admin action in the platform's own UI
252
252
 
253
253
  | Tool | Description |
254
254
  |---|---|
255
- | `suppa_list_docs` | List docs |
256
- | `suppa_get_doc` | Get a doc |
255
+ | `suppa_list_docs` | List docs (`fields_json` narrows each row) |
256
+ | `suppa_get_doc` | Get a doc (page tree included, or only `fields_json`) |
257
257
  | `suppa_create_doc` | Create a doc |
258
258
  | `suppa_update_doc` | Update a doc (confirm-gated) |
259
259
  | `suppa_delete_doc` | Delete a doc (confirm-gated) |
260
- | `suppa_list_pages` | List pages of a doc |
261
- | `suppa_get_page` | Get a page |
260
+ | `suppa_list_pages` | List pages of a doc (`fields_json` narrows each row) |
261
+ | `suppa_get_page` | Get a page (metadata, or only `fields_json`) |
262
262
  | `suppa_create_page` | Create a page |
263
263
  | `suppa_update_page` | Update a page (confirm-gated) |
264
264
  | `suppa_delete_page` | Delete a page (confirm-gated) |
package/dist/server.js CHANGED
@@ -79,6 +79,24 @@ const ProjectionJson = z
79
79
  .string()
80
80
  .describe('JSON projection of fields to return, e.g. {"id": true, "title": true, ' +
81
81
  '"owner": {"id": true, "fullName": true}}. Enums: {"myEnum": {"value": true}}.');
82
+ /**
83
+ * The optional projection on the task/doc read tools. Without it a read answers
84
+ * with the tool's standard field set; with it, only what was named. A model
85
+ * once made seven suppa_get_task calls to collect one shortUID per task — each
86
+ * answered with the whole detail record. This parameter, and task_ids below,
87
+ * make that one call.
88
+ */
89
+ const FieldsJsonOpt = z
90
+ .string()
91
+ .nullable()
92
+ .default(null)
93
+ .describe('Return ONLY these fields: {"id": true, "shortUID": true} or ["id", "shortUID"]; relations as ' +
94
+ 'nested objects ({"assignedTo": {"fullName": true}}). Default: this tool\'s standard field set.');
95
+ const TaskIds = z
96
+ .array(z.number().int())
97
+ .nullable()
98
+ .default(null)
99
+ .describe("Read exactly these task ids in ONE call (combined with the other filters).");
82
100
  // Soft-delete read scoping. Both mirror the platform's own defaults
83
101
  // (captures/api-entity-builder-data.txt:75-76) — this server used to force
84
102
  // includeDeletedRelations=false, which silently hid soft-deleted relations.
@@ -254,7 +272,7 @@ DATA BASICS
254
272
  - Reads are compact: relation objects omit deletedAt when null (a live row); schema reads omit nulls, false flags and default options and carry a _legend (full=true returns the raw form).
255
273
 
256
274
  SEARCH & FILTERS — suppa_search_records' description carries the comparators, nested AND/OR groups, dotted field paths, "$current-user", paging and the auto-diagnosis of an empty result. Read it before your first search.
257
- - PROJECT ONLY THE FIELDS YOU NEED (fields_json): a 600-character answer instead of a 50 000-character one, and every answer is re-sent on every later turn of the conversation.
275
+ - PROJECT ONLY THE FIELDS YOU NEED: fields_json is on suppa_search_records AND on every task/doc read (suppa_get_task, suppa_search_tasks — which also takes task_ids, so several tasks are ONE call, never one suppa_get_task each — suppa_get_doc, suppa_list_pages, …). A 600-character answer instead of a 50 000-character one, re-sent on every later turn.
258
276
  - Unsure of the schema: suppa_list_entities → suppa_describe_entity → suppa_search_records. One record by id needs no filters: suppa_get_record / suppa_get_task / suppa_get_doc.
259
277
 
260
278
  APPROVAL GATES (human-in-the-loop)
@@ -344,8 +362,12 @@ export function buildServer() {
344
362
  annotations: _READ,
345
363
  }, async () => text(await tasks.getMe()));
346
364
  reg("suppa_search_tasks", {
347
- description: "Search tasks. Use my=true for your tasks, active=true for open tasks, or search by title substring.",
365
+ description: "Search tasks. Use my=true for your tasks, active=true for open tasks, or search by title substring.\n" +
366
+ " Several known tasks: task_ids=[…] reads them in ONE call. fields_json narrows each row to\n" +
367
+ " what you need — task_ids + fields_json replaces N suppa_get_task calls.",
348
368
  inputSchema: {
369
+ task_ids: TaskIds,
370
+ fields_json: FieldsJsonOpt,
349
371
  search: TaskSearch.default(""),
350
372
  my: MyFlag.default(false),
351
373
  active: ActiveFlag.default(false),
@@ -359,7 +381,7 @@ export function buildServer() {
359
381
  offset: z.number().int().default(0),
360
382
  },
361
383
  annotations: _READ,
362
- }, async (a) => text(await tasks.searchTasks(a.search, a.my, a.active, a.overdue, a.due_today, a.project_id, a.workflow_id, a.stage_id, a.assigned_to_id, a.limit, a.offset)));
384
+ }, async (a) => text(await tasks.searchTasks(a.search, a.my, a.active, a.overdue, a.due_today, a.project_id, a.workflow_id, a.stage_id, a.assigned_to_id, a.limit, a.offset, a.task_ids, a.fields_json)));
363
385
  reg("suppa_count_tasks", {
364
386
  description: "Count tasks matching filters without returning full data.",
365
387
  inputSchema: {
@@ -374,11 +396,13 @@ export function buildServer() {
374
396
  annotations: _READ,
375
397
  }, async (a) => text(await tasks.countTasks(a.my, a.active, a.project_id, a.workflow_id, a.search, a.overdue, a.due_today)));
376
398
  reg("suppa_get_task", {
377
- description: "Get full details of a task by its ID. The description is htmlDescription;\n" +
378
- " plainDescription is included only when it differs from that HTML with the tags removed.",
379
- inputSchema: { task_id: z.number().int() },
399
+ description: "Get a task by its ID — full details by default, or only fields_json (e.g. [\"id\", \"shortUID\"]).\n" +
400
+ " For SEVERAL tasks call suppa_search_tasks(task_ids=[…], fields_json=…) once, not this per task.\n" +
401
+ " The description is htmlDescription; plainDescription is included only when it differs\n" +
402
+ " from that HTML with the tags removed.",
403
+ inputSchema: { task_id: z.number().int(), fields_json: FieldsJsonOpt },
380
404
  annotations: _READ,
381
- }, async (a) => text(await tasks.getTask(a.task_id)));
405
+ }, async (a) => text(await tasks.getTask(a.task_id, a.fields_json)));
382
406
  reg("suppa_create_task", {
383
407
  description: "Create a new task. Deadline accepts: 'today', 'tomorrow', '+3d', '+2h', '+30m', '+1w', or ISO datetime.\n" +
384
408
  " HTML: plain text is auto-wrapped in <p>…</p>; to pass raw HTML, start the\n" +
@@ -559,21 +583,22 @@ export function buildServer() {
559
583
  // Docs tools
560
584
  // =========================================================================
561
585
  reg("suppa_list_docs", {
562
- description: "List documents, optionally filtering by title.",
586
+ description: "List documents, optionally filtering by title. fields_json narrows each row.",
563
587
  inputSchema: {
564
588
  search: z
565
589
  .string()
566
590
  .default("")
567
591
  .describe("Case-insensitive substring of the doc title."),
568
592
  limit: z.number().int().default(20),
593
+ fields_json: FieldsJsonOpt,
569
594
  },
570
595
  annotations: _READ,
571
596
  }, async (a) => text(await docs.listDocs(a.search, a.limit)));
572
597
  reg("suppa_get_doc", {
573
- description: "Get a document by ID including its page tree.",
574
- inputSchema: { doc_id: z.number().int() },
598
+ description: "Get a document by ID including its page tree, or only fields_json.",
599
+ inputSchema: { doc_id: z.number().int(), fields_json: FieldsJsonOpt },
575
600
  annotations: _READ,
576
- }, async (a) => text(await docs.getDoc(a.doc_id)));
601
+ }, async (a) => text(await docs.getDoc(a.doc_id, a.fields_json)));
577
602
  reg("suppa_create_doc", {
578
603
  description: "Create a new document.",
579
604
  inputSchema: {
@@ -622,18 +647,19 @@ export function buildServer() {
622
647
  return text(await docs.deleteDoc(a.doc_id));
623
648
  });
624
649
  reg("suppa_list_pages", {
625
- description: "List all pages in a document.",
650
+ description: "List all pages in a document. fields_json narrows each row.",
626
651
  inputSchema: {
627
652
  doc_id: z.number().int(),
628
653
  limit: z.number().int().default(50),
654
+ fields_json: FieldsJsonOpt,
629
655
  },
630
656
  annotations: _READ,
631
- }, async (a) => text(await docs.listPages(a.doc_id, a.limit)));
657
+ }, async (a) => text(await docs.listPages(a.doc_id, a.limit, a.fields_json)));
632
658
  reg("suppa_get_page", {
633
- description: "Get a page's metadata.",
634
- inputSchema: { page_id: z.number().int() },
659
+ description: "Get a page's metadata, or only fields_json.",
660
+ inputSchema: { page_id: z.number().int(), fields_json: FieldsJsonOpt },
635
661
  annotations: _READ,
636
- }, async (a) => text(await docs.getPage(a.page_id)));
662
+ }, async (a) => text(await docs.getPage(a.page_id, a.fields_json)));
637
663
  reg("suppa_create_page", {
638
664
  description: "Create a new page in a document.",
639
665
  inputSchema: {
@@ -10,7 +10,7 @@
10
10
  */
11
11
  import { makeRequest, dataUrl, customOrderUrl, searchEntity, selectEntity, insertEntity, updateEntity, removeEntity, } from "../httpClient.js";
12
12
  import { ownProjection } from "../projection.js";
13
- import { makeFilter, stripHtml, jsonResponse, wrapHtml, unescapeUnicode, parseJsonParam, } from "../utils.js";
13
+ import { makeFilter, stripHtml, jsonResponse, wrapHtml, unescapeUnicode, parseJsonParam, parseProjectionParam, } from "../utils.js";
14
14
  // ---------------------------------------------------------------------------
15
15
  // Constants
16
16
  // ---------------------------------------------------------------------------
@@ -263,22 +263,37 @@ async function _fetchBlocks(pageId) {
263
263
  // Docs tools
264
264
  // ---------------------------------------------------------------------------
265
265
  /** List all documents, optionally filtering by title. */
266
- export async function listDocs(search = "", limit = 20) {
266
+ export async function listDocs(search = "", limit = 20, fieldsJson = null) {
267
267
  const filters = [];
268
268
  if (search) {
269
269
  filters.push(makeFilter("title", `%${search}%`, "like"));
270
270
  }
271
- const results = await searchEntity(ENTITY_DOCS, filters, DOC_FIELDS, limit);
271
+ const fields = _projection(fieldsJson, DOC_FIELDS);
272
+ if ("error" in fields)
273
+ return jsonResponse(fields);
274
+ const results = await searchEntity(ENTITY_DOCS, filters, fields.fields, limit);
272
275
  return jsonResponse(results);
273
276
  }
277
+ /** A caller's fields_json, or the tool's own projection when none was passed. */
278
+ function _projection(fieldsJson, own) {
279
+ try {
280
+ return { fields: parseProjectionParam(fieldsJson) ?? own };
281
+ }
282
+ catch (e) {
283
+ return { error: e instanceof Error ? e.message : String(e) };
284
+ }
285
+ }
274
286
  /** The list projection plus the document's pages — tagged once, at module load. */
275
287
  const DOC_DETAIL_FIELDS = ownProjection({
276
288
  ...DOC_FIELDS,
277
289
  pages: { id: true, title: true, status: true, parent: { id: true } },
278
290
  });
279
291
  /** Get a document by ID, including its pages. */
280
- export async function getDoc(docId) {
281
- const result = await selectEntity(ENTITY_DOCS, [makeFilter("id", docId)], DOC_DETAIL_FIELDS);
292
+ export async function getDoc(docId, fieldsJson = null) {
293
+ const fields = _projection(fieldsJson, DOC_DETAIL_FIELDS);
294
+ if ("error" in fields)
295
+ return jsonResponse(fields);
296
+ const result = await selectEntity(ENTITY_DOCS, [makeFilter("id", docId)], fields.fields);
282
297
  return jsonResponse(result);
283
298
  }
284
299
  /** Create a new document. */
@@ -315,13 +330,19 @@ export async function deleteDoc(docId) {
315
330
  // Pages tools
316
331
  // ---------------------------------------------------------------------------
317
332
  /** List all pages in a document. */
318
- export async function listPages(docId, limit = 50) {
319
- const results = await searchEntity(ENTITY_PAGES, [makeFilter("doc", { id: docId })], PAGE_FIELDS, limit, 0, [{ field: "createdAt", order: "asc" }]);
333
+ export async function listPages(docId, limit = 50, fieldsJson = null) {
334
+ const fields = _projection(fieldsJson, PAGE_FIELDS);
335
+ if ("error" in fields)
336
+ return jsonResponse(fields);
337
+ const results = await searchEntity(ENTITY_PAGES, [makeFilter("doc", { id: docId })], fields.fields, limit, 0, [{ field: "createdAt", order: "asc" }]);
320
338
  return jsonResponse(results);
321
339
  }
322
340
  /** Get a page by ID with metadata. */
323
- export async function getPage(pageId) {
324
- const result = await selectEntity(ENTITY_PAGES, [makeFilter("id", pageId)], PAGE_FIELDS);
341
+ export async function getPage(pageId, fieldsJson = null) {
342
+ const fields = _projection(fieldsJson, PAGE_FIELDS);
343
+ if ("error" in fields)
344
+ return jsonResponse(fields);
345
+ const result = await selectEntity(ENTITY_PAGES, [makeFilter("id", pageId)], fields.fields);
325
346
  return jsonResponse(result);
326
347
  }
327
348
  /** Create a new page in a document. */
@@ -10,7 +10,7 @@
10
10
  import { searchEntity, selectEntity, insertEntity, updateEntity, removeEntity, } from "../httpClient.js";
11
11
  import { ownProjection } from "../projection.js";
12
12
  import { dropDerivablePlainDescription, statusValue } from "../readEconomy.js";
13
- import { makeFilter, parseDeadline, wrapHtml, jsonResponse, localDayRange } from "../utils.js";
13
+ import { makeFilter, parseDeadline, parseProjectionParam, wrapHtml, jsonResponse, localDayRange, } from "../utils.js";
14
14
  import * as tenants from "../tenants.js";
15
15
  import { config } from "../config.js";
16
16
  // ---------------------------------------------------------------------------
@@ -125,12 +125,34 @@ export async function getMe() {
125
125
  *
126
126
  * Returns {"tasks": [...], "returned": N, "has_more": bool, "next_offset": int|null}.
127
127
  */
128
- export async function searchTasks(search = "", my = false, active = false, overdue = false, dueToday = false, projectId = null, workflowId = null, stageId = null, assignedToId = null, limit = 20, offset = 0) {
128
+ export async function searchTasks(search = "", my = false, active = false, overdue = false, dueToday = false, projectId = null, workflowId = null, stageId = null, assignedToId = null, limit = 20, offset = 0, taskIds = null, fieldsJson = null) {
129
129
  const filters = _taskFilters(my, active, overdue, dueToday, projectId, workflowId, stageId, assignedToId);
130
+ // Several known tasks in ONE call — the alternative was one suppa_get_task
131
+ // per task, each answering with the full detail record.
132
+ if (taskIds !== null && taskIds !== undefined) {
133
+ const ids = [...new Set(taskIds)].filter((n) => Number.isInteger(n) && n > 0);
134
+ if (ids.length !== taskIds.length) {
135
+ return jsonResponse({
136
+ error: `task_ids must be a list of distinct positive integers, got ${JSON.stringify(taskIds)}.`,
137
+ });
138
+ }
139
+ if (ids.length > 0) {
140
+ filters.push(makeFilter("id", ids, "in"));
141
+ }
142
+ }
143
+ // A caller's projection replaces the server's; it is theirs, so it is neither
144
+ // pruned to the tenant nor trimmed on the way back.
145
+ let fields = TASK_LIST_FIELDS;
146
+ try {
147
+ fields = parseProjectionParam(fieldsJson) ?? TASK_LIST_FIELDS;
148
+ }
149
+ catch (e) {
150
+ return jsonResponse({ error: e instanceof Error ? e.message : String(e) });
151
+ }
130
152
  limit = Math.max(1, Math.min(limit, 500)); // cap a page; deeper results come via offset paging
131
153
  offset = Math.max(0, offset); // clamp BEFORE computing next_offset, or pages overlap
132
154
  // Fetch one extra row so the agent learns whether another page exists.
133
- const rows = await searchEntity("Tasks", filters, TASK_LIST_FIELDS, limit + 1, offset, null, search);
155
+ const rows = await searchEntity("Tasks", filters, fields, limit + 1, offset, null, search);
134
156
  const hasMore = rows.length > limit;
135
157
  return jsonResponse({
136
158
  tasks: rows.slice(0, limit),
@@ -163,7 +185,18 @@ export async function countTasks(my = false, active = false, projectId = null, w
163
185
  });
164
186
  }
165
187
  /** Get full details of a single task by ID. */
166
- export async function getTask(taskId) {
188
+ export async function getTask(taskId, fieldsJson = null) {
189
+ let fields;
190
+ try {
191
+ fields = parseProjectionParam(fieldsJson);
192
+ }
193
+ catch (e) {
194
+ return jsonResponse({ error: e instanceof Error ? e.message : String(e) });
195
+ }
196
+ if (fields) {
197
+ // The caller named the fields — return exactly those, untouched.
198
+ return jsonResponse(await selectEntity("Tasks", [makeFilter("id", taskId)], fields));
199
+ }
167
200
  const result = await selectEntity("Tasks", [makeFilter("id", taskId)], TASK_DETAIL_FIELDS);
168
201
  // plainDescription is dropped only when it is htmlDescription with the tags
169
202
  // removed — see readEconomy.ts; when they differ, both come back.
package/dist/utils.js CHANGED
@@ -246,6 +246,43 @@ export function parseJsonParam(raw, param, expect = "any") {
246
246
  }
247
247
  return value;
248
248
  }
249
+ /**
250
+ * A caller's fields_json as the wire projection: an object projection is
251
+ * taken as is, a list of names becomes {name: true}. Returns null when nothing
252
+ * was passed — the tool's own projection then applies — and throws an
253
+ * instructive Error for anything else, so a typo answers with the fix rather
254
+ * than with a 400 about a field nobody named.
255
+ *
256
+ * A projection parsed here is the CALLER's: it is never pruned to fit the
257
+ * tenant and never trimmed on the way back (see projection.ts, readEconomy.ts).
258
+ */
259
+ export function parseProjectionParam(raw, param = "fields_json") {
260
+ if (raw === null || raw === undefined || raw === "") {
261
+ return null;
262
+ }
263
+ const value = parseJsonParam(raw, param, "any");
264
+ if (Array.isArray(value)) {
265
+ const bad = value.find((f) => typeof f !== "string" || f.trim() === "");
266
+ if (bad !== undefined) {
267
+ throw new Error(`${param}: a projection list must hold field names as strings — got ` +
268
+ `${JSON.stringify(bad)}. Pass ["id", "shortUID"] or {"id": true, "shortUID": true}.`);
269
+ }
270
+ if (value.length === 0) {
271
+ throw new Error(`${param}: an empty projection returns nothing — name at least one field.`);
272
+ }
273
+ // fromEntries defines own properties, so a field literally named
274
+ // "__proto__" survives where `obj[name] = true` would set the prototype.
275
+ return Object.fromEntries(value.map((f) => [f, true]));
276
+ }
277
+ if (typeof value === "object" && value !== null) {
278
+ if (Object.keys(value).length === 0) {
279
+ throw new Error(`${param}: an empty projection returns nothing — name at least one field.`);
280
+ }
281
+ return value;
282
+ }
283
+ throw new Error(`${param} must be a JSON object projection ({"id": true, "shortUID": true}) or a list of ` +
284
+ `field names (["id", "shortUID"]), got ${typeName(value)}.`);
285
+ }
249
286
  function matchesExpectation(value, expect) {
250
287
  const isArray = Array.isArray(value);
251
288
  const isPlainObject = typeof value === "object" && value !== null && !isArray;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "suppa-mcp-2",
3
- "version": "1.25.0",
3
+ "version": "1.26.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": {