@exaudeus/workrail 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,714 @@
1
+ # MCP Tool API Specification v1.0
2
+
3
+ This document formally specifies the JSON-RPC 2.0 API for the Workflow Orchestration System's
4
+ `workflowlookup` MCP server. The system features an advanced **ValidationEngine** with three enhancement types: JSON Schema Validation, Context-Aware Validation, and Logical Composition for comprehensive step output quality assurance.
5
+
6
+ > **Note**: This document focuses on the workflow-specific tools. For complete MCP protocol compliance including server initialization, tool discovery, and handshake procedures, see [MCP Protocol Handshake Specification](mcp-protocol-handshake.md).
7
+
8
+ ## MCP Protocol Compliance
9
+
10
+ This server implements the full MCP (Model Context Protocol) specification:
11
+
12
+ - ✅ **Server Initialization**: Handles `initialize` requests with protocol version validation
13
+ - ✅ **Tool Discovery**: Implements `tools/list` with complete input/output schemas
14
+ - ✅ **Error Handling**: Uses MCP standard error codes (-32000 to -32099 range)
15
+ - ✅ **Communication**: Stdio transport with newline-delimited JSON-RPC messages
16
+ - ✅ **Server Lifecycle**: Proper startup, shutdown, and error recovery
17
+
18
+ For complete protocol details, see [MCP Protocol Handshake Specification](mcp-protocol-handshake.md).
19
+
20
+ ## JSON-RPC 2.0 Base Protocol
21
+
22
+ All communication follows the [JSON-RPC 2.0 Specification](https://www.jsonrpc.org/specification).
23
+
24
+ ### Request Structure
25
+
26
+ Every request to the MCP server must conform to this structure:
27
+
28
+ ```json
29
+ {
30
+ "jsonrpc": "2.0",
31
+ "id": number | string,
32
+ "method": string,
33
+ "params": object | array | null
34
+ }
35
+ ```
36
+
37
+ - `jsonrpc`: Must always be `"2.0"`
38
+ - `id`: Unique identifier for the request (number or string)
39
+ - `method`: The name of the tool being invoked
40
+ - `params`: Parameters specific to the tool (can be object, array, or null)
41
+
42
+ ### Response Structure
43
+
44
+ #### Success Response
45
+
46
+ ```json
47
+ {
48
+ "jsonrpc": "2.0",
49
+ "id": number | string,
50
+ "result": any
51
+ }
52
+ ```
53
+
54
+ - `jsonrpc`: Always `"2.0"`
55
+ - `id`: Must match the request ID
56
+ - `result`: The tool's return value (structure depends on the tool)
57
+
58
+ #### Error Response
59
+
60
+ ```json
61
+ {
62
+ "jsonrpc": "2.0",
63
+ "id": number | string | null,
64
+ "error": {
65
+ "code": number,
66
+ "message": string,
67
+ "data": any
68
+ }
69
+ }
70
+ ```
71
+
72
+ - `jsonrpc`: Always `"2.0"`
73
+ - `id`: Matches request ID, or null if error occurred before ID could be determined
74
+ - `error`: Error object containing:
75
+ - `code`: Numeric error code
76
+ - `message`: Human-readable error message
77
+ - `data`: Optional additional error information
78
+
79
+ ### Standard Error Codes
80
+
81
+ | Code | Message | Description |
82
+ |------|---------|-------------|
83
+ | -32700 | Parse error | Invalid JSON was received |
84
+ | -32600 | Invalid Request | The JSON sent is not a valid Request object |
85
+ | -32601 | Method not found | The method does not exist |
86
+ | -32602 | Invalid params | Invalid method parameter(s) |
87
+ | -32603 | Internal error | Internal JSON-RPC error |
88
+ | -32000 | Server error | Server-specific error (MCP reserved) |
89
+ | -32001 | Workflow not found | The specified workflow ID does not exist |
90
+ | -32002 | Invalid workflow | The workflow file is malformed or invalid |
91
+ | -32003 | Step not found | The specified step ID does not exist in the workflow |
92
+ | -32004 | Validation error | ValidationEngine encountered invalid validation criteria |
93
+ | -32005 | State error | Invalid workflow execution state |
94
+ | -32006 | Storage error | Error accessing workflow storage |
95
+ | -32007 | Security error | Security validation failed |
96
+
97
+ ## Tool Specifications
98
+
99
+ The `workflowlookup` server exposes the following tools:
100
+
101
+ ### workflow_list
102
+
103
+ Lists all available workflows.
104
+
105
+ #### Request
106
+
107
+ ```json
108
+ {
109
+ "jsonrpc": "2.0",
110
+ "id": 1,
111
+ "method": "workflow_list",
112
+ "params": null
113
+ }
114
+ ```
115
+
116
+ #### Response
117
+
118
+ ```json
119
+ {
120
+ "jsonrpc": "2.0",
121
+ "id": 1,
122
+ "result": {
123
+ "workflows": [
124
+ {
125
+ "id": "string",
126
+ "name": "string",
127
+ "description": "string",
128
+ "category": "string",
129
+ "version": "string"
130
+ }
131
+ ]
132
+ }
133
+ }
134
+ ```
135
+
136
+ #### Field Descriptions
137
+
138
+ - `workflows`: Array of workflow summaries
139
+ - `id`: Unique workflow identifier (matches workflow schema pattern)
140
+ - `name`: Human-friendly workflow name
141
+ - `description`: Brief description of what the workflow accomplishes
142
+ - `category`: Workflow category (e.g., "development", "review", "documentation")
143
+ - `version`: Workflow version following semantic versioning
144
+
145
+ ### workflow_get
146
+
147
+ Retrieves a specific workflow by ID.
148
+
149
+ #### Request
150
+
151
+ ```json
152
+ {
153
+ "jsonrpc": "2.0",
154
+ "id": 2,
155
+ "method": "workflow_get",
156
+ "params": {
157
+ "id": "string"
158
+ }
159
+ }
160
+ ```
161
+
162
+ #### Parameters
163
+
164
+ - `id` (required): The workflow ID to retrieve
165
+
166
+ #### Response
167
+
168
+ ```json
169
+ {
170
+ "jsonrpc": "2.0",
171
+ "id": 2,
172
+ "result": {
173
+ "id": "string",
174
+ "name": "string",
175
+ "description": "string",
176
+ "preconditions": ["string"],
177
+ "clarificationPrompts": ["string"],
178
+ "steps": [
179
+ {
180
+ "id": "string",
181
+ "title": "string",
182
+ "prompt": "string",
183
+ "askForFiles": boolean,
184
+ "requireConfirmation": boolean,
185
+ "runCondition": object
186
+ }
187
+ ],
188
+ "metaGuidance": ["string"]
189
+ }
190
+ }
191
+ ```
192
+
193
+ The returned workflow object must validate against the `workflow.schema.json` specification.
194
+
195
+ #### Error Cases
196
+
197
+ - Returns error code `-32001` if workflow ID not found
198
+ - Returns error code `-32002` if workflow file is malformed
199
+
200
+ ### workflow_next
201
+
202
+ Gets the next step guidance based on workflow state.
203
+
204
+ #### Request
205
+
206
+ ```json
207
+ {
208
+ "jsonrpc": "2.0",
209
+ "id": 3,
210
+ "method": "workflow_next",
211
+ "params": {
212
+ "workflowId": "string",
213
+ "currentStep": "string",
214
+ "completedSteps": ["string"],
215
+ "context": {}
216
+ }
217
+ }
218
+ ```
219
+
220
+ #### Parameters
221
+
222
+ - `workflowId` (required): The workflow being executed
223
+ - `currentStep` (optional): The ID of the current step
224
+ - `completedSteps` (required): Array of step IDs that have been completed
225
+ - `context` (optional): Execution context object for evaluating step conditions. Can contain variables like `taskScope`, `userExpertise`, `complexity`, etc.
226
+
227
+ #### Response
228
+
229
+ ```json
230
+ {
231
+ "jsonrpc": "2.0",
232
+ "id": 3,
233
+ "result": {
234
+ "step": {
235
+ "id": "string",
236
+ "title": "string",
237
+ "prompt": "string",
238
+ "askForFiles": boolean,
239
+ "requireConfirmation": boolean,
240
+ "runCondition": object
241
+ },
242
+ "guidance": {
243
+ "prompt": "string",
244
+ "modelHint": "string",
245
+ "requiresConfirmation": boolean,
246
+ "validationCriteria": ["string"]
247
+ },
248
+ "isComplete": boolean
249
+ }
250
+ }
251
+ ```
252
+
253
+ #### Field Descriptions
254
+
255
+ - `step`: The next step to execute (null if workflow is complete)
256
+ - `runCondition`: Optional condition object that determines if this step should execute
257
+ - `guidance`: Additional orchestration guidance
258
+ - `prompt`: Enhanced prompt with context
259
+ - `modelHint`: Suggested model type (e.g., "model-with-strong-reasoning")
260
+ - `requiresConfirmation`: Whether user confirmation is needed
261
+ - `validationCriteria`: List of criteria to validate completion
262
+ - `isComplete`: True if all workflow steps are completed
263
+
264
+ #### Conditional Step Execution
265
+
266
+ Steps can include an optional `runCondition` property that determines whether the step should be executed based on the provided context. The condition uses a simple expression format:
267
+
268
+ ```json
269
+ {
270
+ "runCondition": {
271
+ "var": "taskScope",
272
+ "equals": "large"
273
+ }
274
+ }
275
+ ```
276
+
277
+ **Supported operators:**
278
+ - `equals`: Variable equals value
279
+ - `not_equals`: Variable does not equal value
280
+ - `gt`, `gte`, `lt`, `lte`: Numeric comparisons
281
+ - `and`: Logical AND of multiple conditions
282
+ - `or`: Logical OR of multiple conditions
283
+ - `not`: Logical NOT of a condition
284
+
285
+ **Example context:**
286
+ ```json
287
+ {
288
+ "context": {
289
+ "taskScope": "large",
290
+ "userExpertise": "expert",
291
+ "complexity": 0.8
292
+ }
293
+ }
294
+ ```
295
+
296
+ If a step's `runCondition` evaluates to false, the step is skipped and the next eligible step is returned.
297
+
298
+ #### Error Cases
299
+
300
+ - Returns error code `-32001` if workflow ID not found
301
+ - Returns error code `-32003` if current step ID not found in workflow
302
+
303
+ ### workflow_validate
304
+
305
+ Validates the output of a workflow step using the advanced ValidationEngine. The system supports three enhancement types: **JSON Schema Validation**, **Context-Aware Validation**, and **Logical Composition** for comprehensive output quality assurance.
306
+
307
+ #### Request
308
+
309
+ ```json
310
+ {
311
+ "jsonrpc": "2.0",
312
+ "id": 4,
313
+ "method": "workflow_validate",
314
+ "params": {
315
+ "workflowId": "string",
316
+ "stepId": "string",
317
+ "output": "string",
318
+ "context": {
319
+ "taskScope": "large",
320
+ "userExpertise": "expert",
321
+ "complexity": 0.8
322
+ }
323
+ }
324
+ }
325
+ ```
326
+
327
+ #### Parameters
328
+
329
+ - `workflowId` (required): The workflow being executed
330
+ - `stepId` (required): The step ID being validated
331
+ - `output` (required): The output to validate against the step's validation criteria
332
+ - `context` (optional): Execution context for context-aware validation rules
333
+
334
+ #### Response
335
+
336
+ ```json
337
+ {
338
+ "jsonrpc": "2.0",
339
+ "id": 4,
340
+ "result": {
341
+ "valid": boolean,
342
+ "issues": ["string"],
343
+ "suggestions": ["string"]
344
+ }
345
+ }
346
+ ```
347
+
348
+ #### Field Descriptions
349
+
350
+ - `valid`: Whether the output meets all applicable validation criteria
351
+ - `issues`: List of specific validation problems found (empty if valid)
352
+ - `suggestions`: List of actionable suggestions for improvement
353
+
354
+ #### ValidationEngine Enhancement Types
355
+
356
+ The ValidationEngine supports three types of validation enhancements:
357
+
358
+ ##### 1. JSON Schema Validation
359
+
360
+ Validates structured output against JSON Schema specifications:
361
+
362
+ ```json
363
+ {
364
+ "type": "schema",
365
+ "schema": {
366
+ "type": "object",
367
+ "properties": {
368
+ "endpoint": {"type": "string", "pattern": "^/api/"},
369
+ "method": {"type": "string", "enum": ["GET", "POST", "PUT", "DELETE"]},
370
+ "authentication": {"type": "boolean"}
371
+ },
372
+ "required": ["endpoint", "method"]
373
+ },
374
+ "message": "API endpoint must follow required structure"
375
+ }
376
+ ```
377
+
378
+ ##### 2. Context-Aware Validation
379
+
380
+ Applies validation rules conditionally based on execution context:
381
+
382
+ ```json
383
+ {
384
+ "type": "contains",
385
+ "value": "comprehensive tests",
386
+ "condition": {
387
+ "var": "taskScope",
388
+ "equals": "large"
389
+ },
390
+ "message": "Large tasks require comprehensive testing"
391
+ }
392
+ ```
393
+
394
+ **Supported Condition Operators:**
395
+ - `equals`: Variable equals specific value
396
+ - `not_equals`: Variable does not equal specific value
397
+ - `gt`, `gte`: Greater than, greater than or equal (numeric)
398
+ - `lt`, `lte`: Less than, less than or equal (numeric)
399
+ - `and`, `or`, `not`: Logical operators for complex conditions
400
+
401
+ ##### 3. Logical Composition
402
+
403
+ Combines multiple validation rules with boolean operators:
404
+
405
+ ```json
406
+ {
407
+ "and": [
408
+ {
409
+ "type": "contains",
410
+ "value": "authentication",
411
+ "message": "Must include authentication"
412
+ },
413
+ {
414
+ "or": [
415
+ {"type": "contains", "value": "jwt", "message": "Should use JWT"},
416
+ {"type": "contains", "value": "session", "message": "Should use sessions"}
417
+ ]
418
+ }
419
+ ]
420
+ }
421
+ ```
422
+
423
+ #### Validation Rule Types
424
+
425
+ | Type | Description | Required Fields | Optional Fields |
426
+ |------|-------------|----------------|-----------------|
427
+ | `contains` | Checks if output contains specific text | `type`, `value`, `message` | `condition` |
428
+ | `regex` | Validates against regular expression pattern | `type`, `pattern`, `message` | `flags`, `condition` |
429
+ | `length` | Validates output length constraints | `type`, `message` | `min`, `max`, `condition` |
430
+ | `schema` | Validates against JSON Schema | `type`, `schema`, `message` | `condition` |
431
+
432
+ #### Example Requests and Responses
433
+
434
+ ##### Basic Validation Request
435
+
436
+ ```json
437
+ {
438
+ "jsonrpc": "2.0",
439
+ "id": "validate-1",
440
+ "method": "workflow_validate",
441
+ "params": {
442
+ "workflowId": "auth-implementation",
443
+ "stepId": "create-middleware",
444
+ "output": "Created JWT authentication middleware that extracts tokens from Authorization header and returns 401 for invalid tokens."
445
+ }
446
+ }
447
+ ```
448
+
449
+ ##### Context-Aware Validation Request
450
+
451
+ ```json
452
+ {
453
+ "jsonrpc": "2.0",
454
+ "id": "validate-2",
455
+ "method": "workflow_validate",
456
+ "params": {
457
+ "workflowId": "adaptive-development",
458
+ "stepId": "implementation",
459
+ "output": "Implemented basic feature functionality with standard patterns.",
460
+ "context": {
461
+ "userExpertise": "expert",
462
+ "complexity": 0.9,
463
+ "taskScope": "large"
464
+ }
465
+ }
466
+ }
467
+ ```
468
+
469
+ ##### Successful Validation Response
470
+
471
+ ```json
472
+ {
473
+ "jsonrpc": "2.0",
474
+ "id": "validate-1",
475
+ "result": {
476
+ "valid": true,
477
+ "issues": [],
478
+ "suggestions": []
479
+ }
480
+ }
481
+ ```
482
+
483
+ ##### Failed Validation Response
484
+
485
+ ```json
486
+ {
487
+ "jsonrpc": "2.0",
488
+ "id": "validate-2",
489
+ "result": {
490
+ "valid": false,
491
+ "issues": [
492
+ "Expert implementation should use advanced patterns",
493
+ "Complex tasks require optimization considerations"
494
+ ],
495
+ "suggestions": [
496
+ "Review validation criteria and adjust output accordingly.",
497
+ "Consider adding architectural patterns for expert-level implementation."
498
+ ]
499
+ }
500
+ }
501
+ ```
502
+
503
+ #### Error Cases
504
+
505
+ - Returns error code `-32001` if workflow ID not found
506
+ - Returns error code `-32003` if step ID not found in workflow
507
+ - Returns error code `-32004` if validation criteria format is invalid
508
+ - Returns error code `-32002` if JSON Schema validation fails due to malformed schema
509
+
510
+ ## Example Session
511
+
512
+ Here's a complete example session showing tool usage:
513
+
514
+ ### 1. List Available Workflows
515
+
516
+ ```json
517
+ // Request
518
+ {
519
+ "jsonrpc": "2.0",
520
+ "id": "list-1",
521
+ "method": "workflow_list",
522
+ "params": null
523
+ }
524
+
525
+ // Response
526
+ {
527
+ "jsonrpc": "2.0",
528
+ "id": "list-1",
529
+ "result": {
530
+ "workflows": [
531
+ {
532
+ "id": "ai-task-implementation",
533
+ "name": "AI Task Prompt Workflow",
534
+ "description": "Guides through task understanding → planning → implementation → verification",
535
+ "category": "development",
536
+ "version": "1.0.0"
537
+ }
538
+ ]
539
+ }
540
+ }
541
+ ```
542
+
543
+ ### 2. Get Workflow Details
544
+
545
+ ```json
546
+ // Request
547
+ {
548
+ "jsonrpc": "2.0",
549
+ "id": "get-1",
550
+ "method": "workflow_get",
551
+ "params": {
552
+ "id": "ai-task-implementation"
553
+ }
554
+ }
555
+
556
+ // Response
557
+ {
558
+ "jsonrpc": "2.0",
559
+ "id": "get-1",
560
+ "result": {
561
+ "id": "ai-task-implementation",
562
+ "name": "AI Task Prompt Workflow",
563
+ "description": "Complete task implementation with verification",
564
+ "preconditions": [
565
+ "Task description is clear and complete"
566
+ ],
567
+ "steps": [
568
+ {
569
+ "id": "understand",
570
+ "title": "Deep understanding of task and codebase",
571
+ "prompt": "Analyze the task description...",
572
+ "requireConfirmation": true
573
+ }
574
+ ]
575
+ }
576
+ }
577
+ ```
578
+
579
+ ### 3. Get Next Step
580
+
581
+ ```json
582
+ // Request
583
+ {
584
+ "jsonrpc": "2.0",
585
+ "id": "next-1",
586
+ "method": "workflow_next",
587
+ "params": {
588
+ "workflowId": "ai-task-implementation",
589
+ "completedSteps": [],
590
+ "context": {"taskId": "TASK-123"}
591
+ }
592
+ }
593
+
594
+ // Response
595
+ {
596
+ "jsonrpc": "2.0",
597
+ "id": "next-1",
598
+ "result": {
599
+ "step": {
600
+ "id": "understand",
601
+ "title": "Deep understanding of task and codebase",
602
+ "prompt": "Analyze the task description...",
603
+ "requireConfirmation": true
604
+ },
605
+ "guidance": {
606
+ "prompt": "First, let's understand the task thoroughly. Analyze the task description...",
607
+ "modelHint": "model-with-strong-reasoning",
608
+ "requiresConfirmation": true,
609
+ "validationCriteria": [
610
+ "Clear understanding of requirements",
611
+ "Identified affected files",
612
+ "Documented assumptions"
613
+ ]
614
+ },
615
+ "isComplete": false
616
+ }
617
+ }
618
+ ```
619
+
620
+ ### 4. Validate Step Output
621
+
622
+ ```json
623
+ // Request - Advanced ValidationEngine with context-aware validation
624
+ {
625
+ "jsonrpc": "2.0",
626
+ "id": "validate-1",
627
+ "method": "workflow_validate",
628
+ "params": {
629
+ "workflowId": "auth-implementation",
630
+ "stepId": "implement-login",
631
+ "output": "Created POST /auth/login endpoint that accepts email and password, validates credentials against database using bcrypt, and returns JWT token with 24h expiration on success.",
632
+ "context": {
633
+ "security": "high",
634
+ "environment": "production"
635
+ }
636
+ }
637
+ }
638
+
639
+ // Response - Successful validation
640
+ {
641
+ "jsonrpc": "2.0",
642
+ "id": "validate-1",
643
+ "result": {
644
+ "valid": true,
645
+ "issues": [],
646
+ "suggestions": []
647
+ }
648
+ }
649
+ ```
650
+
651
+ ### 5. Context-Aware Validation Example
652
+
653
+ ```json
654
+ // Request - Expert-level task with high complexity
655
+ {
656
+ "jsonrpc": "2.0",
657
+ "id": "validate-2",
658
+ "method": "workflow_validate",
659
+ "params": {
660
+ "workflowId": "adaptive-development",
661
+ "stepId": "expert-implementation",
662
+ "output": "Implemented feature using basic CRUD operations with standard MVC pattern.",
663
+ "context": {
664
+ "userExpertise": "expert",
665
+ "complexity": 0.9,
666
+ "taskScope": "large"
667
+ }
668
+ }
669
+ }
670
+
671
+ // Response - Failed validation with context-aware feedback
672
+ {
673
+ "jsonrpc": "2.0",
674
+ "id": "validate-2",
675
+ "result": {
676
+ "valid": false,
677
+ "issues": [
678
+ "Expert implementation should use advanced patterns",
679
+ "Should include optimizations for complex features"
680
+ ],
681
+ "suggestions": [
682
+ "Review validation criteria and adjust output accordingly.",
683
+ "Consider adding architectural patterns like Repository, Strategy, or Observer for expert-level implementation."
684
+ ]
685
+ }
686
+ }
687
+ ```
688
+
689
+ ### 6. Error Example
690
+
691
+ ```json
692
+ // Request
693
+ {
694
+ "jsonrpc": "2.0",
695
+ "id": "error-1",
696
+ "method": "workflow_get",
697
+ "params": {
698
+ "id": "non-existent-workflow"
699
+ }
700
+ }
701
+
702
+ // Response
703
+ {
704
+ "jsonrpc": "2.0",
705
+ "id": "error-1",
706
+ "error": {
707
+ "code": -32001,
708
+ "message": "Workflow not found",
709
+ "data": {
710
+ "workflowId": "non-existent-workflow"
711
+ }
712
+ }
713
+ }
714
+ ```