suppa-mcp-2 1.5.0 → 1.6.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 +422 -419
- package/dist/bin.js +1 -1
- package/dist/httpClient.js +29 -0
- package/dist/server.js +76 -3
- package/dist/tools/entity.js +26 -3
- package/dist/tools/files.js +192 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,419 +1,422 @@
|
|
|
1
|
-
# suppa-mcp-2
|
|
2
|
-
|
|
3
|
-
MCP (Model Context Protocol) server for the **Suppa 2.0** platform ([modern.suppa.me](https://modern.suppa.me)).
|
|
4
|
-
Allows LLMs (Claude, GPT, Copilot, Cursor, etc.) to manage Tasks, Docs/Pages, Entities & Schema, Forms, Automations, and file attachments through standardised MCP tools — with multi-tenant Google authentication.
|
|
5
|
-
|
|
6
|
-
This is the Node.js/TypeScript port of the Python [`suppa-mcp`](https://pypi.org/project/suppa-mcp/) package, published to npm as **`suppa-mcp-2`**.
|
|
7
|
-
|
|
8
|
-
[](https://www.npmjs.com/package/suppa-mcp-2)
|
|
9
|
-
[](LICENSE)
|
|
10
|
-
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
## Quick start
|
|
14
|
-
|
|
15
|
-
### Run directly with npx
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
npx suppa-mcp-2
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
### Or install from npm
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
npm install -g suppa-mcp-2
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
No API key needed to start — the server authenticates interactively via the `suppa_login` tool (see [Authentication](#authentication)).
|
|
28
|
-
|
|
29
|
-
---
|
|
30
|
-
|
|
31
|
-
## Authentication
|
|
32
|
-
|
|
33
|
-
There is **no API key to paste**. Run the **`suppa_login`** tool from your MCP client — it opens a browser for Google sign-in, then stores the resulting tokens in the OS keychain (Windows Credential Manager / macOS Keychain / libsecret). The server is **multi-tenant**: log in to more than one Suppa tenant and switch with `suppa_use_tenant`.
|
|
34
|
-
|
|
35
|
-
Credentials stay on your machine, are sent only in the `Authorization` header to your configured `SUPPA_BASE_URL`, and are **never** exposed to the AI agent. A `SUPPA_API_KEY` env var is an optional CI-only alternative.
|
|
36
|
-
|
|
37
|
-
---
|
|
38
|
-
|
|
39
|
-
## Configuration
|
|
40
|
-
|
|
41
|
-
All variables are optional — the server works out of the box and authenticates via `suppa_login`.
|
|
42
|
-
|
|
43
|
-
| Variable | Default | Description |
|
|
44
|
-
|---|---|---|
|
|
45
|
-
| `SUPPA_BASE_URL` | `https://modern.suppa.me` | Platform base URL (the active tenant) |
|
|
46
|
-
| `SUPPA_API_KEY` | (none) | JWT / API key; skips interactive login when set (CI) |
|
|
47
|
-
| `SUPPA_REFRESH_TOKEN` | (none) | Refresh token; paired with `SUPPA_API_KEY` for long-lived CI sessions |
|
|
48
|
-
| `SUPPA_LANG` | `en` | Language (`en` / `uk`) |
|
|
49
|
-
| `SUPPA_LANGS` | (auto) | Languages a multi-language title/Name is written into. When unset, resolved from the platform (the languages already used by existing entity titles), falling back to `en,uk`. Set e.g. `en,uk` to force it. |
|
|
50
|
-
| `SUPPA_TZ` | `Europe/Kyiv` | Timezone |
|
|
51
|
-
| `SUPPA_MCP_LOGIN_PORT` | `8080` | Local loopback port for the browser login callback |
|
|
52
|
-
| `SUPPA_MCP_HOME` | `~/.suppa-mcp` | Directory for the tenant registry |
|
|
53
|
-
| `SUPPA_HTTP_TIMEOUT` | `60` | Per-request timeout, seconds |
|
|
54
|
-
| `SUPPA_MCP_DEBUG` | (off) | `1` logs each request line to stderr |
|
|
55
|
-
|
|
56
|
-
---
|
|
57
|
-
|
|
58
|
-
## Use with Claude Desktop
|
|
59
|
-
|
|
60
|
-
Add to your `claude_desktop_config.json`:
|
|
61
|
-
|
|
62
|
-
```json
|
|
63
|
-
{
|
|
64
|
-
"mcpServers": {
|
|
65
|
-
"suppa-2.0": {
|
|
66
|
-
"command": "npx",
|
|
67
|
-
"args": ["-y", "suppa-mcp-2"]
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
## Use with Cursor
|
|
74
|
-
|
|
75
|
-
Add to `.cursor/mcp.json` in your project:
|
|
76
|
-
|
|
77
|
-
```json
|
|
78
|
-
{
|
|
79
|
-
"mcpServers": {
|
|
80
|
-
"suppa-2.0": {
|
|
81
|
-
"command": "npx",
|
|
82
|
-
"args": ["-y", "suppa-mcp-2"]
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
## Use with VS Code (Copilot)
|
|
89
|
-
|
|
90
|
-
Add to `.vscode/mcp.json`:
|
|
91
|
-
|
|
92
|
-
```json
|
|
93
|
-
{
|
|
94
|
-
"servers": {
|
|
95
|
-
"suppa-2.0": {
|
|
96
|
-
"command": "npx",
|
|
97
|
-
"args": ["-y", "suppa-mcp-2"]
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
Then run **`suppa_login`** once per tenant to authenticate.
|
|
104
|
-
|
|
105
|
-
---
|
|
106
|
-
|
|
107
|
-
## Agent workflow
|
|
108
|
-
|
|
109
|
-
When an AI agent connects, the server provides built-in instructions describing the correct workflow. Auth first, then discover schema before reading or writing data:
|
|
110
|
-
|
|
111
|
-
```
|
|
112
|
-
┌─────────────────────────────────────────────────────────┐
|
|
113
|
-
│ 0. AUTHENTICATE (once per tenant) │
|
|
114
|
-
│ suppa_login — Google browser sign-in │
|
|
115
|
-
│ suppa_use_tenant — switch active tenant │
|
|
116
|
-
├─────────────────────────────────────────────────────────┤
|
|
117
|
-
│ 1. DISCOVER ENTITIES │
|
|
118
|
-
│ suppa_list_entities(search?: "task") │
|
|
119
|
-
│ suppa_search_entities — fuzzy-find + record count │
|
|
120
|
-
├─────────────────────────────────────────────────────────┤
|
|
121
|
-
│ 2. DISCOVER FIELDS │
|
|
122
|
-
│ suppa_describe_entity(entity_name) │
|
|
123
|
-
│ suppa_list_field_types / suppa_list_tabular_parts │
|
|
124
|
-
├─────────────────────────────────────────────────────────┤
|
|
125
|
-
│ 3. READ DATA │
|
|
126
|
-
│ suppa_search_records / suppa_get_record │
|
|
127
|
-
│ suppa_search_tasks / suppa_get_task / … │
|
|
128
|
-
│ suppa_list_docs / suppa_read_page / suppa_get_blocks │
|
|
129
|
-
│ suppa_list_automations / suppa_get_automation │
|
|
130
|
-
├─────────────────────────────────────────────────────────┤
|
|
131
|
-
│ 4. WRITE DATA (destructive/edit tools are confirm-gated)│
|
|
132
|
-
│ suppa_create_record / suppa_update_record │
|
|
133
|
-
│ suppa_copy_record / suppa_restore_record │
|
|
134
|
-
│ suppa_create_entity / suppa_add_field │
|
|
135
|
-
│ suppa_create_automation / suppa_publish_automation │
|
|
136
|
-
└─────────────────────────────────────────────────────────┘
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
> **Important:** discover with `suppa_list_entities` → `suppa_describe_entity` before reading or writing — field names, types, and filters vary between entities. Edit/delete tools return a **confirmation preview** first and only apply when re-called with `confirm=true`.
|
|
140
|
-
|
|
141
|
-
### Deletes are reversible — permanent delete is blocked
|
|
142
|
-
|
|
143
|
-
This server performs **reversible deletes only**. Every delete tool calls the platform's
|
|
144
|
-
soft delete, `POST /core/data/:entity/remove`, which sets `deletedAt` and leaves the row in
|
|
145
|
-
the table; `suppa_restore_record` clears it again.
|
|
146
|
-
|
|
147
|
-
The platform's permanent delete — `POST /core/data/:entity/delete`, where *"the rows leave
|
|
148
|
-
the table and cannot be restored"* — is **deliberately unavailable here**, and the block is
|
|
149
|
-
not a tool-level check that a future tool could miss: `src/httpClient.ts` refuses that route
|
|
150
|
-
shape at the single choke point every request to a 2.0 tenant passes through — `makeRequest`
|
|
151
|
-
and `makeRequestRawBytes` — before any `fetch`. No tool, parameter, `confirm=true` or direct
|
|
152
|
-
`makeRequest` call can reach it, and an attempt raises
|
|
153
|
-
|
|
154
|
-
```
|
|
155
|
-
REFUSED BY POLICY — permanent delete is not available through this server. …
|
|
156
|
-
Use the reversible pair instead: /remove … undone with suppa_restore_record.
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
Neighbouring routes are untouched: `/remove`, `/restore`, `/copy/:id`,
|
|
160
|
-
`/core/builder/:entity/remove-fields` and an entity legitimately named `DeleteRequests` all
|
|
161
|
-
work normally. Erasing data for good is an admin action in the platform's own UI.
|
|
162
|
-
|
|
163
|
-
---
|
|
164
|
-
|
|
165
|
-
## Available tools
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
### Session & identity
|
|
170
|
-
|
|
171
|
-
| Tool | Description |
|
|
172
|
-
|---|---|
|
|
173
|
-
| `suppa_get_me` | Current authenticated user's profile |
|
|
174
|
-
| `suppa_login` | Google browser sign-in for a tenant (stores tokens in OS keychain) |
|
|
175
|
-
| `suppa_use_tenant` | Switch the active tenant (alias / host / URL) |
|
|
176
|
-
| `suppa_list_tenants` | List known tenants + which is active / authenticated |
|
|
177
|
-
| `suppa_logout` | Remove stored credentials for a tenant |
|
|
178
|
-
| `suppa_diagnostics` | Validate the whole multi-tenant setup |
|
|
179
|
-
| `suppa_health_check` | Config + upstream connectivity check |
|
|
180
|
-
|
|
181
|
-
### Tasks
|
|
182
|
-
|
|
183
|
-
| Tool | Description |
|
|
184
|
-
|---|---|
|
|
185
|
-
| `suppa_search_tasks` | Search tasks (my / active / overdue / due-today filters, paginated) |
|
|
186
|
-
| `suppa_count_tasks` | Count tasks matching filters |
|
|
187
|
-
| `suppa_get_task` | Get a single task |
|
|
188
|
-
| `suppa_create_task` | Create a task |
|
|
189
|
-
| `suppa_update_task` | Update a task (confirm-gated) |
|
|
190
|
-
| `suppa_delete_task` | Delete a task (confirm-gated) |
|
|
191
|
-
| `suppa_move_task` | Move a task to another stage (confirm-gated) |
|
|
192
|
-
| `suppa_close_task` | Close a task (confirm-gated) |
|
|
193
|
-
| `suppa_add_comment` | Add a comment (supports @mentions) |
|
|
194
|
-
| `suppa_get_comments` | Get comments on a task |
|
|
195
|
-
| `suppa_attach_file` | Attach a local file to a task |
|
|
196
|
-
| `suppa_list_workflows` | List Task workflows |
|
|
197
|
-
| `suppa_list_stages` | List stages of a workflow |
|
|
198
|
-
| `suppa_list_task_types` | List task types |
|
|
199
|
-
| `suppa_search_users` | Search users (feeds assignee / mentions) |
|
|
200
|
-
|
|
201
|
-
### Docs & pages
|
|
202
|
-
|
|
203
|
-
| Tool | Description |
|
|
204
|
-
|---|---|
|
|
205
|
-
| `suppa_list_docs` | List docs |
|
|
206
|
-
| `suppa_get_doc` | Get a doc |
|
|
207
|
-
| `suppa_create_doc` | Create a doc |
|
|
208
|
-
| `suppa_update_doc` | Update a doc (confirm-gated) |
|
|
209
|
-
| `suppa_delete_doc` | Delete a doc (confirm-gated) |
|
|
210
|
-
| `suppa_list_pages` | List pages of a doc |
|
|
211
|
-
| `suppa_get_page` | Get a page |
|
|
212
|
-
| `suppa_create_page` | Create a page |
|
|
213
|
-
| `suppa_update_page` | Update a page (confirm-gated) |
|
|
214
|
-
| `suppa_delete_page` | Delete a page (confirm-gated) |
|
|
215
|
-
| `suppa_get_blocks` | Get raw blocks of a page |
|
|
216
|
-
| `suppa_read_page` | Read a page rendered to text |
|
|
217
|
-
| `suppa_create_blocks` | Create blocks from a JSON array (11 block types) |
|
|
218
|
-
| `suppa_insert_block` | Insert a block at a position |
|
|
219
|
-
| `suppa_update_block` | Update a block (confirm-gated) |
|
|
220
|
-
| `suppa_delete_block` | Delete a block (confirm-gated) |
|
|
221
|
-
| `suppa_reorder_blocks` | Reorder blocks on a page |
|
|
222
|
-
|
|
223
|
-
### Entities & records
|
|
224
|
-
|
|
225
|
-
| Tool | Description |
|
|
226
|
-
|---|---|
|
|
227
|
-
| `suppa_list_entities` | List entities (tables) |
|
|
228
|
-
| `suppa_describe_entity` | Field definitions + types for an entity |
|
|
229
|
-
| `suppa_list_tabular_parts` | List tabular parts (ТЧ) of an entity |
|
|
230
|
-
| `suppa_search_records` | Search / filter records in any entity — nested AND/OR groups, auto-diagnoses an empty result (`deleted_scope` finds soft-deleted rows) |
|
|
231
|
-
| `suppa_validate_select` | Check a select/filter payload against the entity without running it — names the field that does not resolve |
|
|
232
|
-
| `suppa_get_record` | Get a single record (`deleted_scope` reads a soft-deleted one) |
|
|
233
|
-
| `suppa_create_entity` | Create a new entity (`options_json`: comments / globalSearch / hierarchy …) |
|
|
234
|
-
| `suppa_create_tabular_part` | Create a tabular part (owned rows) of a parent |
|
|
235
|
-
| `suppa_add_field` | Add a field to an entity (`options_json`: searchable / showInTable / canFilter …) |
|
|
236
|
-
| `suppa_update_field` | Edit an existing field — name, title, flags, options, encryption (confirm-gated) |
|
|
237
|
-
| `suppa_update_entity_options` | Toggle the 15 per-entity features — comments, hierarchy, approvals … (confirm-gated) |
|
|
238
|
-
| `suppa_add_enum_values` | Add values to an enum field |
|
|
239
|
-
| `suppa_set_title_field` | Set the representative/title field |
|
|
240
|
-
| `suppa_list_field_types` | List supported field types |
|
|
241
|
-
| `suppa_create_record` | Create a record — or a batch, by passing an array of records (one request) |
|
|
242
|
-
| `suppa_update_record` | Update a record (confirm-gated) |
|
|
243
|
-
| `suppa_delete_record` | Soft-delete a record — reversible (confirm-gated); permanent delete is blocked server-wide |
|
|
244
|
-
| `suppa_restore_record` | Undo a soft delete: clear `deletedAt` on a record (confirm-gated) |
|
|
245
|
-
| `suppa_copy_record` | Duplicate a record, optionally with its files / related records |
|
|
246
|
-
| `suppa_attach_file_to_record` | Attach a local file to any record |
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
|
254
|
-
|
|
255
|
-
| `
|
|
256
|
-
| `
|
|
257
|
-
| `
|
|
258
|
-
| `
|
|
259
|
-
| `
|
|
260
|
-
| `
|
|
261
|
-
| `
|
|
262
|
-
| `
|
|
263
|
-
| `
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
|
271
|
-
|
|
272
|
-
| `
|
|
273
|
-
| `
|
|
274
|
-
| `
|
|
275
|
-
| `
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
|
283
|
-
|
|
284
|
-
| `
|
|
285
|
-
| `
|
|
286
|
-
| `
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
|
298
|
-
|
|
299
|
-
| `
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
```
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
(
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
#
|
|
356
|
-
npm
|
|
357
|
-
|
|
358
|
-
#
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
#
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
#
|
|
365
|
-
npm
|
|
366
|
-
|
|
367
|
-
#
|
|
368
|
-
npm
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
#
|
|
380
|
-
npm
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
│ ├──
|
|
396
|
-
│ ├──
|
|
397
|
-
│ ├──
|
|
398
|
-
│ ├──
|
|
399
|
-
│ ├──
|
|
400
|
-
│ ├──
|
|
401
|
-
│
|
|
402
|
-
│
|
|
403
|
-
│
|
|
404
|
-
│
|
|
405
|
-
│
|
|
406
|
-
├──
|
|
407
|
-
├──
|
|
408
|
-
|
|
409
|
-
├──
|
|
410
|
-
├──
|
|
411
|
-
├──
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
1
|
+
# suppa-mcp-2
|
|
2
|
+
|
|
3
|
+
MCP (Model Context Protocol) server for the **Suppa 2.0** platform ([modern.suppa.me](https://modern.suppa.me)).
|
|
4
|
+
Allows LLMs (Claude, GPT, Copilot, Cursor, etc.) to manage Tasks, Docs/Pages, Entities & Schema, Forms, Automations, and file attachments through standardised MCP tools — with multi-tenant Google authentication.
|
|
5
|
+
|
|
6
|
+
This is the Node.js/TypeScript port of the Python [`suppa-mcp`](https://pypi.org/project/suppa-mcp/) package, published to npm as **`suppa-mcp-2`**.
|
|
7
|
+
|
|
8
|
+
[](https://www.npmjs.com/package/suppa-mcp-2)
|
|
9
|
+
[](LICENSE)
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
### Run directly with npx
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npx suppa-mcp-2
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Or install from npm
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install -g suppa-mcp-2
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
No API key needed to start — the server authenticates interactively via the `suppa_login` tool (see [Authentication](#authentication)).
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Authentication
|
|
32
|
+
|
|
33
|
+
There is **no API key to paste**. Run the **`suppa_login`** tool from your MCP client — it opens a browser for Google sign-in, then stores the resulting tokens in the OS keychain (Windows Credential Manager / macOS Keychain / libsecret). The server is **multi-tenant**: log in to more than one Suppa tenant and switch with `suppa_use_tenant`.
|
|
34
|
+
|
|
35
|
+
Credentials stay on your machine, are sent only in the `Authorization` header to your configured `SUPPA_BASE_URL`, and are **never** exposed to the AI agent. A `SUPPA_API_KEY` env var is an optional CI-only alternative.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Configuration
|
|
40
|
+
|
|
41
|
+
All variables are optional — the server works out of the box and authenticates via `suppa_login`.
|
|
42
|
+
|
|
43
|
+
| Variable | Default | Description |
|
|
44
|
+
|---|---|---|
|
|
45
|
+
| `SUPPA_BASE_URL` | `https://modern.suppa.me` | Platform base URL (the active tenant) |
|
|
46
|
+
| `SUPPA_API_KEY` | (none) | JWT / API key; skips interactive login when set (CI) |
|
|
47
|
+
| `SUPPA_REFRESH_TOKEN` | (none) | Refresh token; paired with `SUPPA_API_KEY` for long-lived CI sessions |
|
|
48
|
+
| `SUPPA_LANG` | `en` | Language (`en` / `uk`) |
|
|
49
|
+
| `SUPPA_LANGS` | (auto) | Languages a multi-language title/Name is written into. When unset, resolved from the platform (the languages already used by existing entity titles), falling back to `en,uk`. Set e.g. `en,uk` to force it. |
|
|
50
|
+
| `SUPPA_TZ` | `Europe/Kyiv` | Timezone |
|
|
51
|
+
| `SUPPA_MCP_LOGIN_PORT` | `8080` | Local loopback port for the browser login callback |
|
|
52
|
+
| `SUPPA_MCP_HOME` | `~/.suppa-mcp` | Directory for the tenant registry |
|
|
53
|
+
| `SUPPA_HTTP_TIMEOUT` | `60` | Per-request timeout, seconds |
|
|
54
|
+
| `SUPPA_MCP_DEBUG` | (off) | `1` logs each request line to stderr |
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Use with Claude Desktop
|
|
59
|
+
|
|
60
|
+
Add to your `claude_desktop_config.json`:
|
|
61
|
+
|
|
62
|
+
```json
|
|
63
|
+
{
|
|
64
|
+
"mcpServers": {
|
|
65
|
+
"suppa-2.0": {
|
|
66
|
+
"command": "npx",
|
|
67
|
+
"args": ["-y", "suppa-mcp-2"]
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Use with Cursor
|
|
74
|
+
|
|
75
|
+
Add to `.cursor/mcp.json` in your project:
|
|
76
|
+
|
|
77
|
+
```json
|
|
78
|
+
{
|
|
79
|
+
"mcpServers": {
|
|
80
|
+
"suppa-2.0": {
|
|
81
|
+
"command": "npx",
|
|
82
|
+
"args": ["-y", "suppa-mcp-2"]
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Use with VS Code (Copilot)
|
|
89
|
+
|
|
90
|
+
Add to `.vscode/mcp.json`:
|
|
91
|
+
|
|
92
|
+
```json
|
|
93
|
+
{
|
|
94
|
+
"servers": {
|
|
95
|
+
"suppa-2.0": {
|
|
96
|
+
"command": "npx",
|
|
97
|
+
"args": ["-y", "suppa-mcp-2"]
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Then run **`suppa_login`** once per tenant to authenticate.
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## Agent workflow
|
|
108
|
+
|
|
109
|
+
When an AI agent connects, the server provides built-in instructions describing the correct workflow. Auth first, then discover schema before reading or writing data:
|
|
110
|
+
|
|
111
|
+
```
|
|
112
|
+
┌─────────────────────────────────────────────────────────┐
|
|
113
|
+
│ 0. AUTHENTICATE (once per tenant) │
|
|
114
|
+
│ suppa_login — Google browser sign-in │
|
|
115
|
+
│ suppa_use_tenant — switch active tenant │
|
|
116
|
+
├─────────────────────────────────────────────────────────┤
|
|
117
|
+
│ 1. DISCOVER ENTITIES │
|
|
118
|
+
│ suppa_list_entities(search?: "task") │
|
|
119
|
+
│ suppa_search_entities — fuzzy-find + record count │
|
|
120
|
+
├─────────────────────────────────────────────────────────┤
|
|
121
|
+
│ 2. DISCOVER FIELDS │
|
|
122
|
+
│ suppa_describe_entity(entity_name) │
|
|
123
|
+
│ suppa_list_field_types / suppa_list_tabular_parts │
|
|
124
|
+
├─────────────────────────────────────────────────────────┤
|
|
125
|
+
│ 3. READ DATA │
|
|
126
|
+
│ suppa_search_records / suppa_get_record │
|
|
127
|
+
│ suppa_search_tasks / suppa_get_task / … │
|
|
128
|
+
│ suppa_list_docs / suppa_read_page / suppa_get_blocks │
|
|
129
|
+
│ suppa_list_automations / suppa_get_automation │
|
|
130
|
+
├─────────────────────────────────────────────────────────┤
|
|
131
|
+
│ 4. WRITE DATA (destructive/edit tools are confirm-gated)│
|
|
132
|
+
│ suppa_create_record / suppa_update_record │
|
|
133
|
+
│ suppa_copy_record / suppa_restore_record │
|
|
134
|
+
│ suppa_create_entity / suppa_add_field │
|
|
135
|
+
│ suppa_create_automation / suppa_publish_automation │
|
|
136
|
+
└─────────────────────────────────────────────────────────┘
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
> **Important:** discover with `suppa_list_entities` → `suppa_describe_entity` before reading or writing — field names, types, and filters vary between entities. Edit/delete tools return a **confirmation preview** first and only apply when re-called with `confirm=true`.
|
|
140
|
+
|
|
141
|
+
### Deletes are reversible — permanent delete is blocked
|
|
142
|
+
|
|
143
|
+
This server performs **reversible deletes only**. Every delete tool calls the platform's
|
|
144
|
+
soft delete, `POST /core/data/:entity/remove`, which sets `deletedAt` and leaves the row in
|
|
145
|
+
the table; `suppa_restore_record` clears it again.
|
|
146
|
+
|
|
147
|
+
The platform's permanent delete — `POST /core/data/:entity/delete`, where *"the rows leave
|
|
148
|
+
the table and cannot be restored"* — is **deliberately unavailable here**, and the block is
|
|
149
|
+
not a tool-level check that a future tool could miss: `src/httpClient.ts` refuses that route
|
|
150
|
+
shape at the single choke point every request to a 2.0 tenant passes through — `makeRequest`
|
|
151
|
+
and `makeRequestRawBytes` — before any `fetch`. No tool, parameter, `confirm=true` or direct
|
|
152
|
+
`makeRequest` call can reach it, and an attempt raises
|
|
153
|
+
|
|
154
|
+
```
|
|
155
|
+
REFUSED BY POLICY — permanent delete is not available through this server. …
|
|
156
|
+
Use the reversible pair instead: /remove … undone with suppa_restore_record.
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Neighbouring routes are untouched: `/remove`, `/restore`, `/copy/:id`,
|
|
160
|
+
`/core/builder/:entity/remove-fields` and an entity legitimately named `DeleteRequests` all
|
|
161
|
+
work normally. Erasing data for good is an admin action in the platform's own UI.
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## Available tools
|
|
166
|
+
|
|
167
|
+
87 tools across the areas below.
|
|
168
|
+
|
|
169
|
+
### Session & identity
|
|
170
|
+
|
|
171
|
+
| Tool | Description |
|
|
172
|
+
|---|---|
|
|
173
|
+
| `suppa_get_me` | Current authenticated user's profile |
|
|
174
|
+
| `suppa_login` | Google browser sign-in for a tenant (stores tokens in OS keychain) |
|
|
175
|
+
| `suppa_use_tenant` | Switch the active tenant (alias / host / URL) |
|
|
176
|
+
| `suppa_list_tenants` | List known tenants + which is active / authenticated |
|
|
177
|
+
| `suppa_logout` | Remove stored credentials for a tenant |
|
|
178
|
+
| `suppa_diagnostics` | Validate the whole multi-tenant setup |
|
|
179
|
+
| `suppa_health_check` | Config + upstream connectivity check |
|
|
180
|
+
|
|
181
|
+
### Tasks
|
|
182
|
+
|
|
183
|
+
| Tool | Description |
|
|
184
|
+
|---|---|
|
|
185
|
+
| `suppa_search_tasks` | Search tasks (my / active / overdue / due-today filters, paginated) |
|
|
186
|
+
| `suppa_count_tasks` | Count tasks matching filters |
|
|
187
|
+
| `suppa_get_task` | Get a single task |
|
|
188
|
+
| `suppa_create_task` | Create a task |
|
|
189
|
+
| `suppa_update_task` | Update a task (confirm-gated) |
|
|
190
|
+
| `suppa_delete_task` | Delete a task (confirm-gated) |
|
|
191
|
+
| `suppa_move_task` | Move a task to another stage (confirm-gated) |
|
|
192
|
+
| `suppa_close_task` | Close a task (confirm-gated) |
|
|
193
|
+
| `suppa_add_comment` | Add a comment (supports @mentions) |
|
|
194
|
+
| `suppa_get_comments` | Get comments on a task |
|
|
195
|
+
| `suppa_attach_file` | Attach a local file to a task |
|
|
196
|
+
| `suppa_list_workflows` | List Task workflows |
|
|
197
|
+
| `suppa_list_stages` | List stages of a workflow |
|
|
198
|
+
| `suppa_list_task_types` | List task types |
|
|
199
|
+
| `suppa_search_users` | Search users (feeds assignee / mentions) |
|
|
200
|
+
|
|
201
|
+
### Docs & pages
|
|
202
|
+
|
|
203
|
+
| Tool | Description |
|
|
204
|
+
|---|---|
|
|
205
|
+
| `suppa_list_docs` | List docs |
|
|
206
|
+
| `suppa_get_doc` | Get a doc |
|
|
207
|
+
| `suppa_create_doc` | Create a doc |
|
|
208
|
+
| `suppa_update_doc` | Update a doc (confirm-gated) |
|
|
209
|
+
| `suppa_delete_doc` | Delete a doc (confirm-gated) |
|
|
210
|
+
| `suppa_list_pages` | List pages of a doc |
|
|
211
|
+
| `suppa_get_page` | Get a page |
|
|
212
|
+
| `suppa_create_page` | Create a page |
|
|
213
|
+
| `suppa_update_page` | Update a page (confirm-gated) |
|
|
214
|
+
| `suppa_delete_page` | Delete a page (confirm-gated) |
|
|
215
|
+
| `suppa_get_blocks` | Get raw blocks of a page |
|
|
216
|
+
| `suppa_read_page` | Read a page rendered to text |
|
|
217
|
+
| `suppa_create_blocks` | Create blocks from a JSON array (11 block types) |
|
|
218
|
+
| `suppa_insert_block` | Insert a block at a position |
|
|
219
|
+
| `suppa_update_block` | Update a block (confirm-gated) |
|
|
220
|
+
| `suppa_delete_block` | Delete a block (confirm-gated) |
|
|
221
|
+
| `suppa_reorder_blocks` | Reorder blocks on a page |
|
|
222
|
+
|
|
223
|
+
### Entities & records
|
|
224
|
+
|
|
225
|
+
| Tool | Description |
|
|
226
|
+
|---|---|
|
|
227
|
+
| `suppa_list_entities` | List entities (tables) |
|
|
228
|
+
| `suppa_describe_entity` | Field definitions + types for an entity |
|
|
229
|
+
| `suppa_list_tabular_parts` | List tabular parts (ТЧ) of an entity |
|
|
230
|
+
| `suppa_search_records` | Search / filter records in any entity — nested AND/OR groups, auto-diagnoses an empty result (`deleted_scope` finds soft-deleted rows) |
|
|
231
|
+
| `suppa_validate_select` | Check a select/filter payload against the entity without running it — names the field that does not resolve |
|
|
232
|
+
| `suppa_get_record` | Get a single record (`deleted_scope` reads a soft-deleted one) |
|
|
233
|
+
| `suppa_create_entity` | Create a new entity (`options_json`: comments / globalSearch / hierarchy …) |
|
|
234
|
+
| `suppa_create_tabular_part` | Create a tabular part (owned rows) of a parent |
|
|
235
|
+
| `suppa_add_field` | Add a field to an entity (`options_json`: searchable / showInTable / canFilter …) |
|
|
236
|
+
| `suppa_update_field` | Edit an existing field — name, title, flags, options, encryption (confirm-gated) |
|
|
237
|
+
| `suppa_update_entity_options` | Toggle the 15 per-entity features — comments, hierarchy, approvals … (confirm-gated) |
|
|
238
|
+
| `suppa_add_enum_values` | Add values to an enum field |
|
|
239
|
+
| `suppa_set_title_field` | Set the representative/title field |
|
|
240
|
+
| `suppa_list_field_types` | List supported field types |
|
|
241
|
+
| `suppa_create_record` | Create a record — or a batch, by passing an array of records (one request) |
|
|
242
|
+
| `suppa_update_record` | Update a record (confirm-gated) |
|
|
243
|
+
| `suppa_delete_record` | Soft-delete a record — reversible (confirm-gated); permanent delete is blocked server-wide |
|
|
244
|
+
| `suppa_restore_record` | Undo a soft delete: clear `deletedAt` on a record (confirm-gated) |
|
|
245
|
+
| `suppa_copy_record` | Duplicate a record, optionally with its files / related records |
|
|
246
|
+
| `suppa_attach_file_to_record` | Attach a local file to any record |
|
|
247
|
+
| `suppa_list_record_files` | List the files attached to a record |
|
|
248
|
+
| `suppa_download_file` | Download one attachment (original, preview, or generated PDF) |
|
|
249
|
+
| `suppa_download_files_zip` | Download several attachments as a ZIP |
|
|
250
|
+
|
|
251
|
+
### Automations
|
|
252
|
+
|
|
253
|
+
| Tool | Description |
|
|
254
|
+
|---|---|
|
|
255
|
+
| `suppa_list_automations` | List automation workflows |
|
|
256
|
+
| `suppa_get_automation` | Get one automation as a normalized graph (nodes + edges) |
|
|
257
|
+
| `suppa_list_automation_runs` | List runs (executions) of an automation |
|
|
258
|
+
| `suppa_get_automation_run` | Get one run with per-node steps + trigger payload |
|
|
259
|
+
| `suppa_list_automation_node_types` | Node-type catalog (authoritative + fallback) |
|
|
260
|
+
| `suppa_get_automation_node_schema` | Parameter schema for one node type |
|
|
261
|
+
| `suppa_search_entities` | Fuzzy-find an entity by name/title (+ record count) |
|
|
262
|
+
| `suppa_create_automation` | Create an automation (pre-flight validated; draft) |
|
|
263
|
+
| `suppa_update_automation` | Update an automation (read-modify-write; confirm-gated) |
|
|
264
|
+
| `suppa_delete_automation` | Delete an automation (confirm-gated) |
|
|
265
|
+
| `suppa_publish_automation` | Publish the draft snapshot (confirm-gated) |
|
|
266
|
+
| `suppa_unpublish_automation` | Deactivate an automation (confirm-gated) |
|
|
267
|
+
|
|
268
|
+
### Forms
|
|
269
|
+
|
|
270
|
+
| Tool | Description |
|
|
271
|
+
|---|---|
|
|
272
|
+
| `suppa_list_forms` | List forms |
|
|
273
|
+
| `suppa_get_form` | Get a form |
|
|
274
|
+
| `suppa_create_form` | Create a form (optionally generated from an entity) |
|
|
275
|
+
| `suppa_update_form` | Update a form (confirm-gated) |
|
|
276
|
+
| `suppa_generate_form_schema` | Generate a grid form schema from an entity |
|
|
277
|
+
| `suppa_add_field_to_form` | Add a field element to a form (confirm-gated) |
|
|
278
|
+
| `suppa_list_form_field_types` | List form element types |
|
|
279
|
+
|
|
280
|
+
### Migration (Suppa 1.0 → 2.0) & workspace
|
|
281
|
+
|
|
282
|
+
| Tool | Description |
|
|
283
|
+
|---|---|
|
|
284
|
+
| `suppa_migrate_entities_from_v1` | Migrate 1.0 entities → 2.0 (dry-run / create / gap-fill / reconcile) |
|
|
285
|
+
| `suppa_read_v1_entities` | Read entity list from a Suppa 1.0 tenant |
|
|
286
|
+
| `suppa_read_v1_entity_props` | Read 1.0 entity field definitions |
|
|
287
|
+
| `suppa_read_v1_enum` | Read 1.0 enum values |
|
|
288
|
+
| `suppa_create_workspace` | Create a workspace + nav item |
|
|
289
|
+
| `suppa_add_menu_item` | Add a navigation-menu item |
|
|
290
|
+
|
|
291
|
+
---
|
|
292
|
+
|
|
293
|
+
## Prompts
|
|
294
|
+
|
|
295
|
+
Guided workflows clients can expose as slash commands:
|
|
296
|
+
|
|
297
|
+
| Prompt | Arguments | Description |
|
|
298
|
+
|---|---|---|
|
|
299
|
+
| `plan_my_day` | — | Triage my Suppa tasks into a prioritized day plan |
|
|
300
|
+
| `build_entity` | `entity_purpose` | Guided design + creation of a new entity, fields, enums, and a form |
|
|
301
|
+
| `migrate_from_v1` | `entity_names?` | Guided Suppa 1.0 → 2.0 schema migration (dry-run, review, execute) |
|
|
302
|
+
| `write_entity_code` | `entity_purpose` | Guided: write v2 application schema code (entities, seeds, registration) instead of API calls |
|
|
303
|
+
|
|
304
|
+
---
|
|
305
|
+
|
|
306
|
+
## Bundled agent skill: suppa-entity-code
|
|
307
|
+
|
|
308
|
+
The package ships an agent skill at `skills/suppa-entity-code/` (also installed
|
|
309
|
+
via npm) that writes **Suppa v2 application schema code** — `*.entity.ts`
|
|
310
|
+
classes, `*.seed.ts` seeds, and the `EntityModule.forFeature()` registration —
|
|
311
|
+
following the platform's declarative-migration rules, where the entity class
|
|
312
|
+
*is* the migration.
|
|
313
|
+
|
|
314
|
+
Two flows:
|
|
315
|
+
|
|
316
|
+
- **Flow A** — design a new entity/seed in an application repo.
|
|
317
|
+
- **Flow B** — port a Suppa 1.0 entity to v2 code, using the same
|
|
318
|
+
type-mapping authority as `suppa_migrate_entities_from_v1`.
|
|
319
|
+
|
|
320
|
+
It includes a static validator that catches everything `tsc` cannot:
|
|
321
|
+
|
|
322
|
+
```bash
|
|
323
|
+
node <this-skill-dir>/scripts/validate-suppa-schema.mjs <app-root>
|
|
324
|
+
# (installed via npm: node_modules/suppa-mcp-2/skills/suppa-entity-code/scripts/validate-suppa-schema.mjs)
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
Checks: SQL-string defaults, decorator misuse, thunk-less relations, an
|
|
328
|
+
`inverse` selector wrongly passed to `@ManyToOne`/`@ManyToMany` (W609) or
|
|
329
|
+
pointing at a non-relation property such as `id` on any of the four relation
|
|
330
|
+
decorators (E111), seed idempotency (importKeyFields / `$key`), forbidden
|
|
331
|
+
seed keys, numeric relation ids, reverse `@OneToMany` references, `forFeature`
|
|
332
|
+
membership, seed dependency order, `dist/` autoload paths, tsconfig decorator
|
|
333
|
+
flags, unknown `@Entity()`/`@Column()` options or field types, and tabular-part rules —
|
|
334
|
+
the `type: 'tabular-part'` + `relationEntityName` + `owner` triad, `owner`
|
|
335
|
+
resolving to the right parent, and `owner` first in `importKeyFields`
|
|
336
|
+
(E108/E109/E110/W607) — validated against the installed `@suppa/sdk` typings
|
|
337
|
+
when resolvable, falling back to the doc tables otherwise
|
|
338
|
+
(E101/E102/E107/E501/E502). Options/records/registration arrays delivered via
|
|
339
|
+
spread or by reference can't be statically checked and fire a W606 warning
|
|
340
|
+
instead. An entity or seed left out of `EntityModule.forFeature()` fires
|
|
341
|
+
E301/E302, naming the module file to edit so the fix is a find-and-add, not a
|
|
342
|
+
search. Exit code 1 on any error. Use the `write_entity_code` MCP prompt to
|
|
343
|
+
drive it from any client.
|
|
344
|
+
|
|
345
|
+
Tabular parts (owned child sub-tables like checklist items or order lines)
|
|
346
|
+
and the remove-and-re-add-a-field semantics — a re-added field restores its
|
|
347
|
+
old data because the key defaults to `<EntityName>.<fieldName>` — are both
|
|
348
|
+
covered; see `references/tabular-parts.md` and `references/registration.md`.
|
|
349
|
+
|
|
350
|
+
---
|
|
351
|
+
|
|
352
|
+
## Development
|
|
353
|
+
|
|
354
|
+
```bash
|
|
355
|
+
# Install dependencies
|
|
356
|
+
npm install
|
|
357
|
+
|
|
358
|
+
# Build
|
|
359
|
+
npm run build
|
|
360
|
+
|
|
361
|
+
# Run locally (stdio)
|
|
362
|
+
node dist/bin.js
|
|
363
|
+
|
|
364
|
+
# Test with MCP Inspector
|
|
365
|
+
npm run inspect
|
|
366
|
+
|
|
367
|
+
# Tests
|
|
368
|
+
npm test
|
|
369
|
+
|
|
370
|
+
# Watch mode
|
|
371
|
+
npm run dev
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
---
|
|
375
|
+
|
|
376
|
+
## Publish to npm
|
|
377
|
+
|
|
378
|
+
```bash
|
|
379
|
+
# 1. Make sure you're logged in
|
|
380
|
+
npm login
|
|
381
|
+
|
|
382
|
+
# 2. Build & publish
|
|
383
|
+
npm publish
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
The `prepublishOnly` script automatically runs `tsc` + the full test suite before publishing.
|
|
387
|
+
|
|
388
|
+
---
|
|
389
|
+
|
|
390
|
+
## Project structure
|
|
391
|
+
|
|
392
|
+
```
|
|
393
|
+
suppa-mcp-node/
|
|
394
|
+
├── src/
|
|
395
|
+
│ ├── bin.ts # Entry point — stdio transport
|
|
396
|
+
│ ├── server.ts # McpServer + all 84 tool + 4 prompt registrations
|
|
397
|
+
│ ├── config.ts # Env / .env config surface
|
|
398
|
+
│ ├── store.ts # Credentials in the OS keychain (@napi-rs/keyring)
|
|
399
|
+
│ ├── registry.ts # Non-secret tenant registry (~/.suppa-mcp/tenants.json)
|
|
400
|
+
│ ├── tenants.ts # Tenant context, active tenant, resolve, diagnostics
|
|
401
|
+
│ ├── auth.ts # JWT refresh (single-flight) + browser Google login
|
|
402
|
+
│ ├── httpClient.ts # fetch client: retry, envelope unwrap, 401→refresh→retry
|
|
403
|
+
│ ├── utils.ts # filters, dates, JSON params, multipart, confirm gate
|
|
404
|
+
│ └── tools/
|
|
405
|
+
│ ├── tasks.ts docs.ts entity.ts forms.ts
|
|
406
|
+
│ ├── automation.ts # read + write automation tools
|
|
407
|
+
│ ├── migrate.ts nameMap.ts v1Fields.ts
|
|
408
|
+
│ └── workspace.ts
|
|
409
|
+
├── skills/suppa-entity-code/ # bundled agent skill: write v2 schema code + validator
|
|
410
|
+
├── test/ # vitest suite (ports the Python test suite)
|
|
411
|
+
├── scripts/ # live read-only / write verify scripts
|
|
412
|
+
├── package.json
|
|
413
|
+
├── tsconfig.json
|
|
414
|
+
├── vitest.config.ts
|
|
415
|
+
└── README.md
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
---
|
|
419
|
+
|
|
420
|
+
## License
|
|
421
|
+
|
|
422
|
+
MIT — see [LICENSE](LICENSE).
|
package/dist/bin.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* stdio entrypoint for the Suppa MCP server (npm `suppa-mcp-2`).
|
|
4
4
|
*
|
|
5
|
-
* Builds the server (all
|
|
5
|
+
* Builds the server (all 87 tools) and connects it to stdio, exactly like the
|
|
6
6
|
* Python package's console script. Faithful 1:1 port.
|
|
7
7
|
*/
|
|
8
8
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
package/dist/httpClient.js
CHANGED
|
@@ -335,6 +335,20 @@ async function sendWithReauth(ctx, buildHeaders, method, url, data, timeout, opt
|
|
|
335
335
|
}
|
|
336
336
|
throw new Error(`HTTP ${code} ${safeStatusText(res)}: ${errorBody}`);
|
|
337
337
|
}
|
|
338
|
+
// A download returns bytes, not JSON — reading it as text would corrupt
|
|
339
|
+
// anything that is not UTF-8 (every PDF, image and zip). Content-Type comes
|
|
340
|
+
// back with it so the caller can name the file sensibly.
|
|
341
|
+
if (opts.binary) {
|
|
342
|
+
const buf = Buffer.from(await res.arrayBuffer());
|
|
343
|
+
if (config.DEBUG) {
|
|
344
|
+
debug(`${method} ${url} -> ${code} ${buf.length}B (${((Date.now() - started) / 1000).toFixed(2)}s)`);
|
|
345
|
+
}
|
|
346
|
+
return {
|
|
347
|
+
bytes: buf,
|
|
348
|
+
contentType: res.headers.get("content-type") ?? "",
|
|
349
|
+
contentDisposition: res.headers.get("content-disposition") ?? "",
|
|
350
|
+
};
|
|
351
|
+
}
|
|
338
352
|
const raw = await res.text();
|
|
339
353
|
if (config.DEBUG) {
|
|
340
354
|
debug(`${method} ${url} -> ${code} (${((Date.now() - started) / 1000).toFixed(2)}s)`);
|
|
@@ -375,6 +389,21 @@ export async function makeRequestRawBytes(method, path, data, contentType, opts
|
|
|
375
389
|
const url = path.startsWith("/") ? `${ctx.baseUrl}${path}` : path;
|
|
376
390
|
return sendWithReauth(ctx, (t) => headers(ctx, t, { "Content-Type": contentType }), method, url, data, timeout, { unwrap: false });
|
|
377
391
|
}
|
|
392
|
+
/**
|
|
393
|
+
* Fetch a response as BYTES rather than JSON — downloads
|
|
394
|
+
* (api-entity-builder-files.txt:80 "Buffer", :100 "ZIP (stream)").
|
|
395
|
+
*
|
|
396
|
+
* Goes through the same choke point as every other request, so the
|
|
397
|
+
* permanent-delete refusal covers it too.
|
|
398
|
+
*/
|
|
399
|
+
export async function makeRequestBinary(method, path, body = null, opts = {}) {
|
|
400
|
+
const ctx = tenants.current();
|
|
401
|
+
await tenants.ensureValid(ctx);
|
|
402
|
+
const timeout = opts.timeout ?? Math.max(120, config.HTTP_TIMEOUT); // downloads need headroom
|
|
403
|
+
const url = path.startsWith("/") ? `${ctx.baseUrl}${path}` : path;
|
|
404
|
+
const payload = body === null || body === undefined ? null : JSON.stringify(body);
|
|
405
|
+
return (await sendWithReauth(ctx, (t) => headers(ctx, t, payload === null ? null : { "Content-Type": "application/json" }), method, url, payload, timeout, { unwrap: false, binary: true }));
|
|
406
|
+
}
|
|
378
407
|
// ---------------------------------------------------------------------------
|
|
379
408
|
// High-level entity helpers
|
|
380
409
|
// ---------------------------------------------------------------------------
|
package/dist/server.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Suppa MCP Server — unified gateway to the Suppa platform.
|
|
3
3
|
*
|
|
4
|
-
* Faithful 1:1 port of the Python `suppa_mcp/server.py`. Wires all
|
|
4
|
+
* Faithful 1:1 port of the Python `suppa_mcp/server.py`. Wires all 87 tools,
|
|
5
5
|
* mirrors the tool-behavior annotations (_READ/_ADD/_MUT), reproduces the
|
|
6
6
|
* server `instructions` string verbatim, and OWNS all confirm-gating (the tool
|
|
7
7
|
* modules mutate unconditionally, exactly like the Python tool functions).
|
|
@@ -11,6 +11,7 @@ import { z } from "zod";
|
|
|
11
11
|
import * as tasks from "./tools/tasks.js";
|
|
12
12
|
import * as docs from "./tools/docs.js";
|
|
13
13
|
import * as entity from "./tools/entity.js";
|
|
14
|
+
import * as files from "./tools/files.js";
|
|
14
15
|
import * as forms from "./tools/forms.js";
|
|
15
16
|
import * as migrate from "./tools/migrate.js";
|
|
16
17
|
import * as workspace from "./tools/workspace.js";
|
|
@@ -258,12 +259,19 @@ APPROVAL GATES (human-in-the-loop)
|
|
|
258
259
|
ENTITY BUILDER (create + edit fields; removal is UI-only)
|
|
259
260
|
- Real field types only: text, numeric, integer, serial, boolean, timestamp, json, uuid, multi-language, bytea, tsvector, multi-type, icon, enum, multi-enum, file, multi-file, many-to-one, many-to-many, many-to-many-backref. There is NO date/datetime/richtext/email/url/phone type — use timestamp (+sub_type='date') or multi-language.
|
|
260
261
|
- sub_type matrix: timestamp → 'date' | 'time' | 'timestamp'; text → 'encrypted'; enum/multi-enum → the enum's global name, set by the platform (never pass it); every other type takes none. Anything else is refused before the request.
|
|
261
|
-
- FIELD OPTIONS
|
|
262
|
+
- FIELD OPTIONS: searchable, searchPriority (1-4), readOnly, canGroup, canSort, showInTable, editFromTable, canFilter. Omit options_json and the platform fills in its own defaults — visible, sortable, groupable, filterable, editable, not read-only, and NOT searchable. So the one worth passing is searchable (+searchPriority): suppa_search_records' free-text search only covers fields marked searchable. Turn any of them on later with suppa_update_field.
|
|
262
263
|
- OWNED CHILD COLLECTIONS ARE TABULAR PARTS. Repeating rows that belong to one parent record (e.g. a part's BOM items) → suppa_create_tabular_part(parent_entity, name), which auto-creates the child's 'owner' relation and the parent link. NEVER model this by hand as parent.one-to-many + child.owner: suppa_add_field REFUSES field_type='one-to-many'. Use 'many-to-many' only for a shared lookup referenced by many records.
|
|
263
264
|
- Relations need relation_entity; enums need enum_name (the enum's global name, conventionally 'Entity.field'). Add the values FIRST with suppa_add_enum_values, then create the field with the same enum_name — the field is bound to the enum by that name.
|
|
264
265
|
- An enum value on a RECORD is a reference, not a string: write {"id": <Enums row id>} for enum and [{"id": ...}, ...] for multi-enum. A bare code like "red" is refused with 'field must contain id for many-to-one relationship'. Read the ids with suppa_search_records on 'Enums' filtered by name = the enum name.
|
|
265
266
|
- Existing fields CAN be edited with suppa_update_field (name, title, notNull/unique/default, relation target, and the options above), within the platform's own limits: a field's TYPE can never be changed, its SUBTYPE only toggles 'encrypted' on/off (text fields only), and a system field takes just title + the options keys. Removing a field is still UI-only — this server has no remove-field call.
|
|
266
267
|
|
|
268
|
+
ATTACHMENTS (files on a record)
|
|
269
|
+
- A record can carry files only if its entity has a 'file' or 'multi-file' field; check with suppa_describe_entity and add one with suppa_add_field if it has none.
|
|
270
|
+
- WRITE: suppa_attach_file_to_record(entity, record_id, absolute_path) uploads from the local disk and returns file_ids — keep them, they are the only handle that gets the bytes back.
|
|
271
|
+
- READ: suppa_list_record_files(entity, record_id) lists fileName/size/mimeType/paths for one record. It does NOT return ids; get those from the attach response, or with suppa_search_records on the 'Files' entity.
|
|
272
|
+
- GET THE BYTES: suppa_download_file(file_id, absolute_dest_path) writes one file to disk — file_type='file' (original), 'preview' or 'pdf'. suppa_download_files_zip(file_ids, dest) fetches several as one archive. Nothing is overwritten unless overwrite=true.
|
|
273
|
+
- To duplicate a record's attachments onto a copy, use suppa_copy_record(copy_files=true) — there is no local path for a file that already lives on the platform.
|
|
274
|
+
|
|
267
275
|
MIGRATION (Suppa 1.0 → 2.0)
|
|
268
276
|
- Always dry-run first: suppa_migrate_entities_from_v1(dry_run=true, output_file="plan.json"), review/edit the plan, then execute with plan_file="plan.json", dry_run=false.
|
|
269
277
|
`;
|
|
@@ -297,7 +305,7 @@ export function buildServer() {
|
|
|
297
305
|
// Reset so repeated buildServer() calls (e.g. in tests) do not double-count.
|
|
298
306
|
TOOL_NAMES.length = 0;
|
|
299
307
|
PROMPT_NAMES.length = 0;
|
|
300
|
-
const server = new McpServer({ name: "suppa-2.0", version: "1.
|
|
308
|
+
const server = new McpServer({ name: "suppa-2.0", version: "1.6.0" }, { instructions: INSTRUCTIONS });
|
|
301
309
|
const reg = (name, cfg, handler) => {
|
|
302
310
|
server.registerTool(name, {
|
|
303
311
|
description: cfg.description,
|
|
@@ -1466,6 +1474,71 @@ export function buildServer() {
|
|
|
1466
1474
|
},
|
|
1467
1475
|
annotations: _ADD,
|
|
1468
1476
|
}, async (a) => text(await entity.copyRecord(a.entity_name, a.record_id, a.fields_json, a.copy_files, a.copy_related_entities)));
|
|
1477
|
+
reg("suppa_list_record_files", {
|
|
1478
|
+
description: "List the files attached to one record of any entity.\n" +
|
|
1479
|
+
"\n" +
|
|
1480
|
+
" Returns fileName, filePath, pdfPath, previewPath, size, mimeType and type\n" +
|
|
1481
|
+
" for each attachment. It does NOT return the file id, and\n" +
|
|
1482
|
+
" suppa_download_file needs one — read ids from the 'Files' entity with\n" +
|
|
1483
|
+
" suppa_search_records, or keep the id suppa_attach_file_to_record returns.\n" +
|
|
1484
|
+
" An empty list can also mean the entity has no file field at all; check it\n" +
|
|
1485
|
+
" with suppa_describe_entity.\n",
|
|
1486
|
+
inputSchema: {
|
|
1487
|
+
entity_name: EntityName,
|
|
1488
|
+
record_id: z.number().int().describe("Id of the record whose attachments to list."),
|
|
1489
|
+
limit: z.number().int().default(50).describe("Page size, 1-500."),
|
|
1490
|
+
offset: z.number().int().default(0).describe("Rows to skip (paging)."),
|
|
1491
|
+
},
|
|
1492
|
+
annotations: _READ,
|
|
1493
|
+
}, async (a) => text(await files.listRecordFiles(a.entity_name, a.record_id, a.limit, a.offset)));
|
|
1494
|
+
reg("suppa_download_file", {
|
|
1495
|
+
description: "Download one attached file to a local path.\n" +
|
|
1496
|
+
"\n" +
|
|
1497
|
+
" file_id is the id of the row in the 'Files' entity — from\n" +
|
|
1498
|
+
" suppa_search_records on 'Files', or from what suppa_attach_file_to_record\n" +
|
|
1499
|
+
" returned. file_type picks the variant: the original ('file'), its image\n" +
|
|
1500
|
+
" preview ('preview'), or the generated PDF ('pdf').\n" +
|
|
1501
|
+
"\n" +
|
|
1502
|
+
" dest_path must be ABSOLUTE. Point it at a directory to keep the platform's\n" +
|
|
1503
|
+
" own file name. An existing file is never overwritten unless overwrite=true\n" +
|
|
1504
|
+
" — the bytes are discarded instead.\n",
|
|
1505
|
+
inputSchema: {
|
|
1506
|
+
file_id: z.number().int().describe("Id of the row in the 'Files' entity."),
|
|
1507
|
+
dest_path: z
|
|
1508
|
+
.string()
|
|
1509
|
+
.describe("Absolute path to write to — a file, or a directory to keep the sent name."),
|
|
1510
|
+
file_type: z
|
|
1511
|
+
.enum(["file", "preview", "pdf"])
|
|
1512
|
+
.default("file")
|
|
1513
|
+
.describe("Which variant to fetch: the original, its preview, or the generated PDF."),
|
|
1514
|
+
overwrite: z
|
|
1515
|
+
.boolean()
|
|
1516
|
+
.default(false)
|
|
1517
|
+
.describe("Allow replacing an existing file at dest_path."),
|
|
1518
|
+
},
|
|
1519
|
+
annotations: _READ,
|
|
1520
|
+
}, async (a) => text(await files.downloadFile(a.file_id, a.dest_path, a.file_type, a.overwrite)));
|
|
1521
|
+
reg("suppa_download_files_zip", {
|
|
1522
|
+
description: "Download several attached files at once as a ZIP archive.\n" +
|
|
1523
|
+
"\n" +
|
|
1524
|
+
" file_ids are ids of rows in the 'Files' entity. dest_path must be ABSOLUTE;\n" +
|
|
1525
|
+
" point it at a directory to keep the archive name the platform sends.\n" +
|
|
1526
|
+
" Nothing is overwritten unless overwrite=true.\n",
|
|
1527
|
+
inputSchema: {
|
|
1528
|
+
file_ids: z
|
|
1529
|
+
.array(z.number().int())
|
|
1530
|
+
.min(1)
|
|
1531
|
+
.describe("Ids of the rows in the 'Files' entity to include."),
|
|
1532
|
+
dest_path: z
|
|
1533
|
+
.string()
|
|
1534
|
+
.describe("Absolute path to write the .zip to — a file, or a directory."),
|
|
1535
|
+
overwrite: z
|
|
1536
|
+
.boolean()
|
|
1537
|
+
.default(false)
|
|
1538
|
+
.describe("Allow replacing an existing archive at dest_path."),
|
|
1539
|
+
},
|
|
1540
|
+
annotations: _READ,
|
|
1541
|
+
}, async (a) => text(await files.downloadFilesZip(a.file_ids, a.dest_path, a.overwrite)));
|
|
1469
1542
|
reg("suppa_attach_file_to_record", {
|
|
1470
1543
|
description: "Attach a local file to a record (instance) of any entity.\n\n" +
|
|
1471
1544
|
" Auto-detects the entity's file/attachment field from its schema; pass\n" +
|
package/dist/tools/entity.js
CHANGED
|
@@ -2317,6 +2317,11 @@ export async function attachFileToRecord(entityName, recordId, filePath, fieldNa
|
|
|
2317
2317
|
if (entityId === null) {
|
|
2318
2318
|
return jsonResponse({ error: `Could not resolve numeric id for entity '${entityName}'.` });
|
|
2319
2319
|
}
|
|
2320
|
+
// files.txt:14-19 documents exactly three required meta keys — entityId,
|
|
2321
|
+
// recordId, entityFieldName — plus optional pdfPath/previewPath. `entityName`
|
|
2322
|
+
// and `type` are NOT in that table; they are inherited from the Python server
|
|
2323
|
+
// and the platform drops unknown keys, so they are harmless extras rather
|
|
2324
|
+
// than doc-backed fields. The documented three are what makes the upload land.
|
|
2320
2325
|
const meta = {
|
|
2321
2326
|
entityId,
|
|
2322
2327
|
recordId: Math.trunc(recordId),
|
|
@@ -2330,14 +2335,32 @@ export async function attachFileToRecord(entityName, recordId, filePath, fieldNa
|
|
|
2330
2335
|
try {
|
|
2331
2336
|
const { body, contentType } = buildFileUpload(meta, filePath);
|
|
2332
2337
|
const result = await makeRequestRawBytes("POST", "/api/core/files/upload", body, contentType);
|
|
2333
|
-
|
|
2334
|
-
|
|
2338
|
+
// files.txt:36-46 — the response is {summary, success[], errors[]}, and
|
|
2339
|
+
// success[].id is the Files record id, the ONLY handle that gets the bytes
|
|
2340
|
+
// back later (suppa_download_file). Lifted out of the raw payload so a
|
|
2341
|
+
// caller does not have to know that shape to keep it.
|
|
2342
|
+
const uploaded = isPlainObject(result) ? result.success : null;
|
|
2343
|
+
const fileIds = Array.isArray(uploaded)
|
|
2344
|
+
? uploaded
|
|
2345
|
+
.filter((f) => f !== null && typeof f === "object")
|
|
2346
|
+
.map((f) => f.id)
|
|
2347
|
+
.filter((id) => typeof id === "number")
|
|
2348
|
+
: [];
|
|
2349
|
+
const failures = isPlainObject(result) ? result.errors : null;
|
|
2350
|
+
const out = {
|
|
2351
|
+
status: Array.isArray(failures) && failures.length > 0 ? "partial" : "ok",
|
|
2335
2352
|
entity: entityName,
|
|
2336
2353
|
record_id: Math.trunc(recordId),
|
|
2337
2354
|
field: fieldName,
|
|
2338
2355
|
file: basename(filePath),
|
|
2356
|
+
file_ids: fileIds,
|
|
2339
2357
|
result,
|
|
2340
|
-
}
|
|
2358
|
+
};
|
|
2359
|
+
if (fileIds.length > 0) {
|
|
2360
|
+
out.next = `Read it back with suppa_download_file(file_id=${fileIds[0]}), or list this ` +
|
|
2361
|
+
`record's attachments with suppa_list_record_files.`;
|
|
2362
|
+
}
|
|
2363
|
+
return jsonResponse(out);
|
|
2341
2364
|
}
|
|
2342
2365
|
catch (e) {
|
|
2343
2366
|
return jsonResponse({
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attachments: reading what is attached to a record, and getting the bytes.
|
|
3
|
+
*
|
|
4
|
+
* Endpoints and shapes are
|
|
5
|
+
* docs/superpowers/specs/captures/api-entity-builder-files.txt:
|
|
6
|
+
* :157 POST core/files/:table — every file attached to one record
|
|
7
|
+
* :68 GET core/files/download — one file's bytes (fileId, fileType)
|
|
8
|
+
* :83 POST core/files/download-all — several files as a ZIP stream
|
|
9
|
+
* Uploading already lives in tools/entity.ts (attachFileToRecord, :2760).
|
|
10
|
+
*
|
|
11
|
+
* NOTE on that capture's "shellAuthorization" header rows: the doc renders a
|
|
12
|
+
* fenced block whose language tag ("shell") is glued to the first line by the
|
|
13
|
+
* text extraction — the header is plain `Authorization`, which httpClient
|
|
14
|
+
* already sends. The same artefact produces "Request examplejson{" elsewhere in
|
|
15
|
+
* the file. Do not "fix" the client to send shellAuthorization.
|
|
16
|
+
*/
|
|
17
|
+
import { existsSync, mkdirSync, statSync, writeFileSync } from "node:fs";
|
|
18
|
+
import { dirname, isAbsolute, join } from "node:path";
|
|
19
|
+
import { makeRequest, makeRequestBinary } from "../httpClient.js";
|
|
20
|
+
import { jsonResponse } from "../utils.js";
|
|
21
|
+
/** files.txt:76 — "Which variant to download: file, preview or pdf." */
|
|
22
|
+
export const FILE_TYPES = ["file", "preview", "pdf"];
|
|
23
|
+
/** The platform caps a page of results; keep the tool from asking for absurd ones. */
|
|
24
|
+
const MAX_LIMIT = 500;
|
|
25
|
+
/**
|
|
26
|
+
* Every file attached to one record — POST core/files/:table (files.txt:157).
|
|
27
|
+
*
|
|
28
|
+
* Body is {recordId, limit, offset} (files.txt:164-167; limit is REQUIRED).
|
|
29
|
+
* The response rows carry fileName/filePath/pdfPath/previewPath/size/mimeType/
|
|
30
|
+
* type (files.txt:176-183) — and, notably, NO id, while the download endpoint
|
|
31
|
+
* is keyed on one. That gap is surfaced in the result rather than papered over.
|
|
32
|
+
*/
|
|
33
|
+
export async function listRecordFiles(entityName, recordId, limit = 50, offset = 0) {
|
|
34
|
+
const name = String(entityName ?? "").trim();
|
|
35
|
+
if (!name) {
|
|
36
|
+
return jsonResponse({ error: "entity_name is required." });
|
|
37
|
+
}
|
|
38
|
+
if (!Number.isFinite(recordId)) {
|
|
39
|
+
return jsonResponse({ error: "record_id must be a number." });
|
|
40
|
+
}
|
|
41
|
+
const body = {
|
|
42
|
+
recordId: Math.trunc(recordId),
|
|
43
|
+
limit: Math.max(1, Math.min(Math.trunc(limit), MAX_LIMIT)),
|
|
44
|
+
offset: Math.max(0, Math.trunc(offset)),
|
|
45
|
+
};
|
|
46
|
+
const result = await makeRequest("POST", `/api/core/files/${name}`, body);
|
|
47
|
+
const rows = Array.isArray(result) ? result : [];
|
|
48
|
+
return jsonResponse({
|
|
49
|
+
entity: name,
|
|
50
|
+
record_id: body.recordId,
|
|
51
|
+
count: rows.length,
|
|
52
|
+
files: rows,
|
|
53
|
+
// Honest about the shape rather than inventing an id: the caller needs one
|
|
54
|
+
// to download, and this endpoint does not return it.
|
|
55
|
+
note: rows.length > 0
|
|
56
|
+
? "This endpoint returns no file id (files.txt:176-183), and suppa_download_file needs " +
|
|
57
|
+
"one. Get ids from suppa_search_records on the 'Files' entity, or from the response of " +
|
|
58
|
+
"suppa_attach_file_to_record, which returns success[].id."
|
|
59
|
+
: "No files attached to this record — or the entity has no file field at all " +
|
|
60
|
+
"(check with suppa_describe_entity).",
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/** Where a download may be written, and under what name. */
|
|
64
|
+
function resolveDestination(destPath, fallbackName, overwrite) {
|
|
65
|
+
const dest = String(destPath ?? "").trim();
|
|
66
|
+
if (!dest) {
|
|
67
|
+
return { error: "dest_path is required — give an absolute file or directory path." };
|
|
68
|
+
}
|
|
69
|
+
if (!isAbsolute(dest)) {
|
|
70
|
+
return { error: `dest_path must be absolute, got '${dest}'.` };
|
|
71
|
+
}
|
|
72
|
+
// A directory target keeps the platform's own file name.
|
|
73
|
+
let target = dest;
|
|
74
|
+
if (existsSync(dest) && statSync(dest).isDirectory()) {
|
|
75
|
+
target = join(dest, fallbackName);
|
|
76
|
+
}
|
|
77
|
+
if (existsSync(target) && !overwrite) {
|
|
78
|
+
return {
|
|
79
|
+
error: `Refused: '${target}' already exists and overwrite=false, so nothing was written. ` +
|
|
80
|
+
"Pass overwrite=true or choose another dest_path.",
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const parent = dirname(target);
|
|
84
|
+
if (!existsSync(parent)) {
|
|
85
|
+
try {
|
|
86
|
+
mkdirSync(parent, { recursive: true });
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
return { error: `Cannot create directory '${parent}': ${e instanceof Error ? e.message : e}` };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return { path: target };
|
|
93
|
+
}
|
|
94
|
+
/** The filename the platform suggests, if it sent one. */
|
|
95
|
+
export function filenameFromDisposition(disposition) {
|
|
96
|
+
if (!disposition)
|
|
97
|
+
return null;
|
|
98
|
+
// RFC 5987 form first — that is what the doc's example uses
|
|
99
|
+
// (files.txt:108: filename*=UTF-8''download_2026-02-25.zip).
|
|
100
|
+
const star = /filename\*\s*=\s*[^']*'[^']*'([^;]+)/i.exec(disposition);
|
|
101
|
+
if (star) {
|
|
102
|
+
try {
|
|
103
|
+
return decodeURIComponent(star[1].trim().replace(/^"|"$/g, "")) || null;
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return star[1].trim().replace(/^"|"$/g, "") || null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const plain = /filename\s*=\s*("([^"]*)"|[^;]+)/i.exec(disposition);
|
|
110
|
+
if (plain) {
|
|
111
|
+
return (plain[2] ?? plain[1]).trim() || null;
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* One file's bytes — GET core/files/download?fileId&fileType (files.txt:68-77).
|
|
117
|
+
*
|
|
118
|
+
* `fileType` picks the variant: the original, its preview, or the generated PDF
|
|
119
|
+
* (files.txt:76). Writes to disk rather than returning bytes, because an MCP
|
|
120
|
+
* result is text and a binary blob would have to be base64'd through the model's
|
|
121
|
+
* context for no benefit.
|
|
122
|
+
*/
|
|
123
|
+
export async function downloadFile(fileId, destPath, fileType = "file", overwrite = false) {
|
|
124
|
+
if (!Number.isFinite(fileId)) {
|
|
125
|
+
return jsonResponse({ error: "file_id must be a number (the Files record id)." });
|
|
126
|
+
}
|
|
127
|
+
if (!FILE_TYPES.includes(fileType)) {
|
|
128
|
+
return jsonResponse({
|
|
129
|
+
error: `file_type must be one of ${FILE_TYPES.join(", ")} (files.txt:76), got '${fileType}'.`,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
const id = Math.trunc(fileId);
|
|
133
|
+
let res;
|
|
134
|
+
try {
|
|
135
|
+
res = await makeRequestBinary("GET", `/api/core/files/download?fileId=${id}&fileType=${fileType}`);
|
|
136
|
+
}
|
|
137
|
+
catch (e) {
|
|
138
|
+
return jsonResponse({
|
|
139
|
+
error: `Download of file ${id} failed: ${e instanceof Error ? e.message : String(e)}`,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
const suggested = filenameFromDisposition(res.contentDisposition) ?? `file-${id}`;
|
|
143
|
+
const dest = resolveDestination(destPath, suggested, overwrite);
|
|
144
|
+
if ("error" in dest) {
|
|
145
|
+
return jsonResponse({ ...dest, bytes_received: res.bytes.length, not_written: true });
|
|
146
|
+
}
|
|
147
|
+
writeFileSync(dest.path, res.bytes);
|
|
148
|
+
return jsonResponse({
|
|
149
|
+
file_id: id,
|
|
150
|
+
file_type: fileType,
|
|
151
|
+
saved_to: dest.path,
|
|
152
|
+
bytes: res.bytes.length,
|
|
153
|
+
content_type: res.contentType,
|
|
154
|
+
suggested_name: suggested,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Several files at once, as a ZIP — POST core/files/download-all (files.txt:83).
|
|
159
|
+
*
|
|
160
|
+
* Body is {instanceIds: number[]} (files.txt:91) and the response is a zip
|
|
161
|
+
* stream (files.txt:100).
|
|
162
|
+
*/
|
|
163
|
+
export async function downloadFilesZip(fileIds, destPath, overwrite = false) {
|
|
164
|
+
const ids = (fileIds ?? []).map((n) => Math.trunc(Number(n))).filter((n) => Number.isFinite(n));
|
|
165
|
+
if (ids.length === 0) {
|
|
166
|
+
return jsonResponse({
|
|
167
|
+
error: "file_ids must hold at least one Files record id (files.txt:91 — instanceIds).",
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
let res;
|
|
171
|
+
try {
|
|
172
|
+
res = await makeRequestBinary("POST", "/api/core/files/download-all", { instanceIds: ids });
|
|
173
|
+
}
|
|
174
|
+
catch (e) {
|
|
175
|
+
return jsonResponse({
|
|
176
|
+
error: `Download of ${ids.length} file(s) failed: ${e instanceof Error ? e.message : String(e)}`,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
const suggested = filenameFromDisposition(res.contentDisposition) ?? "download.zip";
|
|
180
|
+
const dest = resolveDestination(destPath, suggested, overwrite);
|
|
181
|
+
if ("error" in dest) {
|
|
182
|
+
return jsonResponse({ ...dest, bytes_received: res.bytes.length, not_written: true });
|
|
183
|
+
}
|
|
184
|
+
writeFileSync(dest.path, res.bytes);
|
|
185
|
+
return jsonResponse({
|
|
186
|
+
file_ids: ids,
|
|
187
|
+
saved_to: dest.path,
|
|
188
|
+
bytes: res.bytes.length,
|
|
189
|
+
content_type: res.contentType,
|
|
190
|
+
suggested_name: suggested,
|
|
191
|
+
});
|
|
192
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "suppa-mcp-2",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.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": {
|