@exaudeus/workrail 0.0.2-beta.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 (147) hide show
  1. package/README.md +223 -0
  2. package/dist/application/app.d.ts +32 -0
  3. package/dist/application/app.d.ts.map +1 -0
  4. package/dist/application/app.js +133 -0
  5. package/dist/application/app.js.map +1 -0
  6. package/dist/application/services/validation-engine.d.ts +102 -0
  7. package/dist/application/services/validation-engine.d.ts.map +1 -0
  8. package/dist/application/services/validation-engine.js +293 -0
  9. package/dist/application/services/validation-engine.js.map +1 -0
  10. package/dist/application/services/workflow-service.d.ts +47 -0
  11. package/dist/application/services/workflow-service.d.ts.map +1 -0
  12. package/dist/application/services/workflow-service.js +80 -0
  13. package/dist/application/services/workflow-service.js.map +1 -0
  14. package/dist/application/use-cases/get-next-step.d.ts +22 -0
  15. package/dist/application/use-cases/get-next-step.d.ts.map +1 -0
  16. package/dist/application/use-cases/get-next-step.js +21 -0
  17. package/dist/application/use-cases/get-next-step.js.map +1 -0
  18. package/dist/application/use-cases/get-workflow.d.ts +13 -0
  19. package/dist/application/use-cases/get-workflow.d.ts.map +1 -0
  20. package/dist/application/use-cases/get-workflow.js +26 -0
  21. package/dist/application/use-cases/get-workflow.js.map +1 -0
  22. package/dist/application/use-cases/list-workflows.d.ts +13 -0
  23. package/dist/application/use-cases/list-workflows.d.ts.map +1 -0
  24. package/dist/application/use-cases/list-workflows.js +21 -0
  25. package/dist/application/use-cases/list-workflows.js.map +1 -0
  26. package/dist/application/use-cases/validate-step-output.d.ts +20 -0
  27. package/dist/application/use-cases/validate-step-output.d.ts.map +1 -0
  28. package/dist/application/use-cases/validate-step-output.js +21 -0
  29. package/dist/application/use-cases/validate-step-output.js.map +1 -0
  30. package/dist/application/validation.d.ts +6 -0
  31. package/dist/application/validation.d.ts.map +1 -0
  32. package/dist/application/validation.js +19 -0
  33. package/dist/application/validation.js.map +1 -0
  34. package/dist/cli.d.ts +3 -0
  35. package/dist/cli.d.ts.map +1 -0
  36. package/dist/cli.js +106 -0
  37. package/dist/cli.js.map +1 -0
  38. package/dist/container.d.ts +22 -0
  39. package/dist/container.d.ts.map +1 -0
  40. package/dist/container.js +25 -0
  41. package/dist/container.js.map +1 -0
  42. package/dist/core/error-handler.d.ts +93 -0
  43. package/dist/core/error-handler.d.ts.map +1 -0
  44. package/dist/core/error-handler.js +336 -0
  45. package/dist/core/error-handler.js.map +1 -0
  46. package/dist/domain/index.d.ts +3 -0
  47. package/dist/domain/index.d.ts.map +1 -0
  48. package/dist/domain/index.js +6 -0
  49. package/dist/domain/index.js.map +1 -0
  50. package/dist/index.d.ts +3 -0
  51. package/dist/index.d.ts.map +1 -0
  52. package/dist/index.js +30 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/infrastructure/index.d.ts +3 -0
  55. package/dist/infrastructure/index.d.ts.map +1 -0
  56. package/dist/infrastructure/index.js +6 -0
  57. package/dist/infrastructure/index.js.map +1 -0
  58. package/dist/infrastructure/rpc/handler.d.ts +26 -0
  59. package/dist/infrastructure/rpc/handler.d.ts.map +1 -0
  60. package/dist/infrastructure/rpc/handler.js +91 -0
  61. package/dist/infrastructure/rpc/handler.js.map +1 -0
  62. package/dist/infrastructure/rpc/index.d.ts +2 -0
  63. package/dist/infrastructure/rpc/index.d.ts.map +1 -0
  64. package/dist/infrastructure/rpc/index.js +5 -0
  65. package/dist/infrastructure/rpc/index.js.map +1 -0
  66. package/dist/infrastructure/rpc/server.d.ts +4 -0
  67. package/dist/infrastructure/rpc/server.d.ts.map +1 -0
  68. package/dist/infrastructure/rpc/server.js +40 -0
  69. package/dist/infrastructure/rpc/server.js.map +1 -0
  70. package/dist/infrastructure/storage/caching-workflow-storage.d.ts +22 -0
  71. package/dist/infrastructure/storage/caching-workflow-storage.d.ts.map +1 -0
  72. package/dist/infrastructure/storage/caching-workflow-storage.js +61 -0
  73. package/dist/infrastructure/storage/caching-workflow-storage.js.map +1 -0
  74. package/dist/infrastructure/storage/file-workflow-storage.d.ts +56 -0
  75. package/dist/infrastructure/storage/file-workflow-storage.d.ts.map +1 -0
  76. package/dist/infrastructure/storage/file-workflow-storage.js +206 -0
  77. package/dist/infrastructure/storage/file-workflow-storage.js.map +1 -0
  78. package/dist/infrastructure/storage/in-memory-storage.d.ts +17 -0
  79. package/dist/infrastructure/storage/in-memory-storage.d.ts.map +1 -0
  80. package/dist/infrastructure/storage/in-memory-storage.js +43 -0
  81. package/dist/infrastructure/storage/in-memory-storage.js.map +1 -0
  82. package/dist/infrastructure/storage/index.d.ts +6 -0
  83. package/dist/infrastructure/storage/index.d.ts.map +1 -0
  84. package/dist/infrastructure/storage/index.js +9 -0
  85. package/dist/infrastructure/storage/index.js.map +1 -0
  86. package/dist/infrastructure/storage/schema-validating-workflow-storage.d.ts +23 -0
  87. package/dist/infrastructure/storage/schema-validating-workflow-storage.d.ts.map +1 -0
  88. package/dist/infrastructure/storage/schema-validating-workflow-storage.js +70 -0
  89. package/dist/infrastructure/storage/schema-validating-workflow-storage.js.map +1 -0
  90. package/dist/infrastructure/storage/storage.d.ts +16 -0
  91. package/dist/infrastructure/storage/storage.d.ts.map +1 -0
  92. package/dist/infrastructure/storage/storage.js +32 -0
  93. package/dist/infrastructure/storage/storage.js.map +1 -0
  94. package/dist/mcp-server-simple.js +391 -0
  95. package/dist/mcp-server.d.ts +3 -0
  96. package/dist/mcp-server.d.ts.map +1 -0
  97. package/dist/mcp-server.js +223 -0
  98. package/dist/mcp-server.js.map +1 -0
  99. package/dist/tools/mcp_initialize.d.ts +3 -0
  100. package/dist/tools/mcp_initialize.d.ts.map +1 -0
  101. package/dist/tools/mcp_initialize.js +52 -0
  102. package/dist/tools/mcp_initialize.js.map +1 -0
  103. package/dist/tools/mcp_shutdown.d.ts +3 -0
  104. package/dist/tools/mcp_shutdown.d.ts.map +1 -0
  105. package/dist/tools/mcp_shutdown.js +11 -0
  106. package/dist/tools/mcp_shutdown.js.map +1 -0
  107. package/dist/tools/mcp_tools_list.d.ts +3 -0
  108. package/dist/tools/mcp_tools_list.d.ts.map +1 -0
  109. package/dist/tools/mcp_tools_list.js +61 -0
  110. package/dist/tools/mcp_tools_list.js.map +1 -0
  111. package/dist/types/mcp-types.d.ts +251 -0
  112. package/dist/types/mcp-types.d.ts.map +1 -0
  113. package/dist/types/mcp-types.js +27 -0
  114. package/dist/types/mcp-types.js.map +1 -0
  115. package/dist/types/server.d.ts +5 -0
  116. package/dist/types/server.d.ts.map +1 -0
  117. package/dist/types/server.js +3 -0
  118. package/dist/types/server.js.map +1 -0
  119. package/dist/types/storage.d.ts +27 -0
  120. package/dist/types/storage.d.ts.map +1 -0
  121. package/dist/types/storage.js +6 -0
  122. package/dist/types/storage.js.map +1 -0
  123. package/dist/types/workflow-types.d.ts +251 -0
  124. package/dist/types/workflow-types.d.ts.map +1 -0
  125. package/dist/types/workflow-types.js +5 -0
  126. package/dist/types/workflow-types.js.map +1 -0
  127. package/dist/utils/condition-evaluator.d.ts +32 -0
  128. package/dist/utils/condition-evaluator.d.ts.map +1 -0
  129. package/dist/utils/condition-evaluator.js +105 -0
  130. package/dist/utils/condition-evaluator.js.map +1 -0
  131. package/dist/utils/config.d.ts +195 -0
  132. package/dist/utils/config.d.ts.map +1 -0
  133. package/dist/utils/config.js +332 -0
  134. package/dist/utils/config.js.map +1 -0
  135. package/dist/validation/request-validator.d.ts +9 -0
  136. package/dist/validation/request-validator.d.ts.map +1 -0
  137. package/dist/validation/request-validator.js +32 -0
  138. package/dist/validation/request-validator.js.map +1 -0
  139. package/dist/validation/response-validator.d.ts +9 -0
  140. package/dist/validation/response-validator.d.ts.map +1 -0
  141. package/dist/validation/response-validator.js +83 -0
  142. package/dist/validation/response-validator.js.map +1 -0
  143. package/dist/validation/schemas.d.ts +6 -0
  144. package/dist/validation/schemas.d.ts.map +1 -0
  145. package/dist/validation/schemas.js +52 -0
  146. package/dist/validation/schemas.js.map +1 -0
  147. package/package.json +48 -0
