@kya-os/create-mcpi-app 1.7.36 → 1.7.38-canary.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/ARCHITECTURE_ANALYSIS.md +392 -0
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/helpers/config-builder.d.ts +1 -1
  4. package/dist/helpers/config-builder.d.ts.map +1 -1
  5. package/dist/helpers/config-builder.js +1 -1
  6. package/dist/helpers/config-builder.js.map +1 -1
  7. package/dist/helpers/create.d.ts +1 -1
  8. package/dist/helpers/create.d.ts.map +1 -1
  9. package/dist/helpers/fetch-cloudflare-mcpi-template.d.ts.map +1 -1
  10. package/dist/helpers/fetch-cloudflare-mcpi-template.js +2 -1
  11. package/dist/helpers/fetch-cloudflare-mcpi-template.js.map +1 -1
  12. package/dist/helpers/generate-config.d.ts.map +1 -1
  13. package/dist/helpers/generate-config.js.map +1 -1
  14. package/dist/index.js +18 -12
  15. package/dist/index.js.map +1 -1
  16. package/dist/utils/fetch-remote-config.d.ts +74 -0
  17. package/dist/utils/fetch-remote-config.d.ts.map +1 -0
  18. package/dist/utils/fetch-remote-config.js +109 -0
  19. package/dist/utils/fetch-remote-config.js.map +1 -0
  20. package/package.json +7 -12
  21. package/src/helpers/config-builder.ts +1 -1
  22. package/src/helpers/create.ts +1 -1
  23. package/src/helpers/fetch-cloudflare-mcpi-template.ts +2 -1
  24. package/src/helpers/generate-config.ts +0 -1
  25. package/src/index.ts +66 -26
  26. package/src/utils/__tests__/fetch-remote-config.test.ts +271 -0
  27. package/src/utils/fetch-remote-config.ts +179 -0
  28. package/.turbo/turbo-build.log +0 -4
  29. package/.turbo/turbo-test$colon$coverage.log +0 -305
  30. package/.turbo/turbo-test.log +0 -483
  31. package/coverage/base.css +0 -224
  32. package/coverage/block-navigation.js +0 -87
  33. package/coverage/clover.xml +0 -268
  34. package/coverage/config-builder.ts.html +0 -580
  35. package/coverage/coverage-final.json +0 -7
  36. package/coverage/favicon.png +0 -0
  37. package/coverage/fetch-cloudflare-mcpi-template.ts.html +0 -7345
  38. package/coverage/generate-config.ts.html +0 -442
  39. package/coverage/generate-identity.ts.html +0 -574
  40. package/coverage/index.html +0 -191
  41. package/coverage/install.ts.html +0 -322
  42. package/coverage/prettify.css +0 -1
  43. package/coverage/prettify.js +0 -2
  44. package/coverage/sort-arrow-sprite.png +0 -0
  45. package/coverage/sorter.js +0 -210
  46. package/coverage/validate-project-structure.ts.html +0 -466
  47. package/dist/helpers/__tests__/config-builder.spec.d.ts +0 -8
  48. package/dist/helpers/__tests__/config-builder.spec.d.ts.map +0 -1
  49. package/dist/helpers/__tests__/config-builder.spec.js +0 -182
  50. package/dist/helpers/__tests__/config-builder.spec.js.map +0 -1
