@ema.co/mcp-toolkit 2026.1.25 → 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.
- package/README.md +10 -2
- package/dist/mcp/handlers/action/index.js +3 -18
- package/dist/mcp/handlers/data/index.js +385 -41
- package/dist/mcp/handlers/data/templates.js +107 -0
- package/dist/mcp/handlers/deprecation.js +50 -0
- package/dist/mcp/handlers/env/index.js +8 -4
- package/dist/mcp/handlers/knowledge/index.js +44 -237
- package/dist/mcp/handlers/persona/create.js +5 -11
- package/dist/mcp/handlers/persona/index.js +5 -1
- package/dist/mcp/handlers/persona/version.js +234 -0
- package/dist/mcp/handlers/sync/index.js +3 -18
- package/dist/mcp/handlers/template/index.js +75 -10
- package/dist/mcp/handlers/workflow/analyze.js +171 -0
- package/dist/mcp/handlers/workflow/compare.js +70 -0
- package/dist/mcp/handlers/workflow/compile.js +39 -0
- package/dist/mcp/handlers/workflow/deploy.js +73 -0
- package/dist/mcp/handlers/workflow/generate.js +350 -0
- package/dist/mcp/handlers/workflow/index.js +136 -0
- package/dist/mcp/handlers/workflow/modify.js +456 -0
- package/dist/mcp/handlers/workflow/optimize.js +136 -0
- package/dist/mcp/handlers/workflow/types.js +4 -0
- package/dist/mcp/handlers/workflow/utils.js +132 -0
- package/dist/mcp/handlers-consolidated.js +62 -2691
- package/dist/mcp/prompts.js +13 -14
- package/dist/mcp/resources.js +55 -54
- package/dist/mcp/server.js +93 -124
- package/dist/mcp/{tools-v2.js → tools.js} +1 -1
- package/dist/mcp/workflow-operations.js +2 -2
- package/dist/sdk/client-adapter.js +267 -32
- package/dist/sdk/client.js +31 -15
- package/dist/sdk/ema-client.js +183 -0
- package/dist/sdk/generated/template-fallbacks.js +123 -0
- package/dist/sdk/guidance.js +65 -11
- package/dist/sdk/index.js +3 -1
- package/dist/sdk/knowledge.js +16 -86
- package/dist/sdk/workflow-intent.js +27 -0
- package/dist/sdk/workflow-transformer.js +0 -342
- package/docs/DEBUG-ANALYSIS-unused-category-type-mismatch.md +481 -0
- package/docs/TODO-fix-analyzer-and-modify.md +182 -0
- package/package.json +9 -4
- package/dist/mcp/tools-consolidated.js +0 -875
- package/dist/mcp/tools-legacy.js +0 -736
- package/docs/CODEBASE-ANALYSIS-2026-01-23.md +0 -936
- package/docs/CODEBASE-ANALYSIS-PRIORITIZED.md +0 -774
- package/docs/api-contracts.md +0 -216
- package/docs/auto-builder-analysis.md +0 -271
- package/docs/blog/mcp-tool-design-lessons.md +0 -309
- package/docs/data-architecture.md +0 -166
- package/docs/demos/ap-invoice-generation.md +0 -347
- package/docs/demos/ap-invoice-processing.md +0 -271
- package/docs/ema-auto-builder-guide.html +0 -394
- package/docs/lessons-learned.md +0 -209
- package/docs/llm-native-workflow-design.md +0 -252
- package/docs/local-generation.md +0 -508
- package/docs/mcp-flow-diagram.md +0 -135
- package/docs/migration/action-composition-migration.md +0 -270
- package/docs/naming-conventions.md +0 -278
- package/docs/proposals/HANDOFF-tool-restructure.md +0 -526
- package/docs/proposals/action-composition.md +0 -490
- package/docs/proposals/explicit-method-restructure.md +0 -328
- package/docs/proposals/mcp-tool-restructure-2026-01.md +0 -366
- package/docs/proposals/self-contained-guidance.md +0 -427
- package/docs/proto-sdk-generation.md +0 -242
- package/docs/release-impact.md +0 -102
- package/docs/release-process.md +0 -157
- package/docs/staging.RULE.md +0 -142
- package/docs/test-persona-creation.md +0 -196
- package/docs/tool-consolidation-v2.md +0 -225
- package/docs/tool-response-standards.md +0 -256
- package/resources/demo-kits/README.md +0 -175
- package/resources/demo-kits/finance-ap/manifest.json +0 -150
- package/resources/demo-kits/tags.json +0 -91
- package/resources/docs/getting-started.md +0 -97
- package/resources/templates/auto-builder-rules.md +0 -224
- package/resources/templates/chat-ai/README.md +0 -119
- package/resources/templates/chat-ai/persona-config.json +0 -111
- package/resources/templates/dashboard-ai/README.md +0 -156
- package/resources/templates/dashboard-ai/persona-config.json +0 -180
- package/resources/templates/demo-scenarios/README.md +0 -63
- package/resources/templates/demo-scenarios/test-published-package.md +0 -116
- package/resources/templates/document-gen-ai/README.md +0 -132
- package/resources/templates/document-gen-ai/persona-config.json +0 -316
- package/resources/templates/voice-ai/README.md +0 -123
- package/resources/templates/voice-ai/persona-config.json +0 -74
- package/resources/templates/voice-ai/workflow-prompt.md +0 -121
package/dist/mcp/prompts.js
CHANGED
|
@@ -1027,11 +1027,10 @@ ${args.intents ? `**Intents**: ${args.intents}` : ""}
|
|
|
1027
1027
|
|
|
1028
1028
|
## Instructions
|
|
1029
1029
|
|
|
1030
|
-
### Step 1:
|
|
1031
|
-
|
|
1032
|
-
- \`
|
|
1033
|
-
- \`ema://
|
|
1034
|
-
- \`ema://templates/voice-ai/readme\` - Deployment guide template
|
|
1030
|
+
### Step 1: Get Templates
|
|
1031
|
+
Get templates from API or use generated fallbacks:
|
|
1032
|
+
- \`template(config="voice")\` - Voice AI persona configuration (API-first with fallback)
|
|
1033
|
+
- \`ema://catalog/persona-templates\` - Live API templates
|
|
1035
1034
|
- \`ema://catalog/agents-summary\` - Available agents for workflow composition
|
|
1036
1035
|
|
|
1037
1036
|
### Step 2: Read Validation Rules (Resources)
|
|
@@ -1056,9 +1055,9 @@ Using the templates from Step 1 and guidance from Steps 3-4, generate:
|
|
|
1056
1055
|
**Folder structure:**
|
|
1057
1056
|
\`\`\`
|
|
1058
1057
|
${args.name.toLowerCase().replace(/\s+/g, "-")}/
|
|
1059
|
-
├── README.md # Deployment guide
|
|
1060
|
-
├── workflow-prompt.md # Auto Builder prompt
|
|
1061
|
-
├── persona-config.json # Voice settings (
|
|
1058
|
+
├── README.md # Deployment guide
|
|
1059
|
+
├── workflow-prompt.md # Auto Builder prompt
|
|
1060
|
+
├── persona-config.json # Voice settings (from template(config="voice"))
|
|
1062
1061
|
└── proto-config.json # Full API config
|
|
1063
1062
|
\`\`\`
|
|
1064
1063
|
|
|
@@ -1108,10 +1107,10 @@ ${args.data_sources ? `**Data Sources**: ${args.data_sources}` : ""}
|
|
|
1108
1107
|
|
|
1109
1108
|
## Instructions
|
|
1110
1109
|
|
|
1111
|
-
### Step 1:
|
|
1112
|
-
|
|
1113
|
-
- \`
|
|
1114
|
-
- \`ema://
|
|
1110
|
+
### Step 1: Get Templates
|
|
1111
|
+
Get templates from API or use generated fallbacks:
|
|
1112
|
+
- \`template(config="chat")\` - Chat AI persona configuration (API-first with fallback)
|
|
1113
|
+
- \`ema://catalog/persona-templates\` - Live API templates
|
|
1115
1114
|
- \`ema://catalog/agents-summary\` - Available agents for workflow composition
|
|
1116
1115
|
- \`ema://catalog/patterns\` - Common workflow patterns
|
|
1117
1116
|
|
|
@@ -1134,9 +1133,9 @@ Using the templates from Step 1 and guidance from Steps 3-4, generate:
|
|
|
1134
1133
|
**Folder structure:**
|
|
1135
1134
|
\`\`\`
|
|
1136
1135
|
${args.name.toLowerCase().replace(/\s+/g, "-")}/
|
|
1137
|
-
├── README.md # Deployment guide
|
|
1136
|
+
├── README.md # Deployment guide
|
|
1138
1137
|
├── workflow-prompt.md # Auto Builder prompt
|
|
1139
|
-
├── persona-config.json # Chat settings (
|
|
1138
|
+
├── persona-config.json # Chat settings (from template(config="chat"))
|
|
1140
1139
|
└── docs/ # Knowledge base documents
|
|
1141
1140
|
└── _metadata.json
|
|
1142
1141
|
\`\`\`
|
package/dist/mcp/resources.js
CHANGED
|
@@ -4,10 +4,13 @@
|
|
|
4
4
|
* Provides static and file-backed resources for the Ema MCP Server.
|
|
5
5
|
*
|
|
6
6
|
* Resources are the canonical source of truth for:
|
|
7
|
-
* -
|
|
8
|
-
* - Agent Catalog: Dynamic list of available workflow agents
|
|
7
|
+
* - Agent Catalog: Dynamic list of available workflow agents + API templates
|
|
9
8
|
* - Validation Rules: Input/output compatibility rules
|
|
10
9
|
* - Documentation: User guides and references
|
|
10
|
+
* - Schemas: Action schemas and type definitions
|
|
11
|
+
*
|
|
12
|
+
* Note: File-backed templates (ema://templates/*) were removed.
|
|
13
|
+
* Use API templates via ema://catalog/persona-templates or template() tool.
|
|
11
14
|
*
|
|
12
15
|
* Why resources vs tools:
|
|
13
16
|
* - Resources: Static/reference content the AI assistant reads to understand context
|
|
@@ -97,7 +100,7 @@ function hasPathTraversal(uriPath) {
|
|
|
97
100
|
const RESOURCE_MAP = {
|
|
98
101
|
// Core Documentation (files that exist in this repo)
|
|
99
102
|
"ema://docs/getting-started": {
|
|
100
|
-
path: "
|
|
103
|
+
path: "docs/mcp-tools-guide.md",
|
|
101
104
|
description: "Quick start guide: first steps, key concepts, essential rules, common operations",
|
|
102
105
|
mimeType: "text/markdown",
|
|
103
106
|
},
|
|
@@ -116,42 +119,10 @@ const RESOURCE_MAP = {
|
|
|
116
119
|
description: "MCP tools usage guide: tool categories, best practices, example call sequences, workflow review patterns",
|
|
117
120
|
mimeType: "text/markdown",
|
|
118
121
|
},
|
|
119
|
-
// Templates -
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
mimeType: "application/json",
|
|
124
|
-
},
|
|
125
|
-
"ema://templates/voice-ai/workflow-prompt": {
|
|
126
|
-
path: "resources/templates/voice-ai/workflow-prompt.md",
|
|
127
|
-
description: "Voice AI Auto Builder prompt template with node definitions, connections, and validation assertions",
|
|
128
|
-
mimeType: "text/markdown",
|
|
129
|
-
},
|
|
130
|
-
"ema://templates/voice-ai/readme": {
|
|
131
|
-
path: "resources/templates/voice-ai/README.md",
|
|
132
|
-
description: "Voice AI deployment guide: setup steps, testing checklist, maintenance procedures",
|
|
133
|
-
mimeType: "text/markdown",
|
|
134
|
-
},
|
|
135
|
-
"ema://templates/chat-ai/config": {
|
|
136
|
-
path: "resources/templates/chat-ai/persona-config.json",
|
|
137
|
-
description: "Chat AI persona configuration template: chatbotSdkConfig, feedbackMessage, fileUpload settings",
|
|
138
|
-
mimeType: "application/json",
|
|
139
|
-
},
|
|
140
|
-
"ema://templates/chat-ai/readme": {
|
|
141
|
-
path: "resources/templates/chat-ai/README.md",
|
|
142
|
-
description: "Chat AI deployment guide: workflow generation, widget configuration, knowledge base setup",
|
|
143
|
-
mimeType: "text/markdown",
|
|
144
|
-
},
|
|
145
|
-
"ema://templates/dashboard-ai/config": {
|
|
146
|
-
path: "resources/templates/dashboard-ai/persona-config.json",
|
|
147
|
-
description: "Dashboard AI persona configuration template: inputSchema, batchSettings, timeout configuration",
|
|
148
|
-
mimeType: "application/json",
|
|
149
|
-
},
|
|
150
|
-
"ema://templates/dashboard-ai/readme": {
|
|
151
|
-
path: "resources/templates/dashboard-ai/README.md",
|
|
152
|
-
description: "Dashboard AI deployment guide: batch processing setup, input configuration",
|
|
153
|
-
mimeType: "text/markdown",
|
|
154
|
-
},
|
|
122
|
+
// Templates - REMOVED (file-backed templates removed in favor of API + generated fallbacks)
|
|
123
|
+
// Use: client.getPersonaTemplates() for live API templates
|
|
124
|
+
// Use: getTemplateFallback("voice") from sdk/generated/template-fallbacks.ts for offline fallbacks
|
|
125
|
+
// See: ema://catalog/persona-templates for dynamic API-backed template listing
|
|
155
126
|
// DEPRECATED: Use ema://docs/usage-guide (dynamic) instead
|
|
156
127
|
// This static resource is kept for backwards compatibility but now generates from guidance module
|
|
157
128
|
};
|
|
@@ -236,7 +207,7 @@ const DYNAMIC_RESOURCES = [
|
|
|
236
207
|
mimeType: "application/json",
|
|
237
208
|
generate: async () => JSON.stringify(OPTIMIZATION_RULES, null, 2),
|
|
238
209
|
},
|
|
239
|
-
// Persona Templates - Dynamic from API
|
|
210
|
+
// Persona Templates - Dynamic from API with fallback
|
|
240
211
|
{
|
|
241
212
|
uri: "ema://catalog/templates",
|
|
242
213
|
name: "catalog/templates",
|
|
@@ -244,7 +215,15 @@ const DYNAMIC_RESOURCES = [
|
|
|
244
215
|
mimeType: "application/json",
|
|
245
216
|
generate: async (ctx) => {
|
|
246
217
|
const templates = await getDynamicPersonaTemplates({ env: ctx.env });
|
|
247
|
-
|
|
218
|
+
if (templates.length > 0) {
|
|
219
|
+
return JSON.stringify(templates.map(templateDtoToResource), null, 2);
|
|
220
|
+
}
|
|
221
|
+
// Fallback when API unavailable - provide guidance
|
|
222
|
+
return JSON.stringify({
|
|
223
|
+
_note: "API templates unavailable. Use catalog(method='list', type='templates') tool which connects to API directly, or use template(config='voice|chat|dashboard') for config fallbacks.",
|
|
224
|
+
fallback_types: ["voice", "chat", "dashboard"],
|
|
225
|
+
how_to_get: "catalog(method='list', type='templates') or template(config='voice')",
|
|
226
|
+
}, null, 2);
|
|
248
227
|
},
|
|
249
228
|
},
|
|
250
229
|
{
|
|
@@ -255,7 +234,28 @@ const DYNAMIC_RESOURCES = [
|
|
|
255
234
|
generate: async (ctx) => {
|
|
256
235
|
const templates = await getDynamicPersonaTemplates({ env: ctx.env });
|
|
257
236
|
if (templates.length === 0) {
|
|
258
|
-
return
|
|
237
|
+
return `# Persona Templates
|
|
238
|
+
|
|
239
|
+
> API templates not available. Use one of these alternatives:
|
|
240
|
+
|
|
241
|
+
## Option 1: Use the catalog tool directly
|
|
242
|
+
\`\`\`
|
|
243
|
+
catalog(method="list", type="templates")
|
|
244
|
+
\`\`\`
|
|
245
|
+
This connects to the API and may have different credentials.
|
|
246
|
+
|
|
247
|
+
## Option 2: Use config fallbacks
|
|
248
|
+
\`\`\`
|
|
249
|
+
template(config="voice") // Voice AI config template
|
|
250
|
+
template(config="chat") // Chat AI config template
|
|
251
|
+
template(config="dashboard") // Dashboard AI config template
|
|
252
|
+
\`\`\`
|
|
253
|
+
|
|
254
|
+
## Option 3: Create from scratch
|
|
255
|
+
\`\`\`
|
|
256
|
+
persona(method="create", name="My AI", type="voice|chat|dashboard")
|
|
257
|
+
\`\`\`
|
|
258
|
+
`;
|
|
259
259
|
}
|
|
260
260
|
const byCategory = new Map();
|
|
261
261
|
for (const t of templates) {
|
|
@@ -727,10 +727,11 @@ export class ResourceRegistry {
|
|
|
727
727
|
buildResourceIndex() {
|
|
728
728
|
const resources = this.list().filter((r) => r.uri !== "ema://index/all-resources");
|
|
729
729
|
// Group resources by category
|
|
730
|
+
// Note: ema://templates/* file-backed resources removed - use API templates or generated fallbacks
|
|
730
731
|
const docs = resources.filter((r) => r.uri.startsWith("ema://docs/"));
|
|
731
|
-
const templates = resources.filter((r) => r.uri.startsWith("ema://templates/"));
|
|
732
732
|
const catalog = resources.filter((r) => r.uri.startsWith("ema://catalog/"));
|
|
733
733
|
const rules = resources.filter((r) => r.uri.startsWith("ema://rules/"));
|
|
734
|
+
const schemas = resources.filter((r) => r.uri.startsWith("ema://schema/"));
|
|
734
735
|
const markdown = `# Ema MCP Resources Index
|
|
735
736
|
|
|
736
737
|
> Available resources exposed by the Ema MCP Server
|
|
@@ -742,9 +743,9 @@ export class ResourceRegistry {
|
|
|
742
743
|
| Category | Count | Description |
|
|
743
744
|
|----------|-------|-------------|
|
|
744
745
|
| Documentation | ${docs.length} | User guides, README, tool references |
|
|
745
|
-
|
|
|
746
|
-
| Catalog | ${catalog.length} | Agent catalog, workflow patterns, widgets |
|
|
746
|
+
| Catalog | ${catalog.length} | Agent catalog, workflow patterns, templates |
|
|
747
747
|
| Rules | ${rules.length} | Validation rules, anti-patterns, optimizations |
|
|
748
|
+
| Schemas | ${schemas.length} | Action schemas, type definitions |
|
|
748
749
|
|
|
749
750
|
## Documentation (${docs.length})
|
|
750
751
|
|
|
@@ -752,14 +753,6 @@ export class ResourceRegistry {
|
|
|
752
753
|
|-----|-------------|
|
|
753
754
|
${docs.map((r) => `| \`${r.uri}\` | ${r.description} |`).join("\n")}
|
|
754
755
|
|
|
755
|
-
## Templates (${templates.length})
|
|
756
|
-
|
|
757
|
-
> Use templates as starting points for new AI Employees
|
|
758
|
-
|
|
759
|
-
| URI | Description |
|
|
760
|
-
|-----|-------------|
|
|
761
|
-
${templates.map((r) => `| \`${r.uri}\` | ${r.description} |`).join("\n")}
|
|
762
|
-
|
|
763
756
|
## Catalog (${catalog.length})
|
|
764
757
|
|
|
765
758
|
> Dynamic catalogs generated from SDK knowledge
|
|
@@ -776,6 +769,14 @@ ${catalog.map((r) => `| \`${r.uri}\` | ${r.description} |`).join("\n")}
|
|
|
776
769
|
|-----|-------------|
|
|
777
770
|
${rules.map((r) => `| \`${r.uri}\` | ${r.description} |`).join("\n")}
|
|
778
771
|
|
|
772
|
+
## Schemas (${schemas.length})
|
|
773
|
+
|
|
774
|
+
> Action schemas and type definitions
|
|
775
|
+
|
|
776
|
+
| URI | Description |
|
|
777
|
+
|-----|-------------|
|
|
778
|
+
${schemas.map((r) => `| \`${r.uri}\` | ${r.description} |`).join("\n")}
|
|
779
|
+
|
|
779
780
|
## Usage
|
|
780
781
|
|
|
781
782
|
To read a resource, use the \`resources/read\` endpoint:
|
|
@@ -795,7 +796,7 @@ To read a resource, use the \`resources/read\` endpoint:
|
|
|
795
796
|
|------|-----|
|
|
796
797
|
| Get agent definitions | Resource: \`ema://catalog/agents\` |
|
|
797
798
|
| Get input/output compatibility rules | Resource: \`ema://rules/input-sources\` |
|
|
798
|
-
| Get persona
|
|
799
|
+
| Get persona templates | Resource: \`ema://catalog/persona-templates\` (API) or Tool: \`template(config="voice")\` |
|
|
799
800
|
| Query live persona data | Tool: \`persona\` |
|
|
800
801
|
| Generate a workflow | Tool: \`workflow\` |
|
|
801
802
|
| Analyze an existing workflow | Tool: \`workflow(mode="analyze")\` |
|
package/dist/mcp/server.js
CHANGED
|
@@ -41,22 +41,22 @@ import { createVersionPolicyEngine } from "../sdk/version-policy.js";
|
|
|
41
41
|
import { getToolkitRoot } from "../sdk/paths.js";
|
|
42
42
|
import { SYNC_METADATA_KEY } from "../sdk/models.js";
|
|
43
43
|
// Auto Builder Knowledge
|
|
44
|
-
import { AGENT_CATALOG, WIDGET_CATALOG, WORKFLOW_PATTERNS, QUALIFYING_QUESTIONS, PLATFORM_CONCEPTS, WORKFLOW_EXECUTION_MODEL, COMMON_MISTAKES, DEBUG_CHECKLIST, GUIDANCE_TOPICS,
|
|
44
|
+
import { AGENT_CATALOG, WIDGET_CATALOG, WORKFLOW_PATTERNS, QUALIFYING_QUESTIONS, PLATFORM_CONCEPTS, WORKFLOW_EXECUTION_MODEL, COMMON_MISTAKES, DEBUG_CHECKLIST, GUIDANCE_TOPICS, PROJECT_TYPES, getAgentsByCategory, getAgentByName, getWidgetsForPersonaType, checkTypeCompatibility, getQualifyingQuestionsByCategory, getConceptByTerm, suggestAgentsForUseCase, validateWorkflowPrompt,
|
|
45
45
|
// Workflow Analysis
|
|
46
46
|
analyzeWorkflow, detectWorkflowIssues, validateWorkflowConnections, suggestWorkflowFixes, } from "../sdk/knowledge.js";
|
|
47
|
+
// Template fallbacks (generated from protos, used when API unavailable)
|
|
48
|
+
import { getTemplateFallback, getTemplateFieldDocs, VOICE_TEMPLATE_FALLBACK } from "../sdk/generated/template-fallbacks.js";
|
|
47
49
|
// Workflow Compiler (Template-driven)
|
|
48
50
|
import { compileWorkflow, } from "../sdk/workflow-generator.js";
|
|
49
51
|
// V2 Tools (4 tools: persona, catalog, sync, env) - NEW DEFAULT
|
|
50
|
-
import {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
//
|
|
57
|
-
|
|
58
|
-
const ENABLE_LEGACY_TOOLS = process.env.EMA_ENABLE_LEGACY_TOOLS === "true";
|
|
59
|
-
import { handleEnv, handlePersona, handleWorkflow, handleAction, handleData, handleTemplate, handleKnowledge, handleReference, } from "./handlers-consolidated.js";
|
|
52
|
+
import { generateTools, } from "./tools.js";
|
|
53
|
+
import { handleEnv, handlePersona,
|
|
54
|
+
// handleWorkflow - removed, now using extracted handler from ./handlers/workflow/index.js
|
|
55
|
+
handleAction,
|
|
56
|
+
// handleData - removed, now using extracted handler from ./handlers/data/index.js
|
|
57
|
+
handleTemplate, handleKnowledge, handleReference, } from "./handlers-consolidated.js";
|
|
58
|
+
// Import extracted handlers
|
|
59
|
+
import { handleWorkflow } from "./handlers/workflow/index.js";
|
|
60
60
|
// Import from handler utilities (normalizeTriggerType uses generated enum labels)
|
|
61
61
|
import { normalizeTriggerType } from "./handlers/utils.js";
|
|
62
62
|
// Import from SDK proto-config (CANONICAL widget validation and merging)
|
|
@@ -1093,102 +1093,46 @@ function withEnvParam(props, required = []) {
|
|
|
1093
1093
|
// Tool Definitions
|
|
1094
1094
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
1095
1095
|
//
|
|
1096
|
-
//
|
|
1097
|
-
//
|
|
1098
|
-
//
|
|
1099
|
-
// - Defined in: ./tools-consolidated.ts
|
|
1100
|
-
//
|
|
1101
|
-
// 2. LEGACY TOOLS (40+ tools) - Old separate tools for backwards compatibility
|
|
1102
|
-
// - Defined in: ./tools-legacy.ts
|
|
1103
|
-
// - Enable with EMA_ENABLE_LEGACY_TOOLS=true
|
|
1096
|
+
// V2 TOOLS (5 tools) - LLM-optimized minimal interface
|
|
1097
|
+
// - env, persona, catalog, workflow, sync
|
|
1098
|
+
// - Defined in: ./tools.ts
|
|
1104
1099
|
//
|
|
1105
1100
|
// NAMING CONVENTION:
|
|
1106
|
-
// - Tool names are defined as BASE NAMES (e.g., "persona"
|
|
1101
|
+
// - Tool names are defined as BASE NAMES (e.g., "persona")
|
|
1107
1102
|
// - MCP clients prefix with "mcp_{server}_" (e.g., "mcp_ema_persona")
|
|
1108
1103
|
//
|
|
1109
1104
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
1110
1105
|
/**
|
|
1111
|
-
* Generate all available tools
|
|
1106
|
+
* Generate all available tools
|
|
1112
1107
|
*
|
|
1113
|
-
*
|
|
1114
|
-
* - V2 (default): 4 tools (persona, catalog, sync, env) - LLM-optimized
|
|
1115
|
-
* - V1: 7 mode-based tools - set EMA_ENABLE_V1_TOOLS=true
|
|
1116
|
-
* - Legacy: Individual tools - set EMA_ENABLE_LEGACY_TOOLS=true
|
|
1108
|
+
* V2: 5 tools (persona, catalog, workflow, sync, env) - LLM-optimized
|
|
1117
1109
|
*
|
|
1118
|
-
* Why V2
|
|
1110
|
+
* Why V2:
|
|
1119
1111
|
* - Minimal tool count optimizes LLM tool selection
|
|
1120
1112
|
* - Data operations under persona (always persona-scoped)
|
|
1121
1113
|
* - Catalog consolidates all reference data (actions, templates, etc.)
|
|
1122
|
-
* - Clear separation: entity (persona), reference (catalog), operation (sync)
|
|
1114
|
+
* - Clear separation: entity (persona), reference (catalog), operation (sync, workflow)
|
|
1123
1115
|
*/
|
|
1124
1116
|
function generateAllTools() {
|
|
1125
1117
|
const envNames = getAvailableEnvironments().map(e => e.name);
|
|
1126
1118
|
const defaultEnv = getDefaultEnvName();
|
|
1127
|
-
|
|
1128
|
-
if (ENABLE_V1_TOOLS) {
|
|
1129
|
-
console.error("[MCP] V1 mode-based tools enabled via EMA_ENABLE_V1_TOOLS=true");
|
|
1130
|
-
const consolidatedTools = generateConsolidatedTools(envNames, defaultEnv);
|
|
1131
|
-
if (ENABLE_LEGACY_TOOLS) {
|
|
1132
|
-
console.error("[MCP] WARNING: Legacy tools also enabled");
|
|
1133
|
-
const legacyTools = generateLegacyTools(envNames, defaultEnv);
|
|
1134
|
-
return [...consolidatedTools, ...legacyTools];
|
|
1135
|
-
}
|
|
1136
|
-
return consolidatedTools;
|
|
1137
|
-
}
|
|
1138
|
-
// V2 minimal tools (default) - 4 tools: persona, catalog, sync, env
|
|
1139
|
-
const v2Tools = generateToolsV2(envNames, defaultEnv);
|
|
1140
|
-
if (ENABLE_LEGACY_TOOLS) {
|
|
1141
|
-
console.error("[MCP] WARNING: Legacy tools enabled alongside V2");
|
|
1142
|
-
const legacyTools = generateLegacyTools(envNames, defaultEnv);
|
|
1143
|
-
return [...v2Tools, ...legacyTools];
|
|
1144
|
-
}
|
|
1145
|
-
return v2Tools;
|
|
1119
|
+
return generateTools(envNames, defaultEnv);
|
|
1146
1120
|
}
|
|
1147
1121
|
// Generate tools (called once at module load)
|
|
1148
1122
|
const TOOLS = generateAllTools();
|
|
1149
1123
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
1150
|
-
// ADDITIONAL TOOLS (
|
|
1151
|
-
// These
|
|
1124
|
+
// ADDITIONAL TOOLS (special-purpose inline tools)
|
|
1125
|
+
// These handle specific operations that don't fit the V2 pattern
|
|
1152
1126
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
1153
1127
|
const ADDITIONAL_TOOLS = [
|
|
1154
|
-
//
|
|
1155
|
-
// NOTE: Legacy tools (get_persona, find_personas, create_ai_employee, etc.)
|
|
1156
|
-
// have been moved to ./tools-legacy.ts for backwards compatibility.
|
|
1157
|
-
//
|
|
1158
|
-
// Consolidated tools (persona, workflow, action, etc.) are generated from
|
|
1159
|
-
// ./tools-consolidated.ts following Unix CLI patterns.
|
|
1128
|
+
// NOTE: Tools (persona, catalog, workflow, sync, env) are in ./tools.ts
|
|
1160
1129
|
//
|
|
1161
|
-
//
|
|
1162
|
-
// -
|
|
1163
|
-
// - Demo data tools -
|
|
1164
|
-
//
|
|
1165
|
-
// INLINE LEGACY TOOLS REMOVED
|
|
1166
|
-
// All legacy tools (get_workflow_action, find_workflow_actions, compare_ai_employees,
|
|
1167
|
-
// list_ai_employee_templates, sync, sync_info, list_auto_builder_agents, etc.)
|
|
1168
|
-
// have been moved to ./tools-legacy.ts
|
|
1169
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
1170
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
1171
|
-
// LEGACY INLINE TOOLS REMOVED - See ./tools-legacy.ts
|
|
1172
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
1173
|
-
// The following tools have been removed from this file and are now generated
|
|
1174
|
-
// from tools-legacy.ts: list_auto_builder_agents, get_auto_builder_agent,
|
|
1175
|
-
// suggest_agents_for_use_case, get_workflow_pattern, list_workflow_patterns,
|
|
1176
|
-
// check_type_compatibility, get_widget_reference, get_qualifying_questions,
|
|
1177
|
-
// get_voice_persona_template, validate_workflow_prompt, get_auto_builder_guidance,
|
|
1178
|
-
// get_platform_concept, list_platform_concepts, get_common_mistakes,
|
|
1179
|
-
// get_debug_checklist, get_workflow_execution_model, analyze_workflow,
|
|
1180
|
-
// detect_workflow_issues, validate_workflow_connections, suggest_workflow_fixes,
|
|
1181
|
-
// compare_workflow_versions, get_workflow_metrics, compile_workflow,
|
|
1182
|
-
// upload_data_source, delete_data_source, list_data_sources, get_embedding_status,
|
|
1130
|
+
// Special-purpose tools here:
|
|
1131
|
+
// - compile_workflow - Direct workflow compilation
|
|
1132
|
+
// - Demo data tools - RAG document generation/validation
|
|
1133
|
+
// - Data source tools - Upload/delete/manage knowledge sources
|
|
1183
1134
|
// toggle_embedding
|
|
1184
1135
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
1185
|
-
// The remaining legacy tools are handled by the LEGACY_TOOL_MAPPING in
|
|
1186
|
-
// tools-consolidated.ts for routing to consolidated handlers.
|
|
1187
|
-
//
|
|
1188
|
-
// INLINE DEFINITIONS REMOVED - They are now in tools-legacy.ts
|
|
1189
|
-
// (analyze_workflow, detect_workflow_issues, validate_workflow_connections, suggest_workflow_fixes)
|
|
1190
|
-
// (compare_workflow_versions, get_workflow_metrics) - moved to tools-legacy.ts
|
|
1191
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
1192
1136
|
// Workflow Compilation - Template-driven, no biased patterns
|
|
1193
1137
|
// Read ema://catalog/patterns for pattern references, then construct nodes
|
|
1194
1138
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
@@ -1606,11 +1550,6 @@ Returns:
|
|
|
1606
1550
|
required: ["entity_type"],
|
|
1607
1551
|
},
|
|
1608
1552
|
},
|
|
1609
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
1610
|
-
// CONSOLIDATED TOOLS (Unix CLI pattern)
|
|
1611
|
-
// These 9 tools follow Unix conventions: single command with flags
|
|
1612
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
1613
|
-
...generateConsolidatedTools(getAvailableEnvironments().map(e => e.name), getDefaultEnvName()),
|
|
1614
1553
|
];
|
|
1615
1554
|
const toolHandlers = {
|
|
1616
1555
|
// Environment Management
|
|
@@ -2826,10 +2765,14 @@ const toolHandlers = {
|
|
|
2826
2765
|
};
|
|
2827
2766
|
},
|
|
2828
2767
|
get_voice_persona_template: async () => {
|
|
2768
|
+
// Use generated fallback from proto definitions
|
|
2769
|
+
// In production, prefer API templates via client.getPersonaTemplates()
|
|
2770
|
+
const template = getTemplateFallback("voice");
|
|
2829
2771
|
return {
|
|
2830
|
-
template:
|
|
2831
|
-
|
|
2832
|
-
|
|
2772
|
+
template: template || VOICE_TEMPLATE_FALLBACK,
|
|
2773
|
+
field_docs: getTemplateFieldDocs("voice"),
|
|
2774
|
+
required_fields: ["conversationSettings.welcomeMessage", "conversationSettings.identityAndPurpose", "conversationSettings.takeActionInstructions", "conversationSettings.hangupInstructions"],
|
|
2775
|
+
optional_fields: ["conversationSettings.transferCallInstructions", "conversationSettings.speechCharacteristics", "conversationSettings.systemPrompt", "conversationSettings.formFillingInstructions", "conversationSettings.waitMessage"],
|
|
2833
2776
|
project_type: PROJECT_TYPES.voice,
|
|
2834
2777
|
widget_ids: {
|
|
2835
2778
|
voiceSettings: 38,
|
|
@@ -2837,12 +2780,8 @@ const toolHandlers = {
|
|
|
2837
2780
|
vadSettings: 43,
|
|
2838
2781
|
dataStorageSettings: 42,
|
|
2839
2782
|
},
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
"takeActionInstructions uses </Case N> format for each action",
|
|
2843
|
-
"speechCharacteristics should include TTS pronunciation rules",
|
|
2844
|
-
"systemPrompt defines tool calling behavior",
|
|
2845
|
-
],
|
|
2783
|
+
_source: "generated_fallback",
|
|
2784
|
+
_note: "This template is auto-generated from proto definitions. For live templates, use client.getPersonaTemplates().",
|
|
2846
2785
|
};
|
|
2847
2786
|
},
|
|
2848
2787
|
validate_workflow_prompt: async (args) => {
|
|
@@ -4049,28 +3988,32 @@ const toolHandlers = {
|
|
|
4049
3988
|
const { handleData: handleDataNew } = await import("./handlers/data/index.js");
|
|
4050
3989
|
return handleDataNew({ persona_id: personaId, env: args.env, data }, client);
|
|
4051
3990
|
}
|
|
4052
|
-
// LEGACY FLAG FORMAT (backwards compatibility)
|
|
3991
|
+
// LEGACY FLAG FORMAT (backwards compatibility) - use extracted handler
|
|
3992
|
+
const { handleData: handleDataExtracted } = await import("./handlers/data/index.js");
|
|
3993
|
+
const readFileFn = (path) => fs.readFile(path);
|
|
4053
3994
|
if (data.list === true) {
|
|
4054
|
-
return
|
|
3995
|
+
return handleDataExtracted({ method: "list", persona_id: personaId, env: args.env }, client, readFileFn);
|
|
4055
3996
|
}
|
|
4056
3997
|
if (typeof data.upload === "string") {
|
|
4057
|
-
return
|
|
3998
|
+
return handleDataExtracted({ method: "upload", persona_id: personaId, data: { path: data.upload }, env: args.env }, client, readFileFn);
|
|
4058
3999
|
}
|
|
4059
4000
|
if (typeof data.delete === "string") {
|
|
4060
|
-
return
|
|
4001
|
+
return handleDataExtracted({ method: "delete", persona_id: personaId, data: { file_id: data.delete }, env: args.env }, client, readFileFn);
|
|
4061
4002
|
}
|
|
4062
4003
|
if (typeof data.generate === "string" || data.template) {
|
|
4063
|
-
return
|
|
4064
|
-
|
|
4004
|
+
return handleDataExtracted({
|
|
4005
|
+
method: "generate",
|
|
4065
4006
|
persona_id: personaId,
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4007
|
+
data: {
|
|
4008
|
+
input: data.generate,
|
|
4009
|
+
from: data.template,
|
|
4010
|
+
count: data.count,
|
|
4011
|
+
},
|
|
4069
4012
|
env: args.env
|
|
4070
|
-
}, client,
|
|
4013
|
+
}, client, readFileFn);
|
|
4071
4014
|
}
|
|
4072
4015
|
if (typeof data.embed === "boolean") {
|
|
4073
|
-
return
|
|
4016
|
+
return handleDataExtracted({ method: "embedding", persona_id: personaId, data: { enabled: data.embed }, env: args.env }, client, readFileFn);
|
|
4074
4017
|
}
|
|
4075
4018
|
if (typeof data.search === "string") {
|
|
4076
4019
|
return handleKnowledge({ mode: "search", persona_id: personaId, query: data.search, env: args.env }, client, (path) => fs.readFile(path));
|
|
@@ -4149,7 +4092,9 @@ const toolHandlers = {
|
|
|
4149
4092
|
data: async (args) => {
|
|
4150
4093
|
const client = createClient(args.env);
|
|
4151
4094
|
const fs = await import("fs/promises");
|
|
4152
|
-
|
|
4095
|
+
// Use extracted handler
|
|
4096
|
+
const { handleData: handleDataExtracted } = await import("./handlers/data/index.js");
|
|
4097
|
+
return handleDataExtracted(args, client, (path) => fs.readFile(path));
|
|
4153
4098
|
},
|
|
4154
4099
|
reference: async (args) => {
|
|
4155
4100
|
// v2: expanded reference handler with envs, actions, templates, patterns support
|
|
@@ -4169,9 +4114,11 @@ const toolHandlers = {
|
|
|
4169
4114
|
// catalog: Consolidated reference data (actions, templates, widgets, voices, patterns, concepts)
|
|
4170
4115
|
catalog: async (args) => {
|
|
4171
4116
|
const catalogType = args.type;
|
|
4117
|
+
const method = args.method;
|
|
4172
4118
|
const id = args.id;
|
|
4173
4119
|
const query = args.query;
|
|
4174
|
-
|
|
4120
|
+
// Note: schema uses 'for' parameter for recommend (not 'recommend')
|
|
4121
|
+
const forUseCase = args.for;
|
|
4175
4122
|
const category = args.category;
|
|
4176
4123
|
const client = createClient(args.env);
|
|
4177
4124
|
if (!catalogType) {
|
|
@@ -4183,9 +4130,16 @@ const toolHandlers = {
|
|
|
4183
4130
|
switch (catalogType) {
|
|
4184
4131
|
case "actions": {
|
|
4185
4132
|
// Route to action handler
|
|
4186
|
-
if (recommend) {
|
|
4187
|
-
const suggestions = suggestAgentsForUseCase(
|
|
4188
|
-
return {
|
|
4133
|
+
if (method === "recommend" && forUseCase) {
|
|
4134
|
+
const suggestions = suggestAgentsForUseCase(forUseCase);
|
|
4135
|
+
return {
|
|
4136
|
+
type: "actions",
|
|
4137
|
+
use_case: forUseCase,
|
|
4138
|
+
recommendations: suggestions,
|
|
4139
|
+
_tip: suggestions.length > 0
|
|
4140
|
+
? `Found ${suggestions.length} relevant agents. Use catalog(method="get", type="actions", id="<name>") for details.`
|
|
4141
|
+
: "No specific recommendations. Try browsing with catalog(method=\"list\", type=\"actions\").",
|
|
4142
|
+
};
|
|
4189
4143
|
}
|
|
4190
4144
|
if (id) {
|
|
4191
4145
|
const action = getAgentByName(id);
|
|
@@ -4209,7 +4163,9 @@ const toolHandlers = {
|
|
|
4209
4163
|
return {
|
|
4210
4164
|
type: "actions",
|
|
4211
4165
|
count: actions.length,
|
|
4212
|
-
actions: actions.map(a => ({ name: a.actionName, displayName: a.displayName, category: a.category, description: a.description }))
|
|
4166
|
+
actions: actions.map(a => ({ name: a.actionName, displayName: a.displayName, category: a.category, description: a.description })),
|
|
4167
|
+
_tip: "Get details: catalog(method=\"get\", type=\"actions\", id=\"<name>\")",
|
|
4168
|
+
_next_step: actions.length > 0 ? `catalog(method="get", type="actions", id="${actions[0].actionName}")` : undefined,
|
|
4213
4169
|
};
|
|
4214
4170
|
}
|
|
4215
4171
|
case "templates": {
|
|
@@ -4231,7 +4187,13 @@ const toolHandlers = {
|
|
|
4231
4187
|
return {
|
|
4232
4188
|
type: "templates",
|
|
4233
4189
|
count: filtered.length,
|
|
4234
|
-
templates: filtered.map(t => ({ id: t.id, name: t.name, description: t.description }))
|
|
4190
|
+
templates: filtered.map(t => ({ id: t.id, name: t.name, description: t.description })),
|
|
4191
|
+
_tip: filtered.length > 0
|
|
4192
|
+
? "Create from template: persona(method=\"create\", name=\"My AI\", from=\"<template_id>\")"
|
|
4193
|
+
: "No templates found. Create from scratch: persona(method=\"create\", name=\"My AI\", type=\"voice|chat|dashboard\")",
|
|
4194
|
+
_next_step: filtered.length > 0
|
|
4195
|
+
? `catalog(method="get", type="templates", id="${filtered[0].id}")`
|
|
4196
|
+
: undefined,
|
|
4235
4197
|
};
|
|
4236
4198
|
}
|
|
4237
4199
|
case "widgets": {
|
|
@@ -4266,13 +4228,20 @@ const toolHandlers = {
|
|
|
4266
4228
|
};
|
|
4267
4229
|
}
|
|
4268
4230
|
case "patterns": {
|
|
4269
|
-
if (recommend) {
|
|
4231
|
+
if (method === "recommend" && forUseCase) {
|
|
4270
4232
|
// Find patterns matching use case
|
|
4271
|
-
const q =
|
|
4233
|
+
const q = forUseCase.toLowerCase();
|
|
4272
4234
|
const matches = WORKFLOW_PATTERNS.filter(p => p.name.toLowerCase().includes(q) ||
|
|
4273
4235
|
p.description.toLowerCase().includes(q) ||
|
|
4274
4236
|
p.useCase.toLowerCase().includes(q));
|
|
4275
|
-
return {
|
|
4237
|
+
return {
|
|
4238
|
+
type: "patterns",
|
|
4239
|
+
use_case: forUseCase,
|
|
4240
|
+
recommendations: matches,
|
|
4241
|
+
_tip: matches.length > 0
|
|
4242
|
+
? `Found ${matches.length} matching patterns. Use catalog(method="get", type="patterns", id="<name>") for full details.`
|
|
4243
|
+
: "No matching patterns. Try catalog(method=\"list\", type=\"patterns\") to see all available.",
|
|
4244
|
+
};
|
|
4276
4245
|
}
|
|
4277
4246
|
if (id) {
|
|
4278
4247
|
const pattern = WORKFLOW_PATTERNS.find(p => p.name === id);
|
|
@@ -4324,14 +4293,14 @@ const toolHandlers = {
|
|
|
4324
4293
|
// Note: demo is handled via a consolidated adapter below
|
|
4325
4294
|
};
|
|
4326
4295
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
4327
|
-
//
|
|
4296
|
+
// V2 Tool Adapters (contract ↔ implementation)
|
|
4328
4297
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
4329
4298
|
//
|
|
4330
|
-
// The tool schemas in tools
|
|
4331
|
-
// This file still contains
|
|
4299
|
+
// The tool schemas in tools.ts are the public MCP contract.
|
|
4300
|
+
// This file still contains proven handlers that we reuse
|
|
4332
4301
|
// (e.g. deploy_workflow, optimize_workflow, compile_workflow, etc.).
|
|
4333
4302
|
//
|
|
4334
|
-
// These adapters ensure the
|
|
4303
|
+
// These adapters ensure the V2 tool surface behaves as documented,
|
|
4335
4304
|
// while preserving the existing internal implementations.
|
|
4336
4305
|
const legacyWorkflowTool = toolHandlers.workflow;
|
|
4337
4306
|
const legacyDeployWorkflow = toolHandlers.deploy_workflow;
|
|
@@ -4904,8 +4873,8 @@ function determineOperation(toolName, args) {
|
|
|
4904
4873
|
if (toolName === "catalog") {
|
|
4905
4874
|
if (args.id)
|
|
4906
4875
|
return "get";
|
|
4907
|
-
if (args.
|
|
4908
|
-
return "recommend";
|
|
4876
|
+
if (args.for)
|
|
4877
|
+
return "recommend"; // V2 schema uses 'for' parameter
|
|
4909
4878
|
if (args.query)
|
|
4910
4879
|
return "search";
|
|
4911
4880
|
return "list";
|
|
@@ -19,7 +19,7 @@ import { generateInputDescription, SUPPORTED_OPERATIONS, LIMITATIONS } from "./w
|
|
|
19
19
|
/**
|
|
20
20
|
* Generate the v2 tool set
|
|
21
21
|
*/
|
|
22
|
-
export function
|
|
22
|
+
export function generateTools(envNames, defaultEnv) {
|
|
23
23
|
const envDescription = envNames.length > 0
|
|
24
24
|
? `Environment: ${envNames.join(", ")}. Default: ${defaultEnv}`
|
|
25
25
|
: "Environment name";
|