@sensigo/realm-mcp 0.1.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 (50) hide show
  1. package/README.md +67 -0
  2. package/dist/index.d.ts +6 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +5 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/json-trace-buffer-store.d.ts +17 -0
  7. package/dist/json-trace-buffer-store.d.ts.map +1 -0
  8. package/dist/json-trace-buffer-store.js +128 -0
  9. package/dist/json-trace-buffer-store.js.map +1 -0
  10. package/dist/protocol/generator.d.ts +37 -0
  11. package/dist/protocol/generator.d.ts.map +1 -0
  12. package/dist/protocol/generator.js +99 -0
  13. package/dist/protocol/generator.js.map +1 -0
  14. package/dist/server.d.ts +39 -0
  15. package/dist/server.d.ts.map +1 -0
  16. package/dist/server.js +72 -0
  17. package/dist/server.js.map +1 -0
  18. package/dist/tools/append-trace.d.ts +30 -0
  19. package/dist/tools/append-trace.d.ts.map +1 -0
  20. package/dist/tools/append-trace.js +125 -0
  21. package/dist/tools/append-trace.js.map +1 -0
  22. package/dist/tools/create-workflow.d.ts +30 -0
  23. package/dist/tools/create-workflow.d.ts.map +1 -0
  24. package/dist/tools/create-workflow.js +228 -0
  25. package/dist/tools/create-workflow.js.map +1 -0
  26. package/dist/tools/execute-step.d.ts +51 -0
  27. package/dist/tools/execute-step.d.ts.map +1 -0
  28. package/dist/tools/execute-step.js +91 -0
  29. package/dist/tools/execute-step.js.map +1 -0
  30. package/dist/tools/get-run-state.d.ts +31 -0
  31. package/dist/tools/get-run-state.d.ts.map +1 -0
  32. package/dist/tools/get-run-state.js +63 -0
  33. package/dist/tools/get-run-state.js.map +1 -0
  34. package/dist/tools/get-workflow-protocol.d.ts +13 -0
  35. package/dist/tools/get-workflow-protocol.d.ts.map +1 -0
  36. package/dist/tools/get-workflow-protocol.js +30 -0
  37. package/dist/tools/get-workflow-protocol.js.map +1 -0
  38. package/dist/tools/list-workflows.d.ts +20 -0
  39. package/dist/tools/list-workflows.d.ts.map +1 -0
  40. package/dist/tools/list-workflows.js +21 -0
  41. package/dist/tools/list-workflows.js.map +1 -0
  42. package/dist/tools/start-run.d.ts +26 -0
  43. package/dist/tools/start-run.d.ts.map +1 -0
  44. package/dist/tools/start-run.js +90 -0
  45. package/dist/tools/start-run.js.map +1 -0
  46. package/dist/tools/submit-human-response.d.ts +15 -0
  47. package/dist/tools/submit-human-response.d.ts.map +1 -0
  48. package/dist/tools/submit-human-response.js +63 -0
  49. package/dist/tools/submit-human-response.js.map +1 -0
  50. package/package.json +57 -0
