@ema.co/mcp-toolkit 2026.1.24 → 2026.1.26-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.

Potentially problematic release.


This version of @ema.co/mcp-toolkit might be problematic. Click here for more details.

Files changed (81) hide show
  1. package/README.md +10 -2
  2. package/dist/mcp/handlers/action/index.js +3 -18
  3. package/dist/mcp/handlers/data/index.js +385 -41
  4. package/dist/mcp/handlers/data/templates.js +107 -0
  5. package/dist/mcp/handlers/deprecation.js +50 -0
  6. package/dist/mcp/handlers/env/index.js +8 -4
  7. package/dist/mcp/handlers/knowledge/index.js +44 -237
  8. package/dist/mcp/handlers/persona/create.js +5 -11
  9. package/dist/mcp/handlers/persona/index.js +5 -1
  10. package/dist/mcp/handlers/persona/version.js +234 -0
  11. package/dist/mcp/handlers/reference/index.js +101 -1
  12. package/dist/mcp/handlers/sync/index.js +3 -18
  13. package/dist/mcp/handlers/template/index.js +75 -10
  14. package/dist/mcp/handlers/workflow/analyze.js +171 -0
  15. package/dist/mcp/handlers/workflow/compare.js +70 -0
  16. package/dist/mcp/handlers/workflow/compile.js +39 -0
  17. package/dist/mcp/handlers/workflow/deploy.js +73 -0
  18. package/dist/mcp/handlers/workflow/generate.js +350 -0
  19. package/dist/mcp/handlers/workflow/index.js +136 -0
  20. package/dist/mcp/handlers/workflow/modify.js +456 -0
  21. package/dist/mcp/handlers/workflow/optimize.js +136 -0
  22. package/dist/mcp/handlers/workflow/types.js +4 -0
  23. package/dist/mcp/handlers/workflow/utils.js +132 -0
  24. package/dist/mcp/handlers-consolidated.js +62 -2691
  25. package/dist/mcp/prompts.js +13 -14
  26. package/dist/mcp/resources.js +55 -54
  27. package/dist/mcp/server.js +93 -124
  28. package/dist/mcp/{tools-v2.js → tools.js} +1 -1
  29. package/dist/mcp/workflow-operations.js +2 -2
  30. package/dist/sdk/client-adapter.js +267 -32
  31. package/dist/sdk/client.js +31 -15
  32. package/dist/sdk/ema-client.js +183 -0
  33. package/dist/sdk/generated/template-fallbacks.js +123 -0
  34. package/dist/sdk/guidance.js +65 -11
  35. package/dist/sdk/index.js +3 -1
  36. package/dist/sdk/knowledge.js +16 -86
  37. package/dist/sdk/workflow-intent.js +27 -0
  38. package/dist/sdk/workflow-transformer.js +0 -342
  39. package/docs/DEBUG-ANALYSIS-unused-category-type-mismatch.md +481 -0
  40. package/docs/TODO-fix-analyzer-and-modify.md +182 -0
  41. package/package.json +9 -4
  42. package/dist/mcp/tools-consolidated.js +0 -866
  43. package/dist/mcp/tools-legacy.js +0 -736
  44. package/docs/CODEBASE-ANALYSIS-2026-01-23.md +0 -936
  45. package/docs/CODEBASE-ANALYSIS-PRIORITIZED.md +0 -774
  46. package/docs/api-contracts.md +0 -216
  47. package/docs/auto-builder-analysis.md +0 -271
  48. package/docs/blog/mcp-tool-design-lessons.md +0 -309
  49. package/docs/data-architecture.md +0 -166
  50. package/docs/ema-auto-builder-guide.html +0 -394
  51. package/docs/lessons-learned.md +0 -209
  52. package/docs/llm-native-workflow-design.md +0 -252
  53. package/docs/local-generation.md +0 -508
  54. package/docs/mcp-flow-diagram.md +0 -135
  55. package/docs/migration/action-composition-migration.md +0 -270
  56. package/docs/naming-conventions.md +0 -278
  57. package/docs/proposals/HANDOFF-tool-restructure.md +0 -526
  58. package/docs/proposals/action-composition.md +0 -490
  59. package/docs/proposals/explicit-method-restructure.md +0 -328
  60. package/docs/proposals/mcp-tool-restructure-2026-01.md +0 -366
  61. package/docs/proposals/self-contained-guidance.md +0 -427
  62. package/docs/proto-sdk-generation.md +0 -242
  63. package/docs/release-impact.md +0 -102
  64. package/docs/release-process.md +0 -157
  65. package/docs/staging.RULE.md +0 -142
  66. package/docs/test-persona-creation.md +0 -196
  67. package/docs/tool-consolidation-v2.md +0 -225
  68. package/docs/tool-response-standards.md +0 -256
  69. package/resources/docs/getting-started.md +0 -97
  70. package/resources/templates/auto-builder-rules.md +0 -224
  71. package/resources/templates/chat-ai/README.md +0 -119
  72. package/resources/templates/chat-ai/persona-config.json +0 -111
  73. package/resources/templates/dashboard-ai/README.md +0 -156
  74. package/resources/templates/dashboard-ai/persona-config.json +0 -180
  75. package/resources/templates/demo-scenarios/README.md +0 -63
  76. package/resources/templates/demo-scenarios/test-published-package.md +0 -116
  77. package/resources/templates/document-gen-ai/README.md +0 -132
  78. package/resources/templates/document-gen-ai/persona-config.json +0 -316
  79. package/resources/templates/voice-ai/README.md +0 -123
  80. package/resources/templates/voice-ai/persona-config.json +0 -74
  81. package/resources/templates/voice-ai/workflow-prompt.md +0 -121