package/README.md ADDED
@@ -0,0 +1,223 @@
1
+ # Workflow Orchestration Server (MCP-Compatible)
2
+
3
+ > **Reliable, test-driven workflow execution for AI coding assistants – powered by Clean Architecture**
4
+
5
+ [![Build](https://img.shields.io/github/actions/workflow/status/yourusername/workflow-orchestration/ci.yml?branch=main)]()
6
+ [![Version](https://img.shields.io/badge/version-0.0.1--alpha-orange)]()
7
+ [![MCP Compatible](https://img.shields.io/badge/MCP-compatible-purple.svg)](https://modelcontextprotocol.org)
8
+
9
+ ---
10
+
11
+ ## 🚀 Overview
12
+
13
+ Large language models are phenomenal at generating code, yet they often hallucinate, lose context, or perform unsafe operations.
14
+ This server provides **structured, step-by-step workflows** (defined as JSON documents) that guide an AI assistant through safe, repeatable tasks.
15
+ It follows [Model Context Protocol (MCP)](https://modelcontextprotocol.org) conventions and exposes a **JSON-RPC 2.0** interface on `stdin/stdout`.
16
+
17
+ The codebase now implements the full MVP described in the original specification, refactored with Clean Architecture for long-term maintainability.
18
+
19
+ ---
20
+
21
+ ## ✨ Key Features
22
+
23
+ * **Clean Architecture** – clear separation of **Domain → Application → Infrastructure** layers.
24
+ * **MCP Protocol Support** – Full MCP SDK integration with proper tool definitions and stdio transport.
25
+ * **Workflow Orchestration Tools** – 4 core tools for workflow management:
26
+ - `workflow_list` - List all available workflows
27
+ - `workflow_get` - Get detailed workflow information
28
+ - `workflow_next` - Get the next step in a workflow
29
+ - `workflow_validate` - Advanced validation of step outputs with schema, context-aware, and composition rules
30
+ * **Dependency Injection** – pluggable components are wired by `src/container.ts` (Inversify-style, no runtime reflection).
31
+ * **Async, Secure Storage** – interchangeable back-ends: in-memory (default for tests) and file-based storage with path-traversal safeguards.
32
+ * **Advanced ValidationEngine** – Three-tier validation system with JSON Schema validation (AJV), Context-Aware Validation (conditional rules), and Logical Composition (and/or/not operators) for comprehensive step output quality assurance.
33
+ * **Typed Error Mapping** – domain errors (`WorkflowNotFoundError`, `ValidationError`, …) automatically translate to proper JSON-RPC codes.
34
+ * **CLI Validation** – `validate` command for testing workflow files locally with comprehensive error reporting.
35
+ * **Comprehensive Test Coverage** – 81 tests passing, 7 failing (performance optimizations in progress), 88 total tests covering storage, validation, error mapping, CLI, and server logic.
36
+
37
+ ---
38
+
39
+ ## ⚡ Quick Start
40
+
41
+ ### Prerequisites
42
+ * Node 18+
43
+ * `npm install`
44
+
45
+ ### Development mode
46
+ ```bash
47
+ npm run dev
48
+ ```
49
+ The MCP server listens for JSON-RPC requests on **stdin/stdout**.
50
+
51
+ ### Production build
52
+ ```bash
53
+ npm run build
54
+ node dist/mcp-server.js
55
+ ```
56
+
57
+ ### Workflow validation (CLI utility)
58
+ ```bash
59
+ npx ts-node src/cli.ts validate <workflow-file.json>
60
+ ```
61
+
62
+ ### Docker
63
+ ```bash
64
+ docker-compose up
65
+ ```
66
+
67
+ ---
68
+
69
+ ## 🔧 Configuration
70
+
71
+ ### Usage with Claude Desktop
72
+
73
+ Add this to your `claude_desktop_config.json`:
74
+
75
+ #### npx (once published to npm)
76
+
77
+ ```json
78
+ {
79
+ "mcpServers": {
80
+ "workflow-orchestration": {
81
+ "command": "npx",
82
+ "args": [
83
+ "-y",
84
+ "@exaudeus/workrail"
85
+ ]
86
+ }
87
+ }
88
+ }
89
+ ```
90
+
91
+ #### Local development
92
+
93
+ ```json
94
+ {
95
+ "mcpServers": {
96
+ "workflow-orchestration": {
97
+ "command": "node",
98
+ "args": [
99
+ "/path/to/your/workflow-orchestration/dist/mcp-server.js"
100
+ ]
101
+ }
102
+ }
103
+ }
104
+ ```
105
+
106
+ ### Usage with VS Code
107
+
108
+ For manual installation, add this to your User Settings (JSON) or `.vscode/mcp.json`:
109
+
110
+ #### npx (once published)
111
+
112
+ ```json
113
+ {
114
+ "mcp": {
115
+ "servers": {
116
+ "workflow-orchestration": {
117
+ "command": "npx",
118
+ "args": [
119
+ "-y",
120
+ "@exaudeus/workrail"
121
+ ]
122
+ }
123
+ }
124
+ }
125
+ }
126
+ ```
127
+
128
+ #### Local development
129
+
130
+ ```json
131
+ {
132
+ "mcp": {
133
+ "servers": {
134
+ "workflow-orchestration": {
135
+ "command": "node",
136
+ "args": [
137
+ "/path/to/your/workflow-orchestration/dist/mcp-server.js"
138
+ ]
139
+ }
140
+ }
141
+ }
142
+ }
143
+ ```
144
+
145
+ ---
146
+
147
+ ## 🗂️ Project Structure (post-refactor)
148
+
149
+ ```
150
+ workflow-orchestration/
151
+ ├─ src/
152
+ │ ├─ domain/ # Pure entities & errors (no dependencies)
153
+ │ ├─ application/ # Use-cases, services, ValidationEngine (depends on domain)
154
+ │ ├─ infrastructure/
155
+ │ │ ├─ rpc/ # JSON-RPC server adapter
156
+ │ │ └─ storage/ # File, in-memory, caching, schema-validating adapters
157
+ │ ├─ mcp-server.ts # MCP server implementation (main entry point)
158
+ │ ├─ cli.ts # CLI utility for workflow validation
159
+ │ ├─ container.ts # DI registrations
160
+ │ └─ index.ts # Library entrypoint (exports container)
161
+ ├─ tests/ # Jest test suites (unit & integration)
162
+ └─ docs/ # Guides, reference, advanced topics
163
+ ```
164
+
165
+ ### Layered flow
166
+ ```
167
+ Client (AI Agent)
168
+ ▼ MCP Protocol (stdin/stdout)
169
+ MCP Server ── mcp-server.ts (MCP SDK adapter)
170
+ ▼ calls
171
+ Application ── use-cases (pure biz logic)
172
+ ▼ operates on
173
+ Domain ── entities & value objects
174
+ ```
175
+
176
+ ---
177
+
178
+ ## 🛠️ Environment Variables
179
+
180
+ | Env Var | Default | Description |
181
+ |---------|---------|-------------|
182
+ | `WORKFLOW_DIR` | `spec/examples` | Path where workflow JSON files are loaded (file storage) |
183
+ | `CACHE_TTL` | `300000` | Cache TTL in ms for `CachingWorkflowStorage` |
184
+ | `PORT` | _n/a_ | Not used (stdin/stdout transport) |
185
+
186
+ Change them before starting the server, e.g. `export WORKFLOW_DIR=/opt/workflows`.
187
+
188
+ ---
189
+
190
+ ## 🧪 Running Tests
191
+
192
+ ```bash
193
+ npm test
194
+ ```
195
+ Current status: 81 tests passing, 7 failing (performance optimizations in progress), 88 total tests.
196
+
197
+ ---
198
+
199
+ ## 📚 Documentation Status
200
+
201
+ | Component | Status | Updated |
202
+ |-----------|--------|---------|
203
+ | Root README | ✅ Complete | 2024-07-10 |
204
+ | Implementation guides | 🔄 In Progress | 2024-07-10 |
205
+ | Migration guide 1.2 | 🔄 In Progress | 2024-07-10 |
206
+ | Code snippet refresh | 🔄 In Progress | 2024-07-10 |
207
+
208
+ ---
209
+
210
+ ## 🤝 Contributing
211
+
212
+ 1. **Fork & PR** – small, focused pull requests please.
213
+ 2. **Follow the Architecture** – domain logic must remain framework-free; side effects live in infrastructure.
214
+ 3. **Add Tests** – no code is accepted without unit tests.
215
+ 4. **Run `npm run lint:fix`** before pushing.
216
+
217
+ See `docs/advanced/contributing.md` for full details.
218
+
219
+ ---
220
+
221
+ ## 📄 License
222
+
223
+ MIT – see [LICENSE](LICENSE).
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Lightweight mediator that maps JSON-RPC method names to handler functions.
3
+ * It delegates parameter validation to an injected validator and remains
4
+ * agnostic of transport concerns.
5
+ */
6
+ export type MethodHandler = (params: any) => Promise<any> | any;
7
+ export interface MethodValidator {
8
+ validate(method: string, params: any): void;
9
+ }
10
+ export declare class ApplicationMediator {
11
+ private readonly handlers;
12
+ private readonly validateFn;
13
+ constructor(validator: MethodValidator);
14
+ register(method: string, handler: MethodHandler): void;
15
+ /** Execute a method after validation. */
16
+ execute(method: string, params: any): Promise<any>;
17
+ private responseValidate?;
18
+ setResponseValidator(fn: (method: string, result: any) => void): void;
19
+ }
20
+ import { WorkflowService } from './services/workflow-service';
21
+ export declare const METHOD_NAMES: {
22
+ readonly WORKFLOW_LIST: "workflow_list";
23
+ readonly WORKFLOW_GET: "workflow_get";
24
+ readonly WORKFLOW_NEXT: "workflow_next";
25
+ readonly WORKFLOW_VALIDATE: "workflow_validate";
26
+ readonly INITIALIZE: "initialize";
27
+ readonly TOOLS_LIST: "tools/list";
28
+ readonly SHUTDOWN: "shutdown";
29
+ };
30
+ export type MethodName = typeof METHOD_NAMES[keyof typeof METHOD_NAMES];
31
+ export declare function buildWorkflowApplication(workflowService: WorkflowService, validator?: MethodValidator): ApplicationMediator;
32
+ //# sourceMappingURL=app.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../src/application/app.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;AAEhE,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,IAAI,CAAC;CAC7C;AAED,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAoC;IAC7D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAwC;gBAEvD,SAAS,EAAE,eAAe;IAItC,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,IAAI;IAOtD,yCAAyC;IACnC,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IAexD,OAAO,CAAC,gBAAgB,CAAC,CAAwC;IAEjE,oBAAoB,CAAC,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,IAAI,GAAG,IAAI;CAGtE;AAMD,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAQ9D,eAAO,MAAM,YAAY;;;;;;;;CAQf,CAAC;AAEX,MAAM,MAAM,UAAU,GAAG,OAAO,YAAY,CAAC,MAAM,OAAO,YAAY,CAAC,CAAC;AAExE,wBAAgB,wBAAwB,CACtC,eAAe,EAAE,eAAe,EAChC,SAAS,GAAE,eAAkC,GAC5C,mBAAmB,CAmErB"}
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.METHOD_NAMES = exports.ApplicationMediator = void 0;
37
+ exports.buildWorkflowApplication = buildWorkflowApplication;
38
+ const error_handler_1 = require("../core/error-handler");
39
+ const mcp_types_1 = require("../types/mcp-types");
40
+ class ApplicationMediator {
41
+ handlers = new Map();
42
+ validateFn;
43
+ constructor(validator) {
44
+ this.validateFn = validator.validate.bind(validator);
45
+ }
46
+ register(method, handler) {
47
+ if (this.handlers.has(method)) {
48
+ throw new Error(`Method already registered: ${method}`);
49
+ }
50
+ this.handlers.set(method, handler);
51
+ }
52
+ /** Execute a method after validation. */
53
+ async execute(method, params) {
54
+ const handler = this.handlers.get(method);
55
+ if (!handler) {
56
+ throw new error_handler_1.MCPError(mcp_types_1.MCPErrorCodes.METHOD_NOT_FOUND, 'Method not found', { method });
57
+ }
58
+ // Perform validation once
59
+ this.validateFn(method, params);
60
+ const result = await handler(params);
61
+ // Validate output if a response validator is registered
62
+ if (this.responseValidate) {
63
+ this.responseValidate(method, result);
64
+ }
65
+ return result;
66
+ }
67
+ // Optional response validator injection
68
+ responseValidate;
69
+ setResponseValidator(fn) {
70
+ this.responseValidate = fn;
71
+ }
72
+ }
73
+ exports.ApplicationMediator = ApplicationMediator;
74
+ const request_validator_1 = require("../validation/request-validator");
75
+ const response_validator_1 = require("../validation/response-validator");
76
+ const list_workflows_1 = require("./use-cases/list-workflows");
77
+ const get_workflow_1 = require("./use-cases/get-workflow");
78
+ const get_next_step_1 = require("./use-cases/get-next-step");
79
+ const validate_step_output_1 = require("./use-cases/validate-step-output");
80
+ exports.METHOD_NAMES = {
81
+ WORKFLOW_LIST: 'workflow_list',
82
+ WORKFLOW_GET: 'workflow_get',
83
+ WORKFLOW_NEXT: 'workflow_next',
84
+ WORKFLOW_VALIDATE: 'workflow_validate',
85
+ INITIALIZE: 'initialize',
86
+ TOOLS_LIST: 'tools/list',
87
+ SHUTDOWN: 'shutdown'
88
+ };
89
+ function buildWorkflowApplication(workflowService, validator = request_validator_1.requestValidator) {
90
+ const app = new ApplicationMediator(validator);
91
+ // Attach response validator
92
+ app.setResponseValidator((method, result) => response_validator_1.responseValidator.validate(method, result));
93
+ // ------------------------------------------------------------------------
94
+ // Create use-case instances with injected dependencies
95
+ // ------------------------------------------------------------------------
96
+ const listWorkflowsUseCase = (0, list_workflows_1.createListWorkflows)(workflowService);
97
+ const getWorkflowUseCase = (0, get_workflow_1.createGetWorkflow)(workflowService);
98
+ const getNextStepUseCase = (0, get_next_step_1.createGetNextStep)(workflowService);
99
+ const validateStepOutputUseCase = (0, validate_step_output_1.createValidateStepOutput)(workflowService);
100
+ // ------------------------------------------------------------------------
101
+ // Workflow tool methods
102
+ // ------------------------------------------------------------------------
103
+ app.register(exports.METHOD_NAMES.WORKFLOW_LIST, async (_params) => {
104
+ const workflows = await listWorkflowsUseCase();
105
+ return { workflows };
106
+ });
107
+ app.register(exports.METHOD_NAMES.WORKFLOW_GET, async (params) => {
108
+ return getWorkflowUseCase(params.id);
109
+ });
110
+ app.register(exports.METHOD_NAMES.WORKFLOW_NEXT, async (params) => {
111
+ return getNextStepUseCase(params.workflowId, params.completedSteps || [], params.context);
112
+ });
113
+ app.register(exports.METHOD_NAMES.WORKFLOW_VALIDATE, async (params) => {
114
+ return validateStepOutputUseCase(params.workflowId, params.stepId, params.output);
115
+ });
116
+ // ------------------------------------------------------------------------
117
+ // System/handshake methods – dynamic imports to avoid circular deps
118
+ // ------------------------------------------------------------------------
119
+ app.register(exports.METHOD_NAMES.INITIALIZE, async (params) => {
120
+ const { initializeHandler } = await Promise.resolve().then(() => __importStar(require('../tools/mcp_initialize')));
121
+ return (await initializeHandler({ id: 0, params, method: 'initialize', jsonrpc: '2.0' })).result;
122
+ });
123
+ app.register(exports.METHOD_NAMES.TOOLS_LIST, async (params) => {
124
+ const { toolsListHandler } = await Promise.resolve().then(() => __importStar(require('../tools/mcp_tools_list')));
125
+ return (await toolsListHandler({ id: 0, params, method: 'tools/list', jsonrpc: '2.0' })).result;
126
+ });
127
+ app.register(exports.METHOD_NAMES.SHUTDOWN, async (params) => {
128
+ const { shutdownHandler } = await Promise.resolve().then(() => __importStar(require('../tools/mcp_shutdown')));
129
+ return (await shutdownHandler({ id: 0, params, method: 'shutdown', jsonrpc: '2.0' })).result;
130
+ });
131
+ return app;
132
+ }
133
+ //# sourceMappingURL=app.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/application/app.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4EA,4DAsEC;AAlJD,yDAAiD;AACjD,kDAAmD;AAanD,MAAa,mBAAmB;IACb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AAC,QAAQ,EAAE,KAAK,EAAE,MAAW,EAAE,EAAE;QACxD,MAAM,EAAE,eAAe,EAAE,GAAG,wDAAa,uBAAuB,GAAC,CAAC;QAClE,OAAO,CACL,MAAM,eAAe,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,EAAS,CAAC,CACpF,CAAC,MAAM,CAAC;IACX,CAAC,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,102 @@
1
+ import { Condition, ConditionContext } from '../../utils/condition-evaluator';
2
+ export interface ValidationRule {
3
+ type: 'contains' | 'regex' | 'length' | 'schema';
4
+ message: string;
5
+ value?: string;
6
+ pattern?: string;
7
+ flags?: string;
8
+ min?: number;
9
+ max?: number;
10
+ schema?: Record<string, any>;
11
+ condition?: Condition;
12
+ }
13
+ export interface ValidationComposition {
14
+ and?: ValidationCriteria[];
15
+ or?: ValidationCriteria[];
16
+ not?: ValidationCriteria;
17
+ }
18
+ export type ValidationCriteria = ValidationRule | ValidationComposition;
19
+ export interface ValidationResult {
20
+ valid: boolean;
21
+ issues: string[];
22
+ suggestions: string[];
23
+ }
24
+ /**
25
+ * ValidationEngine handles step output validation with support for
26
+ * multiple validation rule types. This engine is responsible for
27
+ * evaluating validation criteria against step outputs.
28
+ */
29
+ export declare class ValidationEngine {
30
+ private ajv;
31
+ private schemaCache;
32
+ constructor();
33
+ /**
34
+ * Compiles a JSON schema with caching for performance.
35
+ *
36
+ * @param schema - The JSON schema to compile
37
+ * @returns Compiled schema validator function
38
+ */
39
+ private compileSchema;
40
+ /**
41
+ * Evaluates validation criteria (either array or composition format).
42
+ *
43
+ * @param output - The step output to validate
44
+ * @param criteria - Validation criteria to evaluate
45
+ * @param context - Execution context for conditional validation
46
+ * @returns ValidationResult with validation status and issues
47
+ */
48
+ private evaluateCriteria;
49
+ /**
50
+ * Evaluates an array of validation rules (legacy format).
51
+ *
52
+ * @param output - The step output to validate
53
+ * @param rules - Array of validation rules to apply
54
+ * @param context - Execution context for conditional validation
55
+ * @returns ValidationResult with validation status and issues
56
+ */
57
+ private evaluateRuleArray;
58
+ /**
59
+ * Evaluates a validation composition with logical operators.
60
+ *
61
+ * @param output - The step output to validate
62
+ * @param composition - The validation composition to evaluate
63
+ * @param context - Execution context for conditional validation
64
+ * @returns Boolean indicating if the composition is valid
65
+ */
66
+ private evaluateComposition;
67
+ /**
68
+ * Evaluates a single validation criteria (rule or composition).
69
+ *
70
+ * @param output - The step output to validate
71
+ * @param criteria - Single validation criteria to evaluate
72
+ * @param context - Execution context for conditional validation
73
+ * @returns Boolean indicating if the criteria is valid
74
+ */
75
+ private evaluateSingleCriteria;
76
+ /**
77
+ * Type guard to check if criteria is a ValidationRule.
78
+ */
79
+ private isValidationRule;
80
+ /**
81
+ * Type guard to check if criteria is a ValidationComposition.
82
+ */
83
+ private isValidationComposition;
84
+ /**
85
+ * Validates a step output against validation criteria.
86
+ *
87
+ * @param output - The step output to validate
88
+ * @param criteria - Array of validation rules or composition object to apply
89
+ * @param context - Optional context for context-aware validation
90
+ * @returns ValidationResult with validation status and any issues
91
+ */
92
+ validate(output: string, criteria: ValidationRule[] | ValidationComposition, context?: ConditionContext): Promise<ValidationResult>;
93
+ /**
94
+ * Evaluates a single validation rule against the output.
95
+ *
96
+ * @param output - The step output to validate
97
+ * @param rule - The validation rule to apply
98
+ * @param issues - Array to collect validation issues
99
+ */
100
+ private evaluateRule;
101
+ }
102
+ //# sourceMappingURL=validation-engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation-engine.d.ts","sourceRoot":"","sources":["../../../src/application/services/validation-engine.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,SAAS,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAGjG,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,UAAU,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC;IACjD,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