@ema.co/mcp-toolkit 2026.1.25 → 2026.1.26-4

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 (87) 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 +47 -18
  9. package/dist/mcp/handlers/persona/index.js +14 -11
  10. package/dist/mcp/handlers/persona/update.js +4 -2
  11. package/dist/mcp/handlers/persona/version.js +234 -0
  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/deploy.js +73 -0
  17. package/dist/mcp/handlers/workflow/generate.js +350 -0
  18. package/dist/mcp/handlers/workflow/index.js +294 -0
  19. package/dist/mcp/handlers/workflow/modify.js +456 -0
  20. package/dist/mcp/handlers/workflow/optimize.js +136 -0
  21. package/dist/mcp/handlers/workflow/types.js +4 -0
  22. package/dist/mcp/handlers/workflow/utils.js +30 -0
  23. package/dist/mcp/handlers-consolidated.js +73 -2696
  24. package/dist/mcp/prompts.js +83 -43
  25. package/dist/mcp/resources.js +382 -57
  26. package/dist/mcp/server.js +199 -391
  27. package/dist/mcp/{tools-v2.js → tools.js} +20 -54
  28. package/dist/mcp/workflow-operations.js +2 -2
  29. package/dist/sdk/client-adapter.js +267 -32
  30. package/dist/sdk/client.js +45 -16
  31. package/dist/sdk/ema-client.js +183 -0
  32. package/dist/sdk/generated/deprecated-actions.js +171 -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 +139 -86
  37. package/dist/sdk/workflow-intent.js +27 -0
  38. package/dist/sdk/workflow-transformer.js +0 -342
  39. package/docs/mcp-tools-guide.md +37 -45
  40. package/package.json +10 -4
  41. package/dist/mcp/handlers/persona/analyze.js +0 -275
  42. package/dist/mcp/handlers/persona/compare.js +0 -32
  43. package/dist/mcp/tools-consolidated.js +0 -875
  44. package/dist/mcp/tools-legacy.js +0 -736
  45. package/docs/CODEBASE-ANALYSIS-2026-01-23.md +0 -936
  46. package/docs/CODEBASE-ANALYSIS-PRIORITIZED.md +0 -774
  47. package/docs/api-contracts.md +0 -216
  48. package/docs/auto-builder-analysis.md +0 -271
  49. package/docs/blog/mcp-tool-design-lessons.md +0 -309
  50. package/docs/data-architecture.md +0 -166
  51. package/docs/demos/ap-invoice-generation.md +0 -347
  52. package/docs/demos/ap-invoice-processing.md +0 -271
  53. package/docs/ema-auto-builder-guide.html +0 -394
  54. package/docs/lessons-learned.md +0 -209
  55. package/docs/llm-native-workflow-design.md +0 -252
  56. package/docs/local-generation.md +0 -508
  57. package/docs/mcp-flow-diagram.md +0 -135
  58. package/docs/migration/action-composition-migration.md +0 -270
  59. package/docs/naming-conventions.md +0 -278
  60. package/docs/proposals/HANDOFF-tool-restructure.md +0 -526
  61. package/docs/proposals/action-composition.md +0 -490
  62. package/docs/proposals/explicit-method-restructure.md +0 -328
  63. package/docs/proposals/mcp-tool-restructure-2026-01.md +0 -366
  64. package/docs/proposals/self-contained-guidance.md +0 -427
  65. package/docs/proto-sdk-generation.md +0 -242
  66. package/docs/release-impact.md +0 -102
  67. package/docs/release-process.md +0 -157
  68. package/docs/staging.RULE.md +0 -142
  69. package/docs/test-persona-creation.md +0 -196
  70. package/docs/tool-consolidation-v2.md +0 -225
  71. package/docs/tool-response-standards.md +0 -256
  72. package/resources/demo-kits/README.md +0 -175
  73. package/resources/demo-kits/finance-ap/manifest.json +0 -150
  74. package/resources/demo-kits/tags.json +0 -91
  75. package/resources/docs/getting-started.md +0 -97
  76. package/resources/templates/auto-builder-rules.md +0 -224
  77. package/resources/templates/chat-ai/README.md +0 -119
  78. package/resources/templates/chat-ai/persona-config.json +0 -111
  79. package/resources/templates/dashboard-ai/README.md +0 -156
  80. package/resources/templates/dashboard-ai/persona-config.json +0 -180
  81. package/resources/templates/demo-scenarios/README.md +0 -63
  82. package/resources/templates/demo-scenarios/test-published-package.md +0 -116
  83. package/resources/templates/document-gen-ai/README.md +0 -132
  84. package/resources/templates/document-gen-ai/persona-config.json +0 -316
  85. package/resources/templates/voice-ai/README.md +0 -123
  86. package/resources/templates/voice-ai/persona-config.json +0 -74
  87. package/resources/templates/voice-ai/workflow-prompt.md +0 -121
