@ema.co/mcp-toolkit 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +321 -0
  3. package/config.example.yaml +32 -0
  4. package/dist/cli/index.js +333 -0
  5. package/dist/config.js +136 -0
  6. package/dist/emaClient.js +398 -0
  7. package/dist/index.js +109 -0
  8. package/dist/mcp/handlers-consolidated.js +851 -0
  9. package/dist/mcp/index.js +15 -0
  10. package/dist/mcp/prompts.js +1753 -0
  11. package/dist/mcp/resources.js +624 -0
  12. package/dist/mcp/server.js +4723 -0
  13. package/dist/mcp/tools-consolidated.js +590 -0
  14. package/dist/mcp/tools-legacy.js +736 -0
  15. package/dist/models.js +8 -0
  16. package/dist/scheduler.js +21 -0
  17. package/dist/sdk/client.js +788 -0
  18. package/dist/sdk/config.js +136 -0
  19. package/dist/sdk/contracts.js +429 -0
  20. package/dist/sdk/generation-schema.js +189 -0
  21. package/dist/sdk/index.js +39 -0
  22. package/dist/sdk/knowledge.js +2780 -0
  23. package/dist/sdk/models.js +8 -0
  24. package/dist/sdk/state.js +88 -0
  25. package/dist/sdk/sync-options.js +216 -0
  26. package/dist/sdk/sync.js +220 -0
  27. package/dist/sdk/validation-rules.js +355 -0
  28. package/dist/sdk/workflow-generator.js +291 -0
  29. package/dist/sdk/workflow-intent.js +1585 -0
  30. package/dist/state.js +88 -0
  31. package/dist/sync.js +416 -0
  32. package/dist/syncOptions.js +216 -0
  33. package/dist/ui.js +334 -0
  34. package/docs/advisor-comms-assistant-fixes.md +175 -0
  35. package/docs/api-contracts.md +216 -0
  36. package/docs/auto-builder-analysis.md +271 -0
  37. package/docs/data-architecture.md +166 -0
  38. package/docs/ema-auto-builder-guide.html +394 -0
  39. package/docs/ema-user-guide.md +1121 -0
  40. package/docs/mcp-tools-guide.md +149 -0
  41. package/docs/naming-conventions.md +218 -0
  42. package/docs/tool-consolidation-proposal.md +427 -0
  43. package/package.json +98 -0
  44. package/resources/templates/chat-ai/README.md +119 -0
  45. package/resources/templates/chat-ai/persona-config.json +111 -0
  46. package/resources/templates/dashboard-ai/README.md +156 -0
  47. package/resources/templates/dashboard-ai/persona-config.json +180 -0
  48. package/resources/templates/voice-ai/README.md +123 -0
  49. package/resources/templates/voice-ai/persona-config.json +74 -0
  50. package/resources/templates/voice-ai/workflow-prompt.md +120 -0