@@ -1,526 +0,0 @@
1
- # MCP Tool Restructure: Session Handoff
2
-
3
- **Date**: 2026-01-18
4
- **Branch**: `feat/mcp-tool-restructure`
5
- **Base**: `main` (PR #49 merged)
6
- **Status**: **IN PROGRESS** - V2 tools implemented, testing
7
-
8
- ---
9
-
10
- ## Executive Summary
11
-
12
- Restructure MCP tools from **7 mode-based tools** to **4 LLM-optimized tools**.
13
-
14
- | Before (V1) | After (V2) |
15
- |-------------|------------|
16
- | 7 tools with mode params | 4 focused tools |
17
- | `persona(mode="list")` | `persona()` |
18
- | `data(mode="upload")` | `persona(id, data={upload:...})` |
19
- | `action`, `template`, `reference` | `catalog(type="actions")` |
20
-
21
- **Why**: Minimal tool count optimizes LLM tool selection. Data under persona (always persona-scoped). Catalog consolidates all reference data.
22
-
23
- ---
24
-
25
- ## Current State
26
-
27
- ### Implemented (V2 - Default)
28
-
29
- | Tool | Purpose | Key Operations |
30
- |------|---------|----------------|
31
- | `persona` | AI Employee entity + data | query, create, update, delete, analyze, sanitize, snapshot/history/restore, data ops |
32
- | `catalog` | Reference data | actions, templates, widgets, voices, patterns, concepts |
33
- | `sync` | Cross-env operations | run, status |
34
- | `env` | Environment info | list |
35
-
36
- **Total**: 4 tools exposed to LLM
37
-
38
- ### Feature Flags
39
-
40
- | Flag | Effect |
41
- |------|--------|
42
- | (default) | V2 tools only (4 tools) |
43
- | `EMA_ENABLE_V1_TOOLS=true` | V1 mode-based tools (7 tools) |
44
- | `EMA_ENABLE_LEGACY_TOOLS=true` | Add legacy individual tools |
45
-
46
- ### Files Changed
47
-
48
- | File | Status | Description |
49
- |------|--------|-------------|
50
- | `src/mcp/tools-v2.ts` | **NEW** | V2 tool definitions (4 tools) |
51
- | `src/mcp/server.ts` | **MODIFIED** | V2 routing, persona v2 handler, catalog handler |
52
-
53
- ### V2 Persona Operations
54
-
55
- ```typescript
56
- // Query (list/get)
57
- persona() // list all
58
- persona(id="abc") // get one
59
- persona(type="voice") // filter
60
-
61
- // Create
62
- persona(create={name:"Bot", type:"voice"})
63
- persona(create={name:"Bot", from:"template-id"}) // from template
64
- persona(create={name:"Bot", from:"other-id"}) // clone
65
-
66
- // Update
67
- persona(id="abc", update={config:{...}})
68
- persona(id="abc", update={input:"add HITL"})
69
-
70
- // Delete
71
- persona(id="abc", delete=true)
72
-
73
- // Analyze
74
- persona(id="abc", analyze=true)
75
- persona(id="abc", analyze=true, fix=true)
76
-
77
- // History (snapshots)
78
- persona(id="abc", snapshot="message") // create
79
- persona(id="abc", history=true) // list
80
- persona(id="abc", restore="v3") // rollback
81
-
82
- // Compare
83
- persona(id="abc", compare="def")
84
-
85
- // Data (owned by persona)
86
- persona(id="abc", data={list:true})
87
- persona(id="abc", data={upload:"/path/to/file"})
88
- persona(id="abc", data={generate:"5 customers"})
89
- persona(id="abc", data={embed:true})
90
- persona(id="abc", data={search:"pricing"})
91
- ```
92
-
93
- ### V2 Catalog Operations
94
-
95
- ```typescript
96
- catalog(type="actions") // list actions
97
- catalog(type="actions", id="knowledge_search") // get one
98
- catalog(type="actions", recommend="email") // recommendations
99
- catalog(type="templates") // list templates
100
- catalog(type="widgets") // list widgets
101
- catalog(type="patterns") // list patterns
102
- catalog(type="concepts") // platform terms
103
- ```
104
-
105
- ---
106
-
107
- ## Research Summary
108
-
109
- ### Industry Patterns
110
-
111
- | Server | Pattern | Tools | Example |
112
- |--------|---------|-------|---------|
113
- | Playwright | `browser_{action}` | 15+ | `browser_click`, `browser_type` |
114
- | Firecrawl | `firecrawl_{action}` | 6 | `firecrawl_scrape`, `firecrawl_crawl` |
115
- | Filesystem | `{action}` | 10+ | `read_file`, `write_file` |
116
- | Supabase | `{resource}_{action}` | 10+ | `list_tables`, `execute_sql` |
117
-
118
- ### MCP Spec Guidance
119
-
120
- - **Tools**: Model-controlled, LLM invokes automatically
121
- - **Prompts**: User-controlled, user triggers explicitly
122
- - **Tool names**: `A-Z`, `a-z`, `0-9`, `_`, `-`, `.` allowed
123
-
124
- ### Ema Backend Convention
125
-
126
- OpenAPI uses `{Verb}{Resource}`:
127
- - `GetPersona`, `ListPersonas`, `UpdateAiEmployee`
128
-
129
- MCP convention `{resource}_{action}` is compatible (just inverted order).
130
-
131
- ---
132
-
133
- ## Proposed Tool Inventory
134
-
135
- ### Persona Tools (9)
136
-
137
- ```
138
- persona_list - List all personas (basic info)
139
- persona_get - Get persona details (with workflow)
140
- persona_create - Create from template or clone
141
- persona_update - Update config/workflow
142
- persona_delete - Delete persona
143
- persona_clone - Clone existing persona
144
- persona_compare - Compare two personas
145
- persona_sanitize - Clean up for export
146
- persona_analyze - Analyze workflow/config/data issues
147
- ```
148
-
149
- ### Persona Version Tools (5)
150
-
151
- ```
152
- persona_version_list - List versions
153
- persona_version_get - Get specific version
154
- persona_version_create - Create snapshot
155
- persona_version_restore - Restore from version
156
- persona_version_compare - Compare versions
157
- ```
158
-
159
- ### Data Tools (5)
160
-
161
- ```
162
- data_list - List data sources
163
- data_get - Get data source details
164
- data_upload - Upload new data
165
- data_delete - Delete data source
166
- data_search - Search across data
167
- ```
168
-
169
- ### Document Tools (4)
170
-
171
- ```
172
- document_create - Create document (async)
173
- document_get - Get document status/content
174
- document_regenerate - Regenerate document
175
- document_update - Update with instructions
176
- ```
177
-
178
- ### Workflow Tools (4)
179
-
180
- ```
181
- workflow_analyze - Detect issues
182
- workflow_optimize - Suggest/apply fixes
183
- workflow_compile - Compile spec to def
184
- workflow_explain - Explain in natural language
185
- ```
186
-
187
- ### Sync Tools (3)
188
-
189
- ```
190
- sync_run - Execute sync
191
- sync_status - Check sync status
192
- sync_configure - Update sync config
193
- ```
194
-
195
- ### Action Tools (3)
196
-
197
- ```
198
- action_list - List available actions
199
- action_get - Get action details
200
- action_recommend - Recommend actions for intent
201
- ```
202
-
203
- ### Template Tools (2)
204
-
205
- ```
206
- template_list - List templates by type
207
- template_get - Get template details
208
- ```
209
-
210
- ### Utility Tools (2)
211
-
212
- ```
213
- env_list - List environments
214
- reference_get - Get platform reference info
215
- ```
216
-
217
- **Total: 37 tools**
218
-
219
- ---
220
-
221
- ## Implementation Strategy
222
-
223
- ### Phase 1: Define New Tools
224
-
225
- Create `src/mcp/tools-v2.ts` with new tool definitions:
226
-
227
- ```typescript
228
- export const PERSONA_TOOLS = [
229
- {
230
- name: "persona_list",
231
- description: "List all AI Employee personas",
232
- inputSchema: {
233
- type: "object",
234
- properties: {
235
- env: { type: "string", description: "Environment" },
236
- type: {
237
- type: "string",
238
- enum: ["voice", "chat", "dashboard"],
239
- description: "Filter by persona type"
240
- }
241
- }
242
- }
243
- },
244
- // ... more tools
245
- ];
246
- ```
247
-
248
- ### Phase 2: Update Routing
249
-
250
- In `src/mcp/server.ts`, parse tool names:
251
-
252
- ```typescript
253
- function parseToolName(name: string): { resource: string; action: string } {
254
- const parts = name.split('_');
255
- if (parts.length === 2) {
256
- return { resource: parts[0], action: parts[1] };
257
- }
258
- // Handle persona_version_* pattern
259
- if (parts.length === 3 && parts[0] === 'persona' && parts[1] === 'version') {
260
- return { resource: 'persona_version', action: parts[2] };
261
- }
262
- throw new Error(`Invalid tool name: ${name}`);
263
- }
264
-
265
- // Route to handlers
266
- const { resource, action } = parseToolName(toolName);
267
- switch (resource) {
268
- case 'persona':
269
- return handlePersona({ ...args, _action: action }, client, env);
270
- case 'persona_version':
271
- return handlePersonaVersion({ ...args, _action: action }, client, env);
272
- // ...
273
- }
274
- ```
275
-
276
- ### Phase 3: Backwards Compatibility
277
-
278
- Keep old tools working during migration:
279
-
280
- ```typescript
281
- // Old tool calls route to new
282
- if (toolName === 'persona') {
283
- const action = args.mode || 'list';
284
- console.warn(`DEPRECATED: Use persona_${action} instead of persona(mode="${action}")`);
285
- return handlePersona({ ...args, _action: action }, client, env);
286
- }
287
- ```
288
-
289
- ### Phase 4: Prompts for Workflows
290
-
291
- Add user-triggered workflow prompts:
292
-
293
- ```typescript
294
- export const WORKFLOW_PROMPTS = [
295
- {
296
- name: "create_voice_ai",
297
- description: "Guided workflow to create a Voice AI persona",
298
- arguments: [
299
- { name: "name", description: "Persona name", required: true },
300
- { name: "description", description: "What should it do?", required: true }
301
- ]
302
- },
303
- {
304
- name: "troubleshoot",
305
- description: "Diagnose and fix persona issues",
306
- arguments: [
307
- { name: "persona", description: "Persona ID or name", required: true }
308
- ]
309
- }
310
- ];
311
- ```
312
-
313
- ---
314
-
315
- ## Key Design Decisions
316
-
317
- ### 1. Tool Name Format: `{resource}_{action}`
318
-
319
- **Chosen**: `persona_list`, `data_upload`, `sync_run`
320
-
321
- **Why**:
322
- - Alphabetically groups related tools
323
- - Matches Playwright, Supabase patterns
324
- - Clear, predictable naming
325
-
326
- **Rejected**:
327
- - `listPersonas` (camelCase) - doesn't group
328
- - `persona.list` (dot notation) - uncommon
329
- - `persona(mode="list")` (current) - param sprawl
330
-
331
- ### 2. Nested Resources: `persona_version_*`
332
-
333
- **Chosen**: `persona_version_list`, `persona_version_create`
334
-
335
- **Why**:
336
- - Clear hierarchy
337
- - Still groups alphabetically
338
- - Avoids ambiguity
339
-
340
- **Alternative considered**: `version_list` with `persona_id` param - less discoverable
341
-
342
- ### 3. Document vs Data
343
-
344
- **Chosen**: Separate `document_*` tools for doc generation
345
-
346
- **Why**:
347
- - Different API (Ema Document Generation API)
348
- - Different workflow (async, polling)
349
- - Clearer separation of concerns
350
-
351
- ### 4. Workflow as Separate Resource
352
-
353
- **Chosen**: `workflow_analyze`, `workflow_optimize`
354
-
355
- **Why**:
356
- - Workflow operations are complex enough to warrant separation
357
- - Prevents persona_* bloat
358
- - Clear when you're operating on workflow vs persona config
359
-
360
- ---
361
-
362
- ## Migration Path
363
-
364
- ### For Users
365
-
366
- ```typescript
367
- // Old (deprecated)
368
- persona(mode="list", type="voice")
369
-
370
- // New
371
- persona_list(type="voice")
372
- ```
373
-
374
- ### Deprecation Timeline
375
-
376
- 1. **Phase 1**: New tools available, old tools warn
377
- 2. **Phase 2**: Old tools in docs marked deprecated
378
- 3. **Phase 3**: Old tools removed (major version bump)
379
-
380
- ---
381
-
382
- ## Files to Modify
383
-
384
- | File | Change |
385
- |------|--------|
386
- | `src/mcp/tools-v2.ts` | **NEW** - All new tool definitions |
387
- | `src/mcp/server.ts` | Update routing to handle new tool names |
388
- | `src/mcp/handlers-consolidated.ts` | Minor updates (accept `_action` param) |
389
- | `src/mcp/prompts.ts` | Add workflow prompts |
390
- | `docs/mcp-tools-guide.md` | Full rewrite for new tools |
391
- | `.cursor/rules/ema/mcp/RULE.md` | Update tool reference |
392
-
393
- ---
394
-
395
- ## Testing Strategy
396
-
397
- 1. **Unit tests**: Each new tool definition validates
398
- 2. **Integration tests**: Tool routing works correctly
399
- 3. **Backwards compat tests**: Old tool calls still work
400
- 4. **Deprecation tests**: Warnings are emitted
401
-
402
- ---
403
-
404
- ## Open Questions
405
-
406
- 1. **Should `env` be a tool or implicit?**
407
- - Every tool needs env - maybe it should be in transport headers?
408
-
409
- 2. **Prompt implementation detail**
410
- - Should prompts call tools internally or return guidance for LLM to call?
411
-
412
- 3. **Tool count concern**
413
- - 37 tools - is this too many for some MCP clients?
414
-
415
- ---
416
-
417
- ## DONE: Workflow Fix - Cascading Dependencies (Implemented)
418
-
419
- **Problem**: Removing "orphan" nodes created dangling references in consumer nodes.
420
-
421
- **Solution implemented**:
422
- 1. `detectOrphanNodes()` in `knowledge.ts` now calls `findNodeConsumers()` to track dependent nodes
423
- 2. `applySimpleFixes()` in `handlers-consolidated.ts` now:
424
- - Removes orphan nodes
425
- - Cleans up `incoming_edges` that reference removed nodes
426
- - Cleans up `inputBindings` that reference removed nodes
427
- 3. Issue reason now includes dependent nodes: `"Removing will also clean dangling refs in: node1, node2"`
428
-
429
- **Files changed**:
430
- - `src/sdk/knowledge.ts`: Added `findNodeConsumers()`, updated `detectOrphanNodes()`
431
- - `src/mcp/handlers-consolidated.ts`: Implemented `applySimpleFixes()` with cascading cleanup
432
-
433
- ---
434
-
435
- ## TODO: Extract knowledge.ts to Config Files
436
-
437
- **Problem**: `knowledge.ts` has 4,370 lines of hardcoded data that should be config-driven.
438
-
439
- **Current state (hardcoded)**:
440
- | Data | Lines | Should Be |
441
- |------|-------|-----------|
442
- | `AGENT_CATALOG` | ~2000 | `resources/config/agents.json` |
443
- | `WORKFLOW_PATTERNS` | ~300 | `resources/config/patterns.json` |
444
- | `PLATFORM_CONCEPTS` | ~400 | `resources/config/concepts.json` |
445
- | `WIDGET_CATALOG` | ~100 | Proto/OpenAPI derived |
446
- | `QUALIFYING_QUESTIONS` | ~100 | `resources/config/questions.json` |
447
-
448
- **Migration plan**:
449
- 1. Create JSON config files in `resources/config/`
450
- 2. Add loader functions that read and cache configs at startup
451
- 3. Update knowledge.ts exports to use loaded configs
452
- 4. Add JSON schema validation for configs
453
- 5. Update `npm run generate:types` to also validate configs against schemas
454
-
455
- **Note**: Some data is domain knowledge (glossary, best practices) that's NOT derivable from specs.
456
- This is intentional - it should be config, not code, but can't be auto-generated.
457
-
458
- ---
459
-
460
- ## DONE: Generate Enum Mappings from OpenAPI
461
-
462
- - Modified `scripts/generate-types.ts` to extract enum labels from `x-enum-varnames`
463
- - Generated `PersonaTriggerTypeEnumLabels` and `PersonaTriggerTypeEnumValues`
464
- - Updated `handlers-consolidated.ts` to use generated mapping (no hardcoding)
465
-
466
- ---
467
-
468
- ## DONE: Deprecation Tracking for Old Param Names
469
-
470
- Added deprecation warnings for legacy param names:
471
- - `identifier` → `id`
472
- - `clone_from` → `from`
473
- - `template_id` → `from`
474
- - `clone_data` → `include_data`
475
-
476
- Warnings logged to console. Target removal: v2.0.0
477
-
478
- ---
479
-
480
- ## TODO: Test Coverage Gaps
481
-
482
- **Problem**: 631 tests exist but recent bugs (e.g., `proto_config` ignored without explicit `mode`) weren't caught.
483
-
484
- **Root cause**: Tests validate happy paths and individual functions, but miss:
485
- - **Integration gaps**: Handler → SDK → API round-trips
486
- - **Param interaction**: What happens when params combine unexpectedly
487
- - **Mode inference edge cases**: The auto-detection logic was never tested for ambiguity
488
- - **Real API contracts**: Tests mock responses, don't validate actual API shape
489
-
490
- **Needed**:
491
- 1. **Negative tests**: "What should NOT work" - explicit failure cases
492
- 2. **Ambiguity tests**: Multiple valid interpretations → should clarify, not guess
493
- 3. **Contract tests**: Validate mocks match real API responses (use HAR captures)
494
- 4. **E2E smoke tests**: Against real sandbox env, not mocks
495
- 5. **Regression tests**: Every bug fix needs a test that would have caught it
496
-
497
- **Priority**: Address during or after restructure - new tools need proper test discipline from the start.
498
-
499
- ---
500
-
501
- ## Quick Start
502
-
503
- ```bash
504
- # 1. You're on this branch
505
- git checkout feat/mcp-tool-restructure
506
-
507
- # 2. Start with tools-v2.ts
508
- # Create new tool definitions following the inventory above
509
-
510
- # 3. Update server.ts routing
511
- # Parse {resource}_{action} and route
512
-
513
- # 4. Run tests
514
- npm run build && npm test
515
-
516
- # 5. Update docs last
517
- ```
518
-
519
- ---
520
-
521
- ## Reference
522
-
523
- - **Full proposal**: `docs/proposals/mcp-tool-restructure-2026-01.md`
524
- - **MCP spec**: https://modelcontextprotocol.io/specification/2025-11-25/server/tools
525
- - **Playwright MCP**: https://github.com/microsoft/playwright-mcp
526
- - **Current tools**: `src/mcp/tools-consolidated.ts`