@siglo/query 0.0.0-stage → 1.2.8

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 (87) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +64 -2
  3. package/dist/cursor.d.ts +16 -0
  4. package/dist/cursor.d.ts.map +1 -0
  5. package/dist/cursor.js +49 -0
  6. package/dist/cursor.js.map +1 -0
  7. package/dist/engine.d.ts +27 -0
  8. package/dist/engine.d.ts.map +1 -0
  9. package/dist/engine.js +225 -0
  10. package/dist/engine.js.map +1 -0
  11. package/dist/graphql/backing.d.ts +4 -0
  12. package/dist/graphql/backing.d.ts.map +1 -0
  13. package/dist/graphql/backing.js +6 -0
  14. package/dist/graphql/backing.js.map +1 -0
  15. package/dist/graphql/projection.d.ts +15 -0
  16. package/dist/graphql/projection.d.ts.map +1 -0
  17. package/dist/graphql/projection.js +69 -0
  18. package/dist/graphql/projection.js.map +1 -0
  19. package/dist/graphql/resolvers.d.ts +89 -0
  20. package/dist/graphql/resolvers.d.ts.map +1 -0
  21. package/dist/graphql/resolvers.js +178 -0
  22. package/dist/graphql/resolvers.js.map +1 -0
  23. package/dist/graphql/scalars.d.ts +5 -0
  24. package/dist/graphql/scalars.d.ts.map +1 -0
  25. package/dist/graphql/scalars.js +86 -0
  26. package/dist/graphql/scalars.js.map +1 -0
  27. package/dist/graphql/schema.d.ts +6 -0
  28. package/dist/graphql/schema.d.ts.map +1 -0
  29. package/dist/graphql/schema.js +254 -0
  30. package/dist/graphql/schema.js.map +1 -0
  31. package/dist/graphql/subscriptions.d.ts +44 -0
  32. package/dist/graphql/subscriptions.d.ts.map +1 -0
  33. package/dist/graphql/subscriptions.js +253 -0
  34. package/dist/graphql/subscriptions.js.map +1 -0
  35. package/dist/graphql/transport.d.ts +37 -0
  36. package/dist/graphql/transport.d.ts.map +1 -0
  37. package/dist/graphql/transport.js +230 -0
  38. package/dist/graphql/transport.js.map +1 -0
  39. package/dist/index.d.ts +13 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +29 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/integrations/express.d.ts +17 -0
  44. package/dist/integrations/express.d.ts.map +1 -0
  45. package/dist/integrations/express.js +150 -0
  46. package/dist/integrations/express.js.map +1 -0
  47. package/dist/integrations/fastify.d.ts +17 -0
  48. package/dist/integrations/fastify.d.ts.map +1 -0
  49. package/dist/integrations/fastify.js +110 -0
  50. package/dist/integrations/fastify.js.map +1 -0
  51. package/dist/integrations/hono.d.ts +18 -0
  52. package/dist/integrations/hono.d.ts.map +1 -0
  53. package/dist/integrations/hono.js +126 -0
  54. package/dist/integrations/hono.js.map +1 -0
  55. package/dist/integrations/index.d.ts +4 -0
  56. package/dist/integrations/index.d.ts.map +1 -0
  57. package/dist/integrations/index.js +20 -0
  58. package/dist/integrations/index.js.map +1 -0
  59. package/dist/mcp/index.d.ts +5 -0
  60. package/dist/mcp/index.d.ts.map +1 -0
  61. package/dist/mcp/index.js +21 -0
  62. package/dist/mcp/index.js.map +1 -0
  63. package/dist/mcp/prompts.d.ts +25 -0
  64. package/dist/mcp/prompts.d.ts.map +1 -0
  65. package/dist/mcp/prompts.js +102 -0
  66. package/dist/mcp/prompts.js.map +1 -0
  67. package/dist/mcp/resources.d.ts +25 -0
  68. package/dist/mcp/resources.d.ts.map +1 -0
  69. package/dist/mcp/resources.js +111 -0
  70. package/dist/mcp/resources.js.map +1 -0
  71. package/dist/mcp/server.d.ts +108 -0
  72. package/dist/mcp/server.d.ts.map +1 -0
  73. package/dist/mcp/server.js +233 -0
  74. package/dist/mcp/server.js.map +1 -0
  75. package/dist/mcp/tools.d.ts +212 -0
  76. package/dist/mcp/tools.d.ts.map +1 -0
  77. package/dist/mcp/tools.js +317 -0
  78. package/dist/mcp/tools.js.map +1 -0
  79. package/dist/memory.d.ts +33 -0
  80. package/dist/memory.d.ts.map +1 -0
  81. package/dist/memory.js +78 -0
  82. package/dist/memory.js.map +1 -0
  83. package/dist/types.d.ts +112 -0
  84. package/dist/types.d.ts.map +1 -0
  85. package/dist/types.js +3 -0
  86. package/dist/types.js.map +1 -0
  87. package/package.json +89 -4
