@ratifia/mcp 0.8.0 → 0.9.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.
Files changed (3) hide show
  1. package/README.md +19 -2
  2. package/dist/index.js +31 -6
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -58,9 +58,26 @@ real decisions. CI runs it on every push.
58
58
  | `RATIFIA_API_URL` | | `https://api.ratifia.com` | Ratifia API base. |
59
59
  | `RATIFIA_APP_URL` | | `https://app.ratifia.com` | Dashboard base for decision links. |
60
60
  | `RATIFIA_APPROVER_EMAIL` | | — | Who the decision is assigned to / notified. |
61
- | `RATIFIA_POLICY` | | — | Named policy deciding **who** reviews and the quorum they need. It must exist in your org: an unknown name is a tool error, and the `gate` hook denies. |
61
+ | `RATIFIA_POLICY` | | — | The **key** of a policy deciding **who** reviews and the quorum they need. It must exist in your org: an unknown key is a tool error, and the `gate` hook denies. |
62
+ | `RATIFIA_WORKFLOW` | | `ratifia-mcp` (`ratifia-gate` for the hook) | The **workflow** decisions are filed under — the category the dashboard's Workflow filter groups by, e.g. `deploys` or `billing-agent`. A `request_decision` call can override it. |
62
63
 
63
- Routing (email / SMS / escalation) is decided **inside Ratifia** by your org's policy — this server is a thin request/verdict bridge.
64
+ Who is notified is decided **inside Ratifia** by your org's policy — this server is a thin request/verdict bridge.
65
+
66
+ ### Filing decisions: workflow and step
67
+
68
+ Every decision carries two labels:
69
+
70
+ - **Workflow** (`workflowRef`) — the *category*: "deploys", "refunds". The dashboard's Workflow filter groups by it. Set a default per server with `RATIFIA_WORKFLOW`, or pass `workflow` to `request_decision`.
71
+ - **Step** (`stepRef`) — the *specific instance* inside it: "api-v2.3-to-prod", "refund-INV-1042". Pass `step` to `request_decision`; it defaults to the title.
72
+
73
+ ```
74
+ request_decision(
75
+ title: "Deploy API to prod?",
76
+ question: "Ship v2.3 to production?",
77
+ workflow: "deploys",
78
+ step: "api-v2.3-to-prod"
79
+ )
80
+ ```
64
81
 
65
82
  ## Tools
66
83
 
package/dist/index.js CHANGED
@@ -25,8 +25,11 @@
25
25
  * RATIFIA_API_KEY org-scoped worker API key (required)