@@ -0,0 +1,149 @@
1
+ # Ema MCP Tools Guide (Consolidated)
2
+
3
+ This MCP server is intentionally designed for **LLM + agent ergonomics**:
4
+
5
+ - **Few tools, consistent shapes**: a small set of noun-based tools with predictable `mode` / flag patterns
6
+ - **Resources-first**: use `ema://...` resources for reference data/templates, then tools for actions
7
+ - **Low ambiguity**: defaults are chosen to avoid “which of 5 similar tools?” confusion
8
+
9
+ ## Tool names in MCP clients
10
+
11
+ The server defines **base tool names** like `persona`, `workflow`, `template`.
12
+
13
+ Some clients show a **prefixed name** (for example Cursor: `mcp_ema_workflow`). Always call **the tool name your client displays**; the semantics are the same.
14
+
15
+ ## The tool set (9 tools)
16
+
17
+ | Tool | Purpose |
18
+ |------|---------|
19
+ | `env` | List available environments and which is default |
20
+ | `persona` | AI Employee management (get/list/create/update/compare/templates) |
21
+ | `workflow` | Generate/analyze/deploy/optimize/compare/compile workflows |
22
+ | `action` | Actions/agents lookup (API + embedded docs), plus recommendations |
23
+ | `template` | Workflow patterns, widget references, qualifying questions |
24
+ | `knowledge` | Data sources + embedding (upload/list/delete/status/toggle) |
25
+ | `reference` | Concepts + guidance + validation + common mistakes |
26
+ | `sync` | Sync across environments (run/status/config) |
27
+ | `demo` | Demo/RAG document utilities (template/consolidate/generate/validate) |
28
+
29
+ ## Start-here flows (LLM-friendly)
30
+
31
+ ### Create a new AI Employee (recommended sequence)
32
+
33
+ 1. **Requirements**: `template(questions=true)` (and `template(questions=true, category="Voice")` for voice)
34
+ 2. **Pick agents/pattern**: `action(suggest="<use case>")`
35
+ 3. **Get the pattern**: `template(pattern="<pattern>")`
36
+ 4. **Generate configs**:
37
+ - `workflow(input="<requirements>", type="chat|voice|dashboard")`
38
+ - If you want deterministic local generation: add `use_autobuilder=false`
39
+ 5. **Create persona** (if needed): `persona(mode="create", name="...", type="chat|voice|dashboard")`
40
+ 6. **Deploy**: `workflow(mode="deploy", persona_id="...", workflow_def=<...>, proto_config=<...>)`
41
+ 7. **Review**: `workflow(mode="analyze", persona_id="...")`
42
+
43
+ ### Review or debug an existing AI Employee
44
+
45
+ 1. Fetch full workflow: `persona(id="<id-or-exact-name>", include_workflow=true)`
46
+ 2. Analyze: `workflow(mode="analyze", persona_id="<persona_id>")`
47
+ 3. Preview fixes: `workflow(mode="optimize", persona_id="<persona_id>", preview=true)`
48
+ 4. Apply fixes: `workflow(mode="optimize", persona_id="<persona_id>")`
49
+
50
+ ### Upload / manage knowledge base documents
51
+
52
+ 1. Upload: `knowledge(persona_id="...", mode="upload", file="/path/to/file.pdf")`
53
+ 2. Enable embedding: `knowledge(persona_id="...", mode="toggle", enabled=true)`
54
+ 3. Verify: `knowledge(persona_id="...", mode="list")`
55
+
56
+ ### Sync between environments
57
+
58
+ - Run (single): `sync(id="My Bot", source="demo", target="dev", dry_run=true|false)`
59
+ - Run (all tagged): `sync(target="dev", scope="all", dry_run=true|false)`
60
+ - Status: `sync(mode="status", id="My Bot", env="dev")`
61
+ - List all synced in env: `sync(mode="status", list_synced=true, env="dev")`
62
+ - Config: `sync(mode="config")`
63
+
64
+ ### Demo data → RAG-ready Markdown → upload
65
+
66
+ 1. Get a template: `demo(mode="template", entity="customer")`
67
+ 2. Consolidate a dataset: `demo(mode="consolidate", source="./data", output="./kb", entity="customer", primary="customers.json", joins=[...])`
68
+ 3. Upload: `knowledge(persona_id="...", mode="upload", file="/full/path/to/kb/customer_*.md")`
69
+
70
+ ## Tool reference (high-signal)
71
+
72
+ ### `persona`
73
+
74
+ - **Get**: `persona(id="...", include_workflow=true)`
75
+ - **List/search**: `persona(all=true)` / `persona(query="support", status="active")`
76
+ - **Create**: `persona(mode="create", name="...", type="chat|voice|dashboard")`
77
+ - **Update**: `persona(id="<id>", mode="update", name="...", description="...", enabled=true|false)`
78
+ - **Compare**: `persona(id="<id>", mode="compare", compare_to="<id>", compare_env="dev")`
79
+ - **Templates**: `persona(templates=true)`
80
+
81
+ ### `workflow`
82
+
83
+ - **Generate**: `workflow(input="<requirements>", type="chat|voice|dashboard")`
84
+ - **Analyze**:
85
+ - By persona: `workflow(mode="analyze", persona_id="<id>")`
86
+ - By JSON: `workflow(mode="analyze", workflow_def={<...>})`
87
+ - Limit output: `workflow(mode="analyze", persona_id="<id>", include=["issues"|"connections"|"fixes"|"metrics"])`
88
+ - **Deploy**: `workflow(mode="deploy", persona_id="<id>", workflow_def={<...>}, proto_config={<...>}, auto_fix=true)`
89
+ - **Optimize** (analyze + fixes + deploy): `workflow(mode="optimize", persona_id="<id>", preview=true|false)`
90
+ - **Compare**: `workflow(mode="compare", persona_id="<before>", compare_to="<after>")`
91
+ - **Compile** (from explicit nodes): `workflow(mode="compile", name="...", description="...", type="chat|voice|dashboard", nodes=[...], result_mappings=[...])`
92
+
93
+ ### `action`
94
+
95
+ - **Get**: `action(id="chat_categorizer", include_docs=true)`
96
+ - **List/search**: `action(all=true)` / `action(query="search")` / `action(category="routing")`
97
+ - **Suggest**: `action(suggest="IT helpdesk that creates ServiceNow tickets")`
98
+
99
+ ### `template`
100
+
101
+ - **Patterns**: `template(patterns=true)` / `template(pattern="intent-routing")`
102
+ - **Qualifying questions**: `template(questions=true)` / `template(questions=true, category="Voice", required_only=true)`
103
+ - **Widget reference**: `template(widgets="voice")`
104
+
105
+ ### `reference`
106
+
107
+ - **Concept**: `reference(concept="HITL")`
108
+ - **Guidance**: `reference(guidance="categorizer-routing")`
109
+ - **Validate Auto Builder prompt**: `reference(validate_prompt="<prompt>")`
110
+ - **Common mistakes**: `reference(mistakes=true)`
111
+ - **Debug checklist**: `reference(checklist=true)`
112
+
113
+ ## Resources (read-first)
114
+
115
+ Start with:
116
+
117
+ - `ema://index/all-resources` (index)
118
+ - `ema://docs/readme` (toolkit overview)
119
+ - `ema://docs/ema-user-guide` (platform concepts)
120
+ - `ema://catalog/agents-summary` (quick agent overview)
121
+ - `ema://catalog/templates` (persona templates from API - dynamic)
122
+ - `ema://catalog/templates-summary` (template overview - dynamic)
123
+ - `ema://catalog/patterns` (workflow patterns)
124
+ - `ema://rules/input-sources` and `ema://rules/anti-patterns` (validation rules)
125
+
126
+ ## Auto-Fix Capabilities
127
+
128
+ The `workflow(mode="optimize")` can automatically fix common issues:
129
+
130
+ | Issue | Auto-Fix Action |
131
+ |-------|----------------|
132
+ | `wrong_input_source` (email_to) | Adds `entity_extraction` node, wires to extracted `email_address` |
133
+ | `wrong_input_source` (query) | Rewires from `chat_conversation` to `user_query` |
134
+ | `missing_workflow_output` | Adds results mapping for response nodes |
135
+ | `missing_category_edge` | Validates runIf pattern as alternative |
136
+
137
+ Issues requiring manual intervention:
138
+ - `incomplete_hitl` - Needs success/failure response node configuration
139
+ - Complex routing changes - Multiple nodes affected
140
+
141
+ ## Legacy tools (migration only)
142
+
143
+ Legacy tools are **disabled by default** to reduce duplicate semantics and tool confusion for LLMs.
144
+
145
+ If you must enable them (temporary):
146
+
147
+ - Set `EMA_ENABLE_LEGACY_TOOLS=true`
148
+ - Prefer the consolidated tools for new usage
149
+
@@ -0,0 +1,218 @@
1
+ # MCP Naming Conventions (AUTHORITATIVE)
2
+
3
+ > **THIS IS THE SINGLE SOURCE OF TRUTH FOR ALL NAMING IN THIS PROJECT.**
4
+ > Any deviation from this document is a bug.
5
+
6
+ ---
7
+
8
+ ## Core Principle
9
+
10
+ **ONE pattern for similar things. Tools and prompts that relate to the same domain MUST use the same naming structure.**
11
+
12
+ ---
13
+
14
+ ## 1. MCP Tools (Consolidated)
15
+
16
+ Tools use **noun-based naming with `mode` parameter**:
17
+
18
+ ```
19
+ {noun}(mode="{action}", ...)
20
+ ```
21
+
22
+ ### Current Consolidated Tools
23
+
24
+ | Tool | Modes | Pattern |
25
+ |------|-------|---------|
26
+ | `workflow` | generate, analyze, deploy, optimize, compare, compile, explain, extend | `workflow(mode="deploy", ...)` |
27
+ | `persona` | get, list, create, update, compare, templates | `persona(mode="create", ...)` |
28
+ | `action` | list, docs, suggest, recommendations | `action(mode="suggest", ...)` |
29
+ | `template` | (patterns, questions, widgets) | `template(pattern="...", ...)` |
30
+ | `knowledge` | upload, list, delete, status, toggle | `knowledge(mode="upload", ...)` |
31
+ | `reference` | (validation, guidance) | `reference(check_types=..., ...)` |
32
+ | `sync` | run, status, config | `sync(mode="run", ...)` |
33
+ | `demo` | template, consolidate, generate, validate | `demo(mode="generate", ...)` |
34
+ | `env` | (list environments) | `env()` |
35
+
36
+ ### Legacy Tool Aliases (DEPRECATED - for backwards compatibility only)
37
+
38
+ These exist ONLY for backwards compatibility and redirect to consolidated tools:
39
+
40
+ ```
41
+ deploy_workflow → workflow(mode="deploy")
42
+ optimize_workflow → workflow(mode="optimize")
43
+ analyze_workflow → workflow(mode="analyze")
44
+ ```
45
+
46
+ **DO NOT create new tools with `verb_noun` pattern.**
47
+
48
+ ---
49
+
50
+ ## 2. MCP Prompts
51
+
52
+ Prompts are **guided multi-step workflows**. They MUST follow the **same `{noun}_{action}` pattern** as tools:
53
+
54
+ ```
55
+ {noun}_{action}
56
+ {noun}_{action}_{qualifier} # only when disambiguation needed
57
+ ```
58
+
59
+ ### Prompt Naming Rules
60
+
61
+ | Pattern | Example | Maps To Tool |
62
+ |---------|---------|--------------|
63
+ | `workflow_generate` | Generate a workflow | `workflow(mode="generate")` |
64
+ | `workflow_deploy` | Deploy a workflow | `workflow(mode="deploy")` |
65
+ | `workflow_explain` | Explain a workflow | `workflow(mode="explain")` |
66
+ | `workflow_extend` | Extend a workflow | `workflow(mode="extend")` |
67
+ | `workflow_analyze_intent` | Analyze workflow intent | `workflow(mode="analyze", include=["intent"])` |
68
+ | `persona_create` | Create a persona | `persona(mode="create")` |
69
+ | `persona_sync` | Sync a persona | `sync(mode="run")` |
70
+
71
+ ### FORBIDDEN Patterns
72
+
73
+ ```
74
+ ❌ deploy_workflow # verb_noun is WRONG
75
+ ❌ explain_workflow # verb_noun is WRONG
76
+ ❌ generate_workflow_direct # _direct suffix is unclear
77
+ ❌ analyze_workflow_intent # should be workflow_analyze_intent
78
+ ```
79
+
80
+ ### Acceptable Legacy Exceptions (for backwards compat only)
81
+
82
+ These prompts exist and are grandfathered but should not be used as templates:
83
+
84
+ - `generate_ai_employee` - legacy, use `persona_create` for new
85
+ - `create_voice_ai` - legacy, use `persona_create` with `type="voice"`
86
+ - `create_chat_ai` - legacy, use `persona_create` with `type="chat"`
87
+
88
+ ---
89
+
90
+ ## 3. Functions & Interfaces
91
+
92
+ ### Functions
93
+
94
+ ```typescript
95
+ // Pattern: {verb}{Noun} or {verb}{Noun}{Qualifier}
96
+ parseNaturalLanguage()
97
+ validateIntent()
98
+ detectActionChains()
99
+ calculateIntentConfidence()
100
+ generateOutputSemanticsPrompt()
101
+ applyExtractedSemantics()
102
+ ```
103
+
104
+ ### Interfaces/Types
105
+
106
+ ```typescript
107
+ // Pattern: {Noun}{Qualifier}
108
+ WorkflowIntent
109
+ OutputSemantics
110
+ IntentConfidence
111
+ ValidationResult
112
+ AgentDefinition
113
+ ```
114
+
115
+ ### Constants
116
+
117
+ ```typescript
118
+ // Pattern: SCREAMING_SNAKE_CASE
119
+ AGENT_CATALOG
120
+ WORKFLOW_PATTERNS
121
+ TYPE_COMPATIBILITY
122
+ ACTION_CHAIN_PATTERNS
123
+ ```
124
+
125
+ ---
126
+
127
+ ## 4. Issue Types (Validation)
128
+
129
+ Issue types use **snake_case** with category prefix:
130
+
131
+ ```
132
+ {category}_{specific_problem}
133
+ ```
134
+
135
+ | Category | Examples |
136
+ |----------|----------|
137
+ | `unused_` | `unused_output` |
138
+ | `missing_` | `missing_entity_extraction`, `missing_category_edge` |
139
+ | `wrong_` | `wrong_input_source` |
140
+ | `side_effect_` | `side_effect_without_hitl` |
141
+ | `redundant_` | `redundant_search` |
142
+ | `sequential_` | `sequential_search` |
143
+ | `duplicate_` | `duplicate_llm_processing` |
144
+
145
+ ---
146
+
147
+ ## 5. Resource URIs
148
+
149
+ Resource URIs use **path-like structure**:
150
+
151
+ ```
152
+ ema://{category}/{subcategory}/{item}
153
+ ```
154
+
155
+ | Pattern | Example |
156
+ |---------|---------|
157
+ | Catalogs | `ema://catalog/agents`, `ema://catalog/agents/summary` |
158
+ | Patterns | `ema://patterns/workflows` |
159
+ | Templates | `ema://templates/voice-ai/config` |
160
+ | Validation | `ema://validation/input-sources`, `ema://validation/anti-patterns` |
161
+ | Index | `ema://index/all-resources` |
162
+
163
+ ---
164
+
165
+ ## 6. File Naming
166
+
167
+ | Type | Pattern | Example |
168
+ |------|---------|---------|
169
+ | TypeScript source | `kebab-case.ts` | `workflow-intent.ts`, `validation-rules.ts` |
170
+ | Test files | `{module}.test.ts` | `workflow-intent.test.ts` |
171
+ | Documentation | `kebab-case.md` | `naming-conventions.md` |
172
+ | Config | `kebab-case.yaml/json` | `config.example.yaml` |
173
+
174
+ ---
175
+
176
+ ## Enforcement Checklist
177
+
178
+ Before adding ANY new name:
179
+
180
+ - [ ] Does it follow `{noun}_{action}` for prompts?
181
+ - [ ] Does it follow `{noun}(mode="{action}")` for tools?
182
+ - [ ] Does it follow `{verb}{Noun}` for functions?
183
+ - [ ] Does it follow `{Noun}{Qualifier}` for interfaces?
184
+ - [ ] Is there already a similar pattern established? If so, follow it exactly.
185
+ - [ ] Does it avoid hardcoded specific values?
186
+ - [ ] Is it clear what the name refers to?
187
+
188
+ ---
189
+
190
+ ## Migration Notes
191
+
192
+ ### Renamed in this cleanup:
193
+
194
+ | Old (WRONG) | New (CORRECT) |
195
+ |-------------|---------------|
196
+ | `deploy_workflow` | `workflow_deploy` |
197
+ | `explain_workflow` | `workflow_explain` |
198
+ | `extend_workflow` | `workflow_extend` |
199
+ | `analyze_workflow_intent` | `workflow_analyze_intent` |
200
+ | `generate_workflow_direct` | `workflow_generate` |
201
+ | `generate_ai_employee` | `ai_employee_generate` |
202
+ | `review_workflow` | `workflow_review` |
203
+ | `debug_workflow` | `workflow_debug` |
204
+ | `create_voice_ai` | `persona_create_voice` |
205
+ | `create_chat_ai` | `persona_create_chat` |
206
+ | `sync_persona` | `persona_sync` |
207
+ | `compare_personas` | `persona_compare` |
208
+ | `validate_prompt` | `prompt_validate` |
209
+ | `onboard_toolkit` | `toolkit_onboard` |
210
+ | `clarify_requirements` | `requirements_clarify` |
211
+
212
+ ---
213
+
214
+ ## References
215
+
216
+ - Tools defined in: `src/mcp/tools-consolidated.ts`
217
+ - Prompts defined in: `src/mcp/prompts.ts`
218
+ - Legacy mappings in: `src/mcp/tools-legacy.ts`