@@ -0,0 +1,63 @@
1
+ // get-run-state tool — returns the current state summary of a run.
2
+ import { z } from 'zod';
3
+ import { JsonFileStore, WorkflowError, resolvePreExecutionAgentAction, } from '@sensigo/realm';
4
+ /**
5
+ * Business logic for the get_run_state tool.
6
+ * Returns a structured summary of the run without the full evidence array.
7
+ */
8
+ export async function handleGetRunState(args, stores) {
9
+ const runStore = stores?.runStore ?? new JsonFileStore();
10
+ const run = await runStore.get(args.run_id);
11
+ return {
12
+ run_id: run.id,
13
+ workflow_id: run.workflow_id,
14
+ run_phase: run.run_phase,
15
+ terminal_state: run.terminal_state,
16
+ completed_steps: run.completed_steps,
17
+ in_progress_steps: run.in_progress_steps,
18
+ failed_steps: run.failed_steps,
19
+ skipped_steps: run.skipped_steps,
20
+ pending_gate: run.pending_gate,
21
+ evidence_count: run.evidence.length,
22
+ last_step: run.evidence.at(-1)?.step_id ?? null,
23
+ created_at: run.created_at,
24
+ updated_at: run.updated_at,
25
+ params: run.params,
26
+ };
27
+ }
28
+ /** Registers the get_run_state MCP tool on the server. */
29
+ export function registerGetRunState(server, opts) {
30
+ server.tool('get_run_state', 'Get the current state summary of a workflow run.', { run_id: z.string() }, async (args) => {
31
+ try {
32
+ const result = await handleGetRunState(args, opts);
33
+ return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
34
+ }
35
+ catch (err) {
36
+ const agentAction = err instanceof WorkflowError ? resolvePreExecutionAgentAction(err) : 'report_to_user';
37
+ const message = err instanceof Error ? err.message : String(err);
38
+ const contextHint = err instanceof WorkflowError && err.code === 'STATE_RUN_NOT_FOUND'
39
+ ? `Run '${args.run_id}' not found.`
40
+ : `An error occurred while loading run state.`;
41
+ return {
42
+ content: [
43
+ {
44
+ type: 'text',
45
+ text: JSON.stringify({
46
+ command: 'get_run_state',
47
+ run_id: args.run_id,
48
+ status: 'error',
49
+ data: {},
50
+ evidence: [],
51
+ warnings: [],
52
+ errors: [message],
53
+ agent_action: agentAction,
54
+ context_hint: contextHint,
55
+ next_actions: [],
56
+ }, null, 2),
57
+ },
58
+ ],
59
+ };
60
+ }
61
+ });
62
+ }
63
+ //# sourceMappingURL=get-run-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-run-state.js","sourceRoot":"","sources":["../../src/tools/get-run-state.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EACL,aAAa,EACb,aAAa,EACb,8BAA8B,GAE/B,MAAM,gBAAgB,CAAC;AAuBxB;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,IAAwB,EACxB,MAA6B;IAE7B,MAAM,QAAQ,GAAG,MAAM,EAAE,QAAQ,IAAI,IAAI,aAAa,EAAE,CAAC;IACzD,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAE5C,OAAO;QACL,MAAM,EAAE,GAAG,CAAC,EAAE;QACd,WAAW,EAAE,GAAG,CAAC,WAAW;QAC5B,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,cAAc,EAAE,GAAG,CAAC,cAAc;QAClC,eAAe,EAAE,GAAG,CAAC,eAAe;QACpC,iBAAiB,EAAE,GAAG,CAAC,iBAAiB;QACxC,YAAY,EAAE,GAAG,CAAC,YAAY;QAC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C,CAAC,CAAC,4CAA4C,CAAC;YACnD,OAAO;gBACL,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,MAAe;wBACrB,IAAI,EAAE,IAAI,CAAC,SAAS,CAClB;4BACE,OAAO,EAAE,eAAe;4BACxB,MAAM,EAAE,IAAI,CAAC,MAAM;4BACnB,MAAM,EAAE,OAAO;4BACf,IAAI,EAAE,EAAE;4BACR,QAAQ,EAAE,EAAE;4BACZ,QAAQ,EAAE,EAAE;4BACZ,MAAM,EAAE,CAAC,OAAO,CAAC;4BACjB,YAAY,EAAE,WAAW;4BACzB,YAAY,EAAE,WAAW;4BACzB,YAAY,EAAE,EAAE;yBACjB,EACD,IAAI,EACJ,CAAC,CACF;qBACF;iBACF;aACF,CAAC;QACJ,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import { type WorkflowProtocol } from '../protocol/generator.js';
3
+ import type { HandleStores } from './list-workflows.js';
4
+ /**
5
+ * Business logic for the get_workflow_protocol tool.
6
+ * Returns the full agent protocol for the specified workflow.
7
+ */
8
+ export declare function handleGetWorkflowProtocol(args: {
9
+ workflow_id: string;
10
+ }, stores?: HandleStores): Promise<WorkflowProtocol>;
11
+ /** Registers the get_workflow_protocol MCP tool on the server. */
12
+ export declare function registerGetWorkflowProtocol(server: McpServer, opts?: HandleStores): void;
13
+ //# sourceMappingURL=get-workflow-protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-workflow-protocol.d.ts","sourceRoot":"","sources":["../../src/tools/get-workflow-protocol.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEzE,OAAO,EAAoB,KAAK,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACnF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD;;;GAGG;AACH,wBAAsB,yBAAyB,CAC7C,IAAI,EAAE;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,EAC7B,MAAM,CAAC,EAAE,YAAY,GACpB,OAAO,CAAC,gBAAgB,CAAC,CAI3B;AAED,kEAAkE;AAClE,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,YAAY,GAAG,IAAI,CAkBxF"}
@@ -0,0 +1,30 @@
1
+ // get-workflow-protocol tool — returns the agent protocol for a workflow.
2
+ import { z } from 'zod';
3
+ import { JsonWorkflowStore, WorkflowError } from '@sensigo/realm';
4
+ import { generateProtocol } from '../protocol/generator.js';
5
+ /**
6
+ * Business logic for the get_workflow_protocol tool.
7
+ * Returns the full agent protocol for the specified workflow.
8
+ */
9
+ export async function handleGetWorkflowProtocol(args, stores) {
10
+ const store = stores?.workflowStore ?? new JsonWorkflowStore();
11
+ const definition = await store.get(args.workflow_id);
12
+ return generateProtocol(definition);
13
+ }
14
+ /** Registers the get_workflow_protocol MCP tool on the server. */
15
+ export function registerGetWorkflowProtocol(server, opts) {
16
+ server.tool('get_workflow_protocol', 'Get the full agent protocol briefing for a registered workflow.', { workflow_id: z.string() }, async (args) => {
17
+ try {
18
+ const result = await handleGetWorkflowProtocol(args, opts);
19
+ return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
20
+ }
21
+ catch (err) {
22
+ const message = err instanceof WorkflowError ? err.message : String(err);
23
+ return {
24
+ content: [{ type: 'text', text: `Error: ${message}` }],
25
+ isError: true,
26
+ };
27
+ }
28
+ });
29
+ }
30
+ //# sourceMappingURL=get-workflow-protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-workflow-protocol.js","sourceRoot":"","sources":["../../src/tools/get-workflow-protocol.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,gBAAgB,C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dk/server/mcp.js';
2
+ import { JsonWorkflowStore } from '@sensigo/realm';
3
+ export interface HandleStores {
4
+ workflowStore?: JsonWorkflowStore;
5
+ }
6
+ /**
7
+ * Business logic for the list_workflows tool.
8
+ * Returns a summary of all registered workflows.
9
+ */
10
+ export declare function handleListWorkflows(stores?: HandleStores): Promise<{
11
+ workflows: Array<{
12
+ id: string;
13
+ name: string;
14
+ version: number;
15
+ }>;
16
+ hint: string;
17
+ }>;
18
+ /** Registers the list_workflows MCP tool on the server. */
19
+ export declare function registerListWorkflows(server: McpServer, opts?: HandleStores): void;
20
+ //# sourceMappingURL=list-workflows.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list-workflows.d.ts","sourceRoot":"","sources":["../../src/tools/list-workflows.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD,MAAM,WAAW,YAAY;IAC3B,aAAa,CAAC,EAAE,iBAAiB,CAAC;CACnC;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,CACvC,MAAM,CAAC,EAAE,YAAY,GACpB,OAAO,CAAC;IAAE,SAAS,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAO5F;AAED,2DAA2D;AAC3D,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,YAAY,GAAG,IAAI,CAKlF"}
@@ -0,0 +1,21 @@
1
+ import { JsonWorkflowStore } from '@sensigo/realm';
2
+ /**
3
+ * Business logic for the list_workflows tool.
4
+ * Returns a summary of all registered workflows.
5
+ */
6
+ export async function handleListWorkflows(stores) {
7
+ const store = stores?.workflowStore ?? new JsonWorkflowStore();
8
+ const workflows = await store.list();
9
+ return {
10
+ workflows: workflows.map((w) => ({ id: w.id, name: w.name, version: w.version })),
11
+ hint: 'Call get_workflow_protocol with a workflow_id before calling start_run. If no workflow matches your task, use create_workflow to define and start your own plan.',
12
+ };
13
+ }
14
+ /** Registers the list_workflows MCP tool on the server. */
15
+ export function registerListWorkflows(server, opts) {
16
+ server.tool('list_workflows', 'List all registered Realm workflows.', async () => {
17
+ const result = await handleListWorkflows(opts);
18
+ return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
19
+ });
20
+ }
21
+ //# sourceMappingURL=list-workflows.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list-workflows.js","sourceRoot":"","sources":["../../src/tools/list-workflows.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAMnD;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,MAAqB;IAErB,MAAM,KAAK,GAAG,MAAM,EAAE,aAAa,IAAI,IAAI,iBAAiB,EAAE,CAAC;IAC/D,MAAM,SAAS,GAAG,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;IACrC,OAAO;QACL,SAAS,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;QACjF,IAAI,EAAE,kKAAkK;KACzK,CAAC;AACJ,CAAC;AAED,2DAA2D;AAC3D,MAAM,UAAU,qBAAqB,CAAC,MAAiB,EAAE,IAAmB;IAC1E,MAAM,CAAC,IAAI,CAAC,gBAAgB,EAAE,sCAAsC,EAAE,KAAK,IAAI,EAAE;QAC/E,MAAM,MAAM,GAAG,MAAM,mBAAmB,CAAC,IAAI,CAAC,CAAC;QAC/C,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;IACzF,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,26 @@
1
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import { JsonWorkflowStore, JsonFileStore, type ResponseEnvelope, type TraceBufferStore, ExtensionRegistry } from '@sensigo/realm';
3
+ export interface HandleRunStores {
4
+ runStore?: JsonFileStore;
5
+ workflowStore?: JsonWorkflowStore;
6
+ /** Extension registry for resolving service adapters and step handlers. */
7
+ registry?: ExtensionRegistry;
8
+ /** Resolved secrets for use by service adapters. */
9
+ secrets?: Record<string, string>;
10
+ /** Trace buffer store for incremental WAL-based trace ingestion (B-lite). */
11
+ traceBufferStore?: TraceBufferStore;
12
+ }
13
+ /**
14
+ * Business logic for the start_run tool.
15
+ * Creates a run and immediately chains through any leading auto steps.
16
+ */
17
+ export declare function handleStartRun(args: {
18
+ workflow_id: string;
19
+ params?: Record<string, unknown>;
20
+ }, stores?: HandleRunStores): Promise<ResponseEnvelope>;
21
+ /** Registers the start_run MCP tool on the server. */
22
+ export declare function registerStartRun(server: McpServer, opts?: {
23
+ registry?: import('@sensigo/realm').ExtensionRegistry;
24
+ secrets?: Record<string, string>;
25
+ }): void;
26
+ //# sourceMappingURL=start-run.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"start-run.d.ts","sourceRoot":"","sources":["../../src/tools/start-run.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,EACL,iBAAiB,EACjB,aAAa,EAOb,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AAExB,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,aAAa,CAAC,EAAE,iBAAiB,CAAC;IAClC,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,iBAAiB,CAAC;IAC7B,oDAAoD;IACpD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,6EAA6E;IAC7E,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;CACrC;AAKD;;;GAGG;AACH,wBAAsB,cAAc,CAClC,IAAI,EAAE;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,EAC/D,MAAM,CAAC,EAAE,eAAe,GACvB,OAAO,CAAC,gBAAgB,CAAC,CAwC3B;AAED,sDAAsD;AACtD,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,SAAS,EACjB,IAAI,CAAC,EAAE;IACL,QAAQ,CAAC,EAAE,OAAO,gBAAgB,EAAE,iBAAiB,CAAC;IACtD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC,GACA,IAAI,CAqDN"}
@@ -0,0 +1,90 @@
1
+ // start-run tool — creates a new run and chains through initial auto steps.
2
+ import { z } from 'zod';
3
+ import { JsonWorkflowStore, JsonFileStore, executeChain, buildNextActions, findEligibleSteps, WorkflowError, buildPreExecutionErrorEnvelope, } from '@sensigo/realm';
4
+ // Fallback dispatcher for agent steps and auto steps without a registry entry.
5
+ const passthroughDispatcher = async () => ({});
6
+ /**
7
+ * Business logic for the start_run tool.
8
+ * Creates a run and immediately chains through any leading auto steps.
9
+ */
10
+ export async function handleStartRun(args, stores) {
11
+ const workflowStore = stores?.workflowStore ?? new JsonWorkflowStore();
12
+ const runStore = stores?.runStore ?? new JsonFileStore();
13
+ const definition = await workflowStore.get(args.workflow_id);
14
+ const params = args.params ?? {};
15
+ const run = await runStore.create({
16
+ workflowId: definition.id,
17
+ workflowVersion: definition.version,
18
+ params,
19
+ });
20
+ const eligible = findEligibleSteps(definition, run);
21
+ const firstAutoStep = eligible.find((name) => definition.steps[name]?.execution === 'auto');
22
+ if (firstAutoStep !== undefined) {
23
+ const result = await executeChain(runStore, definition, {
24
+ runId: run.id,
25
+ command: firstAutoStep,
26
+ input: params,
27
+ dispatcher: passthroughDispatcher,
28
+ ...(stores?.registry !== undefined ? { registry: stores.registry } : {}),
29
+ ...(stores?.secrets !== undefined ? { secrets: stores.secrets } : {}),
30
+ });
31
+ return { ...result, run_id: run.id, data: {}, evidence: [] };
32
+ }
33
+ const nextActions = buildNextActions(definition, run);
34
+ return {
35
+ command: 'start_run',
36
+ run_id: run.id,
37
+ run_version: run.version,
38
+ status: 'ok',
39
+ data: {},
40
+ evidence: [],
41
+ warnings: [],
42
+ errors: [],
43
+ context_hint: `Run '${run.id}' created for workflow '${definition.id}'.`,
44
+ next_actions: nextActions,
45
+ };
46
+ }
47
+ /** Registers the start_run MCP tool on the server. */
48
+ export function registerStartRun(server, opts) {
49
+ server.tool('start_run', 'Create a new workflow run and chain through initial auto steps.', {
50
+ workflow_id: z.string(),
51
+ params: z.record(z.unknown()).optional().default({}),
52
+ }, async (args) => {
53
+ try {
54
+ const result = await handleStartRun(args, opts);
55
+ // Override command to 'start_run': MCP callers invoked start_run, not
56
+ // the first auto step that executeChain may have executed.
57
+ return {
58
+ content: [
59
+ {
60
+ type: 'text',
61
+ text: JSON.stringify({ ...result, command: 'start_run' }, null, 2),
62
+ },
63
+ ],
64
+ };
65
+ }
66
+ catch (err) {
67
+ const workflowErr = err instanceof WorkflowError
68
+ ? err
69
+ : new WorkflowError(err instanceof Error ? err.message : String(err), {
70
+ code: 'ENGINE_INTERNAL',
71
+ category: 'ENGINE',
72
+ agentAction: 'stop',
73
+ retryable: false,
74
+ });
75
+ const contextHint = workflowErr.code === 'STATE_WORKFLOW_NOT_FOUND'
76
+ ? `Workflow '${args.workflow_id}' not found.`
77
+ : `An error occurred before the run could be started.`;
78
+ const envelope = buildPreExecutionErrorEnvelope('start_run', '', 0, workflowErr, contextHint);
79
+ return {
80
+ content: [
81
+ {
82
+ type: 'text',
83
+ text: JSON.stringify(envelope, null, 2),
84
+ },
85
+ ],
86
+ };
87
+ }
88
+ });
89
+ }
90
+ //# sourceMappingURL=start-run.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"start-run.js","sourceRoot":"","sources":["../../src/tools/start-run.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,aAAa,EACb,8BAA8B,GAK/B,MAAM,gBAAgB,CAAC;AAaxB,+EAA+E;AAC/E,MAAM,qBAAqB,GAAmB,KAAK,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;AAE/D;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,IAA+D,EAC/D,MAAwB;IAExB,MAAM,aAAa,GAAG,MAAM,EAAE,aAAa,IAAI,IAAI,iBAAiB,EAAE,CAAC;IACvE,MAAM,QAAQ,GAAG,MAAM,EAAE,QAAQ,IAAI,IAAI,aAAa,EAAE,CAAC;IACzD,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC7D,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC;IAEjC,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC;QAChC,UAAU,EAAE,UAAU,CAAC,EAAE;QACzB,eAAe,EAAE,UAAU,CAAC,OAAO;QACnC,MAAM;KACP,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,iBAAiB,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;IACpD,MAAM,aAAa,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,C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ACrB,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;qBACxC;iBACF;aACF,CAAC;QACJ,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import { type ResponseEnvelope } from '@sensigo/realm';
3
+ import type { HandleRunStores } from './start-run.js';
4
+ /**
5
+ * Business logic for the submit_human_response tool.
6
+ * Validates the gate_id and choice, then advances the run past the gate.
7
+ */
8
+ export declare function handleSubmitHumanResponse(args: {
9
+ run_id: string;
10
+ gate_id: string;
11
+ choice: string;
12
+ }, stores?: HandleRunStores): Promise<ResponseEnvelope>;
13
+ /** Registers the submit_human_response MCP tool on the server. */
14
+ export declare function registerSubmitHumanResponse(server: McpServer, opts?: HandleRunStores): void;
15
+ //# sourceMappingURL=submit-human-response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"submit-human-response.d.ts","sourceRoot":"","sources":["../../src/tools/submit-human-response.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,EAML,KAAK,gBAAgB,EACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD;;;GAGG;AACH,wBAAsB,yBAAyB,CAC7C,IAAI,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EACzD,MAAM,CAAC,EAAE,eAAe,GACvB,OAAO,CAAC,gBAAgB,CAAC,CAW3B;AAED,kEAAkE;AAClE,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,eAAe,GAAG,IAAI,CAsD3F"}
@@ -0,0 +1,63 @@
1
+ // submit-human-response tool — advances a gate-waiting run with a human choice.
2
+ import { z } from 'zod';
3
+ import { JsonWorkflowStore, JsonFileStore, submitHumanResponse, WorkflowError, buildPreExecutionErrorEnvelope, } from '@sensigo/realm';
4
+ /**
5
+ * Business logic for the submit_human_response tool.
6
+ * Validates the gate_id and choice, then advances the run past the gate.
7
+ */
8
+ export async function handleSubmitHumanResponse(args, stores) {
9
+ const workflowStore = stores?.workflowStore ?? new JsonWorkflowStore();
10
+ const runStore = stores?.runStore ?? new JsonFileStore();
11
+ const run = await runStore.get(args.run_id);
12
+ const definition = await workflowStore.get(run.workflow_id);
13
+ return submitHumanResponse(runStore, definition, {
14
+ runId: args.run_id,
15
+ gateId: args.gate_id,
16
+ choice: args.choice,
17
+ });
18
+ }
19
+ /** Registers the submit_human_response MCP tool on the server. */
20
+ export function registerSubmitHumanResponse(server, opts) {
21
+ server.tool('submit_human_response', "Advance a gate-waiting run by submitting the human's choice.", {
22
+ run_id: z.string(),
23
+ gate_id: z.string(),
24
+ choice: z.string(),
25
+ }, async (args) => {
26
+ try {
27
+ const result = await handleSubmitHumanResponse(args, opts);
28
+ return {
29
+ content: [
30
+ {
31
+ type: 'text',
32
+ text: JSON.stringify({ ...result, data: {}, evidence: [] }, null, 2),
33
+ },
34
+ ],
35
+ };
36
+ }
37
+ catch (err) {
38
+ const workflowErr = err instanceof WorkflowError
39
+ ? err
40
+ : new WorkflowError(err instanceof Error ? err.message : String(err), {
41
+ code: 'ENGINE_INTERNAL',
42
+ category: 'ENGINE',
43
+ agentAction: 'stop',
44
+ retryable: false,
45
+ });
46
+ const contextHint = workflowErr.code === 'STATE_WORKFLOW_NOT_FOUND'
47
+ ? `Workflow definition for run '${args.run_id}' not found.`
48
+ : workflowErr.code === 'STATE_RUN_NOT_FOUND'
49
+ ? `Run '${args.run_id}' not found.`
50
+ : `An error occurred before gate response could be submitted.`;
51
+ const envelope = buildPreExecutionErrorEnvelope('submit_human_response', args.run_id, 0, workflowErr, contextHint);
52
+ return {
53
+ content: [
54
+ {
55
+ type: 'text',
56
+ text: JSON.stringify(envelope, null, 2),
57
+ },
58
+ ],
59
+ };
60
+ }
61
+ });
62
+ }
63
+ //# sourceMappingURL=submit-human-response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"submit-human-response.js","sourceRoot":"","sources":["../../src/tools/submit-human-response.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,mBAAmB,EACnB,aAAa,EACb,8BAA8B,GAE/B,MAAM,gBAAgB,CAAC;AAGxB;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC7C,IAAyD,EACzD,MAAwB;IAExB,MAAM,aAAa,GAAG,MAAM,EAAE,aAAa,IAAI,IAAI,iBAAiB,EAAE,CAAC;IACvE,MAAM,QAAQ,GAAG,MAAM,EAAE,QAAQ,IAAI,IAAI,aAAa,EAAE,CAAC;IACzD,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC5C,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAE5D,OAAO,mBAAmB,CAAC,QAAQ,EAAE,UAAU,EAAE;QAC/C,KAAK,EAAE,IAAI,CAAC,MAAM;QAClB,MAAM,EAAE,IAAI,CAAC,OAAO;QACpB,MAAM,EAAE,IAAI,CAAC,MAAM;KACpB,CAAC,CAAC;AACL,CAAC;AAED,kEAAkE;AAClE,MAAM,UAAU,2BAA2B,CAAC,MAAiB,EAAE,IAAsB;IACnF,MAAM,CAAC,IAAI,CACT,uBAAuB,EACvB,8DAA8D,EAC9D;QACE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;QAClB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;QACnB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;KACnB,EACD,K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C;iBACF;aACF,CAAC;QACJ,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@sensigo/realm-mcp",
3
+ "version": "0.1.0",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "description": "MCP server for Realm — exposes 7 tools for AI agent connections over stdio or HTTP.",
8
+ "license": "Apache-2.0",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/sensigo-hq/realm.git"
12
+ },
13
+ "homepage": "https://github.com/sensigo-hq/realm#readme",
14
+ "keywords": [
15
+ "mcp",
16
+ "model-context-protocol",
17
+ "ai-agent",
18
+ "agent-workflow",
19
+ "workflow",
20
+ "typescript"
21
+ ],
22
+ "private": false,
23
+ "type": "module",
24
+ "main": "./dist/index.js",
25
+ "types": "./dist/index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "import": "./dist/index.js",
29
+ "types": "./dist/index.d.ts"
30
+ }
31
+ },
32
+ "engines": {
33
+ "node": ">=22.0.0"
34
+ },
35
+ "bin": {
36
+ "realm-mcp": "./dist/server.js"
37
+ },
38
+ "scripts": {
39
+ "build": "tsc --build",
40
+ "test": "vitest run",
41
+ "lint": "eslint src"
42
+ },
43
+ "dependencies": {
44
+ "@modelcontextprotocol/sdk": "1.29.0",
45
+ "@sensigo/realm": "^0.1.0",
46
+ "zod": "^3.25.7"
47
+ },
48
+ "devDependencies": {
49
+ "@types/node": "^25.5.0",
50
+ "typescript": "*",
51
+ "vitest": "*"
52
+ },
53
+ "files": [
54
+ "dist",
55
+ "README.md"
56
+ ]
57
+ }