@ema.co/mcp-toolkit 2026.1.27 → 2026.1.28-2
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.
Potentially problematic release.
This version of @ema.co/mcp-toolkit might be problematic. Click here for more details.
- package/dist/mcp/handlers/data/index.js +3 -0
- package/dist/mcp/handlers/persona/create.js +16 -0
- package/dist/mcp/handlers/persona/list.js +9 -4
- package/dist/mcp/handlers/persona/update.js +24 -2
- package/dist/mcp/handlers/workflow/deploy.js +20 -2
- package/dist/mcp/handlers/workflow/generate.js +39 -2
- package/dist/mcp/handlers/workflow/index.js +8 -3
- package/dist/mcp/handlers/workflow/modify.js +34 -7
- package/dist/mcp/handlers/workflow/validate.js +85 -0
- package/dist/mcp/handlers/workflow/validation.js +160 -0
- package/dist/mcp/resources.js +286 -4
- package/dist/mcp/server.js +16 -3
- package/dist/mcp/tools.js +32 -11
- package/dist/sdk/client.js +36 -9
- package/dist/sdk/ema-client.js +32 -4
- package/dist/sdk/index.js +3 -1
- package/dist/sdk/knowledge.js +5 -5
- package/dist/sdk/structural-rules.js +498 -0
- package/dist/sdk/workflow-generator.js +2 -1
- package/dist/sdk/workflow-intent.js +28 -96
- package/dist/sdk/workflow-path-enumerator.js +278 -0
- package/dist/sdk/workflow-static-validator.js +291 -0
- package/dist/sdk/workflow-validation-types.js +7 -0
- package/docs/README.md +14 -0
- package/docs/go-validator-analysis.md +323 -0
- package/docs/rule-format-specification.md +346 -0
- package/docs/validation-contract.md +397 -0
- package/docs/validation-error-format.md +326 -0
- package/package.json +1 -1
- package/dist/mcp/workflow-operations.js +0 -100
- package/dist/sdk/workflow-fixer.js +0 -48
- package/docs/dashboard-operations.md +0 -281
- package/docs/ema-user-guide.md +0 -1201
- package/docs/email-patterns.md +0 -120
- package/docs/mcp-tools-guide.md +0 -575
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
# Rule Format Specification for LLM Consumption
|
|
2
|
+
|
|
3
|
+
**Date**: 2026-01-27
|
|
4
|
+
**Purpose**: Define structured rule format for MCP resources and LLM prompts
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Design Principles
|
|
9
|
+
|
|
10
|
+
1. **LLM-Friendly**: Easy for LLM to parse and understand
|
|
11
|
+
2. **Structured**: Both JSON (programmatic) and Markdown (human-readable)
|
|
12
|
+
3. **Complete**: Includes logic, rules, examples, remediation
|
|
13
|
+
4. **Referenceable**: Each rule has unique ID
|
|
14
|
+
5. **Actionable**: Rules guide workflow generation, not just validation
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Rule Structure
|
|
19
|
+
|
|
20
|
+
### JSON Format (Programmatic)
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
export interface ValidationRule {
|
|
24
|
+
// Identification
|
|
25
|
+
id: string; // Unique rule ID: "required_output_all_paths"
|
|
26
|
+
name: string; // Human-readable name: "Required Output on All Paths"
|
|
27
|
+
version: string; // Rule version: "1.0.0"
|
|
28
|
+
|
|
29
|
+
// Logic (Algorithmic)
|
|
30
|
+
logic: {
|
|
31
|
+
algorithm: string; // Algorithm description
|
|
32
|
+
steps: string[]; // Step-by-step algorithm
|
|
33
|
+
complexity: "O(P*A)" | ...; // Time complexity
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// Rules (Constraints)
|
|
37
|
+
rules: {
|
|
38
|
+
constraint: string; // Human-readable constraint
|
|
39
|
+
severity: "critical" | "warning" | "info";
|
|
40
|
+
applies_to: string[]; // What it applies to: ["named_results", "paths"]
|
|
41
|
+
}[];
|
|
42
|
+
|
|
43
|
+
// Examples
|
|
44
|
+
examples: {
|
|
45
|
+
bad: {
|
|
46
|
+
description: string;
|
|
47
|
+
workflow_snippet: string; // JSON snippet
|
|
48
|
+
why_bad: string;
|
|
49
|
+
};
|
|
50
|
+
good: {
|
|
51
|
+
description: string;
|
|
52
|
+
workflow_snippet: string; // JSON snippet
|
|
53
|
+
why_good: string;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// Remediation
|
|
58
|
+
remediation: {
|
|
59
|
+
steps: string[]; // How to fix
|
|
60
|
+
common_fixes: string[]; // Common solutions
|
|
61
|
+
prevention: string; // How to avoid in generation
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// Metadata
|
|
65
|
+
source: "go_validator" | "mcp_extension";
|
|
66
|
+
error_type?: string; // Go error type if from Go validator
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Markdown Format (LLM-Friendly)
|
|
71
|
+
|
|
72
|
+
```markdown
|
|
73
|
+
## Rule: Required Output on All Paths
|
|
74
|
+
|
|
75
|
+
**Rule ID**: `required_output_all_paths`
|
|
76
|
+
**Severity**: Critical
|
|
77
|
+
**Applies To**: Named results, execution paths
|
|
78
|
+
|
|
79
|
+
### Logic
|
|
80
|
+
|
|
81
|
+
**Algorithm**: Enumerate all execution paths. For each path, check if all named results are produced.
|
|
82
|
+
|
|
83
|
+
**Steps**:
|
|
84
|
+
1. Enumerate all paths from trigger to completion
|
|
85
|
+
2. For each path, collect all outputs produced
|
|
86
|
+
3. For each named result, check if it's in path outputs
|
|
87
|
+
4. If missing on any path → error
|
|
88
|
+
|
|
89
|
+
**Complexity**: O(P * R) where P = paths, R = named results
|
|
90
|
+
|
|
91
|
+
### Rules
|
|
92
|
+
|
|
93
|
+
**Constraint**: Every execution path must produce all named results.
|
|
94
|
+
|
|
95
|
+
**Why**: Named results are contract guarantees. If a path doesn't produce a required output, the contract is violated.
|
|
96
|
+
|
|
97
|
+
### Examples
|
|
98
|
+
|
|
99
|
+
**Bad Pattern**:
|
|
100
|
+
```json
|
|
101
|
+
{
|
|
102
|
+
"path": ["trigger", "categorizer", "billing_branch", "search"],
|
|
103
|
+
"named_result": "response_with_sources",
|
|
104
|
+
"produces": [] // Missing response
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**Why Bad**: Path ends without producing required output.
|
|
109
|
+
|
|
110
|
+
**Good Pattern**:
|
|
111
|
+
```json
|
|
112
|
+
{
|
|
113
|
+
"path": ["trigger", "categorizer", "billing_branch", "search", "respond_with_sources"],
|
|
114
|
+
"named_result": "response_with_sources",
|
|
115
|
+
"produces": ["response_with_sources"] // ✅ Produced
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**Why Good**: All paths produce required output.
|
|
120
|
+
|
|
121
|
+
### Remediation
|
|
122
|
+
|
|
123
|
+
**How to Fix**:
|
|
124
|
+
1. Identify the path missing the output
|
|
125
|
+
2. Add a node that produces the required output
|
|
126
|
+
3. Connect the node's output to WORKFLOW_OUTPUT
|
|
127
|
+
|
|
128
|
+
**Common Fixes**:
|
|
129
|
+
- Add `respond_with_sources` node after search
|
|
130
|
+
- Add `call_llm` node for text generation
|
|
131
|
+
- Add `fixed_response` for static responses
|
|
132
|
+
|
|
133
|
+
**Prevention** (During Generation):
|
|
134
|
+
- Always ensure every categorizer branch has a response node
|
|
135
|
+
- Check that all paths end with nodes connected to WORKFLOW_OUTPUT
|
|
136
|
+
- Verify resultMappings include all required outputs
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## Rule Collection Format
|
|
142
|
+
|
|
143
|
+
### MCP Resource Format
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
// ema://validation/rules
|
|
147
|
+
|
|
148
|
+
export interface ValidationRulesResource {
|
|
149
|
+
version: string;
|
|
150
|
+
rules: ValidationRule[];
|
|
151
|
+
summary: {
|
|
152
|
+
total_rules: number;
|
|
153
|
+
critical_rules: number;
|
|
154
|
+
warning_rules: number;
|
|
155
|
+
info_rules: number;
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### LLM Prompt Format
|
|
161
|
+
|
|
162
|
+
```markdown
|
|
163
|
+
# Workflow Validation Rules
|
|
164
|
+
|
|
165
|
+
Before generating or modifying workflows, ensure these rules are followed:
|
|
166
|
+
|
|
167
|
+
## Critical Rules (Must Never Violate)
|
|
168
|
+
|
|
169
|
+
### 1. Required Output on All Paths
|
|
170
|
+
**Rule**: Every execution path must produce all named results.
|
|
171
|
+
|
|
172
|
+
**Algorithm**:
|
|
173
|
+
1. Enumerate all paths from trigger
|
|
174
|
+
2. Check each path produces all named results
|
|
175
|
+
3. Report error if any path missing any result
|
|
176
|
+
|
|
177
|
+
**Example Bad**: Path ends without response node
|
|
178
|
+
**Example Good**: All paths end with response → WORKFLOW_OUTPUT
|
|
179
|
+
|
|
180
|
+
**Prevention**: Always add response nodes to every categorizer branch.
|
|
181
|
+
|
|
182
|
+
[... more rules ...]
|
|
183
|
+
|
|
184
|
+
## Self-Check Checklist
|
|
185
|
+
|
|
186
|
+
After generating a workflow, verify:
|
|
187
|
+
- [ ] All paths produce all named results
|
|
188
|
+
- [ ] No multiple writers on same path
|
|
189
|
+
- [ ] Every path has response or abstain
|
|
190
|
+
- [ ] Category hierarchy is valid
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
## Rule Deconstruction
|
|
196
|
+
|
|
197
|
+
### For LLM Consumption
|
|
198
|
+
|
|
199
|
+
Rules are deconstructed into:
|
|
200
|
+
|
|
201
|
+
1. **Logic** (Algorithmic):
|
|
202
|
+
- How to detect the violation
|
|
203
|
+
- Step-by-step algorithm
|
|
204
|
+
- Complexity analysis
|
|
205
|
+
|
|
206
|
+
2. **Rules** (Constraints):
|
|
207
|
+
- What must be true
|
|
208
|
+
- Why it matters
|
|
209
|
+
- When it applies
|
|
210
|
+
|
|
211
|
+
3. **Examples** (Patterns):
|
|
212
|
+
- Bad patterns to avoid
|
|
213
|
+
- Good patterns to follow
|
|
214
|
+
- Why each is bad/good
|
|
215
|
+
|
|
216
|
+
4. **Remediation** (Fixes):
|
|
217
|
+
- How to fix violations
|
|
218
|
+
- Common solutions
|
|
219
|
+
- Prevention during generation
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## Rule IDs
|
|
224
|
+
|
|
225
|
+
### Naming Convention
|
|
226
|
+
|
|
227
|
+
```
|
|
228
|
+
{error_type}_{scope}_{constraint}
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
**Examples**:
|
|
232
|
+
- `required_output_all_paths`
|
|
233
|
+
- `single_writer_per_output`
|
|
234
|
+
- `response_or_abstain_required`
|
|
235
|
+
- `category_hierarchy_valid`
|
|
236
|
+
|
|
237
|
+
### Rule Reference Format
|
|
238
|
+
|
|
239
|
+
```
|
|
240
|
+
ema://validation/rules#{rule_id}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
## Integration Points
|
|
246
|
+
|
|
247
|
+
### 1. MCP Resource
|
|
248
|
+
|
|
249
|
+
**URI**: `ema://validation/rules`
|
|
250
|
+
|
|
251
|
+
**Format**: Markdown (LLM-friendly) with JSON metadata
|
|
252
|
+
|
|
253
|
+
**Access**: Via `resources.ts` handler
|
|
254
|
+
|
|
255
|
+
### 2. Generation Prompts
|
|
256
|
+
|
|
257
|
+
**Location**: `workflow_generate` prompt, `workflow_intent.ts` system prompt
|
|
258
|
+
|
|
259
|
+
**Format**: Markdown rules section
|
|
260
|
+
|
|
261
|
+
**Purpose**: LLM self-validates during generation
|
|
262
|
+
|
|
263
|
+
### 3. Validation Tool
|
|
264
|
+
|
|
265
|
+
**Location**: `workflow(mode="validate")` tool
|
|
266
|
+
|
|
267
|
+
**Format**: Returns errors with rule references
|
|
268
|
+
|
|
269
|
+
**Purpose**: Post-generation validation
|
|
270
|
+
|
|
271
|
+
---
|
|
272
|
+
|
|
273
|
+
## Example: Complete Rule
|
|
274
|
+
|
|
275
|
+
### JSON Format
|
|
276
|
+
|
|
277
|
+
```json
|
|
278
|
+
{
|
|
279
|
+
"id": "required_output_all_paths",
|
|
280
|
+
"name": "Required Output on All Paths",
|
|
281
|
+
"version": "1.0.0",
|
|
282
|
+
"logic": {
|
|
283
|
+
"algorithm": "Enumerate all execution paths. For each path, check if all named results are produced.",
|
|
284
|
+
"steps": [
|
|
285
|
+
"1. Enumerate all paths from trigger to completion",
|
|
286
|
+
"2. For each path, collect all outputs produced",
|
|
287
|
+
"3. For each named result, check if it's in path outputs",
|
|
288
|
+
"4. If missing on any path → error"
|
|
289
|
+
],
|
|
290
|
+
"complexity": "O(P * R)"
|
|
291
|
+
},
|
|
292
|
+
"rules": [{
|
|
293
|
+
"constraint": "Every execution path must produce all named results",
|
|
294
|
+
"severity": "critical",
|
|
295
|
+
"applies_to": ["named_results", "paths"]
|
|
296
|
+
}],
|
|
297
|
+
"examples": {
|
|
298
|
+
"bad": {
|
|
299
|
+
"description": "Path ends without response",
|
|
300
|
+
"workflow_snippet": "{\"path\": [\"trigger\", \"categorizer\", \"billing\"], \"produces\": []}",
|
|
301
|
+
"why_bad": "Path ends without producing required output"
|
|
302
|
+
},
|
|
303
|
+
"good": {
|
|
304
|
+
"description": "All paths produce response",
|
|
305
|
+
"workflow_snippet": "{\"path\": [\"trigger\", \"categorizer\", \"billing\", \"respond\"], \"produces\": [\"response_with_sources\"]}",
|
|
306
|
+
"why_good": "All paths produce required output"
|
|
307
|
+
}
|
|
308
|
+
},
|
|
309
|
+
"remediation": {
|
|
310
|
+
"steps": [
|
|
311
|
+
"Identify the path missing the output",
|
|
312
|
+
"Add a node that produces the required output",
|
|
313
|
+
"Connect the node's output to WORKFLOW_OUTPUT"
|
|
314
|
+
],
|
|
315
|
+
"common_fixes": [
|
|
316
|
+
"Add respond_with_sources node after search",
|
|
317
|
+
"Add call_llm node for text generation",
|
|
318
|
+
"Add fixed_response for static responses"
|
|
319
|
+
],
|
|
320
|
+
"prevention": "Always ensure every categorizer branch has a response node"
|
|
321
|
+
},
|
|
322
|
+
"source": "go_validator",
|
|
323
|
+
"error_type": "RESULT_ERROR_TYPE_REQUIRED_OUTPUT_NOT_PRODUCED"
|
|
324
|
+
}
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### Markdown Format
|
|
328
|
+
|
|
329
|
+
See example in "Markdown Format (LLM-Friendly)" section above.
|
|
330
|
+
|
|
331
|
+
---
|
|
332
|
+
|
|
333
|
+
## Implementation Checklist
|
|
334
|
+
|
|
335
|
+
- [ ] Define TypeScript interfaces
|
|
336
|
+
- [ ] Create rule extraction from Go code
|
|
337
|
+
- [ ] Generate JSON format
|
|
338
|
+
- [ ] Generate Markdown format
|
|
339
|
+
- [ ] Create MCP resource handler
|
|
340
|
+
- [ ] Integrate into generation prompts
|
|
341
|
+
- [ ] Test rule consumption by LLM
|
|
342
|
+
|
|
343
|
+
---
|
|
344
|
+
|
|
345
|
+
**Status**: ✅ Format designed
|
|
346
|
+
**Next**: Implement rule extraction and generation
|