@@ -0,0 +1,212 @@
1
+ import { type GraphQLSchema } from 'graphql';
2
+ import type { WorkflowQueryEngine } from '../engine';
3
+ import type { WorkflowExecution } from '../types';
4
+ export interface McpTenantScopeOptions {
5
+ /**
6
+ * Bound tenant namespace. When configured, requests are locked to this tenant
7
+ * and conflicting `namespace` arguments are rejected.
8
+ */
9
+ namespace?: string;
10
+ /**
11
+ * Default namespace used when `namespace` is not locked and the caller omits `namespace`.
12
+ * Defaults to `'default'`.
13
+ */
14
+ defaultNamespace?: string;
15
+ }
16
+ export declare function resolveMcpNamespace(requested?: string, options?: McpTenantScopeOptions): string;
17
+ export declare function formatWorkflowSummary(item: WorkflowExecution): {
18
+ waitRecord?: {
19
+ correlationKey: string;
20
+ eventName: string | null;
21
+ expiresAt: string | null;
22
+ lockedBy: string | null;
23
+ status: string | null;
24
+ } | undefined;
25
+ metadata?: Record<string, unknown> | undefined;
26
+ expiresAt?: string | undefined;
27
+ stackId: string;
28
+ workflowId: string | null;
29
+ namespace: string;
30
+ status: string;
31
+ revision: number;
32
+ createdAt: string;
33
+ updatedAt: string;
34
+ };
35
+ export declare function formatWorkflowDetail(item: WorkflowExecution, includeSteps?: boolean): {
36
+ compensations: import("../types").CompensationRecord[];
37
+ steps?: import("../types").StepExecution[] | undefined;
38
+ error?: object | undefined;
39
+ context: {} | null;
40
+ waitRecord?: {
41
+ correlationKey: string;
42
+ eventName: string | null;
43
+ expiresAt: string | null;
44
+ lockedBy: string | null;
45
+ status: string | null;
46
+ } | undefined;
47
+ metadata?: Record<string, unknown> | undefined;
48
+ expiresAt?: string | undefined;
49
+ stackId: string;
50
+ workflowId: string | null;
51
+ namespace: string;
52
+ status: string;
53
+ revision: number;
54
+ createdAt: string;
55
+ updatedAt: string;
56
+ };
57
+ export declare const WORKFLOW_MCP_TOOLS: ({
58
+ name: string;
59
+ description: string;
60
+ inputSchema: {
61
+ type: "object";
62
+ properties: {
63
+ workflowId: {
64
+ type: string;
65
+ description: string;
66
+ };
67
+ status: {
68
+ type: string;
69
+ enum: string[];
70
+ };
71
+ namespace: {
72
+ type: string;
73
+ description: string;
74
+ };
75
+ createdAfter: {
76
+ type: string;
77
+ description: string;
78
+ };
79
+ createdBefore: {
80
+ type: string;
81
+ description: string;
82
+ };
83
+ metadataFilter: {
84
+ type: string;
85
+ description: string;
86
+ };
87
+ limit: {
88
+ type: string;
89
+ default: number;
90
+ };
91
+ stackId?: undefined;
92
+ contextPath?: undefined;
93
+ includeSteps?: undefined;
94
+ query?: undefined;
95
+ variables?: undefined;
96
+ correlationKey?: undefined;
97
+ payload?: undefined;
98
+ };
99
+ required?: undefined;
100
+ };
101
+ } | {
102
+ name: string;
103
+ description: string;
104
+ inputSchema: {
105
+ type: "object";
106
+ properties: {
107
+ stackId: {
108
+ type: string;
109
+ description: string;
110
+ };
111
+ namespace: {
112
+ type: string;
113
+ description: string;
114
+ };
115
+ contextPath: {
116
+ type: string;
117
+ description: string;
118
+ };
119
+ includeSteps: {
120
+ type: string;
121
+ default: boolean;
122
+ };
123
+ workflowId?: undefined;
124
+ status?: undefined;
125
+ createdAfter?: undefined;
126
+ createdBefore?: undefined;
127
+ metadataFilter?: undefined;
128
+ limit?: undefined;
129
+ query?: undefined;
130
+ variables?: undefined;
131
+ correlationKey?: undefined;
132
+ payload?: undefined;
133
+ };
134
+ required: string[];
135
+ };
136
+ } | {
137
+ name: string;
138
+ description: string;
139
+ inputSchema: {
140
+ type: "object";
141
+ properties: {
142
+ query: {
143
+ type: string;
144
+ description: string;
145
+ };
146
+ variables: {
147
+ type: string;
148
+ description: string;
149
+ };
150
+ namespace: {
151
+ type: string;
152
+ description: string;
153
+ };
154
+ workflowId?: undefined;
155
+ status?: undefined;
156
+ createdAfter?: undefined;
157
+ createdBefore?: undefined;
158
+ metadataFilter?: undefined;
159
+ limit?: undefined;
160
+ stackId?: undefined;
161
+ contextPath?: undefined;
162
+ includeSteps?: undefined;
163
+ correlationKey?: undefined;
164
+ payload?: undefined;
165
+ };
166
+ required: string[];
167
+ };
168
+ } | {
169
+ name: string;
170
+ description: string;
171
+ inputSchema: {
172
+ type: "object";
173
+ properties: {
174
+ correlationKey: {
175
+ type: string;
176
+ description: string;
177
+ };
178
+ payload: {
179
+ type: string;
180
+ description: string;
181
+ };
182
+ namespace: {
183
+ type: string;
184
+ description: string;
185
+ };
186
+ workflowId?: undefined;
187
+ status?: undefined;
188
+ createdAfter?: undefined;
189
+ createdBefore?: undefined;
190
+ metadataFilter?: undefined;
191
+ limit?: undefined;
192
+ stackId?: undefined;
193
+ contextPath?: undefined;
194
+ includeSteps?: undefined;
195
+ query?: undefined;
196
+ variables?: undefined;
197
+ };
198
+ required: string[];
199
+ };
200
+ })[];
201
+ export interface McpToolExecutionContext extends McpTenantScopeOptions {
202
+ engine: WorkflowQueryEngine;
203
+ schema?: GraphQLSchema;
204
+ }
205
+ export declare function executeMcpTool(name: string, rawArgs: Record<string, unknown> | undefined, ctx: McpToolExecutionContext): Promise<{
206
+ content: Array<{
207
+ type: 'text';
208
+ text: string;
209
+ }>;
210
+ isError?: boolean;
211
+ }>;
212
+ //# sourceMappingURL=tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/mcp/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAErD,OAAO,KAAK,EAAE,iBAAiB,EAAkB,MAAM,UAAU,CAAC;AAElE,MAAM,WAAW,qBAAqB;IAClC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,wBAAgB,mBAAmB,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,MAAM,CAkB/F;AA4BD,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,iBAAiB;;;;;;;;;;;;;;;;;EAuB5D;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,iBAAiB,EAAE,YAAY,UAAO;;;;;;;;;;;;;;;;;;;;;EAahF;AA8BD,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAoE9B,CAAC;AAEF,MAAM,WAAW,uBAAwB,SAAQ,qBAAqB;IAClE,MAAM,EAAE,mBAAmB,CAAC;IAC5B,MAAM,CAAC,EAAE,aAAa,CAAC;CAC1B;AAED,wBAAsB,cAAc,CAChC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAC5C,GAAG,EAAE,uBAAuB,GAC7B,OAAO,CAAC;IAAE,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC,CA0JhF"}
@@ -0,0 +1,317 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WORKFLOW_MCP_TOOLS = void 0;
4
+ exports.resolveMcpNamespace = resolveMcpNamespace;
5
+ exports.formatWorkflowSummary = formatWorkflowSummary;
6
+ exports.formatWorkflowDetail = formatWorkflowDetail;
7
+ exports.executeMcpTool = executeMcpTool;
8
+ const graphql_1 = require("graphql");
9
+ const schema_1 = require("../graphql/schema");
10
+ function resolveMcpNamespace(requested, options) {
11
+ const trimmedRequested = typeof requested === 'string' && requested.trim() ? requested.trim() : undefined;
12
+ const boundNamespace = typeof options?.namespace === 'string' && options.namespace.trim() ? options.namespace.trim() : undefined;
13
+ if (boundNamespace) {
14
+ if (trimmedRequested && trimmedRequested !== boundNamespace) {
15
+ throw new Error('Workflow namespace does not match the MCP server tenant scope');
16
+ }
17
+ return boundNamespace;
18
+ }
19
+ const fallback = typeof options?.defaultNamespace === 'string' && options.defaultNamespace.trim()
20
+ ? options.defaultNamespace.trim()
21
+ : 'default';
22
+ return trimmedRequested ?? fallback;
23
+ }
24
+ const VALID_STATUSES = new Set(['running', 'waiting', 'completed', 'failed', 'cancelled']);
25
+ function parseWorkflowStatus(status) {
26
+ if (status === undefined || status === null || status === '')
27
+ return undefined;
28
+ if (typeof status !== 'string') {
29
+ throw new Error('Invalid workflow status filter');
30
+ }
31
+ const normalized = status.toLowerCase();
32
+ if (!VALID_STATUSES.has(normalized)) {
33
+ throw new Error(`Unsupported workflow status '${status}'`);
34
+ }
35
+ return normalized;
36
+ }
37
+ function parseIsoDate(value, fieldName) {
38
+ if (value === undefined || value === null || value === '')
39
+ return undefined;
40
+ if (typeof value !== 'string') {
41
+ throw new Error(`Invalid ISO 8601 timestamp for ${fieldName}`);
42
+ }
43
+ const date = new Date(value);
44
+ if (Number.isNaN(date.getTime())) {
45
+ throw new Error(`Invalid ISO 8601 timestamp for ${fieldName}: '${value}'`);
46
+ }
47
+ return date;
48
+ }
49
+ function formatWorkflowSummary(item) {
50
+ return {
51
+ stackId: item.stackId,
52
+ workflowId: item.workflowId ?? null,
53
+ namespace: item.namespace,
54
+ status: (item.status ?? 'running').toUpperCase(),
55
+ revision: item.revision,
56
+ createdAt: item.createdAt.toISOString(),
57
+ updatedAt: item.updatedAt.toISOString(),
58
+ ...(item.expiresAt ? { expiresAt: item.expiresAt.toISOString() } : {}),
59
+ ...(item.metadata ? { metadata: item.metadata } : {}),
60
+ ...(item.waitRecord
61
+ ? {
62
+ waitRecord: {
63
+ correlationKey: item.waitRecord.correlationKey,
64
+ eventName: item.waitRecord.eventName ?? null,
65
+ expiresAt: item.waitRecord.expiresAt?.toISOString() ?? null,
66
+ lockedBy: item.waitRecord.lockedBy ?? null,
67
+ status: item.waitRecord.status ?? null,
68
+ },
69
+ }
70
+ : {}),
71
+ };
72
+ }
73
+ function formatWorkflowDetail(item, includeSteps = true) {
74
+ const errorDiagnostics = item.metadata && typeof item.metadata.error === 'object' && item.metadata.error !== null
75
+ ? item.metadata.error
76
+ : undefined;
77
+ return {
78
+ ...formatWorkflowSummary(item),
79
+ context: item.context ?? null,
80
+ ...(errorDiagnostics ? { error: errorDiagnostics } : {}),
81
+ ...(includeSteps ? { steps: item.steps ?? [] } : {}),
82
+ compensations: item.compensations ?? [],
83
+ };
84
+ }
85
+ function assertGraphQLRedactionGuardrails(query, variables) {
86
+ const doc = (0, graphql_1.parse)(query);
87
+ for (const def of doc.definitions) {
88
+ if (def.kind === graphql_1.Kind.OPERATION_DEFINITION && def.operation === 'subscription') {
89
+ throw new Error('Subscription operations are not supported in execute_workflow_query');
90
+ }
91
+ }
92
+ (0, graphql_1.visit)(doc, {
93
+ Field(node) {
94
+ if (node.name.value !== 'context' && node.name.value !== 'output')
95
+ return;
96
+ for (const arg of node.arguments ?? []) {
97
+ if (arg.name.value !== 'redact')
98
+ continue;
99
+ if (arg.value.kind === graphql_1.Kind.BOOLEAN && arg.value.value === false) {
100
+ throw new Error('Unredacted field access (redact: false) is not permitted over MCP');
101
+ }
102
+ if (arg.value.kind === graphql_1.Kind.VARIABLE) {
103
+ const varName = arg.value.name.value;
104
+ if (variables && variables[varName] === false) {
105
+ throw new Error('Unredacted field access (redact: false) is not permitted over MCP');
106
+ }
107
+ }
108
+ }
109
+ },
110
+ });
111
+ }
112
+ exports.WORKFLOW_MCP_TOOLS = [
113
+ {
114
+ name: 'search_workflows',
115
+ description: 'Search workflow executions by status, workflow type, date range, or metadata.',
116
+ inputSchema: {
117
+ type: 'object',
118
+ properties: {
119
+ workflowId: { type: 'string', description: "e.g. 'order-checkout'" },
120
+ status: {
121
+ type: 'string',
122
+ enum: ['RUNNING', 'WAITING', 'COMPLETED', 'FAILED', 'CANCELLED'],
123
+ },
124
+ namespace: { type: 'string', description: 'Tenant partition' },
125
+ createdAfter: { type: 'string', description: 'ISO 8601 timestamp' },
126
+ createdBefore: { type: 'string', description: 'ISO 8601 timestamp' },
127
+ metadataFilter: {
128
+ type: 'object',
129
+ description: 'Key-value match, e.g. { "orderId": "ord_101" }',
130
+ },
131
+ limit: { type: 'number', default: 10 },
132
+ },
133
+ },
134
+ },
135
+ {
136
+ name: 'inspect_workflow',
137
+ description: 'Retrieve detailed execution state, step lifecycle history, and focused context for a single workflow.',
138
+ inputSchema: {
139
+ type: 'object',
140
+ properties: {
141
+ stackId: { type: 'string', description: 'The execution stack UUID' },
142
+ namespace: { type: 'string', description: 'Tenant partition' },
143
+ contextPath: {
144
+ type: 'string',
145
+ description: "Optional dot-path to extract specific context (e.g. 'payment.status')",
146
+ },
147
+ includeSteps: { type: 'boolean', default: true },
148
+ },
149
+ required: ['stackId'],
150
+ },
151
+ },
152
+ {
153
+ name: 'execute_workflow_query',
154
+ description: 'Allows the LLM to execute an arbitrary GraphQL query against the Siglo schema for complex filtering or aggregations.',
155
+ inputSchema: {
156
+ type: 'object',
157
+ properties: {
158
+ query: { type: 'string', description: 'Valid GraphQL query string' },
159
+ variables: { type: 'object', description: 'Optional GraphQL variables map' },
160
+ namespace: { type: 'string', description: 'Tenant partition' },
161
+ },
162
+ required: ['query'],
163
+ },
164
+ },
165
+ {
166
+ name: 'resume_workflow',
167
+ description: 'Resume a suspended workflow waiting for an external approval or event.',
168
+ inputSchema: {
169
+ type: 'object',
170
+ properties: {
171
+ correlationKey: { type: 'string', description: 'Correlation key of the wait record' },
172
+ payload: { type: 'object', description: 'Data payload to merge upon resumption' },
173
+ namespace: { type: 'string', description: 'Tenant partition' },
174
+ },
175
+ required: ['correlationKey'],
176
+ },
177
+ },
178
+ ];
179
+ async function executeMcpTool(name, rawArgs, ctx) {
180
+ const args = rawArgs ?? {};
181
+ const { engine } = ctx;
182
+ try {
183
+ switch (name) {
184
+ case 'search_workflows': {
185
+ const namespace = resolveMcpNamespace(args.namespace, ctx);
186
+ const status = parseWorkflowStatus(args.status);
187
+ const createdAfter = parseIsoDate(args.createdAfter, 'createdAfter');
188
+ const createdBefore = parseIsoDate(args.createdBefore, 'createdBefore');
189
+ const limit = typeof args.limit === 'number' ? args.limit : 10;
190
+ const metadata = args.metadataFilter &&
191
+ typeof args.metadataFilter === 'object' &&
192
+ !Array.isArray(args.metadataFilter)
193
+ ? args.metadataFilter
194
+ : undefined;
195
+ const page = await engine.findMany({
196
+ filter: {
197
+ namespace,
198
+ workflowId: typeof args.workflowId === 'string' ? args.workflowId : undefined,
199
+ status,
200
+ createdAfter,
201
+ createdBefore,
202
+ metadata,
203
+ },
204
+ pagination: { limit },
205
+ select: { includeContext: false },
206
+ });
207
+ const payload = {
208
+ workflows: page.items.map(formatWorkflowSummary),
209
+ totalCount: page.totalCount,
210
+ pageInfo: page.pageInfo,
211
+ };
212
+ return {
213
+ content: [{ type: 'text', text: JSON.stringify(payload, null, 2) }],
214
+ };
215
+ }
216
+ case 'inspect_workflow': {
217
+ const stackId = typeof args.stackId === 'string' ? args.stackId.trim() : '';
218
+ if (!stackId) {
219
+ throw new Error('stackId is required for inspect_workflow');
220
+ }
221
+ const namespace = resolveMcpNamespace(args.namespace, ctx);
222
+ const contextPath = typeof args.contextPath === 'string' && args.contextPath.trim()
223
+ ? args.contextPath.trim()
224
+ : undefined;
225
+ const includeSteps = args.includeSteps !== false;
226
+ const execution = await engine.findById(stackId, {
227
+ namespace,
228
+ includeContext: true,
229
+ contextPath,
230
+ redact: true,
231
+ });
232
+ if (!execution) {
233
+ return {
234
+ isError: true,
235
+ content: [
236
+ {
237
+ type: 'text',
238
+ text: JSON.stringify({
239
+ error: `Workflow '${stackId}' was not found in namespace '${namespace}'`,
240
+ }),
241
+ },
242
+ ],
243
+ };
244
+ }
245
+ const detail = formatWorkflowDetail(execution, includeSteps);
246
+ return {
247
+ content: [{ type: 'text', text: JSON.stringify(detail, null, 2) }],
248
+ };
249
+ }
250
+ case 'execute_workflow_query': {
251
+ const query = typeof args.query === 'string' ? args.query.trim() : '';
252
+ if (!query) {
253
+ throw new Error('query is required for execute_workflow_query');
254
+ }
255
+ const namespace = resolveMcpNamespace(args.namespace, ctx);
256
+ const variables = args.variables && typeof args.variables === 'object' && !Array.isArray(args.variables)
257
+ ? args.variables
258
+ : undefined;
259
+ assertGraphQLRedactionGuardrails(query, variables);
260
+ const schema = ctx.schema ?? (0, schema_1.createWorkflowGraphQLSchema)(engine);
261
+ const result = await (0, graphql_1.graphql)({
262
+ schema,
263
+ source: query,
264
+ variableValues: variables,
265
+ contextValue: {
266
+ namespace,
267
+ engine,
268
+ subscriptionManager: engine.getSubscriptionManager(),
269
+ },
270
+ });
271
+ const hasFatalError = Boolean(result.errors && result.errors.length > 0 && !result.data);
272
+ return {
273
+ ...(hasFatalError ? { isError: true } : {}),
274
+ content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
275
+ };
276
+ }
277
+ case 'resume_workflow': {
278
+ const correlationKey = typeof args.correlationKey === 'string' ? args.correlationKey.trim() : '';
279
+ if (!correlationKey) {
280
+ throw new Error('correlationKey is required for resume_workflow');
281
+ }
282
+ const namespace = resolveMcpNamespace(args.namespace, ctx);
283
+ const resumed = await engine.resumeWorkflow(correlationKey, args.payload, namespace);
284
+ return {
285
+ content: [
286
+ {
287
+ type: 'text',
288
+ text: JSON.stringify({ resumed, correlationKey, namespace }, null, 2),
289
+ },
290
+ ],
291
+ };
292
+ }
293
+ default:
294
+ return {
295
+ isError: true,
296
+ content: [
297
+ {
298
+ type: 'text',
299
+ text: JSON.stringify({ error: `Unknown MCP tool: '${name}'` }),
300
+ },
301
+ ],
302
+ };
303
+ }
304
+ }
305
+ catch (err) {
306
+ return {
307
+ isError: true,
308
+ content: [
309
+ {
310
+ type: 'text',
311
+ text: JSON.stringify({ error: err?.message || 'MCP tool execution failed' }),
312
+ },
313
+ ],
314
+ };
315
+ }
316
+ }
317
+ //# sourceMappingURL=tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/mcp/tools.ts"],"names":[],"mappings":";;;AAkBA,kDAkBC;AA4BD,sDAuBC;AAED,oDAaC;AAyGD,wCA8JC;AA7WD,qCAA0E;AAE1E,8CAAgE;AAgBhE,SAAgB,mBAAmB,CAAC,SAAkB,EAAE,OAA+B;IACnF,MAAM,gBAAgB,GAAG,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAC1G,MAAM,cAAc,GAChB,OAAO,OAAO,EAAE,SAAS,KAAK,QAAQ,IAAI,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAE9G,IAAI,cAAc,EAAE,CAAC;QACjB,IAAI,gBAAgB,IAAI,gBAAgB,KAAK,cAAc,EAAE,CAAC;YAC1D,MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC,CAAC;QACrF,CAAC;QACD,OAAO,cAAc,CAAC;IAC1B,CAAC;IAED,MAAM,QAAQ,GACV,OAAO,OAAO,EAAE,gBAAgB,KAAK,QAAQ,IAAI,OAAO,CAAC,gBAAgB,CAAC,IAAI,EAAE;QAC5E,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,IAAI,EAAE;QACjC,CAAC,CAAC,SAAS,CAAC;IAEpB,OAAO,gBAAgB,IAAI,QAAQ,CAAC;AACxC,CAAC;AAED,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,CAAC,CA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C;yBACxE;qBACJ;iBACJ,CAAC;YACN,CAAC;YAED;gBACI,OAAO;oBACH,OAAO,EAAE,IAAI;oBACb,OAAO,EAAE;wBACL;4BACI,IAAI,EAAE,MAAM;4BACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,sBAAsB,IAAI,GAAG,EAAE,CAAC;yBACjE;qBACJ;iBACJ,CAAC;QACV,CAAC;IACL,CAAC;IAAC,OAAO,GAAQ,EAAE,CAAC;QAChB,OAAO;YACH,OAAO,EAAE,IAAI;YACb,OAAO,EAAE;gBACL;oBACI,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,IAAI,2BAA2B,EAAE,CAAC;iBAC/E;aACJ;SACJ,CAAC;IACN,CAAC;AACL,CAAC"}
@@ -0,0 +1,33 @@
1
+ import type { SerializedExecutionStack } from '@siglo/core';
2
+ import type { QueryableStorageAdapter } from './types';
3
+ export declare class MemoryStorageAdapter implements QueryableStorageAdapter {
4
+ readonly name = "memory";
5
+ private readonly records;
6
+ saveCheckpoint(checkpoint: SerializedExecutionStack): Promise<void>;
7
+ getCheckpoint(stackId: string): Promise<{
8
+ contexts: Record<string, Record<string, any>>;
9
+ version: number;
10
+ schemaVersion?: string | undefined;
11
+ stackId: string;
12
+ workflowId?: string | undefined;
13
+ namespace?: string | undefined;
14
+ type: string;
15
+ status?: "running" | "completed" | "failed" | "cancelled" | "waiting" | undefined;
16
+ revision: number;
17
+ chains: string[];
18
+ timestamp: number;
19
+ expiresAt?: number | undefined;
20
+ metadata?: Record<string, any> | undefined;
21
+ createdAt: number;
22
+ } | undefined>;
23
+ cancelWorkflow(stackId: string): Promise<void>;
24
+ getWaitRecord(correlationKeyOrStackId: string): Promise<any | undefined>;
25
+ queryWorkflows({ filter, sort, pagination, includeContext, }: Parameters<NonNullable<QueryableStorageAdapter['queryWorkflows']>>[0]): Promise<{
26
+ checkpoints: (Omit<SerializedExecutionStack, "contexts"> & {
27
+ createdAt: number;
28
+ })[];
29
+ totalCount: number;
30
+ hasNextPage: boolean;
31
+ }>;
32
+ }
33
+ //# sourceMappingURL=memory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAG5D,OAAO,KAAK,EAAE,uBAAuB,EAAwC,MAAM,SAAS,CAAC;AAwB7F,qBAAa,oBAAqB,YAAW,uBAAuB;IAChE,QAAQ,CAAC,IAAI,YAAY;IACzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAMpB;IAEE,cAAc,CAAC,UAAU,EAAE,wBAAwB;IAWnD,aAAa,CAAC,OAAO,EAAE,MAAM;;;;;;;;;;;;;;mBAhBwC,MAAM;;IAqB3E,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAY9C,aAAa,CAAC,uBAAuB,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,GAAG,SAAS,CAAC;IAaxE,cAAc,CAAC,EACjB,MAAM,EACN,IAAI,EACJ,UAAU,EACV,cAAc,GACjB,EAAE,UAAU,CAAC,WAAW,CAAC,uBAAuB,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;;uBAnDG,MAAM;;;;;CAoEpF"}
package/dist/memory.js ADDED
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MemoryStorageAdapter = void 0;
4
+ const node_util_1 = require("node:util");
5
+ const cursor_1 = require("./cursor");
6
+ function matches(record, filter) {
7
+ const created = record.createdAt ?? record.timestamp;
8
+ const wait = record.metadata?.waitRecord;
9
+ return (record.namespace === filter.namespace &&
10
+ (filter.workflowId === undefined || record.workflowId === filter.workflowId) &&
11
+ (filter.status === undefined || (record.status ?? 'running') === filter.status) &&
12
+ (!filter.createdAfter || created > filter.createdAfter.getTime()) &&
13
+ (!filter.createdBefore || created < filter.createdBefore.getTime()) &&
14
+ (filter.correlationKey === undefined ||
15
+ (wait?.correlationKey === filter.correlationKey &&
16
+ wait.stackId === record.stackId &&
17
+ (wait.namespace === undefined || wait.namespace === filter.namespace))) &&
18
+ Object.entries(filter.metadata ?? {}).every(([key, value]) => record.metadata &&
19
+ Object.hasOwn(record.metadata, key) &&
20
+ (0, node_util_1.isDeepStrictEqual)(record.metadata[key], value)));
21
+ }
22
+ class MemoryStorageAdapter {
23
+ name = 'memory';
24
+ records = new Map();
25
+ async saveCheckpoint(checkpoint) {
26
+ const existing = this.records.get(checkpoint.stackId);
27
+ if (existing && existing.summary.revision > checkpoint.revision)
28
+ return;
29
+ // Match persistent adapters when core includes runtime step functions in wait metadata.
30
+ const { contexts, ...summary } = JSON.parse(JSON.stringify(checkpoint));
31
+ this.records.set(checkpoint.stackId, {
32
+ summary: { ...summary, createdAt: existing?.summary.createdAt ?? checkpoint.timestamp },
33
+ contexts,
34
+ });
35
+ }
36
+ async getCheckpoint(stackId) {
37
+ const record = this.records.get(stackId);
38
+ return record && structuredClone({ ...record.summary, contexts: record.contexts });
39
+ }
40
+ async cancelWorkflow(stackId) {
41
+ const record = this.records.get(stackId);
42
+ if (record) {
43
+ record.summary.status = 'cancelled';
44
+ record.summary.revision += 1;
45
+ record.summary.timestamp = Date.now();
46
+ if (record.summary.metadata?.waitRecord) {
47
+ record.summary.metadata.waitRecord.status = 'CANCELLED';
48
+ }
49
+ }
50
+ }
51
+ async getWaitRecord(correlationKeyOrStackId) {
52
+ for (const record of this.records.values()) {
53
+ const wait = record.summary.metadata?.waitRecord;
54
+ if (wait?.correlationKey === correlationKeyOrStackId ||
55
+ record.summary.stackId === correlationKeyOrStackId) {
56
+ return structuredClone(wait);
57
+ }
58
+ }
59
+ return undefined;
60
+ }
61
+ async queryWorkflows({ filter, sort, pagination, includeContext, }) {
62
+ const order = (0, cursor_1.sortOrder)(sort);
63
+ const cursor = pagination?.cursor === undefined ? undefined : (0, cursor_1.decodeCursor)(pagination.cursor, order);
64
+ const matchesFilter = Array.from(this.records.values(), record => record.summary).filter(record => matches(record, filter));
65
+ const remaining = matchesFilter
66
+ .filter(record => !cursor || (0, cursor_1.compare)((0, cursor_1.position)(record, order), cursor, order) > 0)
67
+ .sort((a, b) => (0, cursor_1.compare)((0, cursor_1.position)(a, order), (0, cursor_1.position)(b, order), order));
68
+ const page = remaining.slice(0, pagination?.limit ?? 20);
69
+ const checkpoints = page.map(record => {
70
+ if (includeContext)
71
+ return structuredClone({ ...record, contexts: this.records.get(record.stackId).contexts });
72
+ return structuredClone(record);
73
+ });
74
+ return { checkpoints, totalCount: matchesFilter.length, hasNextPage: remaining.length > page.length };
75
+ }
76
+ }
77
+ exports.MemoryStorageAdapter = MemoryStorageAdapter;
78
+ //# sourceMappingURL=memory.js.map