inistate-mcp 1.0.2 → 1.0.3
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 +6 -5
- package/facts-frontend-guide.md +368 -0
- package/facts-module-design-guide.md +669 -0
- package/inistate-schema.json +1197 -0
- package/package.json +6 -3
- package/server.json +2 -2
package/README.md
CHANGED
|
@@ -174,12 +174,13 @@ npx changeset
|
|
|
174
174
|
npm run release
|
|
175
175
|
|
|
176
176
|
# This does:
|
|
177
|
-
#
|
|
177
|
+
# install dependencies
|
|
178
178
|
# test
|
|
179
|
-
# bump version
|
|
180
|
-
#
|
|
181
|
-
#
|
|
182
|
-
# publish npm
|
|
179
|
+
# bump version + update changelog + sync server.json
|
|
180
|
+
# validate MCP server config
|
|
181
|
+
# build (via npm prepare hook)
|
|
182
|
+
# publish to npm
|
|
183
|
+
# publish to MCP registry
|
|
183
184
|
```
|
|
184
185
|
|
|
185
186
|
## PM2 (Ubuntu/AWS)
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
# Inistate Frontend Integration Guide
|
|
2
|
+
|
|
3
|
+
This guide is for generating custom frontends (Vue, React, or any framework) that call the Inistate REST API directly. Look, feel, and component choice are entirely up to the user — this document covers only the API contract.
|
|
4
|
+
|
|
5
|
+
**Separation of concerns:** the generated frontend holds no long-lived secrets. The user supplies an API token at runtime (form field, env var in the host app, OAuth callback, etc.), and the frontend includes it in the `Authorization` header on every request.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 1. Base URL and headers
|
|
10
|
+
|
|
11
|
+
- Production base URL: `https://api.inistate.com`
|
|
12
|
+
- Every request must include:
|
|
13
|
+
- `Authorization: fsk <api-token>` — the user-supplied token (API key format). For JWT-based auth, use `Authorization: Bearer <jwt>` instead.
|
|
14
|
+
- `wsid: <workspace-id>` — the active workspace ID.
|
|
15
|
+
- `Content-Type: application/json` on POST/PUT bodies.
|
|
16
|
+
- `Accept: application/json`.
|
|
17
|
+
|
|
18
|
+
**CORS:** if the browser blocks direct calls to `api.inistate.com`, route requests through a thin same-origin proxy that only forwards the `Authorization` and `wsid` headers. Do **not** proxy by wrapping the token on the server — keep the token client-supplied so each user uses their own credentials.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## 2. Discovering workspaces and modules
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
GET /api/workspace
|
|
26
|
+
GET /api/workspace/{workspaceId}
|
|
27
|
+
GET /api/mcp/ # list modules (wsid header required)
|
|
28
|
+
GET /api/mcp/{moduleName}?tier=basic # fields + states
|
|
29
|
+
GET /api/mcp/{moduleName}?tier=extended # + activities + flows
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Use `tier=extended` when the UI needs to render action buttons and state transitions; `tier=basic` is enough for read-only lists.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## 3. Querying entries (list views)
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
POST /api/mcp/list
|
|
40
|
+
{
|
|
41
|
+
"module": "Invoices",
|
|
42
|
+
"state": "Pending", // optional: filter by state name
|
|
43
|
+
"search": "acme", // optional: free text
|
|
44
|
+
"filters": { ... }, // optional: see §6
|
|
45
|
+
"sortBy": "Due Date",
|
|
46
|
+
"sortDirection": "asc", // or "desc"
|
|
47
|
+
"currentPage": 0, // 0-based
|
|
48
|
+
"pageSize": 50 // default 50, max 500
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Response shape:
|
|
53
|
+
```
|
|
54
|
+
{
|
|
55
|
+
"list": [ { "id": "...", "state": "...", "data": { "<Field Name>": <value>, ... } }, ... ],
|
|
56
|
+
"totalItems": 123,
|
|
57
|
+
"currentPage": 0,
|
|
58
|
+
"pageSize": 50
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Filter keys are **display names** (not internal IDs). Values are either equality (`"Status": "Open"`) or operator objects (see §6).
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## 4. Reading a single entry
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
POST /api/mcp/entry
|
|
70
|
+
{ "module": "Invoices", "entryId": 42 }
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Returns current field values, state, audit metadata, and the list of activities currently available to the caller.
|
|
74
|
+
|
|
75
|
+
Audit trail:
|
|
76
|
+
```
|
|
77
|
+
POST /api/mcp/history
|
|
78
|
+
{ "module": "Invoices", "entryId": 42, "page": 0 }
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## 5. Forms and submissions (create, edit, custom activities)
|
|
84
|
+
|
|
85
|
+
**Always** call `get_form` before rendering a form or submitting. It tells you required fields, types, valid options, defaults, and (for AI-driven flows) the confidence threshold.
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
POST /api/mcp/form
|
|
89
|
+
{
|
|
90
|
+
"module": "Invoices",
|
|
91
|
+
"activity": "create", // or "edit", "view", or any custom activity
|
|
92
|
+
"entryId": 42 // omit or null for "create"
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Submit:
|
|
97
|
+
```
|
|
98
|
+
POST /api/mcp/activity
|
|
99
|
+
{
|
|
100
|
+
"module": "Invoices",
|
|
101
|
+
"activity": "create", // "create" (no entryId), "edit", "delete", "changeStatus", "comment", "duplicate", "manage", or custom
|
|
102
|
+
"entryId": 42, // omit for create
|
|
103
|
+
"entryIds": [1,2,3], // for bulk ops
|
|
104
|
+
"input": { "<Field Name>": <value>, ... },
|
|
105
|
+
"state": "Approved", // optional target state for changeStatus
|
|
106
|
+
"comment": "...", // optional
|
|
107
|
+
"assignees": ["alice"], // optional usernames
|
|
108
|
+
"due": "2026-05-01T00:00:00Z", // optional ISO 8601
|
|
109
|
+
"ai": { // optional for human-driven UIs; required when an AI agent originated the action
|
|
110
|
+
"reasoning": "...",
|
|
111
|
+
"model": "claude-opus-4-7",
|
|
112
|
+
"confidence": 0.92
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
For a purely user-driven UI (button click → form submit) the `ai` block can be omitted. If your app has an AI layer that pre-fills or auto-submits, include it so the audit trail is honest — when `confidence` falls below the activity's `confidence_threshold`, the server suppresses the state transition and flags the entry for human review.
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## 6. Filter operators
|
|
122
|
+
|
|
123
|
+
Filters live under the `filters` key on `POST /api/mcp/list`. Value forms:
|
|
124
|
+
|
|
125
|
+
| Form | Meaning |
|
|
126
|
+
|---|---|
|
|
127
|
+
| `"Status": "Open"` | equals |
|
|
128
|
+
| `"Amount": { "min": 100, "max": 500 }` | range (inclusive) |
|
|
129
|
+
| `"Title": { "contains": "invoice" }` | substring |
|
|
130
|
+
| `"Title": { "startsWith": "INV-" }` | prefix |
|
|
131
|
+
| `"Title": { "endsWith": ".pdf" }` | suffix |
|
|
132
|
+
| `"Amount": { "above": 1000 }` | strictly greater |
|
|
133
|
+
| `"Amount": { "below": 100 }` | strictly less |
|
|
134
|
+
| `"Date": { "after": "2026-01-01" }` | strictly after |
|
|
135
|
+
| `"Date": { "before": "2026-12-31" }` | strictly before |
|
|
136
|
+
| `"Date": { "between": ["2026-01-01", "2026-03-31"] }` | date range |
|
|
137
|
+
| `"Tags": { "excludes": "archived" }` | does not contain |
|
|
138
|
+
| `"Approved": { "yes": true }` / `{ "no": true }` | boolean |
|
|
139
|
+
| `"Notes": { "empty": true }` / `{ "exists": true }` | null/present |
|
|
140
|
+
| `"Status": { "not": "Closed" }` / `{ "is": "Open" }` | equality variants |
|
|
141
|
+
| `"Owner": "me"` | current authenticated user (User fields only) |
|
|
142
|
+
|
|
143
|
+
Combine with `or`:
|
|
144
|
+
```
|
|
145
|
+
"filters": {
|
|
146
|
+
"or": [
|
|
147
|
+
{ "Status": "Open" },
|
|
148
|
+
{ "Status": "In Review" }
|
|
149
|
+
],
|
|
150
|
+
"Amount": { "min": 100 } // AND with the OR group
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
Multiple top-level keys are AND-ed.
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## 7. Field value shapes
|
|
158
|
+
|
|
159
|
+
When reading an entry (`data["<Field Name>"]`) or writing through `input`:
|
|
160
|
+
|
|
161
|
+
| Field type | Value shape |
|
|
162
|
+
|---|---|
|
|
163
|
+
| `Text`, `Long Text`, `Email`, `Phone`, `URL` | string |
|
|
164
|
+
| `Number`, `Currency`, `Percent` | number |
|
|
165
|
+
| `Date`, `DateTime` | ISO 8601 string |
|
|
166
|
+
| `Yes/No` | boolean |
|
|
167
|
+
| `Selection(...)` | string (one of the options) |
|
|
168
|
+
| `File`, `Image` | `{ "name": "report.pdf", "path": "/s/{guid}/report.pdf" }` |
|
|
169
|
+
| `Files`, `Images` | array of the above |
|
|
170
|
+
| `User` | `{ "value": "Alice Lee", "id": 17, "username": "alice" }` |
|
|
171
|
+
| `Users` | array of the above |
|
|
172
|
+
| `Module` | `{ "value": "INV-001", "id": 42 }` (reference to entry in another module) |
|
|
173
|
+
| `Modules` | array of the above |
|
|
174
|
+
| `Table` | array of row objects — each row keys by sub-field display name |
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## 8. File uploads (two-step, presigned)
|
|
179
|
+
|
|
180
|
+
Step 1 — request a presigned URL:
|
|
181
|
+
```
|
|
182
|
+
POST /api/mcp/request-upload-url
|
|
183
|
+
{
|
|
184
|
+
"module": "Invoices",
|
|
185
|
+
"fileName": "scan.pdf",
|
|
186
|
+
"contentType": "application/pdf",
|
|
187
|
+
"fileSize": 512345
|
|
188
|
+
}
|
|
189
|
+
→ { "uploadUrl": "https://s3...", "s3Key": "..." }
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Step 2 — PUT the raw bytes directly to S3 with the **exact** Content-Type you declared:
|
|
193
|
+
```js
|
|
194
|
+
await fetch(uploadUrl, {
|
|
195
|
+
method: "PUT",
|
|
196
|
+
headers: { "Content-Type": "application/pdf" },
|
|
197
|
+
body: file // File or Blob
|
|
198
|
+
});
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
Step 3 — confirm:
|
|
202
|
+
```
|
|
203
|
+
POST /api/mcp/confirm-upload
|
|
204
|
+
{ "s3Key": "..." }
|
|
205
|
+
→ { "url": "/s/{guid}/scan.pdf", "filename": "scan.pdf", "mimeType": "application/pdf", "size": 512345 }
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Use `url` as `path` in a File/Image field value:
|
|
209
|
+
```
|
|
210
|
+
"input": { "Attachment": { "name": "scan.pdf", "path": "/s/abc/scan.pdf" } }
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
**Max size:** 500 MB. `uploadUrl` expires after ~1 hour — request again if it does. The older base64 endpoint (`POST /api/mcp/upload`) exists but should only be used as a fallback.
|
|
214
|
+
|
|
215
|
+
Download (returns a 302 to a short-lived S3 URL):
|
|
216
|
+
```
|
|
217
|
+
GET /api/mcp/download/{moduleName}/s/{guid}/{fileName}
|
|
218
|
+
```
|
|
219
|
+
In a browser, setting `<a href>` or `window.location` to the download URL is usually enough — follow the redirect.
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## 9. Error handling
|
|
224
|
+
|
|
225
|
+
Non-2xx responses return JSON:
|
|
226
|
+
```
|
|
227
|
+
{
|
|
228
|
+
"error": "ValidationError",
|
|
229
|
+
"message": "Field 'Amount' is required.",
|
|
230
|
+
"details": [ { "field": "Amount", "message": "..." } ],
|
|
231
|
+
"agent_action": "Validation failed. Check details[].field for specifics."
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Map by status:
|
|
236
|
+
- `400` — fix input, retry.
|
|
237
|
+
- `401` — token invalid/expired; prompt the user to re-enter.
|
|
238
|
+
- `403` — user lacks permission; show a friendly message.
|
|
239
|
+
- `404` — module/entry not found.
|
|
240
|
+
- `422` — structured validation errors in `details[]`; surface per-field in the form.
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
## 10. Minimal reference client (framework-agnostic)
|
|
245
|
+
|
|
246
|
+
```ts
|
|
247
|
+
// inistate.ts
|
|
248
|
+
export interface InistateConfig {
|
|
249
|
+
baseUrl?: string; // default https://api.inistate.com
|
|
250
|
+
getToken: () => string; // user-supplied, read at call time
|
|
251
|
+
getWorkspaceId: () => string;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export function createInistate(cfg: InistateConfig) {
|
|
255
|
+
const base = (cfg.baseUrl ?? "https://api.inistate.com").replace(/\/+$/, "");
|
|
256
|
+
|
|
257
|
+
async function call<T>(method: string, path: string, body?: unknown): Promise<T> {
|
|
258
|
+
const res = await fetch(base + path, {
|
|
259
|
+
method,
|
|
260
|
+
headers: {
|
|
261
|
+
Accept: "application/json",
|
|
262
|
+
"Content-Type": "application/json",
|
|
263
|
+
Authorization: `fsk ${cfg.getToken()}`,
|
|
264
|
+
wsid: cfg.getWorkspaceId(),
|
|
265
|
+
},
|
|
266
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
267
|
+
});
|
|
268
|
+
const text = await res.text();
|
|
269
|
+
const data = text ? JSON.parse(text) : null;
|
|
270
|
+
if (!res.ok) throw Object.assign(new Error(data?.message ?? res.statusText), { status: res.status, payload: data });
|
|
271
|
+
return data as T;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return {
|
|
275
|
+
listModules: () => call<any>("GET", "/api/mcp/"),
|
|
276
|
+
getSchema: (module: string, tier: "basic" | "extended" = "basic") =>
|
|
277
|
+
call<any>("GET", `/api/mcp/${encodeURIComponent(module)}?tier=${tier}`),
|
|
278
|
+
listEntries: (body: Record<string, unknown>) => call<any>("POST", "/api/mcp/list", body),
|
|
279
|
+
getEntry: (module: string, entryId: string | number) => call<any>("POST", "/api/mcp/entry", { module, entryId }),
|
|
280
|
+
getForm: (module: string, activity = "create", entryId?: string | number) =>
|
|
281
|
+
call<any>("POST", "/api/mcp/form", { module, activity, ...(entryId != null ? { entryId } : {}) }),
|
|
282
|
+
submit: (payload: Record<string, unknown>) => call<any>("POST", "/api/mcp/activity", payload),
|
|
283
|
+
history: (module: string, entryId: string | number, page = 0) =>
|
|
284
|
+
call<any>("POST", "/api/mcp/history", { module, entryId, page }),
|
|
285
|
+
requestUpload: (module: string, fileName: string, contentType: string, fileSize: number) =>
|
|
286
|
+
call<any>("POST", "/api/mcp/request-upload-url", { module, fileName, contentType, fileSize }),
|
|
287
|
+
confirmUpload: (s3Key: string) => call<any>("POST", "/api/mcp/confirm-upload", { s3Key }),
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
## 11. React reference patterns (adapt to any UI library)
|
|
295
|
+
|
|
296
|
+
```tsx
|
|
297
|
+
// useEntries.ts
|
|
298
|
+
import { useEffect, useState } from "react";
|
|
299
|
+
import { inistate } from "./client";
|
|
300
|
+
|
|
301
|
+
export function useEntries(module: string, filters?: Record<string, unknown>) {
|
|
302
|
+
const [data, setData] = useState<any>();
|
|
303
|
+
const [error, setError] = useState<Error>();
|
|
304
|
+
useEffect(() => {
|
|
305
|
+
inistate.listEntries({ module, filters, currentPage: 0, pageSize: 50 })
|
|
306
|
+
.then(setData).catch(setError);
|
|
307
|
+
}, [module, JSON.stringify(filters)]);
|
|
308
|
+
return { data, error };
|
|
309
|
+
}
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
```tsx
|
|
313
|
+
// EntryForm.tsx — form driven entirely by get_form
|
|
314
|
+
export function EntryForm({ module, activity, entryId }: Props) {
|
|
315
|
+
const [form, setForm] = useState<any>();
|
|
316
|
+
const [values, setValues] = useState<Record<string, unknown>>({});
|
|
317
|
+
|
|
318
|
+
useEffect(() => {
|
|
319
|
+
inistate.getForm(module, activity, entryId).then(f => {
|
|
320
|
+
setForm(f);
|
|
321
|
+
setValues(f.defaults ?? {});
|
|
322
|
+
});
|
|
323
|
+
}, [module, activity, entryId]);
|
|
324
|
+
|
|
325
|
+
async function submit() {
|
|
326
|
+
await inistate.submit({ module, activity, entryId, input: values });
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// Render fields from form.fields[] — each has { name, type, required, options, ... }.
|
|
330
|
+
// Style and layout are up to you.
|
|
331
|
+
}
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
## 12. Vue reference patterns
|
|
335
|
+
|
|
336
|
+
```ts
|
|
337
|
+
// useEntries.ts
|
|
338
|
+
import { ref, watchEffect } from "vue";
|
|
339
|
+
import { inistate } from "./client";
|
|
340
|
+
|
|
341
|
+
export function useEntries(module: Ref<string>, filters?: Ref<Record<string, unknown>>) {
|
|
342
|
+
const data = ref<any>();
|
|
343
|
+
const error = ref<Error>();
|
|
344
|
+
watchEffect(async () => {
|
|
345
|
+
try {
|
|
346
|
+
data.value = await inistate.listEntries({
|
|
347
|
+
module: module.value,
|
|
348
|
+
filters: filters?.value,
|
|
349
|
+
currentPage: 0,
|
|
350
|
+
pageSize: 50,
|
|
351
|
+
});
|
|
352
|
+
} catch (e) { error.value = e as Error; }
|
|
353
|
+
});
|
|
354
|
+
return { data, error };
|
|
355
|
+
}
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
---
|
|
359
|
+
|
|
360
|
+
## 13. Recommended generation flow
|
|
361
|
+
|
|
362
|
+
When the user asks for "a page that does X":
|
|
363
|
+
|
|
364
|
+
1. `listModules()` → confirm the module exists and pick one.
|
|
365
|
+
2. `getSchema(module, "extended")` → know the fields, states, activities, flows.
|
|
366
|
+
3. For each activity or view the UI exposes: `getForm(module, activity)` → know the fields to render.
|
|
367
|
+
4. Generate components in the user's chosen framework / design system, wiring them to the client from §10.
|
|
368
|
+
5. Keep the token input + workspace selector at the top level (localStorage, a login view, or whatever fits). Never bake a token into source code or commit it.
|