26
26
  * RATIFIA_APP_URL dashboard base for the decision link (default https://app.ratifia.com)
27
27
  * RATIFIA_APPROVER_EMAIL who the decision is assigned to / notified
28
- * RATIFIA_POLICY optional: policy name deciding who reviews (must exist in the org)
28
+ * RATIFIA_POLICY optional: policy key deciding who reviews (must exist in the org)
29
29
  * (e.g. a route to your phone)
30
+ * RATIFIA_WORKFLOW optional: the workflow (category) decisions are filed under —
31
+ * what the dashboard's Workflow filter groups by. Defaults to
32
+ * `ratifia-mcp` (tools) / `ratifia-gate` (the gate hook).
30
33
  */
31
34
  import { McpServer } from '@modelcontextprotocol/server';
32
35
  import { StdioServerTransport } from '@modelcontextprotocol/server/stdio';
@@ -37,6 +40,17 @@ const API_KEY = process.env.RATIFIA_API_KEY;
37
40
  const APP_URL = (process.env.RATIFIA_APP_URL ?? 'https://app.ratifia.com').replace(/\/+$/, '');
38
41
  const APPROVER_EMAIL = process.env.RATIFIA_APPROVER_EMAIL;
39
42
  const POLICY = process.env.RATIFIA_POLICY;
43
+ const WORKFLOW = process.env.RATIFIA_WORKFLOW;
44
+ /**
45
+ * Where a decision is filed. `workflowRef` is the category (the dashboard's
46
+ * Workflow filter groups by it — e.g. "deploys", "billing-agent");
47
+ * `stepRef` is the specific instance within it. Blank or whitespace-only values
48
+ * fall back rather than filing under an empty name.
49
+ */
50
+ function label(value, fallback, max) {
51
+ const v = value?.trim();
52
+ return (v ? v : fallback).slice(0, max);
53
+ }
40
54
  if (!API_KEY) {
41
55
  console.error('RATIFIA_API_KEY is required');
42
56
  process.exit(1);
@@ -75,7 +89,7 @@ function errorCode(body) {
75
89
  }
76
90
  /** FN-255: RATIFIA_POLICY names a policy the org doesn't have. A misconfiguration, not an outage. */
77
91
  const isUnknownPolicy = (err) => err instanceof ApiError && err.code === 'unknown_policy';
78
- const unknownPolicyMessage = () => `RATIFIA_POLICY "${POLICY}" does not exist in this Ratifia org. Create the policy in the Ratifia dashboard (Policies) or fix RATIFIA_POLICY in this MCP server's config. No decision was created: do not proceed with the action.`;
92
+ const unknownPolicyMessage = () => `RATIFIA_POLICY "${POLICY}" is not a policy key in this Ratifia org. Create a policy with this key in the Ratifia dashboard (Policies) or fix RATIFIA_POLICY in this MCP server's config. No decision was created: do not proceed with the action.`;
79
93
  const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
80
94
  /** `idempotencyKey` makes a retried write safe to collapse server-side; mint it
81
95
  * once per tool invocation so two independent asks never share one. */
@@ -289,7 +303,7 @@ async function runGate() {
289
303
  engine: 'mcp',
290
304
  externalRunId,
291
305
  stepRef: `tool:${toolName}`.slice(0, 80),
292
- workflowRef: 'ratifia-gate',
306
+ workflowRef: label(WORKFLOW, 'ratifia-gate', 100),
293
307
  ...(APPROVER_EMAIL ? { assigneeEmail: APPROVER_EMAIL } : {}),
294
308
  ...(POLICY ? { policy: POLICY } : {}),
295
309
  required: true,
@@ -343,6 +357,7 @@ const server = new McpServer({ name: 'ratifia', version: '0.7.0' }, {
343
357
  '',
344
358
  'Workflow:',
345
359
  '1. Call request_decision with a short title, a precise question, and enough context to decide (the command/diff/options + tradeoffs). Set timeout_minutes if it is time-sensitive.',
360
+ 'Filing: set `workflow` to the project or ongoing effort the decision belongs to (e.g. the repo name, "billing-refunds") so a human can see related decisions together in the dashboard, and reuse the exact same string every time. Put what is specific to this decision (the release, record, environment) in `step`, e.g. "deploy-v2.3-prod". Without them every decision lands in one "ratifia-mcp" bucket.',
346
361
  '2. It returns a decision_id (+ url). The human is notified and may be away from their keyboard, so a verdict can take a while. (If the org policy auto-resolved that no approval was needed, it returns approval_required=false — just proceed.)',
347
362
  '3. Wait for the verdict: prefer await_decision (it blocks until answered) over polling check_decision in a loop. Either way, "approved"/"rejected" comes with a note — the note is the human\'s actual answer/input, so read and follow it. If you asked for a choice/typed value (response_type select/text), the answer is in response_value (selected option ids — map them back via response_spec.options — or text), not just the note.',
348
363
  '4. Do NOT perform the gated action until it resolves approved. On rejected or expired, do not proceed — adapt or ask again.',
@@ -397,13 +412,23 @@ server.registerTool('request_decision', {
397
412
  .record(z.string(), z.unknown())
398
413
  .optional()
399
414
  .describe('The arguments you would call `tool_name` with, as an object, e.g. { "amount_cents": 600000, "currency": "USD" }. Displayed next to the tool name. Ignored unless `tool_name` is set.'),
415
+ workflow: z
416
+ .string()
417
+ .max(100)
418
+ .optional()
419
+ .describe('The project or ongoing effort this decision belongs to, e.g. the repo name or "billing-refunds" — the dashboard groups and filters by it, so reuse the exact same string for related decisions and keep ids/versions out of it. Omit to use the server default (RATIFIA_WORKFLOW, else "ratifia-mcp").'),
420
+ step: z
421
+ .string()
422
+ .max(80)
423
+ .optional()
424
+ .describe('What is specific to this decision within the workflow, e.g. "deploy-v2.3-prod" or "refund-INV-1042". Omit to use the title.'),
400
425
  evidence: z
401
426
  .array(evidenceItemSchema)
402
427
  .max(20)
403
428
  .optional()
404
429
  .describe('Material this decision should be made ON — the Slack thread, the email, the policy excerpt you are relying on. Stored immutably against the decision and sealed when it resolves, so the record shows what the human could see. Attach what you already have; use attach_evidence for anything you find afterwards.'),
405
430
  },
406
- }, async ({ title, question, context, timeout_minutes, response_type, options, allow_multiple, proposed_output, tool_name, tool_args, evidence }) => {
431
+ }, async ({ title, question, context, timeout_minutes, response_type, options, allow_multiple, proposed_output, tool_name, tool_args, workflow, step, evidence }) => {
407
432
  if (response_type === 'select' && (!options || options.length < 2)) {
408
433
  return asToolResult({
409
434
  error: 'invalid_request',
@@ -435,8 +460,8 @@ server.registerTool('request_decision', {
435
460
  // verdict rather than parking on an engine resume event.
436
461
  engine: 'mcp',
437
462
  externalRunId,
438
- stepRef: title.slice(0, 80),
439
- workflowRef: 'ratifia-mcp',
463
+ stepRef: label(step, title, 80),
464
+ workflowRef: label(workflow, label(WORKFLOW, 'ratifia-mcp', 100), 100),
440
465
  ...(APPROVER_EMAIL ? { assigneeEmail: APPROVER_EMAIL } : {}),
441
466
  ...(POLICY ? { policy: POLICY } : {}),
442
467
  required: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ratifia/mcp",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "type": "module",
5
5
  "description": "Ratifia MCP server \u2014 let an AI agent request a human decision/approval (HITL) mid-task and resume once it's answered. The agent becomes a Ratifia 'engine'.",
6
6
  "keywords": [