inistate-mcp 1.3.5 → 1.4.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.
@@ -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: {
@@ -548,9 +562,12 @@ export async function getModuleStates(moduleName, fetchSchema = defaultSchemaFet
548
562
  *
549
563
  * Split out so bulk callers (submit_activities) can fetch once and reuse the
550
564
  * map across items via validateInputShapesWith.
565
+ *
566
+ * `fresh` skips the cache (and refills it): for a key the cached map does not
567
+ * know, which may be a field added since the schema was cached.
551
568
  */
552
- export async function getModuleFieldTypes(moduleName, fetchSchema = defaultSchemaFetcher) {
553
- const schema = await getExtendedSchema(moduleName, fetchSchema);
569
+ export async function getModuleFieldTypes(moduleName, fetchSchema = defaultSchemaFetcher, { fresh = false } = {}) {
570
+ const schema = await getExtendedSchema(moduleName, fetchSchema, fresh);
554
571
  const info = schema?.information;
555
572
  if (!info || info.length === 0)
556
573
  return null;
@@ -638,6 +655,10 @@ export function resolveInputKeys(types, input, labels) {
638
655
  for (const key of Object.keys(input)) {
639
656
  if (types.has(key))
640
657
  continue;
658
+ // A people module's Username is on its forms but never in its field list;
659
+ // the platform maps it (or refuses it on a module that is not one).
660
+ if (isSystemFieldName(key))
661
+ continue;
641
662
  const labelled = labels?.get(fieldKey(key));
642
663
  const nearMiss = byKey.get(fieldKey(key));
643
664
  const viaLabel = !!labelled && types.has(labelled) && (!nearMiss || nearMiss === labelled);
package/build/api.d.ts CHANGED
@@ -7,6 +7,11 @@ export declare function getWorkspaceId(): string | null;
7
7
  * the two possible fixes.
8
8
  */
9
9
  export declare function annotateModuleNotFound(message: string): string;
10
+ /**
11
+ * The next step for the agent after an API error: the server's own when it sends one (it knows why, e.g. a
12
+ * write that may already be saved), else the status's generic one.
13
+ */
14
+ export declare function errorAgentAction(status: number, body: Record<string, unknown>): string;
10
15
  /** What a tool result may weigh, as the compact JSON the tools send (tools.ts `ok`). */
11
16
  export declare const TRUNCATE_BUDGET = 30000;
12
17
  /**
@@ -28,8 +33,9 @@ export declare const TRUNCATE_BUDGET = 30000;
28
33
  */
29
34
  export declare function fitListPage<T>(data: T, budget?: number): T;
30
35
  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>;
36
+ export declare function post(path: string, body?: unknown, extraHeaders?: Record<string, string>): Promise<unknown>;
37
+ export declare function del(path: string): Promise<unknown>;
38
+ export declare function put(path: string, body?: unknown, extraHeaders?: Record<string, string>): Promise<unknown>;
33
39
  /**
34
40
  * Upload a file via multipart/form-data.
35
41
  */
package/build/api.js CHANGED
@@ -87,10 +87,21 @@ export function annotateModuleNotFound(message) {
87
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
88
  : `${message.trim().replace(/\.$/, "")}. No active workspace is set — call set_workspace (or pass workspaceId) first.`;
89
89
  }
90
+ /**
91
+ * The next step for the agent after an API error: the server's own when it sends one (it knows why, e.g. a
92
+ * write that may already be saved), else the status's generic one.
93
+ */
94
+ export function errorAgentAction(status, body) {
95
+ const own = body?.agent_action;
96
+ return typeof own === "string" && own.trim() ? own : agentAction(status);
97
+ }
90
98
  function agentAction(status) {
91
99
  switch (status) {
92
100
  case 400:
93
101
  return "Check the error message, correct the input, and retry.";
102
+ case 409:
103
+ // e.g. a create the source has not confirmed: submitting it again could save it twice
104
+ 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
105
  case 401:
95
106
  return "API key or token is invalid or expired. Check credentials and retry.";
96
107
  case 403:
@@ -117,10 +128,13 @@ async function handleResponse(res) {
117
128
  error: body.error || `HTTP ${res.status}`,
118
129
  message: annotateModuleNotFound(String(body.message || text || res.statusText)),
119
130
  details: body.details || null,
120
- agent_action: agentAction(res.status),
131
+ agent_action: errorAgentAction(res.status, body),
121
132
  };
122
133
  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 });
134
+ // `body` keeps the server's own envelope for the tools that relay it whole
135
+ // (set_module_access: changes, warnings, the server's agent_action). err()
136
+ // serializes `structured` only, so every other tool's error is unchanged.
137
+ throw Object.assign(new Error(String(error.message)), { structured: error, status: res.status, body });
124
138
  }
125
139
  if (!text)
126
140
  return null;
@@ -202,18 +216,26 @@ export async function get(path) {
202
216
  const res = await request(`${BASE_URL}${path}`, {}, headers);
203
217
  return handleResponse(res);
204
218
  }
205
- export async function post(path, body) {
219
+ /** The JSON headers plus a call's own (e.g. the design-write provenance headers). */
220
+ function withHeaders(extra) {
221
+ return extra ? () => ({ ...headers(), ...extra }) : headers;
222
+ }
223
+ export async function post(path, body, extraHeaders) {
206
224
  const res = await request(`${BASE_URL}${path}`, {
207
225
  method: "POST",
208
226
  body: body !== undefined ? JSON.stringify(body) : undefined,
209
- }, headers);
227
+ }, withHeaders(extraHeaders));
228
+ return handleResponse(res);
229
+ }
230
+ export async function del(path) {
231
+ const res = await request(`${BASE_URL}${path}`, { method: "DELETE" }, headers);
210
232
  return handleResponse(res);
211
233
  }
212
- export async function put(path, body) {
234
+ export async function put(path, body, extraHeaders) {
213
235
  const res = await request(`${BASE_URL}${path}`, {
214
236
  method: "PUT",
215
237
  body: body !== undefined ? JSON.stringify(body) : undefined,
216
- }, headers);
238
+ }, withHeaders(extraHeaders));
217
239
  return handleResponse(res);
218
240
  }
219
241
  /**
@@ -47,7 +47,45 @@ 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;
50
86
  }
87
+ /** Who is writing a design: the provenance headers a configure write carries (see provenance.ts). */
88
+ export type DesignWriteHeaders = Record<string, string>;
51
89
  export interface ListEntriesParams {
52
90
  module: string;
53
91
  listing?: string;
@@ -99,12 +137,34 @@ export interface DownloadFileParams {
99
137
  guid: string;
100
138
  fileName: string;
101
139
  }
140
+ /** get_document: one document of one entry, as a link (the default) or as the file. */
141
+ export interface GetDocumentParams {
142
+ module: string;
143
+ /** The entry's document number or its entry id. */
144
+ entry: string;
145
+ /** The document's name or id; optional when the entry has one document. */
146
+ document?: string;
147
+ format?: string;
148
+ as?: "link" | "file";
149
+ }
102
150
  export interface RequestUploadUrlParams {
103
151
  module: string;
104
152
  fileName: string;
105
153
  contentType: string;
106
154
  fileSize: number;
107
155
  }
156
+ /** get_skill: one module skill's body, or one of its reference files. */
157
+ export interface GetModuleSkillParams {
158
+ module: string;
159
+ skill: string;
160
+ file?: string;
161
+ }
162
+ export interface GetModuleHistoryParams {
163
+ module: string;
164
+ limit?: number;
165
+ before?: string;
166
+ version?: string;
167
+ }
108
168
  export interface ConfirmUploadParams {
109
169
  s3Key: string;
110
170
  }
@@ -143,8 +203,47 @@ export interface Backend {
143
203
  listModules(): Promise<unknown>;
144
204
  getModuleSchema(module: string, tier: "basic" | "extended"): Promise<unknown>;
145
205
  getModuleCanvas(module: string): Promise<unknown>;
146
- createModule(payload: Record<string, unknown>): Promise<unknown>;
147
- updateModule(payload: Record<string, unknown>): Promise<unknown>;
206
+ /**
207
+ * The module's access rules in the access vocabulary (get_module_access).
208
+ * Optional: a backend without access rules leaves it out, and the tool
209
+ * answers with the authorization capability message.
210
+ */
211
+ getModuleAccess?(module: string): Promise<unknown>;
212
+ /**
213
+ * Change the rules of the items `payload.access` names (set_module_access).
214
+ * Optional like getModuleAccess.
215
+ */
216
+ setModuleAccess?(module: string, payload: Record<string, unknown>): Promise<unknown>;
217
+ /** Make or change one listing, with its access (save_listing). Optional like getModuleAccess. */
218
+ saveListing?(module: string, payload: Record<string, unknown>): Promise<unknown>;
219
+ /** Remove one listing by id or name, with the rules on it (save_listing remove). */
220
+ removeListing?(module: string, listing: string, options: {
221
+ dryRun: boolean;
222
+ confirmed: boolean;
223
+ }): Promise<unknown>;
224
+ /**
225
+ * A module's automations: those that run when an activity is submitted and the schedules that run one on each
226
+ * entry they match, in display names with scripts hidden, each with its stored tests (get_module_automations).
227
+ * Only when capabilities().automations is true; optional so other backends need not stub them.
228
+ */
229
+ getModuleAutomations?(module: string): Promise<unknown>;
230
+ /** Add or change one automation, dry run included (save_automation): `{ automation, dryRun?, confirmed? }`. */
231
+ saveAutomation?(module: string, payload: Record<string, unknown>): Promise<unknown>;
232
+ /** An automation's latest live runs and its probation (get_automation_runs). */
233
+ getAutomationRuns?(module: string, automationId: string, limit?: number): Promise<unknown>;
234
+ /** A module's recent real entries replayed on a changed automation, nothing saved (replay_change):
235
+ * `{ automation?, count?, entryIds? }`. */
236
+ replayChange?(module: string, payload: Record<string, unknown>): Promise<unknown>;
237
+ /** A module's design history (get_module_history). Only when capabilities().designRecord is true. */
238
+ getModuleHistory?(params: GetModuleHistoryParams): Promise<unknown>;
239
+ /** Only when capabilities().skills is true; optional so a backend without skills need not stub it. */
240
+ getModuleSkill?(params: GetModuleSkillParams): Promise<unknown>;
241
+ /** Only when capabilities().approvals is true; optional so other backends need not stub them. */
242
+ requestApproval?(payload: Record<string, unknown>): Promise<unknown>;
243
+ getApprovalRequest?(requestId: string): Promise<unknown>;
244
+ /** `provenance`: who is writing (designWriteHeaders), for the module's history; a backend may ignore it. */
245
+ createModule(payload: Record<string, unknown>, provenance?: DesignWriteHeaders): Promise<unknown>;
246
+ updateModule(payload: Record<string, unknown>, provenance?: DesignWriteHeaders): Promise<unknown>;
148
247
  listEntries(params: ListEntriesParams): Promise<unknown>;
149
248
  aggregateEntries(params: AggregateEntriesParams): Promise<unknown>;
150
249
  getEntry(params: GetEntryParams): Promise<unknown>;
@@ -156,6 +255,8 @@ export interface Backend {
156
255
  downloadFile(params: DownloadFileParams): Promise<DownloadResult>;
157
256
  requestUploadUrl(params: RequestUploadUrlParams): Promise<unknown>;
158
257
  confirmUpload(params: ConfirmUploadParams): Promise<unknown>;
258
+ /** Only when capabilities().documents is true; optional so other backends need not stub it. */
259
+ getDocument?(params: GetDocumentParams): Promise<unknown>;
159
260
  /**
160
261
  * Scaffold a module schema from an existing table/database. Only meaningful
161
262
  * when capabilities().scaffold is true; the tool gates on that before calling,
@@ -176,8 +277,23 @@ export declare class CloudBackend implements Backend {
176
277
  listModules(): Promise<unknown>;
177
278
  getModuleSchema(module: string, tier: "basic" | "extended"): Promise<unknown>;
178
279
  getModuleCanvas(module: string): Promise<unknown>;
179
- createModule(payload: Record<string, unknown>): Promise<unknown>;
180
- updateModule(payload: Record<string, unknown>): Promise<unknown>;
280
+ getModuleAccess(module: string): Promise<unknown>;
281
+ setModuleAccess(module: string, payload: Record<string, unknown>): Promise<unknown>;
282
+ saveListing(module: string, payload: Record<string, unknown>): Promise<unknown>;
283
+ removeListing(module: string, listing: string, options: {
284
+ dryRun: boolean;
285
+ confirmed: boolean;
286
+ }): Promise<unknown>;
287
+ getModuleAutomations(module: string): Promise<unknown>;
288
+ saveAutomation(module: string, payload: Record<string, unknown>): Promise<unknown>;
289
+ getAutomationRuns(module: string, automationId: string, limit?: number): Promise<unknown>;
290
+ replayChange(module: string, payload: Record<string, unknown>): Promise<unknown>;
291
+ getModuleHistory(p: GetModuleHistoryParams): Promise<unknown>;
292
+ getModuleSkill(p: GetModuleSkillParams): Promise<unknown>;
293
+ requestApproval(payload: Record<string, unknown>): Promise<unknown>;
294
+ getApprovalRequest(requestId: string): Promise<unknown>;
295
+ createModule(payload: Record<string, unknown>, provenance?: DesignWriteHeaders): Promise<unknown>;
296
+ updateModule(payload: Record<string, unknown>, provenance?: DesignWriteHeaders): Promise<unknown>;
181
297
  listEntries(p: ListEntriesParams): Promise<unknown>;
182
298
  aggregateEntries(p: AggregateEntriesParams): Promise<unknown>;
183
299
  getEntry(p: GetEntryParams): Promise<unknown>;
@@ -189,5 +305,6 @@ export declare class CloudBackend implements Backend {
189
305
  downloadFile(p: DownloadFileParams): Promise<DownloadResult>;
190
306
  requestUploadUrl(p: RequestUploadUrlParams): Promise<unknown>;
191
307
  confirmUpload(p: ConfirmUploadParams): Promise<unknown>;
308
+ getDocument(p: GetDocumentParams): Promise<unknown>;
192
309
  scaffoldModule(_p: ScaffoldModuleParams): Promise<unknown>;
193
310
  }
package/build/backend.js CHANGED
@@ -17,6 +17,7 @@
17
17
  * tool surface does not yet adapt to it (that is the next step).
18
18
  */
19
19
  import * as api from "./api.js";
20
+ import { experimentalEnabled } from "./experimental.js";
20
21
  /**
21
22
  * The hosted Inistate Platform backend. A thin wrapper over api.ts that builds
22
23
  * the same paths and request bodies the handlers used to construct inline.
@@ -34,6 +35,12 @@ export class CloudBackend {
34
35
  scaffold: false,
35
36
  modes: ["runtime", "configure", "frontend"],
36
37
  card: true,
38
+ skills: true,
39
+ approvals: true,
40
+ automations: experimentalEnabled(),
41
+ designRecord: true,
42
+ designApprovals: true,
43
+ documents: experimentalEnabled(),
37
44
  };
38
45
  }
39
46
  setActiveWorkspace(wsid) {
@@ -57,11 +64,55 @@ export class CloudBackend {
57
64
  getModuleCanvas(module) {
58
65
  return api.get(`/api/configure/${api.enc(module)}`);
59
66
  }
60
- createModule(payload) {
61
- return api.post("/api/configure", payload);
67
+ getModuleAccess(module) {
68
+ return api.get(`/api/configure/${api.enc(module)}/access`);
62
69
  }
63
- updateModule(payload) {
64
- return api.put("/api/configure", payload);
70
+ setModuleAccess(module, payload) {
71
+ return api.put(`/api/configure/${api.enc(module)}/access`, payload);
72
+ }
73
+ saveListing(module, payload) {
74
+ return api.put(`/api/configure/${api.enc(module)}/listing`, payload);
75
+ }
76
+ removeListing(module, listing, options) {
77
+ const query = [options.dryRun ? "dryRun=true" : "", options.confirmed ? "confirmed=true" : ""].filter(Boolean).join("&");
78
+ return api.del(`/api/configure/${api.enc(module)}/listing/${api.enc(listing)}${query ? `?${query}` : ""}`);
79
+ }
80
+ getModuleAutomations(module) {
81
+ return api.get(`/api/configure/${api.enc(module)}/automations`);
82
+ }
83
+ saveAutomation(module, payload) {
84
+ return api.put(`/api/configure/${api.enc(module)}/automations`, payload);
85
+ }
86
+ getAutomationRuns(module, automationId, limit) {
87
+ const query = limit ? `?limit=${limit}` : "";
88
+ return api.get(`/api/configure/${api.enc(module)}/automations/${api.enc(automationId)}/runs${query}`);
89
+ }
90
+ replayChange(module, payload) {
91
+ return api.post(`/api/configure/${api.enc(module)}/replay`, payload);
92
+ }
93
+ getModuleHistory(p) {
94
+ const query = [
95
+ p.limit ? `limit=${p.limit}` : "",
96
+ p.before ? `before=${api.enc(p.before)}` : "",
97
+ p.version ? `version=${api.enc(p.version)}` : "",
98
+ ].filter(Boolean).join("&");
99
+ return api.get(`/api/configure/${api.enc(p.module)}/history${query ? `?${query}` : ""}`);
100
+ }
101
+ getModuleSkill(p) {
102
+ const file = p.file ? `&file=${api.enc(p.file)}` : "";
103
+ return api.get(`/api/mcp/module-skill?module=${api.enc(p.module)}&name=${api.enc(p.skill)}${file}`);
104
+ }
105
+ requestApproval(payload) {
106
+ return api.post("/api/mcp/approval-requests", payload);
107
+ }
108
+ getApprovalRequest(requestId) {
109
+ return api.get(`/api/mcp/approval-requests/${api.enc(requestId)}`);
110
+ }
111
+ createModule(payload, provenance) {
112
+ return api.post("/api/configure", payload, provenance);
113
+ }
114
+ updateModule(payload, provenance) {
115
+ return api.put("/api/configure", payload, provenance);
65
116
  }
66
117
  listEntries(p) {
67
118
  const body = { module: p.module };
@@ -150,6 +201,17 @@ export class CloudBackend {
150
201
  confirmUpload(p) {
151
202
  return api.post("/api/mcp/confirm-upload", { s3Key: p.s3Key });
152
203
  }
204
+ getDocument(p) {
205
+ // `as` travels only when given: without it the server picks (a link, or the file for an Inistate-designed document).
206
+ const body = { module: p.module, entry: p.entry };
207
+ if (p.document)
208
+ body.document = p.document;
209
+ if (p.format)
210
+ body.format = p.format;
211
+ if (p.as)
212
+ body.as = p.as;
213
+ return api.post("/api/mcp/document", body);
214
+ }
153
215
  // The hosted Platform designs modules directly and does not introspect
154
216
  // external stores; capabilities().scaffold is false, so the tool gates this
155
217
  // off and never calls it. Present only to satisfy the interface.
@@ -15,7 +15,7 @@
15
15
  * 2. Attribute the limit to the substrate, not to withholding.
16
16
  * No crippleware tone, no sales pitch beyond one factual `upgrade` line.
17
17
  */
18
- export type CapabilityCode = "workspaces" | "governed_history" | "files" | "authorization" | "frontend_guide" | "scaffold";
18
+ export type CapabilityCode = "workspaces" | "governed_history" | "files" | "authorization" | "frontend_guide" | "scaffold" | "skills" | "approvals" | "automations" | "design_history" | "documents";
19
19
  export interface CapabilityMessage {
20
20
  error: "capability_unavailable";
21
21
  backend: string;
@@ -22,6 +22,11 @@ const MESSAGES = {
22
22
  authorization: "Authentication and authorization are not available on this backend. A local runtime runs within a local trust boundary and has no user identity to authorize against.",
23
23
  frontend_guide: "The frontend guide targets the Inistate Platform REST API, which this backend does not serve.",
24
24
  scaffold: "Scaffolding a module from an existing table or database is a local-runtime introspection capability. This backend designs modules directly — use design_workflow to draft one here.",
25
+ skills: "Module skills are not available on this backend. They are procedures a workspace's designers attach to its modules on the Inistate Platform.",
26
+ approvals: "Approval requests are not available on this backend. Sending a human-actor activity to a person to approve in the app is a capability of the Inistate Platform.",
27
+ automations: "Automations are not available on this backend. Checking, testing and running a module's automations is a capability of the Inistate Platform.",
28
+ design_history: "Module design history is not available on this backend. Who changed a module's design and why is kept by the Inistate Platform.",
29
+ documents: "Documents are not available on this backend. Printing an entry's documents, a connected system's own or one designed in Inistate, is a capability of the Inistate Platform.",
25
30
  };
26
31
  const UPGRADE = {
27
32
  workspaces: "Connect to the Inistate Platform to enable workspaces.",
@@ -30,6 +35,11 @@ const UPGRADE = {
30
35
  authorization: "Connect to the Inistate Platform to enable authentication and authorization.",
31
36
  frontend_guide: "Connect to the Inistate Platform to use the frontend guide.",
32
37
  scaffold: "Run the local runtime (inistate-core) to scaffold a module from an existing SQLite, Notion, or Airtable table.",
38
+ skills: "Connect to the Inistate Platform to use module skills.",
39
+ approvals: "Connect to the Inistate Platform to send approval requests.",
40
+ automations: "Connect to the Inistate Platform to design and run automations.",
41
+ design_history: "Connect to the Inistate Platform to read a module's design history.",
42
+ documents: "Connect to the Inistate Platform to get an entry's documents.",
33
43
  };
34
44
  export function capabilityMessage(capability, backend = "local") {
35
45
  return {
@@ -9,5 +9,9 @@ export interface RequestContext {
9
9
  userId?: string;
10
10
  /** Mode the server was built in for this request (resolved before McpServer construction) */
11
11
  mode?: Mode;
12
+ /** The calling client as its User-Agent names it — the stateless transport sees no clientInfo */
13
+ client?: string;
14
+ /** The client's Mcp-Session-Id, when it sends one — groups one conversation's design saves */
15
+ sessionId?: string;
12
16
  }
13
17
  export declare const requestContext: AsyncLocalStorage<RequestContext>;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Tools still under test: automations (get_module_automations, save_automation, get_automation_runs,
3
+ * replay_change, the inistate://schema/automation guide) and get_document. They are built and tested on main
4
+ * but not registered unless INISTATE_MCP_EXPERIMENTAL=1, so a release can ship without them.
5
+ */
6
+ export declare function experimentalEnabled(): boolean;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Tools still under test: automations (get_module_automations, save_automation, get_automation_runs,
3
+ * replay_change, the inistate://schema/automation guide) and get_document. They are built and tested on main
4
+ * but not registered unless INISTATE_MCP_EXPERIMENTAL=1, so a release can ship without them.
5
+ */
6
+ export function experimentalEnabled() {
7
+ return process.env.INISTATE_MCP_EXPERIMENTAL === "1";
8
+ }
package/build/http.js CHANGED
@@ -135,6 +135,8 @@ app.post("/mcp", express.raw({ type: "*/*", limit: "4mb" }), async (req, res) =>
135
135
  workspaceId: req.headers["x-workspace-id"],
136
136
  userId,
137
137
  mode,
138
+ client: req.headers["user-agent"] || undefined,
139
+ sessionId: req.headers["mcp-session-id"] || undefined,
138
140
  };
139
141
  await requestContext.run(ctx, async () => {
140
142
  const transport = new StreamableHTTPServerTransport({
@@ -483,6 +483,12 @@ export class InistateOAuthProvider {
483
483
  console.log("Connections API disabled on backend; falling back to JWT session");
484
484
  return null;
485
485
  }
486
+ if (createRes.status === 401) {
487
+ // SS06445 (ruled 2026-11-01): the login JWT the consent page posted had expired
488
+ // or was revoked. Retrying with the same JWT fails the same way, so this is not
489
+ // "try again": the user must sign in again. Still never a JWT session (SS06119).
490
+ throw new ConnectionMintDeniedError("login_expired", "Your Inistate sign-in has expired. Connect again and sign in to Inistate.");
491
+ }
486
492
  if (!createRes.ok) {
487
493
  // 400/403 are policy answers (pricing gate, limit) — deny the exchange
488
494
  // outright. Everything else is an availability problem — also fail, never