@@ -1,427 +0,0 @@
1
- # Self-Contained MCP Guidance System
2
-
3
- > **ID**: PROP-2026-01-21-guidance
4
- > **Status**: ✅ Complete
5
- > **Created**: 2026-01-21
6
- > **Completed**: 2026-01-21
7
- > **Author**: Architecture Review
8
- > **Implemented-by**: feat/agent-coordination branch
9
-
10
- ## Implementation Tracking
11
-
12
- | Step | Status | Commit | Test | Notes |
13
- |------|--------|--------|------|-------|
14
- | Step 1: guidance.ts | ✅ Done | `pending` | `test/guidance.test.ts` | Centralized guidance content |
15
- | Step 2: Server instructions | ✅ Done | `pending` | - | Add to init response |
16
- | Step 3: Tool descriptions | ✅ Done | `pending` | - | Import TOOL_GUIDANCE into tools-v2.ts |
17
- | Step 4: Response tips | ✅ Done | `pending` | - | _tip + _next_step in responses |
18
- | Step 5: Session onboarding | ✅ Done | `pending` | - | env handler getting_started |
19
- | Step 6: Workflow guidance | ✅ Done | `pending` | - | analyze workflow_guidance |
20
- | Step 7: Self-ref prompts | ✅ Done | `pending` | - | toolkit_onboard → usage-guide |
21
- | Step 8: Usage guide resource | ✅ Done | `pending` | - | ema://docs/usage-guide + 3 more |
22
- | Step 9: Remove externals | ✅ Done | `pending` | - | Legacy redirect + comment cleanup |
23
- | Step 10: Documentation | ✅ Done | `pending` | - | README + mcp-tools-guide |
24
-
25
- ## Change Log
26
-
27
- | Date | Change | By |
28
- |------|--------|-----|
29
- | 2026-01-21 | Created proposal | Architecture Review |
30
- | 2026-01-21 | Added implementation tracking | sp-cursor |
31
- | 2026-01-21 | All 10 steps implemented | sp-cursor |
32
-
33
- ---
34
-
35
- ## Problem Statement
36
-
37
- External customers installing only `npx @ema.co/mcp-toolkit@latest` don't have access to:
38
- - `.cursor/rules/` files (50+ rules)
39
- - `.cursor/agents/` definitions
40
- - `AGENTS.md` / `CLAUDE.md` guidance
41
-
42
- This means they start with zero context about Ema patterns, leading to:
43
- - Misuse of tools (wrong order, missing steps)
44
- - Anti-patterns (no Fallback, skipping analysis)
45
- - Inconsistent experiences across different IDEs
46
-
47
- ## Design Principles
48
-
49
- 1. **IDE Agnostic**: Works identically in Cursor, Claude Desktop, any MCP client
50
- 2. **Progressive Disclosure**: Start minimal, provide more on request
51
- 3. **Context-Aware**: Different guidance for different operations
52
- 4. **Single Source of Truth**: All guidance lives in MCP package, not external files
53
- 5. **Fail-Safe**: Even if guidance is ignored, tool responses guide correct usage
54
-
55
- ## Architecture
56
-
57
- ```
58
- ┌─────────────────────────────────────────────────────────┐
59
- │ MCP Toolkit │
60
- ├─────────────────────────────────────────────────────────┤
61
- │ Layer 1: Server Instructions (on init) │
62
- │ - Core workflow patterns │
63
- │ - Essential rules (~300 tokens) │
64
- ├─────────────────────────────────────────────────────────┤
65
- │ Layer 2: Tool Descriptions (on tools/list) │
66
- │ - Per-tool usage patterns │
67
- │ - Common mistakes to avoid │
68
- ├─────────────────────────────────────────────────────────┤
69
- │ Layer 3: Contextual Tips (in tool responses) │
70
- │ - Next-step suggestions │
71
- │ - Warning when doing something risky │
72
- ├─────────────────────────────────────────────────────────┤
73
- │ Layer 4: Prompts (on explicit request) │
74
- │ - Detailed workflows │
75
- │ - Step-by-step guides │
76
- ├─────────────────────────────────────────────────────────┤
77
- │ Layer 5: Resources (on explicit request) │
78
- │ - Reference data (catalogs, schemas) │
79
- │ - Templates │
80
- └─────────────────────────────────────────────────────────┘
81
- ```
82
-
83
- ## Implementation Steps
84
-
85
- ### Step 1: Create Guidance Content Module
86
-
87
- **Files:** `src/sdk/guidance.ts`
88
-
89
- Create a single source of truth for all guidance content:
90
-
91
- ```typescript
92
- // src/sdk/guidance.ts
93
-
94
- export const SERVER_INSTRUCTIONS = `
95
- # Ema MCP Toolkit
96
-
97
- ## Workflow Pattern
98
- 1. **Discover**: persona() to list AI Employees
99
- 2. **Understand**: persona(id="...", analyze=true) before any changes
100
- 3. **Preview**: Always use preview=true before deploying
101
- 4. **Deploy**: Only after reviewing preview
102
-
103
- ## Critical Rules
104
- - NEVER modify a workflow without analyzing first
105
- - ALWAYS include Fallback in categorizers
106
- - Use workflow_spec for modifications, not raw workflow_def
107
-
108
- ## When Stuck
109
- Use the toolkit_onboard prompt for comprehensive guidance.
110
- `;
111
-
112
- export const TOOL_GUIDANCE: Record<string, ToolGuidance> = {
113
- persona: {
114
- quickTip: "Use analyze=true to understand before modifying",
115
- commonMistakes: ["Modifying without analysis", "Missing preview step"],
116
- nextSteps: {
117
- list: "Get details with persona(id='...')",
118
- get: "Analyze with persona(id='...', analyze=true)",
119
- analyze: "Build workflow_spec from issues, then update",
120
- }
121
- },
122
- // ... other tools
123
- };
124
-
125
- export const CONTEXTUAL_WARNINGS: Record<string, string> = {
126
- update_without_analysis: "⚠️ Consider running analyze first",
127
- deploy_without_preview: "⚠️ Use preview=true to review changes first",
128
- };
129
- ```
130
-
131
- **Checkpoint:** `feat(sdk): add centralized guidance module`
132
-
133
- ---
134
-
135
- ### Step 2: Add Server Instructions to Initialization
136
-
137
- **Files:** `src/mcp/server.ts`
138
-
139
- Add instructions to Server constructor:
140
-
141
- ```typescript
142
- import { SERVER_INSTRUCTIONS } from "../sdk/guidance.js";
143
-
144
- const server = new Server(
145
- { name: TOOLKIT_NAME, version: TOOLKIT_VERSION },
146
- {
147
- capabilities: { tools: {}, prompts: {}, resources: {} },
148
- instructions: SERVER_INSTRUCTIONS // NEW
149
- }
150
- );
151
- ```
152
-
153
- **Checkpoint:** `feat(mcp): add server instructions for automatic guidance`
154
-
155
- ---
156
-
157
- ### Step 3: Enhance Tool Descriptions
158
-
159
- **Files:** `src/mcp/tools-v2.ts`
160
-
161
- Update TOOLS array with enhanced descriptions:
162
-
163
- ```typescript
164
- {
165
- name: "persona",
166
- description: `Manage Ema AI Employees (Personas).
167
-
168
- **Quick Start:**
169
- - List all: persona()
170
- - Get one: persona(id="...")
171
- - Analyze before changes: persona(id="...", analyze=true)
172
- - Update: persona(id="...", update={workflow_spec: {...}})
173
-
174
- **Important:** Always analyze before modifying. Use preview=true.`,
175
- inputSchema: { ... }
176
- }
177
- ```
178
-
179
- **Checkpoint:** `feat(mcp): enhance tool descriptions with usage guidance`
180
-
181
- ---
182
-
183
- ### Step 4: Add Contextual Tips to Tool Responses
184
-
185
- **Files:** `src/mcp/handlers-consolidated.ts`
186
-
187
- Add `_guidance` field to tool responses:
188
-
189
- ```typescript
190
- // In persona handler
191
- if (mode === 'list') {
192
- return {
193
- personas: results,
194
- _guidance: {
195
- next_step: "Get details: persona(id='<id>')",
196
- tip: "Use analyze=true to check for issues before modifying"
197
- }
198
- };
199
- }
200
-
201
- if (mode === 'get' && !args.analyze) {
202
- return {
203
- persona: result,
204
- _guidance: {
205
- next_step: "Analyze: persona(id='...', analyze=true)",
206
- warning: needsAnalysis ? "This persona has potential issues" : null
207
- }
208
- };
209
- }
210
- ```
211
-
212
- **Checkpoint:** `feat(mcp): add contextual guidance to tool responses`
213
-
214
- ---
215
-
216
- ### Step 5: Create Session Onboarding
217
-
218
- **Files:** `src/mcp/handlers-consolidated.ts`
219
-
220
- First tool call includes onboarding summary:
221
-
222
- ```typescript
223
- let sessionInitialized = false;
224
-
225
- function maybeAddOnboarding(response: any): any {
226
- if (!sessionInitialized) {
227
- sessionInitialized = true;
228
- return {
229
- ...response,
230
- _onboarding: {
231
- message: "Welcome to Ema MCP Toolkit!",
232
- quick_reference: {
233
- list_personas: "persona()",
234
- analyze_persona: "persona(id='...', analyze=true)",
235
- available_prompts: "prompts/list for detailed workflows",
236
- help: "Use toolkit_onboard prompt for full guide"
237
- }
238
- }
239
- };
240
- }
241
- return response;
242
- }
243
- ```
244
-
245
- **Checkpoint:** `feat(mcp): add session onboarding to first response`
246
-
247
- ---
248
-
249
- ### Step 6: Add Workflow State Guidance
250
-
251
- **Files:** `src/sdk/guidance.ts`, `src/mcp/handlers-consolidated.ts`
252
-
253
- Detect workflow state and provide specific guidance:
254
-
255
- ```typescript
256
- export function getWorkflowGuidance(workflow: any): WorkflowGuidance {
257
- const issues = analyzeWorkflow(workflow);
258
-
259
- if (issues.critical.length > 0) {
260
- return {
261
- status: "needs_attention",
262
- message: `${issues.critical.length} critical issues found`,
263
- suggested_action: "Review issues and build workflow_spec to fix"
264
- };
265
- }
266
-
267
- if (!workflow.nodes?.some(n => n.category === "Fallback")) {
268
- return {
269
- status: "warning",
270
- message: "Missing Fallback category",
271
- suggested_action: "Add Fallback handling for unmatched intents"
272
- };
273
- }
274
-
275
- return { status: "healthy" };
276
- }
277
- ```
278
-
279
- **Checkpoint:** `feat(sdk): add workflow state guidance detection`
280
-
281
- ---
282
-
283
- ### Step 7: Update Prompts to be Self-Referential
284
-
285
- **Files:** `src/mcp/prompts.ts`
286
-
287
- Ensure prompts reference other MCP capabilities:
288
-
289
- ```typescript
290
- // In toolkit_onboard prompt
291
- text: `
292
- ## Available Tools
293
- - persona: Manage AI Employees
294
- - catalog: Browse actions, templates, patterns
295
- - sync: Cross-environment sync
296
-
297
- ## Available Prompts
298
- - requirements_clarify: Get help with ambiguous requirements
299
- - workflow_extend: Step-by-step workflow modification
300
- - workflow_review: Comprehensive workflow analysis
301
-
302
- ## Available Resources
303
- - ema://catalog/agents-summary: Action catalog
304
- - ema://rules/anti-patterns: Common mistakes
305
- - ema://docs/getting-started: Quick start guide
306
-
307
- All guidance is built into this MCP - no external files needed.
308
- `
309
- ```
310
-
311
- **Checkpoint:** `feat(mcp): update prompts with self-referential guidance`
312
-
313
- ---
314
-
315
- ### Step 8: Add Comprehensive Usage Guide Resource
316
-
317
- **Files:** `src/mcp/resources.ts`
318
-
319
- ```typescript
320
- {
321
- uri: "ema://docs/usage-guide",
322
- name: "docs/usage-guide",
323
- description: "Complete usage guide for Ema MCP Toolkit",
324
- mimeType: "text/markdown",
325
- generate: async () => generateUsageGuide()
326
- }
327
- ```
328
-
329
- **Checkpoint:** `feat(mcp): add comprehensive usage guide resource`
330
-
331
- ---
332
-
333
- ### Step 9: Remove External Dependencies
334
-
335
- **Files:** Audit all prompts and resources
336
-
337
- - Remove references to `.cursor/rules/`
338
- - Remove references to `AGENTS.md`
339
- - Replace with MCP-native alternatives
340
-
341
- **Checkpoint:** `refactor(mcp): remove external guidance dependencies`
342
-
343
- ---
344
-
345
- ### Step 10: Documentation Update
346
-
347
- **Files:** `README.md`, `docs/mcp-tools-guide.md`
348
-
349
- ```markdown
350
- ## Self-Contained Guidance
351
-
352
- The Ema MCP Toolkit includes all guidance internally:
353
-
354
- - **Automatic**: Server instructions and tool tips guide usage
355
- - **On-Demand**: Prompts and resources for detailed workflows
356
- - **Contextual**: Response tips based on what you're doing
357
-
358
- No external rules files or IDE configuration required.
359
- ```
360
-
361
- **Checkpoint:** `docs: document self-contained guidance system`
362
-
363
- ---
364
-
365
- ## Affected Files
366
-
367
- | File | Change | Description |
368
- |------|--------|-------------|
369
- | `src/sdk/guidance.ts` | New | Centralized guidance content |
370
- | `src/mcp/server.ts` | Modify | Add server instructions |
371
- | `src/mcp/tools-v2.ts` | Modify | Enhanced tool descriptions |
372
- | `src/mcp/handlers-consolidated.ts` | Modify | Contextual response tips |
373
- | `src/mcp/prompts.ts` | Modify | Self-referential prompts |
374
- | `src/mcp/resources.ts` | Modify | Add usage guide resource |
375
- | `README.md` | Modify | Document self-contained nature |
376
-
377
- ## Testing Strategy
378
-
379
- **Unit Tests:**
380
- - Guidance content is valid markdown
381
- - Contextual tips match workflow states
382
- - No external file references in guidance
383
-
384
- **Integration Tests:**
385
- - Server instructions in init response
386
- - Response tips present and accurate
387
- - Resources generate valid content
388
-
389
- **Manual Testing:**
390
- 1. Fresh `npx @ema.co/mcp-toolkit@latest` in Claude Desktop
391
- 2. Verify onboarding on first call
392
- 3. Verify guidance in responses
393
- 4. Complete full workflow without external docs
394
-
395
- ## Risks and Mitigations
396
-
397
- | Risk | Mitigation |
398
- |------|------------|
399
- | Guidance becomes stale | Generate from code, not static strings |
400
- | Too much guidance bloats responses | Progressive disclosure, keep tips short |
401
- | Clients ignore server instructions | Multiple layers of guidance |
402
- | Token budget exceeded | Measure token counts, optimize |
403
-
404
- ## Open Questions
405
-
406
- - [ ] Token budget for tool descriptions before UX degrades?
407
- - [ ] Track guidance effectiveness (what tips are followed)?
408
- - [ ] Different guidance levels (beginner vs advanced)?
409
-
410
- ## Alternatives Considered
411
-
412
- ### MCP Server Instructions Only
413
- - Pro: Automatic, standard MCP
414
- - Con: Cursor support uncertain, single blob
415
-
416
- ### Onboarding Prompt Only
417
- - Pro: Works now, detailed
418
- - Con: Requires user action
419
-
420
- ### Generated Rules File
421
- - Pro: Full fidelity with internal rules
422
- - Con: Requires user action, version drift
423
-
424
- ### Hybrid (Selected)
425
- - Multiple layers for resilience
426
- - Progressive disclosure
427
- - Works across all clients
@@ -1,242 +0,0 @@
1
- # Proto SDK Generation
2
-
3
- This document describes how the MCP toolkit generates and maintains TypeScript clients from Ema's protocol buffer definitions.
4
-
5
- ## Overview
6
-
7
- The MCP toolkit uses [Connect-ES](https://connectrpc.com/docs/web) to generate typed TypeScript clients from proto definitions. This provides type-safe access to gRPC services that aren't exposed via REST/OpenAPI.
8
-
9
- ```
10
- protos/service/**/*.proto
11
-
12
- │ buf generate
13
-
14
- src/sdk/generated/protos/
15
- ├── service/workflows/v1/
16
- │ ├── action_registry_connect.ts ← Service definition
17
- │ ├── action_registry_pb.ts ← Message types
18
- │ ├── dashboards_connect.ts
19
- │ └── dashboards_pb.ts
20
- └── ...
21
-
22
-
23
- │ wrapped by
24
-
25
- src/sdk/grpc-client.ts ← GrpcClient class
26
- ```
27
-
28
- ## Quick Start
29
-
30
- ### Regenerate Proto SDK
31
-
32
- ```bash
33
- npm run generate:protos
34
- ```
35
-
36
- This command:
37
- 1. Reads `buf.gen.yaml` for codegen configuration
38
- 2. Generates TypeScript files from `../ema-repos/protos/service/`
39
- 3. Outputs to `src/sdk/generated/protos/`
40
-
41
- ### Use the GrpcClient
42
-
43
- ```typescript
44
- import { GrpcClient } from '@ema.co/mcp-toolkit';
45
-
46
- const client = new GrpcClient({
47
- name: 'dev',
48
- baseUrl: 'https://dev.ema.co',
49
- bearerToken: process.env.EMA_DEV_BEARER_TOKEN,
50
- });
51
-
52
- // List all actions (typed response)
53
- const actions = await client.listActions({ includeDocumentation: true });
54
-
55
- // Get dashboard rows (typed response)
56
- const rows = await client.getDashboardRows('dashboard-123', { limit: 50 });
57
- ```
58
-
59
- ## Architecture
60
-
61
- ### Why Both OpenAPI and Proto?
62
-
63
- Ema's API surface is split:
64
-
65
- | Protocol | Services | Generated Client |
66
- |----------|----------|------------------|
67
- | REST/OpenAPI | Personas, Templates, Data Sources | `EmaClientAdapter` |
68
- | gRPC | Actions, Dashboards, Workflows | `GrpcClient` |
69
-
70
- The MCP toolkit needs both clients to cover the full API surface.
71
-
72
- ### Source of Truth
73
-
74
- ```
75
- protos/service/**/*.proto ← Single source of truth for gRPC
76
-
77
- ├── Go services (goservice, workflow-engine)
78
- ├── Python services (ema-backend)
79
- ├── TypeScript clients (ema-app, mcp-toolkit)
80
-
81
-
82
- All generated, never hand-written
83
- ```
84
-
85
- ## Files
86
-
87
- | File | Purpose |
88
- |------|---------|
89
- | `buf.gen.yaml` | Codegen configuration |
90
- | `src/sdk/generated/protos/` | Generated Connect-ES clients (DO NOT EDIT) |
91
- | `src/sdk/grpc-client.ts` | Typed wrapper with retry/auth |
92
- | `.github/workflows/sync-protos.yml` | Automated weekly sync |
93
-
94
- ## Dependencies
95
-
96
- ### Runtime
97
- ```json
98
- {
99
- "@connectrpc/connect": "^1.4.0",
100
- "@connectrpc/connect-node": "^1.4.0",
101
- "@bufbuild/protobuf": "^1.10.0"
102
- }
103
- ```
104
-
105
- ### Development
106
- ```json
107
- {
108
- "@bufbuild/buf": "^1.34.0",
109
- "@bufbuild/protoc-gen-es": "^1.10.0",
110
- "@connectrpc/protoc-gen-connect-es": "^1.4.0"
111
- }
112
- ```
113
-
114
- ## Automation
115
-
116
- ### GitHub Workflow
117
-
118
- The `sync-protos.yml` workflow runs weekly to:
119
-
120
- 1. Checkout the latest `protos` repository
121
- 2. Regenerate TypeScript clients
122
- 3. Create a PR if files changed
123
- 4. Verify build and tests pass
124
-
125
- **Manual trigger:**
126
- ```bash
127
- gh workflow run sync-protos.yml
128
- ```
129
-
130
- ### Local Development
131
-
132
- When protos change:
133
-
134
- ```bash
135
- # Pull latest protos
136
- cd ../ema-repos/protos && git pull
137
-
138
- # Regenerate
139
- cd ../ema-mcp-toolkit && npm run generate:protos
140
-
141
- # Verify
142
- npm run build && npm test
143
- ```
144
-
145
- ## Troubleshooting
146
-
147
- ### "Plugin not found" Error
148
-
149
- ```
150
- Failure: plugin connect-es: could not find protoc plugin
151
- ```
152
-
153
- **Fix:** Ensure dev dependencies are installed:
154
- ```bash
155
- npm install
156
- ```
157
-
158
- ### "Cannot find module" Import Error
159
-
160
- Generated files use `.js` extensions for ESM compatibility:
161
- ```typescript
162
- // Correct
163
- import { ActionManager } from './generated/protos/service/workflows/v1/action_registry_connect.js';
164
-
165
- // Incorrect (will fail at runtime)
166
- import { ActionManager } from './generated/protos/service/workflows/v1/action_registry_connect';
167
- ```
168
-
169
- ### Type Errors After Regeneration
170
-
171
- If types break after regeneration:
172
-
173
- 1. Check if proto field names changed
174
- 2. Update `grpc-client.ts` wrapper accordingly
175
- 3. Run `npm run build` to verify
176
-
177
- ### gRPC Call Fails with 401
178
-
179
- **Fix:** Check bearer token:
180
- ```typescript
181
- const client = new GrpcClient({
182
- name: 'dev',
183
- baseUrl: 'https://dev.ema.co',
184
- bearerToken: process.env.EMA_DEV_BEARER_TOKEN, // Must be valid
185
- });
186
- ```
187
-
188
- ### gRPC Call Returns 404 or 415
189
-
190
- **HTTP 404 - Wrong base URL:**
191
- - Use `api.dev.ema.co` (not `staging.ema.co` or `dev.ema.co`)
192
- - The gRPC endpoints are served from the `api.*` subdomain
193
-
194
- **HTTP 415 - Wrong content type:**
195
- - **Root cause**: Ema backend is a pure gRPC server, not a Connect server
196
- - **Wrong**: `application/proto` (Connect binary format)
197
- - **Wrong**: `application/json` (Connect JSON format)
198
- - **Correct**: `application/grpc-web+proto` (gRPC-web format)
199
-
200
- **Solution**: Use `createGrpcWebTransport` instead of `createConnectTransport`:
201
- ```typescript
202
- import { createGrpcWebTransport } from '@connectrpc/connect-node';
203
-
204
- const transport = createGrpcWebTransport({
205
- baseUrl: 'https://api.dev.ema.co',
206
- httpVersion: '1.1',
207
- });
208
- ```
209
-
210
- ## Extending the Client
211
-
212
- To add new gRPC methods:
213
-
214
- 1. **Check the generated files** - See if the method exists in `*_connect.ts`
215
-
216
- 2. **Add to GrpcClient**:
217
- ```typescript
218
- // In src/sdk/grpc-client.ts
219
- async myNewMethod(param: string) {
220
- const request = new MyNewRequest({ field: param });
221
- return this.myService.myNewMethod(request);
222
- }
223
- ```
224
-
225
- 3. **Export types** (if needed):
226
- ```typescript
227
- // In src/sdk/grpc-client.ts
228
- export type { MyNewResponse } from './generated/protos/...';
229
- ```
230
-
231
- 4. **Add to SDK exports** (if public):
232
- ```typescript
233
- // In src/sdk/index.ts
234
- export { type MyNewResponse as GrpcMyNewResponse } from "./grpc-client.js";
235
- ```
236
-
237
- ## Related Documentation
238
-
239
- - [Connect-ES Documentation](https://connectrpc.com/docs/web)
240
- - [Buf CLI Documentation](https://buf.build/docs/bsr/overview)
241
- - [Ema Protos Repository](https://github.com/Ema-Unlimited/protos)
242
- - [ema-app buf.gen.yaml](../../../ema-repos/ema-app/buf.gen.yaml) - Reference implementation