@kya-os/create-mcpi-app 1.9.32 → 1.9.34

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 (55) hide show
  1. package/.turbo/turbo-build.log +27 -2
  2. package/.turbo/turbo-test$colon$coverage.log +1829 -0
  3. package/.turbo/turbo-test.log +260 -220
  4. package/dist/bundles/blank.js +112104 -0
  5. package/dist/bundles/ecommerce.js +112178 -0
  6. package/dist/bundles/hardware-world.js +112576 -0
  7. package/dist/bundles/manifest.json +28 -0
  8. package/dist/bundles/mix-station.js +112480 -0
  9. package/dist/cli-runner.d.ts.map +1 -1
  10. package/dist/cli-runner.js +23 -0
  11. package/dist/cli-runner.js.map +1 -1
  12. package/dist/helpers/fetch-cloudflare-mcpi-template.js +1 -1
  13. package/dist/helpers/generate-cloudflare-files.d.ts +1 -1
  14. package/dist/helpers/generate-cloudflare-files.d.ts.map +1 -1
  15. package/dist/helpers/generate-cloudflare-files.js +457 -41
  16. package/dist/helpers/generate-cloudflare-files.js.map +1 -1
  17. package/dist/helpers/generate-openapi-project.d.ts +36 -0
  18. package/dist/helpers/generate-openapi-project.d.ts.map +1 -0
  19. package/dist/helpers/generate-openapi-project.js +114 -0
  20. package/dist/helpers/generate-openapi-project.js.map +1 -0
  21. package/dist/helpers/generate-openapi-tools.d.ts +43 -0
  22. package/dist/helpers/generate-openapi-tools.d.ts.map +1 -0
  23. package/dist/helpers/generate-openapi-tools.js +550 -0
  24. package/dist/helpers/generate-openapi-tools.js.map +1 -0
  25. package/dist/helpers/generate-runtime-config.d.ts +16 -0
  26. package/dist/helpers/generate-runtime-config.d.ts.map +1 -0
  27. package/dist/helpers/generate-runtime-config.js +49 -0
  28. package/dist/helpers/generate-runtime-config.js.map +1 -0
  29. package/dist/helpers/get-package-versions.js +8 -8
  30. package/dist/helpers/get-package-versions.js.map +1 -1
  31. package/dist/helpers/openapi-ingestion.d.ts +21 -0
  32. package/dist/helpers/openapi-ingestion.d.ts.map +1 -0
  33. package/dist/helpers/openapi-ingestion.js +433 -0
  34. package/dist/helpers/openapi-ingestion.js.map +1 -0
  35. package/dist/helpers/wrap/command.d.ts +12 -0
  36. package/dist/helpers/wrap/command.d.ts.map +1 -0
  37. package/dist/helpers/wrap/command.js +344 -0
  38. package/dist/helpers/wrap/command.js.map +1 -0
  39. package/dist/helpers/wrap/detect-server.d.ts +30 -0
  40. package/dist/helpers/wrap/detect-server.d.ts.map +1 -0
  41. package/dist/helpers/wrap/detect-server.js +207 -0
  42. package/dist/helpers/wrap/detect-server.js.map +1 -0
  43. package/dist/helpers/wrap/index.d.ts +13 -0
  44. package/dist/helpers/wrap/index.d.ts.map +1 -0
  45. package/dist/helpers/wrap/index.js +11 -0
  46. package/dist/helpers/wrap/index.js.map +1 -0
  47. package/dist/helpers/wrap/templates.d.ts +24 -0
  48. package/dist/helpers/wrap/templates.d.ts.map +1 -0
  49. package/dist/helpers/wrap/templates.js +221 -0
  50. package/dist/helpers/wrap/templates.js.map +1 -0
  51. package/dist/types/openapi-generator.d.ts +142 -0
  52. package/dist/types/openapi-generator.d.ts.map +1 -0
  53. package/dist/types/openapi-generator.js +8 -0
  54. package/dist/types/openapi-generator.js.map +1 -0
  55. package/package.json +35 -9
