inistate-mcp 1.3.5 → 1.5.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
@@ -85,7 +85,7 @@ Tools marked **(configure)** are only exposed in configure mode — see [Modes](
85
85
  | Tool | Description |
86
86
  |------|-------------|
87
87
  | `list_workspaces` | List workspaces the user has access to |
88
- | `set_workspace` | Set the active workspace |
88
+ | `set_workspace` | Look up a workspace by id or name and return its module list (stores nothing) |
89
89
  | `list_modules` | List all discoverable modules in the workspace |
90
90
  | `get_module_schema` | Get the canvas schema (basic or extended tier) — available in every mode |
91
91
  | `get_module_canvas` | Get full module definition with stable IDs (round-trippable) **(configure)** |
@@ -96,6 +96,7 @@ Tools marked **(configure)** are only exposed in configure mode — see [Modes](
96
96
  | `submit_activity` | Create, edit, delete, or run custom activities |
97
97
  | `submit_activities` | Bulk variant — same activity applied to up to 100 entries in one call |
98
98
  | `get_entry_history` | Get entry audit trail and comments |
99
+ | `get_document` | An entry's document, the system's own print or one designed in Inistate: a link that lasts up to an hour (default) or the file itself (max 4 MB) |
99
100
  | `request_upload_url` | Default upload path — get a presigned S3 URL to PUT file bytes to |
100
101
  | `confirm_upload` | Confirm a presigned upload completed; returns the File/Image field path |
101
102
  | `upload_file` | Fallback upload via base64/multipart (use only if the presigned flow fails) |
@@ -143,7 +144,7 @@ Tools and resources marked **(configure)** / **(frontend)** are absent from the
143
144
 
144
145
  ## Typical Workflow
145
146
 
146
- 1. `list_workspaces` → `set_workspace` — select a workspace (auto-selected when exactly one matches; both return the workspace's module list, so `list_modules` is only needed to refresh)
147
+ 1. `list_workspaces` → `set_workspace` — find the workspace (when exactly one matches, list_workspaces returns its module list itself; both return it, so `list_modules` is only needed to refresh). The server keeps no state between calls: pass `workspaceId` on every later call, unless `INISTATE_WORKSPACE_ID` is configured.
147
148
  2. `get_module_schema` — understand a module's fields, states, and activities
148
149
  3. `get_form` — discover required fields before the first submission per (module, activity); reuse its schema for further entries
149
150
  4. `submit_activity` — create or update entries (`submit_activities` for bulk)
@@ -18,6 +18,7 @@
18
18
  interface ActivityDef {
19
19
  name: string;
20
20
  actor?: string;
21
+ humanWhen?: string;
21
22
  }
22
23
  interface FieldInfo {
23
24
  name: string;
@@ -107,8 +108,13 @@ export declare function getModuleStates(moduleName: string, fetchSchema?: Schema
107
108
  *
108
109
  * Split out so bulk callers (submit_activities) can fetch once and reuse the
109
110
  * map across items via validateInputShapesWith.
111
+ *
112
+ * `fresh` skips the cache (and refills it): for a key the cached map does not
113
+ * know, which may be a field added since the schema was cached.
110
114
  */
111
- export declare function getModuleFieldTypes(moduleName: string, fetchSchema?: SchemaFetcher): Promise<Map<string, string> | null>;
115
+ export declare function getModuleFieldTypes(moduleName: string, fetchSchema?: SchemaFetcher, { fresh }?: {
116
+ fresh?: boolean;
117
+ }): Promise<Map<string, string> | null>;
112
118
  /**
113
119
  * Synchronous shape check against a pre-built field-type map. Use this in
114
120
  * bulk loops to avoid rebuilding the map per item. When `types` is null
@@ -1,5 +1,6 @@
1
1
  import * as api from "./api.js";
2
2
  import { requestContext } from "./context.js";
3
+ import { isSystemFieldName } from "./schema.js";
3
4
  const REF_FIELD_TYPES = new Set(["User", "Users", "Module", "Modules"]);
4
5
  const LOCATION_FIELD_TYPE = "Location";
5
6
  // Standard activities are inherent platform operations. Most bypass the actor
@@ -48,11 +49,11 @@ const defaultSchemaFetcher = async (moduleName) => {
48
49
  return null;
49
50
  }
50
51
  };
51
- async function getExtendedSchema(moduleName, fetchSchema = defaultSchemaFetcher) {
52
+ async function getExtendedSchema(moduleName, fetchSchema = defaultSchemaFetcher, fresh = false) {
52
53
  const key = cacheKey("schema", [moduleName]);
53
54
  const now = Date.now();
54
55
  const cached = schemaCache.get(key);
55
- if (cached && now - cached.at < SCHEMA_TTL_MS)
56
+ if (!fresh && cached && now - cached.at < SCHEMA_TTL_MS)
56
57
  return cached.schema;
57
58
  const schema = await fetchSchema(moduleName);
58
59
  if (schema)
@@ -89,11 +90,11 @@ const defaultCanvasFetcher = async (moduleName) => {
89
90
  return null;
90
91
  }
91
92
  };
92
- async function getCanvasSchema(moduleName, fetchCanvas = defaultCanvasFetcher) {
93
+ async function getCanvasSchema(moduleName, fetchCanvas = defaultCanvasFetcher, fresh = false) {
93
94
  const key = cacheKey("canvas", [moduleName]);
94
95
  const now = Date.now();
95
96
  const cached = canvasCache.get(key);
96
- if (cached && now - cached.at < SCHEMA_TTL_MS)
97
+ if (!fresh && cached && now - cached.at < SCHEMA_TTL_MS)
97
98
  return cached.canvas;
98
99
  // Cache the miss too — a caller without configure access would otherwise
99
100
  // pay a failing round trip on every submit.
@@ -112,17 +113,17 @@ function findWithActor(list, activity) {
112
113
  return null;
113
114
  }
114
115
  /** The activity's actor as the extended schema reports it; null when it names none. */
115
- async function getReportedActivityDef(moduleName, activity, fetchSchema) {
116
- const schema = await getExtendedSchema(moduleName, fetchSchema);
116
+ async function getReportedActivityDef(moduleName, activity, fetchSchema, fresh = false) {
117
+ const schema = await getExtendedSchema(moduleName, fetchSchema, fresh);
117
118
  return findWithActor(schema?.activityDetails, activity) ?? findWithActor(schema?.activities, activity);
118
119
  }
119
- async function getActivityDef(moduleName, activity, fetchSchema = defaultSchemaFetcher, fetchCanvas = defaultCanvasFetcher) {
120
- const reported = await getReportedActivityDef(moduleName, activity, fetchSchema);
120
+ async function getActivityDef(moduleName, activity, fetchSchema = defaultSchemaFetcher, fetchCanvas = defaultCanvasFetcher, fresh = false) {
121
+ const reported = await getReportedActivityDef(moduleName, activity, fetchSchema, fresh);
121
122
  if (reported)
122
123
  return reported;
123
124
  // A server that lists names only — the canvas carries the actor (designers
124
125
  // can read it; anyone else gets null, and the API decides).
125
- const canvas = await getCanvasSchema(moduleName, fetchCanvas);
126
+ const canvas = await getCanvasSchema(moduleName, fetchCanvas, fresh);
126
127
  return findWithActor(canvas?.activities, activity);
127
128
  }
128
129
  const FLAG_TTL_MS = 60 * 60 * 1000;
@@ -177,6 +178,10 @@ export function getHumanBlockedStates(moduleName, entryId) {
177
178
  }
178
179
  return rec;
179
180
  }
181
+ /** A hybrid activity the guard itself asks a confirmation for (one with a humanWhen is the server's to decide). */
182
+ function needsConfirmation(def, confirmed) {
183
+ return (def.actor || "").toLowerCase() === "hybrid" && !confirmed && !def.humanWhen;
184
+ }
180
185
  export async function evaluateActivity(input, fetchSchema = defaultSchemaFetcher, fetchCanvas = defaultCanvasFetcher) {
181
186
  const { module: moduleName, activity, entryId, entryIds, state, confidence, confirmed } = input;
182
187
  // Rule 1 — confidence inflation after a prior flag.
@@ -268,17 +273,23 @@ export async function evaluateActivity(input, fetchSchema = defaultSchemaFetcher
268
273
  // Rules 3 & 4 apply to custom (workflow-defined) activities, and to standard
269
274
  // create/edit through the actor the schema reports for them (only a server
270
275
  // with activityDetails reports one; the canvas has no standard actors).
271
- let def;
272
- if (standard) {
273
- if (!ACTOR_CHECKED_STANDARDS.has(standard))
274
- return { ok: true };
275
- def = await getReportedActivityDef(moduleName, standard, fetchSchema);
276
- }
277
- else {
278
- def = await getActivityDef(moduleName, activity, fetchSchema, fetchCanvas);
279
- }
276
+ if (standard && !ACTOR_CHECKED_STANDARDS.has(standard))
277
+ return { ok: true };
278
+ const lookup = (fresh) => standard
279
+ ? getReportedActivityDef(moduleName, standard, fetchSchema, fresh)
280
+ : getActivityDef(moduleName, activity, fetchSchema, fetchCanvas, fresh);
281
+ let def = await lookup(false);
280
282
  if (!def)
281
283
  return { ok: true }; // unknown activity or no actor — let the API decide.
284
+ // The schema is cached for minutes, and a designer may since have given this
285
+ // hybrid activity a humanWhen condition (or another actor). Re-read it before
286
+ // asking for a confirmation, so the agent is not sent to the user for one the
287
+ // server would not take. Only this refusal pays the extra round trip.
288
+ if (needsConfirmation(def, confirmed)) {
289
+ def = await lookup(true);
290
+ if (!def)
291
+ return { ok: true };
292
+ }
282
293
  const actor = (def.actor || "").toLowerCase();
283
294
  if (actor === "human") {
284
295
  // Remember which states this activity would have reached, so a follow-up
@@ -303,11 +314,14 @@ export async function evaluateActivity(input, fetchSchema = defaultSchemaFetcher
303
314
  message: `Activity '${activity}' is marked actor='human'. AI agents are not permitted to execute human-only activities.`,
304
315
  activity,
305
316
  actor: "human",
306
- agent_action: "Do not retry — confirmed: true does NOT unlock this, and neither does changeState. Tell the user the activity must be performed by a human, then stop.",
317
+ agent_action: "Do not retry — confirmed: true does NOT unlock this, and neither does changeState. Tell the user the activity must be performed by a person. If the user wants it done, you may offer to send it to a person for approval: submit_activity with `approval: { summary }`; never send one unasked.",
307
318
  },
308
319
  };
309
320
  }
310
- if (actor === "hybrid" && !confirmed) {
321
+ // A hybrid activity with a humanWhen condition: the server decides first
322
+ // whether the condition makes it human for these values (then no
323
+ // confirmation could unlock it), and asks for the confirmation itself when not.
324
+ if (needsConfirmation(def, confirmed)) {
311
325
  return {
312
326
  ok: false,
313
327
  structured: {
@@ -341,21 +355,13 @@ function checkSingleRef(field, type, value, index) {
341
355
  const valueOk = typeof obj.value === "string";
342
356
  const usernameOk = !isUserType ||
343
357
  (typeof obj.username === "string" && obj.username.length > 0);
344
- if (idOk && valueOk && usernameOk) {
345
- // A display name standing in for the id ({ id: "carol" }) passes the key
346
- // checks but the platform stores it as-is — a silently dangling reference.
347
- // Real ids are numeric or document ids ("CLN00001"); a string id with
348
- // whitespace or no digit at all is a name, not an id.
349
- if (typeof obj.id === "string" && (/\s/.test(obj.id) || !/\d/.test(obj.id))) {
350
- return {
351
- field,
352
- type,
353
- received: value,
354
- message: `${type} field '${locator}' id '${obj.id}' looks like a display name, not an entry id. Look up the entry with list_entries on the connected module and round-trip its reference object unchanged.`,
355
- };
356
- }
358
+ // Shape only: what an id looks like says nothing about whether it is one. A
359
+ // module whose records live in another system uses that system's own keys
360
+ // (HQ, KLG-WH, BANK), so the MCP never judges an id by its spelling. Whether
361
+ // it names an entry is the backend's call: it knows the connected module
362
+ // (KY 2026-11-14, "MCP must stay generic").
363
+ if (idOk && valueOk && usernameOk)
357
364
  return null;
358
- }
359
365
  const missing = [];
360
366
  if (!idOk)
361
367
  missing.push("id (string|number)");
@@ -548,9 +554,12 @@ export async function getModuleStates(moduleName, fetchSchema = defaultSchemaFet
548
554
  *
549
555
  * Split out so bulk callers (submit_activities) can fetch once and reuse the
550
556
  * map across items via validateInputShapesWith.
557
+ *
558
+ * `fresh` skips the cache (and refills it): for a key the cached map does not
559
+ * know, which may be a field added since the schema was cached.
551
560
  */
552
- export async function getModuleFieldTypes(moduleName, fetchSchema = defaultSchemaFetcher) {
553
- const schema = await getExtendedSchema(moduleName, fetchSchema);
561
+ export async function getModuleFieldTypes(moduleName, fetchSchema = defaultSchemaFetcher, { fresh = false } = {}) {
562
+ const schema = await getExtendedSchema(moduleName, fetchSchema, fresh);
554
563
  const info = schema?.information;
555
564
  if (!info || info.length === 0)
556
565
  return null;
@@ -638,6 +647,10 @@ export function resolveInputKeys(types, input, labels) {
638
647
  for (const key of Object.keys(input)) {
639
648
  if (types.has(key))
640
649
  continue;
650
+ // A people module's Username is on its forms but never in its field list;
651
+ // the platform maps it (or refuses it on a module that is not one).
652
+ if (isSystemFieldName(key))
653
+ continue;
641
654
  const labelled = labels?.get(fieldKey(key));
642
655
  const nearMiss = byKey.get(fieldKey(key));
643
656
  const viaLabel = !!labelled && types.has(labelled) && (!nearMiss || nearMiss === labelled);
package/build/api.d.ts CHANGED
@@ -1,12 +1,30 @@
1
+ /**
2
+ * Point the current call at a workspace. The MCP keeps no state between calls: this writes the
3
+ * call's own request context — every tool call runs in one (tools.ts registerTool), as does every
4
+ * HTTP request — and it is gone when the call ends. There used to be a process-wide fallback for
5
+ * stdio, written by set_workspace and by any call that passed workspaceId, so one call silently
6
+ * re-pointed every later one (production, 2026-11-10: a peek at a workspace's copy made the
7
+ * original's Customer list 0 rows). Outside a call there is nothing to write to, so that is an error.
8
+ */
1
9
  export declare function setWorkspaceId(wsid: string): void;
10
+ /**
11
+ * The workspace the current call uses: its own (the tool's workspaceId, or the HTTP request's
12
+ * x-workspace-id header), else INISTATE_WORKSPACE_ID, else none — the server then resolves it
13
+ * (a member with only one workspace) or refuses.
14
+ */
2
15
  export declare function getWorkspaceId(): string | null;
3
16
  /**
4
17
  * A bare "Module 'X' not found" sends agents hunting across workspaces one
5
18
  * set_workspace at a time (observed: 7 calls to locate a module created in
6
- * the wrong workspace). Anchor the error to the active workspace and name
7
- * the two possible fixes.
19
+ * the wrong workspace). Anchor the error to the workspace this call used and
20
+ * name the two possible fixes.
8
21
  */
9
22
  export declare function annotateModuleNotFound(message: string): string;
23
+ /**
24
+ * The next step for the agent after an API error: the server's own when it sends one (it knows why, e.g. a
25
+ * write that may already be saved), else the status's generic one.
26
+ */
27
+ export declare function errorAgentAction(status: number, body: Record<string, unknown>): string;
10
28
  /** What a tool result may weigh, as the compact JSON the tools send (tools.ts `ok`). */
11
29
  export declare const TRUNCATE_BUDGET = 30000;
12
30
  /**
@@ -28,8 +46,9 @@ export declare const TRUNCATE_BUDGET = 30000;
28
46
  */
29
47
  export declare function fitListPage<T>(data: T, budget?: number): T;
30
48
  export declare function get(path: string): Promise<unknown>;
31
- export declare function post(path: string, body?: unknown): Promise<unknown>;
32
- export declare function put(path: string, body?: unknown): Promise<unknown>;
49
+ export declare function post(path: string, body?: unknown, extraHeaders?: Record<string, string>): Promise<unknown>;
50
+ export declare function del(path: string): Promise<unknown>;
51
+ export declare function put(path: string, body?: unknown, extraHeaders?: Record<string, string>): Promise<unknown>;
33
52
  /**
34
53
  * Upload a file via multipart/form-data.
35
54
  */
package/build/api.js CHANGED
@@ -20,29 +20,32 @@ function log(message, data) {
20
20
  const ENV_API_KEY = process.env.INISTATE_ACCESS_TOKEN ||
21
21
  process.env.INISTATE_API_TOKEN ||
22
22
  process.env.INISTATE_API_KEY;
23
- let workspaceId = process.env.INISTATE_WORKSPACE_ID ?? null;
23
+ /** The workspace a call uses when it names none: configuration, fixed for the life of the process. */
24
+ const ENV_WORKSPACE_ID = process.env.INISTATE_WORKSPACE_ID || null;
25
+ /**
26
+ * Point the current call at a workspace. The MCP keeps no state between calls: this writes the
27
+ * call's own request context — every tool call runs in one (tools.ts registerTool), as does every
28
+ * HTTP request — and it is gone when the call ends. There used to be a process-wide fallback for
29
+ * stdio, written by set_workspace and by any call that passed workspaceId, so one call silently
30
+ * re-pointed every later one (production, 2026-11-10: a peek at a workspace's copy made the
31
+ * original's Customer list 0 rows). Outside a call there is nothing to write to, so that is an error.
32
+ */
24
33
  export function setWorkspaceId(wsid) {
25
34
  const ctx = requestContext.getStore();
26
- if (ctx) {
27
- // HTTP mode: write to per-request context, not the global
28
- ctx.workspaceId = wsid;
29
- }
30
- else {
31
- // stdio/session mode: write to the global
32
- workspaceId = wsid;
35
+ if (!ctx) {
36
+ throw new Error("setWorkspaceId outside a tool call: the MCP keeps no workspace between calls.");
33
37
  }
34
- }
35
- export function getWorkspaceId() {
36
- return workspaceId;
38
+ ctx.workspaceId = wsid;
37
39
  }
38
40
  /**
39
- * Resolve the effective workspace ID.
40
- * Priority: per-request context header > tool param (via setWorkspaceId) > env var
41
+ * The workspace the current call uses: its own (the tool's workspaceId, or the HTTP request's
42
+ * x-workspace-id header), else INISTATE_WORKSPACE_ID, else none — the server then resolves it
43
+ * (a member with only one workspace) or refuses.
41
44
  */
42
- function effectiveWorkspaceId() {
43
- const ctx = requestContext.getStore();
44
- return ctx?.workspaceId || workspaceId;
45
+ export function getWorkspaceId() {
46
+ return requestContext.getStore()?.workspaceId || ENV_WORKSPACE_ID;
45
47
  }
48
+ const effectiveWorkspaceId = getWorkspaceId;
46
49
  /**
47
50
  * Resolve the effective Authorization header value.
48
51
  * Priority: per-request context header (HTTP/OAuth flow) > env API key (stdio).
@@ -76,21 +79,32 @@ function authHeader() {
76
79
  /**
77
80
  * A bare "Module 'X' not found" sends agents hunting across workspaces one
78
81
  * set_workspace at a time (observed: 7 calls to locate a module created in
79
- * the wrong workspace). Anchor the error to the active workspace and name
80
- * the two possible fixes.
82
+ * the wrong workspace). Anchor the error to the workspace this call used and
83
+ * name the two possible fixes.
81
84
  */
82
85
  export function annotateModuleNotFound(message) {
83
86
  if (!/^module '.+' not found\.?$/i.test(message.trim()))
84
87
  return message;
85
88
  const wsid = effectiveWorkspaceId();
86
89
  return wsid
87
- ? `${message.trim().replace(/\.$/, "")} in the active workspace (id ${wsid}). Check list_modules for the exact name, or call set_workspace if the module lives in another workspace.`
88
- : `${message.trim().replace(/\.$/, "")}. No active workspace is set — call set_workspace (or pass workspaceId) first.`;
90
+ ? `${message.trim().replace(/\.$/, "")} in workspace ${wsid}, the one this call used. Check list_modules for the exact name, or pass another workspaceId if the module lives in another workspace.`
91
+ : `${message.trim().replace(/\.$/, "")}. This call named no workspace, and the MCP keeps none between calls — pass workspaceId (list_workspaces lists them).`;
92
+ }
93
+ /**
94
+ * The next step for the agent after an API error: the server's own when it sends one (it knows why, e.g. a
95
+ * write that may already be saved), else the status's generic one.
96
+ */
97
+ export function errorAgentAction(status, body) {
98
+ const own = body?.agent_action;
99
+ return typeof own === "string" && own.trim() ? own : agentAction(status);
89
100
  }
90
101
  function agentAction(status) {
91
102
  switch (status) {
92
103
  case 400:
93
104
  return "Check the error message, correct the input, and retry.";
105
+ case 409:
106
+ // e.g. a create the source has not confirmed: submitting it again could save it twice
107
+ return "This conflicts with a write that may already be saved. Do not submit it again: read the entry or the list first, then tell the user.";
94
108
  case 401:
95
109
  return "API key or token is invalid or expired. Check credentials and retry.";
96
110
  case 403:
@@ -117,10 +131,13 @@ async function handleResponse(res) {
117
131
  error: body.error || `HTTP ${res.status}`,
118
132
  message: annotateModuleNotFound(String(body.message || text || res.statusText)),
119
133
  details: body.details || null,
120
- agent_action: agentAction(res.status),
134
+ agent_action: errorAgentAction(res.status, body),
121
135
  };
122
136
  log("api_error", { status: res.status, url: res.url, error: error.error, message: error.message, details: error.details });
123
- throw Object.assign(new Error(String(error.message)), { structured: error });
137
+ // `body` keeps the server's own envelope for the tools that relay it whole
138
+ // (set_module_access: changes, warnings, the server's agent_action). err()
139
+ // serializes `structured` only, so every other tool's error is unchanged.
140
+ throw Object.assign(new Error(String(error.message)), { structured: error, status: res.status, body });
124
141
  }
125
142
  if (!text)
126
143
  return null;
@@ -202,18 +219,26 @@ export async function get(path) {
202
219
  const res = await request(`${BASE_URL}${path}`, {}, headers);
203
220
  return handleResponse(res);
204
221
  }
205
- export async function post(path, body) {
222
+ /** The JSON headers plus a call's own (e.g. the design-write provenance headers). */
223
+ function withHeaders(extra) {
224
+ return extra ? () => ({ ...headers(), ...extra }) : headers;
225
+ }
226
+ export async function post(path, body, extraHeaders) {
206
227
  const res = await request(`${BASE_URL}${path}`, {
207
228
  method: "POST",
208
229
  body: body !== undefined ? JSON.stringify(body) : undefined,
209
- }, headers);
230
+ }, withHeaders(extraHeaders));
231
+ return handleResponse(res);
232
+ }
233
+ export async function del(path) {
234
+ const res = await request(`${BASE_URL}${path}`, { method: "DELETE" }, headers);
210
235
  return handleResponse(res);
211
236
  }
212
- export async function put(path, body) {
237
+ export async function put(path, body, extraHeaders) {
213
238
  const res = await request(`${BASE_URL}${path}`, {
214
239
  method: "PUT",
215
240
  body: body !== undefined ? JSON.stringify(body) : undefined,
216
- }, headers);
241
+ }, withHeaders(extraHeaders));
217
242
  return handleResponse(res);
218
243
  }
219
244
  /**
@@ -47,7 +47,50 @@ export interface Capabilities {
47
47
  * false: the tools drop the block and log it rather than let it vanish silently.
48
48
  */
49
49
  card?: boolean;
50
+ /**
51
+ * Module skills: procedures a workspace's designers attach to a module, listed by name and
52
+ * description on the module and read on demand (get_skill). Absent or false: get_skill
53
+ * returns a capability message.
54
+ */
55
+ skills?: boolean;
56
+ /**
57
+ * Approval requests: a human-actor activity the agent prepares and sends to a person, who
58
+ * approves it in the Inistate app (submit_activity with `approval`). Absent or false: the approval
59
+ * tools return a capability message.
60
+ */
61
+ approvals?: boolean;
62
+ /**
63
+ * Automations through MCP: a module's automations read, saved (checked, tested, dry run) and their live runs
64
+ * watched (get_module_automations, save_automation, get_automation_runs). Absent or false: those tools return a
65
+ * capability message.
66
+ */
67
+ automations?: boolean;
68
+ /**
69
+ * The module design record: create_module / update_module send the agent's `ai` block (reasoning,
70
+ * sources, model, request) and who is writing (client, session), and the backend keeps them on the
71
+ * module's version history. On such a backend that is also governed, `ai` is required, as on
72
+ * submit_activity. Absent or false: `ai` is optional and not sent.
73
+ */
74
+ designRecord?: boolean;
75
+ /**
76
+ * Human-only approval of AI design changes: create_module / update_module take `approval` and the backend stores
77
+ * a change that needs a person for them to approve in Studio. Absent or false: `approval` is refused with
78
+ * not_supported, never silently dropped.
79
+ */
80
+ designApprovals?: boolean;
81
+ /**
82
+ * An entry's documents (get_document): the module's own system's print or an Inistate-designed document, as a
83
+ * link or as the file. Absent or false: get_document returns a capability message.
84
+ */
85
+ documents?: boolean;
86
+ /**
87
+ * Re-linking a Module field to another module with its entries' values (relink_field), and update_module's pointer
88
+ * to it. Absent or false: relink_field is not registered.
89
+ */
90
+ relink?: boolean;
50
91
  }
92
+ /** Who is writing a design: the provenance headers a configure write carries (see provenance.ts). */
93
+ export type DesignWriteHeaders = Record<string, string>;
51
94
  export interface ListEntriesParams {
52
95
  module: string;
53
96
  listing?: string;
@@ -99,12 +142,34 @@ export interface DownloadFileParams {
99
142
  guid: string;
100
143
  fileName: string;
101
144
  }
145
+ /** get_document: one document of one entry, as a link (the default) or as the file. */
146
+ export interface GetDocumentParams {
147
+ module: string;
148
+ /** The entry's document number or its entry id. */
149
+ entry: string;
150
+ /** The document's name or id; optional when the entry has one document. */
151
+ document?: string;
152
+ format?: string;
153
+ as?: "link" | "file";
154
+ }
102
155
  export interface RequestUploadUrlParams {
103
156
  module: string;
104
157
  fileName: string;
105
158
  contentType: string;
106
159
  fileSize: number;
107
160
  }
161
+ /** get_skill: one module skill's body, or one of its reference files. */
162
+ export interface GetModuleSkillParams {
163
+ module: string;
164
+ skill: string;
165
+ file?: string;
166
+ }
167
+ export interface GetModuleHistoryParams {
168
+ module: string;
169
+ limit?: number;
170
+ before?: string;
171
+ version?: string;
172
+ }
108
173
  export interface ConfirmUploadParams {
109
174
  s3Key: string;
110
175
  }
@@ -136,15 +201,59 @@ export interface Backend {
136
201
  /** Which backend this is — drives capability messages and diagnostics. */
137
202
  readonly kind: "local" | "cloud";
138
203
  capabilities(): Capabilities;
139
- /** Set the active workspace for subsequent calls. Context op, no I/O. */
204
+ /**
205
+ * Point the current tool call at a workspace. Context op, no I/O, and nothing outlives the
206
+ * call: the MCP keeps no workspace between calls.
207
+ */
140
208
  setActiveWorkspace(wsid: string): void;
141
209
  listWorkspaces(search?: string): Promise<unknown>;
142
210
  getWorkspace(workspaceId: string): Promise<unknown>;
143
211
  listModules(): Promise<unknown>;
144
212
  getModuleSchema(module: string, tier: "basic" | "extended"): Promise<unknown>;
145
213
  getModuleCanvas(module: string): Promise<unknown>;
146
- createModule(payload: Record<string, unknown>): Promise<unknown>;
147
- updateModule(payload: Record<string, unknown>): Promise<unknown>;
214
+ /**
215
+ * The module's access rules in the access vocabulary (get_module_access).
216
+ * Optional: a backend without access rules leaves it out, and the tool
217
+ * answers with the authorization capability message.
218
+ */
219
+ getModuleAccess?(module: string): Promise<unknown>;
220
+ /**
221
+ * Change the rules of the items `payload.access` names (set_module_access).
222
+ * Optional like getModuleAccess.
223
+ */
224
+ setModuleAccess?(module: string, payload: Record<string, unknown>): Promise<unknown>;
225
+ /** Make or change one listing, with its access (save_listing). Optional like getModuleAccess. */
226
+ saveListing?(module: string, payload: Record<string, unknown>): Promise<unknown>;
227
+ /** Remove one listing by id or name, with the rules on it (save_listing remove). */
228
+ removeListing?(module: string, listing: string, options: {
229
+ dryRun: boolean;
230
+ confirmed: boolean;
231
+ }): Promise<unknown>;
232
+ /**
233
+ * A module's automations: those that run when an activity is submitted and the schedules that run one on each
234
+ * entry they match, in display names with scripts hidden, each with its stored tests (get_module_automations).
235
+ * Only when capabilities().automations is true; optional so other backends need not stub them.
236
+ */
237
+ getModuleAutomations?(module: string): Promise<unknown>;
238
+ /** Add or change one automation, dry run included (save_automation): `{ automation, dryRun?, confirmed? }`. */
239
+ saveAutomation?(module: string, payload: Record<string, unknown>): Promise<unknown>;
240
+ /** An automation's latest live runs and its probation (get_automation_runs). */
241
+ getAutomationRuns?(module: string, automationId: string, limit?: number): Promise<unknown>;
242
+ /** A module's recent real entries replayed on a changed automation, nothing saved (replay_change):
243
+ * `{ automation?, count?, entryIds? }`. */
244
+ replayChange?(module: string, payload: Record<string, unknown>): Promise<unknown>;
245
+ /** A module's design history (get_module_history). Only when capabilities().designRecord is true. */
246
+ getModuleHistory?(params: GetModuleHistoryParams): Promise<unknown>;
247
+ /** Re-link a Module field to another module, its entries' values with it (relink_field). The Inistate Platform only. */
248
+ relinkField?(module: string, payload: Record<string, unknown>, provenance?: DesignWriteHeaders): Promise<unknown>;
249
+ /** Only when capabilities().skills is true; optional so a backend without skills need not stub it. */
250
+ getModuleSkill?(params: GetModuleSkillParams): Promise<unknown>;
251
+ /** Only when capabilities().approvals is true; optional so other backends need not stub them. */
252
+ requestApproval?(payload: Record<string, unknown>): Promise<unknown>;
253
+ getApprovalRequest?(requestId: string): Promise<unknown>;
254
+ /** `provenance`: who is writing (designWriteHeaders), for the module's history; a backend may ignore it. */
255
+ createModule(payload: Record<string, unknown>, provenance?: DesignWriteHeaders): Promise<unknown>;
256
+ updateModule(payload: Record<string, unknown>, provenance?: DesignWriteHeaders): Promise<unknown>;
148
257
  listEntries(params: ListEntriesParams): Promise<unknown>;
149
258
  aggregateEntries(params: AggregateEntriesParams): Promise<unknown>;
150
259
  getEntry(params: GetEntryParams): Promise<unknown>;
@@ -156,6 +265,8 @@ export interface Backend {
156
265
  downloadFile(params: DownloadFileParams): Promise<DownloadResult>;
157
266
  requestUploadUrl(params: RequestUploadUrlParams): Promise<unknown>;
158
267
  confirmUpload(params: ConfirmUploadParams): Promise<unknown>;
268
+ /** Only when capabilities().documents is true; optional so other backends need not stub it. */
269
+ getDocument?(params: GetDocumentParams): Promise<unknown>;
159
270
  /**
160
271
  * Scaffold a module schema from an existing table/database. Only meaningful
161
272
  * when capabilities().scaffold is true; the tool gates on that before calling,
@@ -176,8 +287,24 @@ export declare class CloudBackend implements Backend {
176
287
  listModules(): Promise<unknown>;
177
288
  getModuleSchema(module: string, tier: "basic" | "extended"): Promise<unknown>;
178
289
  getModuleCanvas(module: string): Promise<unknown>;
179
- createModule(payload: Record<string, unknown>): Promise<unknown>;
180
- updateModule(payload: Record<string, unknown>): Promise<unknown>;
290
+ getModuleAccess(module: string): Promise<unknown>;
291
+ setModuleAccess(module: string, payload: Record<string, unknown>): Promise<unknown>;
292
+ saveListing(module: string, payload: Record<string, unknown>): Promise<unknown>;
293
+ removeListing(module: string, listing: string, options: {
294
+ dryRun: boolean;
295
+ confirmed: boolean;
296
+ }): Promise<unknown>;
297
+ getModuleAutomations(module: string): Promise<unknown>;
298
+ saveAutomation(module: string, payload: Record<string, unknown>): Promise<unknown>;
299
+ getAutomationRuns(module: string, automationId: string, limit?: number): Promise<unknown>;
300
+ replayChange(module: string, payload: Record<string, unknown>): Promise<unknown>;
301
+ getModuleHistory(p: GetModuleHistoryParams): Promise<unknown>;
302
+ getModuleSkill(p: GetModuleSkillParams): Promise<unknown>;
303
+ requestApproval(payload: Record<string, unknown>): Promise<unknown>;
304
+ getApprovalRequest(requestId: string): Promise<unknown>;
305
+ createModule(payload: Record<string, unknown>, provenance?: DesignWriteHeaders): Promise<unknown>;
306
+ updateModule(payload: Record<string, unknown>, provenance?: DesignWriteHeaders): Promise<unknown>;
307
+ relinkField(module: string, payload: Record<string, unknown>, provenance?: DesignWriteHeaders): Promise<unknown>;
181
308
  listEntries(p: ListEntriesParams): Promise<unknown>;
182
309
  aggregateEntries(p: AggregateEntriesParams): Promise<unknown>;
183
310
  getEntry(p: GetEntryParams): Promise<unknown>;
@@ -189,5 +316,6 @@ export declare class CloudBackend implements Backend {
189
316
  downloadFile(p: DownloadFileParams): Promise<DownloadResult>;
190
317
  requestUploadUrl(p: RequestUploadUrlParams): Promise<unknown>;
191
318
  confirmUpload(p: ConfirmUploadParams): Promise<unknown>;
319
+ getDocument(p: GetDocumentParams): Promise<unknown>;
192
320
  scaffoldModule(_p: ScaffoldModuleParams): Promise<unknown>;
193
321
  }