@@ -0,0 +1,392 @@
1
+ # Deep Architecture Analysis: create-mcpi-app
2
+
3
+ ## Executive Summary
4
+
5
+ After thorough analysis of `create-mcpi-app`, I've identified **significant architectural inefficiencies** that can be improved. The package currently has:
6
+ - **7 unused dependencies** (~15MB+ of unnecessary code)
7
+ - **Heavy runtime dependencies** used only for TypeScript types
8
+ - **Redundant HTTP/crypto libraries** when native APIs are available
9
+ - **Architectural patterns** that don't align with modern CLI tooling best practices
10
+
11
+ ## Current Dependency Analysis
12
+
13
+ ### ✅ Actually Used Dependencies
14
+
15
+ | Dependency | Purpose | Can Optimize? |
16
+ |------------|---------|---------------|
17
+ | `fs-extra` | File operations | ✅ Use native `fs/promises` |
18
+ | `chalk` | Terminal colors | ❌ Keep (essential) |
19
+ | `commander` | CLI parsing | ❌ Keep (essential) |
20
+ | `inquirer` | Interactive prompts | ❌ Keep (essential) |
21
+ | `ora` | Loading spinners | ❌ Keep (essential) |
22
+ | `base-x` | Base58 encoding | ❌ Keep (used in generate-identity) |
23
+ | `zod` | Schema validation | ❌ Keep (used in config-builder) |
24
+ | `@kya-os/contracts` | Type definitions | ⚠️ Only types needed |
25
+ | `@kya-os/cli-effects` | UI effects | ❌ Keep (used) |
26
+ | `@kya-os/mcp-i-core` | Types + `fetchRemoteConfig` | ⚠️ Only types + 1 function |
27
+ | `@kya-os/mcp-i` | **ONLY FOR TYPES** | ❌❌❌ **MAJOR ISSUE** |
28
+
29
+ ### ❌ Unused Dependencies (Can Remove)
30
+
31
+ 1. **`axios`** (~500KB) - Not imported anywhere
32
+ 2. **`node-fetch`** (~200KB) - Node 20+ has native `fetch`
33
+ 3. **`jose`** (~300KB) - Not used (used in `@kya-os/cli` but not here)
34
+ 4. **`dotenv-cli`** (~100KB) - Not used
35
+ 5. **`swc-loader`** (~2MB) - Only in generated templates, not scaffolder
36
+ 6. **`tsx`** (~5MB) - Only in generated templates, not scaffolder
37
+ 7. **`@noble/ed25519`** (~100KB) - Not used (using `webcrypto` instead)
38
+
39
+ **Total wasted: ~8MB+ of dependencies**
40
+
41
+ ### ⚠️ Problematic Dependencies
42
+
43
+ #### 1. `@kya-os/mcp-i` - **CRITICAL ISSUE**
44
+
45
+ **Current Usage:**
46
+ - Only used for TypeScript types: `NodeRuntimeConfig`, `XmcpConfig`
47
+ - Imported in `generate-config.ts` for type references in generated code
48
+
49
+ **Problem:**
50
+ - This package is **MASSIVE** (~50MB+ with dependencies):
51
+ - Includes `webpack`, `express`, `@swc/core`, `chokidar`, `webpack-node-externals`
52
+ - Includes `axios`, `jose`, `jsonwebtoken`, `handlebars`
53
+ - Includes entire MCP SDK and runtime
54
+ - **All of this is bundled just for TypeScript types!**
55
+
56
+ **Impact:**
57
+ - Slows down `npm install` for users
58
+ - Increases bundle size unnecessarily
59
+ - Violates separation of concerns (scaffolder shouldn't need runtime)
60
+
61
+ #### 2. `@kya-os/mcp-i-core` - Moderate Issue
62
+
63
+ **Current Usage:**
64
+ - Types: `RemoteConfigCache`, `RemoteConfigOptions`
65
+ - Function: `fetchRemoteConfig` (used in `config-builder.ts`)
66
+
67
+ **Problem:**
68
+ - Includes `@modelcontextprotocol/sdk` as dependency
69
+ - Only needs types + 1 function, but pulls in entire SDK
70
+
71
+ ## Architecture Comparison
72
+
73
+ ### Modern CLI Scaffolders (Best Practices)
74
+
75
+ #### create-next-app (Next.js)
76
+ ```json
77
+ {
78
+ "dependencies": {
79
+ "commander": "^9.0.0",
80
+ "fs-extra": "^11.0.0",
81
+ "chalk": "^5.0.0"
82
+ }
83
+ }
84
+ ```
85
+ - **No runtime dependencies** - only scaffolding tools
86
+ - Types are in separate `@types` packages or peer dependencies
87
+ - Uses native Node.js APIs
88
+
89
+ #### create-vite (Vite)
90
+ ```json
91
+ {
92
+ "dependencies": {
93
+ "commander": "^9.0.0",
94
+ "fs-extra": "^11.0.0",
95
+ "chalk": "^5.0.0",
96
+ "minimist": "^1.2.0"
97
+ }
98
+ }
99
+ ```
100
+ - **Minimal dependencies** - only what's needed for scaffolding
101
+ - No runtime framework dependencies
102
+
103
+ #### create-react-app (Legacy - What NOT to do)
104
+ ```json
105
+ {
106
+ "dependencies": {
107
+ // ... 50+ dependencies including webpack, babel, etc.
108
+ }
109
+ }
110
+ ```
111
+ - **Heavy dependencies** - includes entire build toolchain
112
+ - This is why CRA is deprecated in favor of lighter alternatives
113
+
114
+ ### Our Current Architecture (create-mcpi-app)
115
+
116
+ ```json
117
+ {
118
+ "dependencies": {
119
+ "@kya-os/mcp-i": "^1.5.5", // ❌ 50MB+ runtime framework
120
+ "@kya-os/mcp-i-core": "^1.1.12", // ⚠️ Includes SDK
121
+ "@kya-os/cli": "^1.3.3", // ⚠️ Not used directly
122
+ "axios": "^1.12.0", // ❌ Unused
123
+ "node-fetch": "^3.3.2", // ❌ Unused (native fetch available)
124
+ "jose": "^6.0.12", // ❌ Unused
125
+ // ... 7 more unused deps
126
+ }
127
+ }
128
+ ```
129
+
130
+ **We're following the CRA anti-pattern!**
131
+
132
+ ## Recommended Architecture Improvements
133
+
134
+ ### Option 1: Minimal Dependencies (Recommended)
135
+
136
+ **Remove all unused dependencies and use type-only imports:**
137
+
138
+ ```json
139
+ {
140
+ "dependencies": {
141
+ "chalk": "^5.3.0",
142
+ "commander": "^11.1.0",
143
+ "fs-extra": "^11.2.0",
144
+ "inquirer": "^12.9.4",
145
+ "ora": "^8.0.1",
146
+ "base-x": "^5.0.0",
147
+ "zod": "^3.25.76",
148
+ "@kya-os/cli-effects": "^1.0.19"
149
+ },
150
+ "devDependencies": {
151
+ "@kya-os/contracts": "^1.5.1", // Types only
152
+ "@kya-os/mcp-i-core": "^1.1.12", // Types only
153
+ "@types/node": "^20.19.19",
154
+ "typescript": "^5.3.0",
155
+ "vitest": "^4.0.5"
156
+ },
157
+ "peerDependencies": {
158
+ "@kya-os/mcp-i": ">=1.5.0" // For types, but not bundled
159
+ }
160
+ }
161
+ ```
162
+
163
+ **Changes:**
164
+ 1. Move `@kya-os/contracts` and `@kya-os/mcp-i-core` to `devDependencies` (types only)
165
+ 2. Add `@kya-os/mcp-i` as `peerDependency` (types available but not bundled)
166
+ 3. Remove all unused dependencies
167
+ 4. Use native `fetch` instead of `axios`/`node-fetch`
168
+ 5. Use native `fs/promises` instead of `fs-extra` (or keep fs-extra if convenience is worth it)
169
+
170
+ **Benefits:**
171
+ - **~60MB reduction** in install size
172
+ - Faster `npm install` times
173
+ - Clearer separation of concerns
174
+ - Aligns with modern CLI tooling patterns
175
+
176
+ ### Option 2: Extract Types Package (Best Long-term)
177
+
178
+ Create a separate `@kya-os/mcp-i-types` package:
179
+
180
+ ```json
181
+ {
182
+ "name": "@kya-os/mcp-i-types",
183
+ "version": "1.0.0",
184
+ "types": "./dist/index.d.ts",
185
+ "exports": {
186
+ ".": {
187
+ "types": "./dist/index.d.ts"
188
+ }
189
+ }
190
+ }
191
+ ```
192
+
193
+ **Benefits:**
194
+ - Zero runtime dependencies
195
+ - Can be used by any package needing types
196
+ - Follows TypeScript best practices
197
+ - Matches patterns used by major frameworks
198
+
199
+ ### Option 3: Use Type-Only Imports (Quick Fix)
200
+
201
+ Keep current structure but use TypeScript's `import type`:
202
+
203
+ ```typescript
204
+ // Instead of:
205
+ import { NodeRuntimeConfig } from "@kya-os/mcp-i";
206
+
207
+ // Use:
208
+ import type { NodeRuntimeConfig } from "@kya-os/mcp-i";
209
+ ```
210
+
211
+ Then move to `devDependencies`:
212
+ ```json
213
+ {
214
+ "devDependencies": {
215
+ "@kya-os/mcp-i": "^1.5.5" // Types only, not bundled
216
+ }
217
+ }
218
+ ```
219
+
220
+ **Note:** This still requires the package to be installed, but TypeScript will tree-shake it.
221
+
222
+ ## Specific Code Improvements
223
+
224
+ ### 1. Replace `fs-extra` with Native APIs
225
+
226
+ ```typescript
227
+ // Current:
228
+ import fs from "fs-extra";
229
+ fs.ensureDirSync(path);
230
+ fs.writeJsonSync(path, data);
231
+
232
+ // Better:
233
+ import { mkdir, writeFile } from "fs/promises";
234
+ import { existsSync } from "fs";
235
+
236
+ await mkdir(path, { recursive: true });
237
+ await writeFile(path, JSON.stringify(data, null, 2));
238
+ ```
239
+
240
+ **Trade-off:** More verbose, but removes dependency
241
+
242
+ ### 2. Use Native `fetch` Instead of `axios`/`node-fetch`
243
+
244
+ ```typescript
245
+ // Current (if we were using axios):
246
+ const response = await axios.get(url);
247
+
248
+ // Better (native fetch):
249
+ const response = await fetch(url);
250
+ const data = await response.json();
251
+ ```
252
+
253
+ **Note:** Node 20+ has native `fetch` - no dependency needed!
254
+
255
+ ### 3. Extract `fetchRemoteConfig` Function
256
+
257
+ Instead of importing from `@kya-os/mcp-i-core`, extract the function:
258
+
259
+ ```typescript
260
+ // In create-mcpi-app/src/utils/fetch-remote-config.ts
261
+ export async function fetchRemoteConfig(
262
+ options: RemoteConfigOptions,
263
+ cache?: RemoteConfigCache
264
+ ): Promise<MCPIConfig | null> {
265
+ // Copy implementation from mcp-i-core
266
+ // This removes the dependency on the entire package
267
+ }
268
+ ```
269
+
270
+ **Trade-off:** Code duplication, but removes heavy dependency
271
+
272
+ ### 4. Use `import type` for All Type Imports
273
+
274
+ ```typescript
275
+ // Current:
276
+ import { ScaffolderResult } from "@kya-os/contracts";
277
+ import type { NodeRuntimeConfig } from "@kya-os/mcp-i";
278
+
279
+ // Better (all type-only):
280
+ import type { ScaffolderResult } from "@kya-os/contracts";
281
+ import type { NodeRuntimeConfig } from "@kya-os/mcp-i";
282
+ ```
283
+
284
+ ## Dependency Size Analysis
285
+
286
+ ### Current Install Size (Estimated)
287
+
288
+ ```
289
+ @kya-os/mcp-i: ~50MB (with dependencies)
290
+ @kya-os/mcp-i-core: ~5MB (with SDK)
291
+ @kya-os/cli: ~10MB
292
+ axios: ~500KB
293
+ node-fetch: ~200KB
294
+ jose: ~300KB
295
+ swc-loader: ~2MB
296
+ tsx: ~5MB
297
+ @noble/ed25519: ~100KB
298
+ dotenv-cli: ~100KB
299
+ --------------------------------
300
+ Total wasted: ~73MB+
301
+ ```
302
+
303
+ ### Optimized Install Size
304
+
305
+ ```
306
+ chalk: ~50KB
307
+ commander: ~200KB
308
+ fs-extra: ~100KB
309
+ inquirer: ~500KB
310
+ ora: ~100KB
311
+ base-x: ~50KB
312
+ zod: ~500KB
313
+ @kya-os/cli-effects: ~200KB
314
+ --------------------------------
315
+ Total: ~1.7MB
316
+ ```
317
+
318
+ **Reduction: ~97% smaller!**
319
+
320
+ ## Migration Plan
321
+
322
+ ### Phase 1: Remove Unused Dependencies (Low Risk)
323
+
324
+ 1. Remove `axios`, `node-fetch`, `jose`, `dotenv-cli`, `swc-loader`, `tsx`, `@noble/ed25519`
325
+ 2. Test that scaffolder still works
326
+ 3. Verify generated templates still work
327
+
328
+ **Time:** 1-2 hours
329
+ **Risk:** Low
330
+ **Impact:** Immediate size reduction
331
+
332
+ ### Phase 2: Move Type Dependencies to devDependencies (Medium Risk)
333
+
334
+ 1. Move `@kya-os/contracts` to `devDependencies`
335
+ 2. Move `@kya-os/mcp-i-core` to `devDependencies`
336
+ 3. Add `@kya-os/mcp-i` as `peerDependency`
337
+ 4. Update all imports to use `import type`
338
+ 5. Test thoroughly
339
+
340
+ **Time:** 2-4 hours
341
+ **Risk:** Medium
342
+ **Impact:** Major size reduction
343
+
344
+ ### Phase 3: Extract fetchRemoteConfig (Optional)
345
+
346
+ 1. Copy `fetchRemoteConfig` implementation
347
+ 2. Remove `@kya-os/mcp-i-core` dependency
348
+ 3. Test config-builder functionality
349
+
350
+ **Time:** 1-2 hours
351
+ **Risk:** Low
352
+ **Impact:** Further size reduction
353
+
354
+ ### Phase 4: Replace fs-extra (Optional)
355
+
356
+ 1. Replace `fs-extra` calls with native `fs/promises`
357
+ 2. Add helper functions for common operations
358
+ 3. Test file operations
359
+
360
+ **Time:** 2-3 hours
361
+ **Risk:** Low
362
+ **Impact:** Small size reduction
363
+
364
+ ## Recommendations Summary
365
+
366
+ ### ✅ Immediate Actions (High Impact, Low Risk)
367
+
368
+ 1. **Remove 7 unused dependencies** → ~8MB reduction
369
+ 2. **Move type-only packages to devDependencies** → ~55MB reduction
370
+ 3. **Add `@kya-os/mcp-i` as peerDependency** → Users install only if needed
371
+
372
+ ### ⚠️ Consider (Medium Impact, Medium Risk)
373
+
374
+ 4. **Extract `fetchRemoteConfig` function** → Remove `@kya-os/mcp-i-core` dependency
375
+ 5. **Use native `fs/promises`** → Remove `fs-extra` dependency
376
+
377
+ ### 🎯 Long-term (High Impact, High Effort)
378
+
379
+ 6. **Create `@kya-os/mcp-i-types` package** → Zero runtime dependencies for types
380
+ 7. **Follow create-next-app pattern** → Industry-standard architecture
381
+
382
+ ## Conclusion
383
+
384
+ The current architecture follows anti-patterns from legacy tools like `create-react-app`. By adopting modern CLI tooling patterns (like `create-next-app` or `create-vite`), we can:
385
+
386
+ - **Reduce install size by ~97%** (from ~73MB to ~1.7MB)
387
+ - **Improve install speed** significantly
388
+ - **Align with industry best practices**
389
+ - **Improve maintainability** with clearer dependencies
390
+
391
+ The recommended approach is **Option 1** (Minimal Dependencies) as it provides the best balance of impact vs. effort.
392
+