@@ -0,0 +1,550 @@
1
+ /**
2
+ * OpenAPI Tool File Generator
3
+ *
4
+ * Generates TypeScript tool files from OperationModel instances.
5
+ * Each tool is a factory function that accepts environment variables
6
+ * and returns a ToolDefinition compatible with @kya-os/mcp-i-cloudflare.
7
+ *
8
+ * @module @kya-os/create-mcpi-app/helpers/generate-openapi-tools
9
+ */
10
+ import { writeFile, mkdir } from "fs/promises";
11
+ import { join } from "path";
12
+ import { generateRuntimeConfigTs } from "./generate-runtime-config.js";
13
+ // ============================================================================
14
+ // Public API
15
+ // ============================================================================
16
+ /**
17
+ * Generate TypeScript source code for a single tool file.
18
+ *
19
+ * @param operation - The OperationModel to generate a tool for
20
+ * @param securitySchemes - The full security scheme map (for env type generation)
21
+ * @returns TypeScript source string for the tool file
22
+ */
23
+ export function generateToolFile(operation, _securitySchemes) {
24
+ const factoryName = toFactoryName(operation.toolName);
25
+ const handlerBody = generateHandlerBody(operation);
26
+ return `import type { ToolDefinition } from "@kya-os/mcp-i-cloudflare";
27
+ import type { AgentEnv } from "../agent-env.js";
28
+
29
+ export function ${factoryName}(env: AgentEnv): ToolDefinition {
30
+ return {
31
+ name: ${JSON.stringify(operation.toolName)},
32
+ description: ${JSON.stringify(operation.description)},
33
+ inputSchema: ${serializeSchema(operation.inputSchema)},
34
+ handler: async (args: Record<string, unknown>) => {
35
+ ${handlerBody}
36
+ },
37
+ };
38
+ }
39
+ `;
40
+ }
41
+ /**
42
+ * Generate all tool files plus supporting project files and write them to disk.
43
+ *
44
+ * Files generated:
45
+ * src/tools/<toolName>.ts (one per operation)
46
+ * src/auth.ts (auth helpers)
47
+ * src/agent.ts (MCPIAgent class)
48
+ * src/index.ts (createMCPIApp entry point)
49
+ * wrangler.toml
50
+ * .dev.vars.example
51
+ * README.md
52
+ *
53
+ * @param operations - Parsed operations from ingestOpenAPI
54
+ * @param securitySchemes - Security scheme map
55
+ * @param targetDir - Absolute path to output directory
56
+ * @param identity - Generated agent identity
57
+ */
58
+ export async function generateToolFiles(operations, securitySchemes, targetDir, identity) {
59
+ const toolsDir = join(targetDir, "src", "tools");
60
+ await mkdir(toolsDir, { recursive: true });
61
+ await mkdir(join(targetDir, "src"), { recursive: true });
62
+ // 1. Individual tool files
63
+ for (const op of operations) {
64
+ const toolSource = generateToolFile(op, securitySchemes);
65
+ const fileName = `${op.toolName}.ts`;
66
+ await writeFile(join(toolsDir, fileName), toolSource, "utf-8");
67
+ }
68
+ // 2. auth.ts
69
+ await writeFile(join(targetDir, "src", "auth.ts"), generateAuthTs(securitySchemes), "utf-8");
70
+ // 3. agent-env.ts
71
+ await writeFile(join(targetDir, "src", "agent-env.ts"), generateAgentEnvTs(securitySchemes), "utf-8");
72
+ // 4. agent.ts
73
+ await writeFile(join(targetDir, "src", "agent.ts"), generateAgentTs(operations, securitySchemes), "utf-8");
74
+ // 5. index.ts
75
+ await writeFile(join(targetDir, "src", "index.ts"), generateIndexTs(), "utf-8");
76
+ // 6. wrangler.toml
77
+ await writeFile(join(targetDir, "wrangler.toml"), generateWranglerToml(identity, securitySchemes), "utf-8");
78
+ // 7. .dev.vars.example
79
+ await writeFile(join(targetDir, ".dev.vars.example"), generateDevVarsExample(securitySchemes), "utf-8");
80
+ // 8. src/mcpi-runtime-config.ts (required by agent.ts and index.ts imports)
81
+ await writeFile(join(targetDir, "src", "mcpi-runtime-config.ts"), generateRuntimeConfigTs(), "utf-8");
82
+ // 9. README.md
83
+ await writeFile(join(targetDir, "README.md"), generateReadme(operations, securitySchemes), "utf-8");
84
+ }
85
+ // ============================================================================
86
+ // Code generation helpers
87
+ // ============================================================================
88
+ /**
89
+ * Convert an OpenAPI parameter name to a valid JavaScript identifier.
90
+ * e.g. "user-id" -> "userId", "x.api.key" -> "xApiKey"
91
+ */
92
+ function toJsIdentifier(name) {
93
+ return name
94
+ .replace(/[-_.]+(.)/g, (_, ch) => ch.toUpperCase())
95
+ .replace(/[^a-zA-Z0-9_$]/g, "_")
96
+ .replace(/^([0-9])/, "_$1");
97
+ }
98
+ function generateHandlerBody(op) {
99
+ const lines = [];
100
+ const indent = " ";
101
+ // Extract args with type assertions.
102
+ // Track declared variable names to avoid duplicate const declarations when a body
103
+ // property shares a name with a path/query param. Also build a varMap so that
104
+ // URL construction and query-string logic reference the same collision-resolved
105
+ // names rather than re-deriving them with toJsIdentifier.
106
+ const declaredVars = new Set();
107
+ const toUniqueVar = (base) => {
108
+ let v = base;
109
+ let n = 1;
110
+ while (declaredVars.has(v)) {
111
+ v = `${base}_${++n}`;
112
+ }
113
+ declaredVars.add(v);
114
+ return v;
115
+ };
116
+ // Maps original param name -> resolved variable name (may differ on collision)
117
+ const varMap = new Map();
118
+ for (const p of op.pathParams) {
119
+ const pVar = toUniqueVar(toJsIdentifier(p.name));
120
+ varMap.set(p.name, pVar);
121
+ const pKey = JSON.stringify(p.name);
122
+ lines.push(`${indent}const ${pVar} = (args as Record<string, unknown>)[${pKey}] as string;`);
123
+ }
124
+ for (const q of op.queryParams) {
125
+ const tsType = schemaToTsType(q.schema);
126
+ const qVar = toUniqueVar(toJsIdentifier(q.name));
127
+ varMap.set(q.name, qVar);
128
+ const qKey = JSON.stringify(q.name);
129
+ lines.push(`${indent}const ${qVar} = (args as Record<string, unknown>)[${qKey}] as ${tsType} | undefined;`);
130
+ }
131
+ // Collect request body fields.
132
+ // Track both the JS variable name (identifier-safe) and the original property name
133
+ // (the actual API field name). The body must be serialized with original keys so
134
+ // e.g. "first-name" is not silently renamed to "firstName" in the request.
135
+ const bodyFields = [];
136
+ let nonObjectBody = false;
137
+ if (op.requestBody?.schema?.type === "object" && op.requestBody.schema.properties) {
138
+ for (const propName of Object.keys(op.requestBody.schema.properties)) {
139
+ const propSchema = op.requestBody.schema.properties[propName];
140
+ const tsType = schemaToTsType(propSchema);
141
+ const bodyVar = toUniqueVar(toJsIdentifier(propName));
142
+ const bodyKey = JSON.stringify(propName);
143
+ lines.push(`${indent}const ${bodyVar} = (args as Record<string, unknown>)[${bodyKey}] as ${tsType} | undefined;`);
144
+ bodyFields.push({ varName: bodyVar, originalKey: propName });
145
+ }
146
+ }
147
+ else if (op.requestBody !== undefined && op.requestBody.schema?.type !== "object") {
148
+ // Non-object body (string, array, etc.): buildInputSchema maps it to args["body"]
149
+ const bodyVar = toUniqueVar("body");
150
+ lines.push(`${indent}const ${bodyVar} = (args as Record<string, unknown>)["body"];`);
151
+ nonObjectBody = bodyVar;
152
+ }
153
+ lines.push("");
154
+ // URL construction — sanitize path before embedding in template literal to prevent
155
+ // injection if the spec comes from an untrusted source (e.g. third-party OpenAPI spec).
156
+ // Backslashes must be escaped first, then backticks, then ${ sequences.
157
+ const sanitizePath = (p) => p.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${");
158
+ let urlTemplate = sanitizePath(op.path);
159
+ for (const p of op.pathParams) {
160
+ const resolvedVar = varMap.get(p.name) ?? toJsIdentifier(p.name);
161
+ urlTemplate = urlTemplate.replace(`{${p.name}}`, `\${${resolvedVar}}`);
162
+ }
163
+ lines.push(`${indent}let url = \`\${env.API_BASE_URL || ""}${urlTemplate}\`;`);
164
+ // Query params
165
+ if (op.queryParams.length > 0) {
166
+ lines.push(`${indent}const queryParams = new URLSearchParams();`);
167
+ // Auth injected as query param if applicable
168
+ for (const scheme of op.securitySchemes) {
169
+ if (scheme.type === "apiKey" && scheme.in === "query") {
170
+ const envVar = toEnvVarName(scheme.name);
171
+ lines.push(`${indent}if (env.${envVar}) queryParams.set(${JSON.stringify(scheme.name)}, env.${envVar});`);
172
+ }
173
+ }
174
+ for (const q of op.queryParams) {
175
+ const resolvedQVar = varMap.get(q.name) ?? toJsIdentifier(q.name);
176
+ lines.push(`${indent}if (${resolvedQVar} !== undefined) queryParams.set(${JSON.stringify(q.name)}, String(${resolvedQVar}));`);
177
+ }
178
+ lines.push(`${indent}const qs = queryParams.toString();`);
179
+ lines.push(`${indent}if (qs) url += \`?\${qs}\`;`);
180
+ }
181
+ else {
182
+ // Still might need query-based auth even with no other query params
183
+ let hasQueryAuth = false;
184
+ for (const scheme of op.securitySchemes) {
185
+ if (scheme.type === "apiKey" && scheme.in === "query") {
186
+ if (!hasQueryAuth) {
187
+ lines.push(`${indent}const queryParams = new URLSearchParams();`);
188
+ hasQueryAuth = true;
189
+ }
190
+ const envVar = toEnvVarName(scheme.name);
191
+ lines.push(`${indent}if (env.${envVar}) queryParams.set(${JSON.stringify(scheme.name)}, env.${envVar});`);
192
+ }
193
+ }
194
+ if (hasQueryAuth) {
195
+ lines.push(`${indent}const qs = queryParams.toString();`);
196
+ lines.push(`${indent}if (qs) url += \`?\${qs}\`;`);
197
+ }
198
+ }
199
+ lines.push("");
200
+ // Auth headers
201
+ const authHeaderLines = buildAuthHeaderLines(op.securitySchemes, indent);
202
+ // Request body
203
+ const hasBody = bodyFields.length > 0 || (op.requestBody !== undefined);
204
+ const needsBody = op.method === "post" ||
205
+ op.method === "put" ||
206
+ op.method === "patch" ||
207
+ op.method === "delete";
208
+ // Fetch with timeout
209
+ lines.push(`${indent}const timeoutMs = parseInt(String(env.MCPI_REQUEST_TIMEOUT_MS ?? "30000"), 10);`);
210
+ lines.push(`${indent}const controller = new AbortController();`);
211
+ lines.push(`${indent}const timeoutId = setTimeout(() => controller.abort(), timeoutMs);`);
212
+ lines.push("");
213
+ lines.push(`${indent}try {`);
214
+ lines.push(`${indent} const response = await fetch(url, {`);
215
+ lines.push(`${indent} method: ${JSON.stringify(op.method.toUpperCase())},`);
216
+ lines.push(`${indent} headers: {`);
217
+ if (needsBody && hasBody) {
218
+ lines.push(`${indent} "Content-Type": "application/json",`);
219
+ }
220
+ for (const l of authHeaderLines) {
221
+ lines.push(l);
222
+ }
223
+ lines.push(`${indent} },`);
224
+ if (needsBody && hasBody) {
225
+ let bodyExpr;
226
+ if (nonObjectBody !== false) {
227
+ bodyExpr = `JSON.stringify(${nonObjectBody})`;
228
+ }
229
+ else if (bodyFields.length > 0) {
230
+ // Use original API field names as JSON keys so e.g. "first-name" is not
231
+ // silently renamed to "firstName" in the serialized request body
232
+ const bodyEntries = bodyFields
233
+ .map(({ varName, originalKey }) => `${JSON.stringify(originalKey)}: ${varName}`)
234
+ .join(", ");
235
+ bodyExpr = `JSON.stringify({ ${bodyEntries} })`;
236
+ }
237
+ else {
238
+ bodyExpr = "JSON.stringify({})";
239
+ }
240
+ lines.push(`${indent} body: ${bodyExpr},`);
241
+ }
242
+ lines.push(`${indent} signal: controller.signal,`);
243
+ lines.push(`${indent} });`);
244
+ lines.push(`${indent} clearTimeout(timeoutId);`);
245
+ lines.push(`${indent} const contentType = response.headers.get("content-type") ?? "";`);
246
+ lines.push(`${indent} const text = await response.text();`);
247
+ lines.push(`${indent} let resultText: string;`);
248
+ lines.push(`${indent} if (contentType.includes("application/json")) {`);
249
+ lines.push(`${indent} try {`);
250
+ lines.push(`${indent} const parsed = JSON.parse(text) as unknown;`);
251
+ lines.push(`${indent} resultText = JSON.stringify(parsed, null, 2);`);
252
+ lines.push(`${indent} } catch {`);
253
+ lines.push(`${indent} resultText = text;`);
254
+ lines.push(`${indent} }`);
255
+ lines.push(`${indent} } else {`);
256
+ lines.push(`${indent} resultText = text;`);
257
+ lines.push(`${indent} }`);
258
+ lines.push(`${indent} return { content: [{ type: "text", text: resultText }] };`);
259
+ lines.push(`${indent}} catch (err) {`);
260
+ lines.push(`${indent} clearTimeout(timeoutId);`);
261
+ lines.push(`${indent} const message = err instanceof Error ? err.message : "Request failed";`);
262
+ lines.push(`${indent} return { content: [{ type: "text", text: \`Error: \${message}\` }] };`);
263
+ lines.push(`${indent}}`);
264
+ return lines.join("\n");
265
+ }
266
+ function buildAuthHeaderLines(schemes, indent) {
267
+ const lines = [];
268
+ for (const scheme of schemes) {
269
+ if (scheme.type === "bearer") {
270
+ lines.push(`${indent} ...(env.API_BEARER_TOKEN ? { Authorization: \`Bearer \${env.API_BEARER_TOKEN}\` } : {}),`);
271
+ }
272
+ else if (scheme.type === "apiKey" && scheme.in === "header") {
273
+ const envVar = toEnvVarName(scheme.name);
274
+ lines.push(`${indent} ...(env.${envVar} ? { ${JSON.stringify(scheme.name)}: env.${envVar} } : {}),`);
275
+ }
276
+ }
277
+ return lines;
278
+ }
279
+ /**
280
+ * Generate the shared AgentEnv interface imported by all generated tool files.
281
+ * Includes API_BASE_URL, MCPI_REQUEST_TIMEOUT_MS, and scheme-specific vars.
282
+ */
283
+ export function generateAgentEnvTs(securitySchemes) {
284
+ const schemes = Object.values(securitySchemes);
285
+ const hasBearerAuth = schemes.some((s) => s.type === "bearer");
286
+ const apiKeySchemes = schemes.filter((s) => s.type === "apiKey");
287
+ const fieldLines = [
288
+ ` /** Base URL for the API */`,
289
+ ` API_BASE_URL?: string;`,
290
+ ` /** Timeout for outbound API requests in milliseconds */`,
291
+ ` MCPI_REQUEST_TIMEOUT_MS?: string;`,
292
+ ];
293
+ if (hasBearerAuth) {
294
+ fieldLines.push(` /** Bearer token for authorization */`, ` API_BEARER_TOKEN?: string;`);
295
+ }
296
+ for (const scheme of apiKeySchemes) {
297
+ const envVar = toEnvVarName(scheme.name);
298
+ fieldLines.push(` /** API key for ${scheme.name} */`, ` ${envVar}?: string;`);
299
+ }
300
+ return [
301
+ "// Generated by @kya-os/create-mcpi-app — do not edit manually",
302
+ "export interface AgentEnv {",
303
+ ...fieldLines,
304
+ "}",
305
+ "",
306
+ ].join("\n");
307
+ }
308
+ function generateAuthTs(securitySchemes) {
309
+ const schemes = Object.values(securitySchemes);
310
+ const hasBearerAuth = schemes.some((s) => s.type === "bearer");
311
+ const apiKeySchemes = schemes.filter((s) => s.type === "apiKey");
312
+ const lines = [
313
+ "/**",
314
+ " * API Authentication Helpers",
315
+ " *",
316
+ " * Generated from OpenAPI security scheme definitions.",
317
+ " */",
318
+ "",
319
+ ];
320
+ let hasSchemes = false;
321
+ if (hasBearerAuth) {
322
+ hasSchemes = true;
323
+ lines.push(`export function getBearerAuthHeaders(token: string): Record<string, string> {`, ` return { Authorization: \`Bearer \${token}\` };`, `}`, ``);
324
+ }
325
+ for (const scheme of apiKeySchemes) {
326
+ if (scheme.in === "header") {
327
+ hasSchemes = true;
328
+ const fnName = `get${toPascalCase(scheme.name)}Header`;
329
+ lines.push(`export function ${fnName}(key: string): Record<string, string> {`, ` return { ${JSON.stringify(scheme.name)}: key };`, `}`, ``);
330
+ }
331
+ }
332
+ if (!hasSchemes) {
333
+ // No auth schemes found
334
+ lines.push(`// No security schemes defined in the API spec.`, ``);
335
+ }
336
+ return lines.join("\n");
337
+ }
338
+ function generateAgentTs(operations, _securitySchemes) {
339
+ const imports = operations
340
+ .map((op) => {
341
+ const factoryName = toFactoryName(op.toolName);
342
+ return `import { ${factoryName} } from "./tools/${op.toolName}.js";`;
343
+ })
344
+ .join("\n");
345
+ const registrations = operations
346
+ .map((op) => {
347
+ const factoryName = toFactoryName(op.toolName);
348
+ return [
349
+ ` {`,
350
+ ` const tool = ${factoryName}(this.env as unknown as AgentEnv);`,
351
+ ` this.registerToolWithProof(tool.name, tool.description, tool.inputSchema, tool.handler);`,
352
+ ` }`,
353
+ ].join("\n");
354
+ })
355
+ .join("\n");
356
+ return `import { MCPICloudflareAgent, type CloudflareEnv } from "@kya-os/mcp-i-cloudflare";
357
+ import type { CloudflareRuntimeConfig } from "@kya-os/mcp-i-cloudflare";
358
+ import { getRuntimeConfig } from "./mcpi-runtime-config.js";
359
+ import type { AgentEnv } from "./agent-env.js";
360
+ ${imports}
361
+
362
+ export class MCPIAgent extends MCPICloudflareAgent {
363
+ protected getAgentName(): string {
364
+ return (this.env as CloudflareEnv & { MCP_SERVER_NAME?: string }).MCP_SERVER_NAME || "openapi-agent";
365
+ }
366
+
367
+ protected getAgentVersion(): string {
368
+ return "1.0.0";
369
+ }
370
+
371
+ protected getRuntimeConfigInternal(env: CloudflareEnv): CloudflareRuntimeConfig {
372
+ return getRuntimeConfig(env);
373
+ }
374
+
375
+ protected async registerTools(): Promise<void> {
376
+ ${registrations}
377
+ }
378
+ }
379
+ `;
380
+ }
381
+ function generateIndexTs() {
382
+ return `import { createMCPIApp } from "@kya-os/mcp-i-cloudflare";
383
+ import { MCPIAgent } from "./agent.js";
384
+ import { getRuntimeConfig } from "./mcpi-runtime-config.js";
385
+
386
+ export default createMCPIApp({
387
+ AgentClass: MCPIAgent,
388
+ getRuntimeConfig,
389
+ });
390
+
391
+ export { MCPIAgent };
392
+ `;
393
+ }
394
+ function generateWranglerToml(identity, securitySchemes) {
395
+ const extraVars = generateApiEnvVarComments(securitySchemes);
396
+ return `#:schema node_modules/wrangler/config-schema.json
397
+ name = "openapi-agent"
398
+ main = "src/index.ts"
399
+ compatibility_date = "2025-01-01"
400
+ compatibility_flags = ["nodejs_compat"]
401
+
402
+ [[durable_objects.bindings]]
403
+ name = "MCP_OBJECT"
404
+ class_name = "MCPIAgent"
405
+
406
+ [[migrations]]
407
+ tag = "v1"
408
+ new_sqlite_classes = ["MCPIAgent"]
409
+
410
+ [[kv_namespaces]]
411
+ binding = "MCPI_KV"
412
+
413
+ [vars]
414
+ MCP_IDENTITY_AGENT_DID = "${identity.did}"
415
+ MCP_IDENTITY_PUBLIC_KEY = "${identity.publicKey}"
416
+ ALLOWED_ORIGINS = "https://claude.ai,https://app.anthropic.com"
417
+ DO_ROUTING_STRATEGY = "singleton"
418
+ XMCP_I_TS_SKEW_SEC = "120"
419
+ XMCP_I_SESSION_TTL = "1800"
420
+ AGENTSHIELD_API_URL = "https://kya.vouched.id"
421
+ # AGENTSHIELD_PROJECT_ID = "your-project-id"
422
+ MCPI_ENV = "development"
423
+ MCPI_REQUEST_TIMEOUT_MS = "30000"
424
+
425
+ # API Configuration
426
+ # API_BASE_URL = "https://api.example.com"
427
+ ${extraVars}
428
+ # SECRETS (set via wrangler secret or .dev.vars for local dev)
429
+ # See .dev.vars.example for required secrets
430
+ # AGENTSHIELD_API_KEY - optional: enable proofing
431
+ `;
432
+ }
433
+ function generateApiEnvVarComments(securitySchemes) {
434
+ const lines = [];
435
+ for (const scheme of Object.values(securitySchemes)) {
436
+ if (scheme.type === "bearer") {
437
+ lines.push(`# API_BEARER_TOKEN - set as secret`);
438
+ }
439
+ else if (scheme.type === "apiKey") {
440
+ const envVar = toEnvVarName(scheme.name);
441
+ lines.push(`# ${envVar} - set as secret`);
442
+ }
443
+ }
444
+ return lines.join("\n");
445
+ }
446
+ function generateDevVarsExample(securitySchemes) {
447
+ const schemes = Object.values(securitySchemes);
448
+ const secretLines = [];
449
+ for (const scheme of schemes) {
450
+ if (scheme.type === "bearer") {
451
+ secretLines.push(`API_BEARER_TOKEN="your-bearer-token-here"`);
452
+ }
453
+ else if (scheme.type === "apiKey") {
454
+ const envVar = toEnvVarName(scheme.name);
455
+ secretLines.push(`${envVar}="your-api-key-here"`);
456
+ }
457
+ }
458
+ return `# Copy this to .dev.vars for local development
459
+ # DO NOT commit .dev.vars to version control
460
+
461
+ # Agent Identity (required)
462
+ # Replace with your private key (shown after generation)
463
+ MCP_IDENTITY_PRIVATE_KEY="your-private-key-here"
464
+
465
+ # AgentShield API Key (optional - enables proof submission)
466
+ AGENTSHIELD_API_KEY="sk_your_api_key_here"
467
+
468
+ # API Configuration
469
+ # Timeout for outbound API requests in milliseconds (default: 30000)
470
+ MCPI_REQUEST_TIMEOUT_MS="30000"
471
+
472
+ # API Authentication
473
+ ${secretLines.length > 0 ? secretLines.join("\n") : "# No auth secrets required"}
474
+ `;
475
+ }
476
+ function generateReadme(operations, _securitySchemes) {
477
+ const toolList = operations
478
+ .map((op) => `- \`${op.toolName}\`: ${op.description}`)
479
+ .join("\n");
480
+ return `# OpenAPI MCP-I Agent
481
+
482
+ This agent was generated from an OpenAPI specification using @kya-os/create-mcpi-app.
483
+
484
+ ## Available Tools
485
+
486
+ ${toolList}
487
+
488
+ ## Setup
489
+
490
+ 1. Copy \`.dev.vars.example\` to \`.dev.vars\` and fill in your secrets
491
+ 2. Install dependencies: \`npm install\`
492
+ 3. Start development: \`npm run dev\`
493
+ 4. Deploy: \`npm run deploy\`
494
+
495
+ ## Configuration
496
+
497
+ Set the following environment variables:
498
+
499
+ - \`MCP_IDENTITY_PRIVATE_KEY\` - Agent private key (required)
500
+ - \`API_BASE_URL\` - Base URL for the API (required)
501
+ - \`AGENTSHIELD_API_KEY\` - AgentShield API key (optional)
502
+ `;
503
+ }
504
+ // ============================================================================
505
+ // Utility functions
506
+ // ============================================================================
507
+ function toFactoryName(toolName) {
508
+ const pascal = toolName
509
+ .split("_")
510
+ .map((seg) => seg.charAt(0).toUpperCase() + seg.slice(1))
511
+ .join("");
512
+ return `create${pascal}Tool`;
513
+ }
514
+ function toEnvVarName(name) {
515
+ return name.replace(/[^a-zA-Z0-9]/g, "_").toUpperCase();
516
+ }
517
+ function toPascalCase(str) {
518
+ return str
519
+ .split(/[^a-zA-Z0-9]+/)
520
+ .map((s) => s.charAt(0).toUpperCase() + s.slice(1))
521
+ .join("");
522
+ }
523
+ function schemaToTsType(schema) {
524
+ if (!schema.type)
525
+ return "unknown";
526
+ // OpenAPI 3.1 allows type to be an array (e.g. ["string", "null"] for nullable
527
+ // fields). Normalise to a single type by picking the first non-null, non-undefined
528
+ // entry so that downstream comparisons always operate on a plain string.
529
+ const t = Array.isArray(schema.type)
530
+ ? (schema.type.find((v) => v !== "null" && v !== "undefined") ?? schema.type[0])
531
+ : schema.type;
532
+ if (t === "integer" || t === "number")
533
+ return "number";
534
+ if (t === "boolean")
535
+ return "boolean";
536
+ if (t === "array")
537
+ return "unknown[]";
538
+ if (t === "object")
539
+ return "Record<string, unknown>";
540
+ if (t === "string")
541
+ return "string";
542
+ return "unknown";
543
+ }
544
+ function serializeSchema(schema) {
545
+ return JSON.stringify(schema, null, 4)
546
+ .split("\n")
547
+ .map((line, i) => (i === 0 ? line : ` ${line}`))
548
+ .join("\n");
549
+ }
550
+ //# sourceMappingURL=generate-openapi-tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-openapi-tools.js","sourceRoot":"","sources":["../../src/helpers/generate-openapi-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAUvE,+EAA+E;AAC/E,aAAa;AACb,+EAA+E;AAE/E;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAC9B,SAAyB,EACzB,gBAAmC;IAEnC,MAAM,WAAW,GAAG,aAAa,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IACtD,MAAM,WAAW,GAAG,mBAAmB,CAAC,SAAS,CAAC,CAAC;IAEnD,OAAO;;;kBAGS,WAAW;;YAEjB,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,QAAQ,CAAC;mBA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I,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAChF,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC;IAChB,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,QAAQ;QAAE,OAAO,QAAQ,CAAC;IACvD,IAAI,CAAC,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IACtC,IAAI,CAAC,KAAK,OAAO;QAAE,OAAO,WAAW,CAAC;IACtC,IAAI,CAAC,KAAK,QAAQ;QAAE,OAAO,yBAAyB,CAAC;IACrD,IAAI,CAAC,KAAK,QAAQ;QAAE,OAAO,QAAQ,CAAC;IACpC,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,eAAe,CAAC,MAAmB;IAC1C,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;SACnC,KAAK,CAAC,IAAI,CAAC;SACX,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;SAClD,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Runtime Config Generator
3
+ *
4
+ * Generates the mcpi-runtime-config.ts file used by both standalone tool
5
+ * generation and full project scaffolding. Extracted into its own module to
6
+ * avoid a circular dependency between generate-openapi-tools and
7
+ * generate-openapi-project.
8
+ *
9
+ * @module @kya-os/create-mcpi-app/helpers/generate-runtime-config
10
+ */
11
+ /**
12
+ * Generate the mcpi-runtime-config.ts source for a generated MCP-I project.
13
+ * The file wires Cloudflare env vars into the MCP-I runtime configuration.
14
+ */
15
+ export declare function generateRuntimeConfigTs(): string;
16
+ //# sourceMappingURL=generate-runtime-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-runtime-config.d.ts","sourceRoot":"","sources":["../../src/helpers/generate-runtime-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;;GAGG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,CAiChD"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Runtime Config Generator
3
+ *
4
+ * Generates the mcpi-runtime-config.ts file used by both standalone tool
5
+ * generation and full project scaffolding. Extracted into its own module to
6
+ * avoid a circular dependency between generate-openapi-tools and
7
+ * generate-openapi-project.
8
+ *
9
+ * @module @kya-os/create-mcpi-app/helpers/generate-runtime-config
10
+ */
11
+ /**
12
+ * Generate the mcpi-runtime-config.ts source for a generated MCP-I project.
13
+ * The file wires Cloudflare env vars into the MCP-I runtime configuration.
14
+ */
15
+ export function generateRuntimeConfigTs() {
16
+ return `import { defineConfig, type CloudflareRuntimeConfig, type CloudflareEnv } from "@kya-os/mcp-i-cloudflare";
17
+
18
+ export function getRuntimeConfig(env: CloudflareEnv): CloudflareRuntimeConfig {
19
+ const environment = ((env as Record<string, string>).MCPI_ENV || "development") as "development" | "production";
20
+
21
+ const proofingConfig = (env as Record<string, string>).AGENTSHIELD_API_KEY
22
+ ? {
23
+ enabled: true,
24
+ batchQueue: {
25
+ destinations: [
26
+ {
27
+ type: "agentshield" as const,
28
+ apiKey: (env as Record<string, string>).AGENTSHIELD_API_KEY,
29
+ apiUrl: (env as Record<string, string>).AGENTSHIELD_API_URL || "https://kya.vouched.id",
30
+ },
31
+ ],
32
+ },
33
+ }
34
+ : undefined;
35
+
36
+ return defineConfig({
37
+ environment,
38
+ proofing: proofingConfig,
39
+ vars: {
40
+ ENVIRONMENT: environment,
41
+ AGENTSHIELD_API_KEY: (env as Record<string, string>).AGENTSHIELD_API_KEY,
42
+ AGENTSHIELD_API_URL: (env as Record<string, string>).AGENTSHIELD_API_URL,
43
+ AGENTSHIELD_PROJECT_ID: (env as Record<string, string>).AGENTSHIELD_PROJECT_ID,
44
+ },
45
+ });
46
+ }
47
+ `;
48
+ }
49
+ //# sourceMappingURL=generate-runtime-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-runtime-config.js","sourceRoot":"","sources":["../../src/helpers/generate-runtime-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;;GAGG;AACH,MAAM,UAAU,uBAAuB;IACrC,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BR,CAAC;AACF,CAAC"}