@introspection-ai/recipes 0.13.0 → 0.14.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 (222) hide show
  1. package/README.md +45 -58
  2. package/dist/{agent-tool.d.ts → agents.d.ts} +4 -1
  3. package/dist/agents.d.ts.map +1 -0
  4. package/dist/{agent-tool.js → agents.js} +1 -1
  5. package/dist/agents.js.map +1 -0
  6. package/dist/api/extensions.d.ts +3 -0
  7. package/dist/api/extensions.d.ts.map +1 -0
  8. package/dist/api/extensions.js +2 -0
  9. package/dist/api/extensions.js.map +1 -0
  10. package/dist/api/mcp.d.ts +4 -0
  11. package/dist/api/mcp.d.ts.map +1 -0
  12. package/dist/api/mcp.js +2 -0
  13. package/dist/api/mcp.js.map +1 -0
  14. package/dist/api/session.d.ts +3 -0
  15. package/dist/api/session.d.ts.map +1 -0
  16. package/dist/api/session.js +2 -0
  17. package/dist/api/session.js.map +1 -0
  18. package/dist/child-agent.d.ts +5 -4
  19. package/dist/child-agent.d.ts.map +1 -1
  20. package/dist/child-agent.js +26 -117
  21. package/dist/child-agent.js.map +1 -1
  22. package/dist/child-session.d.ts +23 -0
  23. package/dist/child-session.d.ts.map +1 -0
  24. package/dist/child-session.js +48 -0
  25. package/dist/child-session.js.map +1 -0
  26. package/dist/extensions.d.ts +29 -0
  27. package/dist/extensions.d.ts.map +1 -0
  28. package/dist/extensions.js +119 -0
  29. package/dist/extensions.js.map +1 -0
  30. package/dist/index.d.ts +4 -13
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +2 -13
  33. package/dist/index.js.map +1 -1
  34. package/dist/inspect.d.ts +38 -5
  35. package/dist/inspect.d.ts.map +1 -1
  36. package/dist/inspect.js +92 -41
  37. package/dist/inspect.js.map +1 -1
  38. package/dist/interactions.d.ts +18 -2
  39. package/dist/interactions.d.ts.map +1 -1
  40. package/dist/interactions.js +41 -10
  41. package/dist/interactions.js.map +1 -1
  42. package/dist/mcp-catalog.d.ts +1 -0
  43. package/dist/mcp-catalog.d.ts.map +1 -1
  44. package/dist/mcp-catalog.js +14 -6
  45. package/dist/mcp-catalog.js.map +1 -1
  46. package/dist/mcp-chunks/auth-command-ZLGYIEUY.js +273 -0
  47. package/dist/mcp-chunks/call-arguments-LU3W6D3K.js +13 -0
  48. package/dist/mcp-chunks/call-command-LKTKSYTH.js +612 -0
  49. package/dist/mcp-chunks/chunk-2U4BSDC4.js +3951 -0
  50. package/dist/mcp-chunks/chunk-2XL7MG7R.js +272 -0
  51. package/dist/mcp-chunks/chunk-3BJA27PY.js +2321 -0
  52. package/dist/mcp-chunks/chunk-4SQKWYFF.js +15 -0
  53. package/dist/mcp-chunks/chunk-5QOSCSQB.js +290 -0
  54. package/dist/mcp-chunks/chunk-6W5QFASN.js +77 -0
  55. package/dist/mcp-chunks/chunk-6XCZGU3G.js +1004 -0
  56. package/dist/mcp-chunks/chunk-7FHEBT5G.js +149 -0
  57. package/dist/mcp-chunks/chunk-7KA2VJVZ.js +114 -0
  58. package/dist/mcp-chunks/chunk-7UDVSOOF.js +138 -0
  59. package/dist/mcp-chunks/chunk-BNV3TPE4.js +66 -0
  60. package/dist/mcp-chunks/chunk-BTLAWHTA.js +129 -0
  61. package/dist/mcp-chunks/chunk-BV56DXPW.js +13 -0
  62. package/dist/mcp-chunks/chunk-BWHIA4PC.js +90 -0
  63. package/dist/mcp-chunks/chunk-BZIQOWE6.js +267 -0
  64. package/dist/mcp-chunks/chunk-D3MRAZ6H.js +16140 -0
  65. package/dist/mcp-chunks/chunk-DHBE7UBH.js +750 -0
  66. package/dist/mcp-chunks/chunk-E22DYOW5.js +251 -0
  67. package/dist/mcp-chunks/chunk-ECIVB7P4.js +139 -0
  68. package/dist/mcp-chunks/chunk-HKRJ6O36.js +1076 -0
  69. package/dist/mcp-chunks/chunk-IABRYROW.js +44 -0
  70. package/dist/mcp-chunks/chunk-J6LYIZXN.js +45 -0
  71. package/dist/mcp-chunks/chunk-L7NTQVYN.js +161 -0
  72. package/dist/mcp-chunks/chunk-LEZSACDE.js +141 -0
  73. package/dist/mcp-chunks/chunk-LKIBAYKU.js +208 -0
  74. package/dist/mcp-chunks/chunk-LNH5LAJD.js +152 -0
  75. package/dist/mcp-chunks/chunk-LQQEYD76.js +124 -0
  76. package/dist/mcp-chunks/chunk-LRKZP7DJ.js +47 -0
  77. package/dist/mcp-chunks/chunk-LS7PMWSR.js +109 -0
  78. package/dist/mcp-chunks/chunk-M3TPODXI.js +95 -0
  79. package/dist/mcp-chunks/chunk-MZ2NARG7.js +400 -0
  80. package/dist/mcp-chunks/chunk-N46NEFAF.js +45 -0
  81. package/dist/mcp-chunks/chunk-NNOEGEUZ.js +17273 -0
  82. package/dist/mcp-chunks/chunk-NRAJX5E4.js +69 -0
  83. package/dist/mcp-chunks/chunk-P3PSC54P.js +869 -0
  84. package/dist/mcp-chunks/chunk-PIIYJR44.js +6341 -0
  85. package/dist/mcp-chunks/chunk-PWYFKGKG.js +385 -0
  86. package/dist/mcp-chunks/chunk-SJCCBNZ4.js +45 -0
  87. package/dist/mcp-chunks/chunk-TATVT5IT.js +194 -0
  88. package/dist/mcp-chunks/chunk-TEUKFFQL.js +29 -0
  89. package/dist/mcp-chunks/chunk-UKYNQGNE.js +150 -0
  90. package/dist/mcp-chunks/chunk-UNKB4SBV.js +37 -0
  91. package/dist/mcp-chunks/chunk-WD6BOD24.js +138 -0
  92. package/dist/mcp-chunks/chunk-WQJZMCJN.js +73 -0
  93. package/dist/mcp-chunks/chunk-XANPGTLI.js +364 -0
  94. package/dist/mcp-chunks/chunk-XQK2JSW4.js +35 -0
  95. package/dist/mcp-chunks/chunk-YHQUTU6L.js +571 -0
  96. package/dist/mcp-chunks/chunk-YVZKMV5H.js +57 -0
  97. package/dist/mcp-chunks/cli-UV4QJZZM.js +929 -0
  98. package/dist/mcp-chunks/client-S7RQUG5U.js +13 -0
  99. package/dist/mcp-chunks/config-command-NLAGKID5.js +1101 -0
  100. package/dist/mcp-chunks/daemon-command-U242Z6VY.js +26 -0
  101. package/dist/mcp-chunks/dist-LK3SHAMX.js +6478 -0
  102. package/dist/mcp-chunks/emit-ts-command-VBXVXO6V.js +386 -0
  103. package/dist/mcp-chunks/generate-cli-runner-6CAZZA3P.js +1426 -0
  104. package/dist/mcp-chunks/inspect-cli-command-3ZORTOR7.js +111 -0
  105. package/dist/mcp-chunks/launch-YKRXHXJI.js +10 -0
  106. package/dist/mcp-chunks/lifecycle-XVKRHPH3.js +16 -0
  107. package/dist/mcp-chunks/list-command-2MEGGNFQ.js +4190 -0
  108. package/dist/mcp-chunks/output-utils-NKESLAJ6.js +12 -0
  109. package/dist/mcp-chunks/prompt-B1Yc1NPt-VGOTWJMN.js +918 -0
  110. package/dist/mcp-chunks/record-command-YXHTTTT5.js +17 -0
  111. package/dist/mcp-chunks/replay-command-25HJ6AQU.js +85 -0
  112. package/dist/mcp-chunks/resource-command-OO4NYF5C.js +97 -0
  113. package/dist/mcp-chunks/result-utils-MOHHLNM7.js +15 -0
  114. package/dist/mcp-chunks/runtime-5WJ3G25Y.js +33 -0
  115. package/dist/mcp-chunks/runtime-wrapper-RPWDIDBF.js +10 -0
  116. package/dist/mcp-chunks/serve-command-DHXJZMMN.js +3302 -0
  117. package/dist/mcp-chunks/timeouts-W2XWCCXR.js +18 -0
  118. package/dist/mcp-chunks/vault-command-PIYIUEZL.js +154 -0
  119. package/dist/mcp-daemon-client.d.ts +6 -1
  120. package/dist/mcp-daemon-client.d.ts.map +1 -1
  121. package/dist/mcp-daemon-client.js +119 -2
  122. package/dist/mcp-daemon-client.js.map +1 -1
  123. package/dist/mcp-daemon-protocol.d.ts +18 -1
  124. package/dist/mcp-daemon-protocol.d.ts.map +1 -1
  125. package/dist/mcp-daemon-protocol.js +31 -0
  126. package/dist/mcp-daemon-protocol.js.map +1 -1
  127. package/dist/mcp-daemon.js +169 -76602
  128. package/dist/mcp-daemon.js.map +1 -1
  129. package/dist/mcp-policy.d.ts +11 -0
  130. package/dist/mcp-policy.d.ts.map +1 -0
  131. package/dist/mcp-policy.js +27 -0
  132. package/dist/mcp-policy.js.map +1 -0
  133. package/dist/mcp-run-worker.js +38 -76540
  134. package/dist/mcp-tools.d.ts +39 -0
  135. package/dist/mcp-tools.d.ts.map +1 -0
  136. package/dist/mcp-tools.js +493 -0
  137. package/dist/mcp-tools.js.map +1 -0
  138. package/dist/mcp.d.ts +21 -9
  139. package/dist/mcp.d.ts.map +1 -1
  140. package/dist/mcp.js +101 -31
  141. package/dist/mcp.js.map +1 -1
  142. package/dist/model-binding.d.ts +39 -0
  143. package/dist/model-binding.d.ts.map +1 -0
  144. package/dist/model-binding.js +103 -0
  145. package/dist/model-binding.js.map +1 -0
  146. package/dist/pi-extension.d.ts +2 -22
  147. package/dist/pi-extension.d.ts.map +1 -1
  148. package/dist/pi-extension.js +296 -71
  149. package/dist/pi-extension.js.map +1 -1
  150. package/dist/recipe/resolve.d.ts +43 -20
  151. package/dist/recipe/resolve.d.ts.map +1 -1
  152. package/dist/recipe/resolve.js +215 -70
  153. package/dist/recipe/resolve.js.map +1 -1
  154. package/dist/recipe-agent.d.ts +24 -27
  155. package/dist/recipe-agent.d.ts.map +1 -1
  156. package/dist/recipe-agent.js +278 -230
  157. package/dist/recipe-agent.js.map +1 -1
  158. package/dist/recipe-check.d.ts +17 -0
  159. package/dist/recipe-check.d.ts.map +1 -0
  160. package/dist/recipe-check.js +258 -0
  161. package/dist/recipe-check.js.map +1 -0
  162. package/dist/recipe-extensions.d.ts.map +1 -1
  163. package/dist/recipe-extensions.js +0 -3
  164. package/dist/recipe-extensions.js.map +1 -1
  165. package/dist/recipe-model.d.ts +3 -1
  166. package/dist/recipe-model.d.ts.map +1 -1
  167. package/dist/recipe-model.js +15 -12
  168. package/dist/recipe-model.js.map +1 -1
  169. package/dist/recipe-package.d.ts +6 -28
  170. package/dist/recipe-package.d.ts.map +1 -1
  171. package/dist/recipe-package.js +248 -191
  172. package/dist/recipe-package.js.map +1 -1
  173. package/dist/recipe-skills.d.ts.map +1 -1
  174. package/dist/recipe-skills.js +42 -29
  175. package/dist/recipe-skills.js.map +1 -1
  176. package/dist/run-controller.d.ts +10 -9
  177. package/dist/run-controller.d.ts.map +1 -1
  178. package/dist/run-controller.js +28 -21
  179. package/dist/run-controller.js.map +1 -1
  180. package/dist/session.d.ts +40 -53
  181. package/dist/session.d.ts.map +1 -1
  182. package/dist/session.js +312 -173
  183. package/dist/session.js.map +1 -1
  184. package/dist/test-utils.d.ts +7 -7
  185. package/dist/test-utils.d.ts.map +1 -1
  186. package/dist/test-utils.js +32 -15
  187. package/dist/test-utils.js.map +1 -1
  188. package/docs/agent-composition.md +41 -35
  189. package/docs/host-api.md +201 -0
  190. package/docs/index.md +8 -14
  191. package/docs/interactions.md +12 -11
  192. package/docs/mcp-auth.md +6 -6
  193. package/docs/mcp-configuration.md +72 -24
  194. package/docs/pi-extension.md +39 -11
  195. package/docs/recipe-flow.md +9 -9
  196. package/docs/recipe-format.md +90 -41
  197. package/package.json +23 -17
  198. package/vendor/mcp-client/darwin-arm64/mcp-client +0 -0
  199. package/vendor/mcp-client/darwin-x64/mcp-client +0 -0
  200. package/vendor/mcp-client/linux-arm64/mcp-client +0 -0
  201. package/vendor/recipe-check/darwin-arm64/recipe-check +0 -0
  202. package/vendor/recipe-check/darwin-x64/recipe-check +0 -0
  203. package/vendor/recipe-check/linux-arm64/recipe-check +0 -0
  204. package/vendor/recipe-check/linux-x64/recipe-check +0 -0
  205. package/vendor/recipe-check/linux-x64-musl/recipe-check +0 -0
  206. package/vendor/recipe-check/win32-x64/recipe-check.exe +0 -0
  207. package/dist/agent-tool.d.ts.map +0 -1
  208. package/dist/agent-tool.js.map +0 -1
  209. package/dist/run.d.ts +0 -28
  210. package/dist/run.d.ts.map +0 -1
  211. package/dist/run.js +0 -84
  212. package/dist/run.js.map +0 -1
  213. package/dist/testing.d.ts +0 -25
  214. package/dist/testing.d.ts.map +0 -1
  215. package/dist/testing.js +0 -96
  216. package/dist/testing.js.map +0 -1
  217. package/docs/deployment-configuration.md +0 -65
  218. package/docs/migration.md +0 -70
  219. package/docs/python-bindings-release.md +0 -47
  220. package/docs/recipe-evals.md +0 -70
  221. package/docs/recipe-judges.md +0 -152
  222. package/docs/runtime-library.md +0 -171
@@ -0,0 +1,386 @@
1
+ import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
+ import {
3
+ extractGeneratorFlags,
4
+ readPackageMetadata
5
+ } from "./chunk-DHBE7UBH.js";
6
+ import {
7
+ buildToolDoc
8
+ } from "./chunk-MZ2NARG7.js";
9
+ import {
10
+ loadToolMetadata
11
+ } from "./chunk-IABRYROW.js";
12
+ import "./chunk-XANPGTLI.js";
13
+ import "./chunk-N46NEFAF.js";
14
+ import "./chunk-BNV3TPE4.js";
15
+ import {
16
+ findServerByHttpUrl
17
+ } from "./chunk-TEUKFFQL.js";
18
+ import {
19
+ extractHttpServerTarget
20
+ } from "./chunk-M3TPODXI.js";
21
+ import {
22
+ consumeOutputFormat
23
+ } from "./chunk-YVZKMV5H.js";
24
+ import "./chunk-4SQKWYFF.js";
25
+ import "./chunk-LRKZP7DJ.js";
26
+
27
+ // node_modules/.pnpm/mcporter@0.12.3/node_modules/mcporter/dist/cli/emit-ts-command.js
28
+ import fs from "node:fs/promises";
29
+ import path2 from "node:path";
30
+
31
+ // node_modules/.pnpm/mcporter@0.12.3/node_modules/mcporter/dist/cli/emit-ts-templates.js
32
+ import path from "node:path";
33
+ function renderTypesModule(input) {
34
+ const lines = [];
35
+ lines.push(...renderHeader(input.metadata));
36
+ lines.push("import type { CallResult } from 'mcporter';");
37
+ lines.push("");
38
+ lines.push(`export interface ${input.interfaceName} {`);
39
+ input.docs.forEach((entry, index) => {
40
+ lines.push(...renderDocComment(entry.doc.docLines, " "));
41
+ const methodSignature = toInterfaceSignature(entry.doc.tsSignature, entry.toolName, { wrapInPromise: true });
42
+ lines.push(` ${methodSignature}`);
43
+ if (entry.doc.optionalSummary) {
44
+ lines.push(` // ${entry.doc.optionalSummary.replace(/^\/\//, "").trim()}`);
45
+ }
46
+ if (index !== input.docs.length - 1) {
47
+ lines.push("");
48
+ }
49
+ });
50
+ if (input.docs.length === 0) {
51
+ lines.push(" // No tools reported for this server.");
52
+ }
53
+ lines.push("}");
54
+ lines.push("");
55
+ return lines.join("\n");
56
+ }
57
+ function renderClientModule(input) {
58
+ const lines = [];
59
+ lines.push(...renderHeader(input.metadata));
60
+ lines.push("import { createRuntime, createServerProxy, wrapCallResult } from 'mcporter';");
61
+ lines.push(`import type { ${input.interfaceName} } from '${input.typesImportPath}';`);
62
+ lines.push("");
63
+ lines.push("type RuntimeInstance = Awaited<ReturnType<typeof createRuntime>>;");
64
+ const clientType = `${input.interfaceName.replace(/Tools$/, "Client")}`;
65
+ const factoryName = `create${input.interfaceName.replace(/Tools$/, "")}Client`;
66
+ const serverName = input.metadata.server.name;
67
+ lines.push(`export type ${clientType} = ${input.interfaceName} & { close(): Promise<void> };`);
68
+ lines.push("");
69
+ lines.push("export interface CreateClientOptions {");
70
+ lines.push(" runtime?: RuntimeInstance;");
71
+ lines.push(" configPath?: string;");
72
+ lines.push(" rootDir?: string;");
73
+ lines.push("}");
74
+ lines.push("");
75
+ lines.push(`export async function ${factoryName}(options: CreateClientOptions = {}): Promise<${clientType}> {`);
76
+ lines.push(" const runtime = options.runtime ?? (await createRuntime({");
77
+ lines.push(" configPath: options.configPath,");
78
+ lines.push(" rootDir: options.rootDir,");
79
+ lines.push(" }));");
80
+ lines.push(" const ownsRuntime = !options.runtime;");
81
+ lines.push(` const proxy = createServerProxy(runtime, ${JSON.stringify(serverName)});`);
82
+ lines.push(` const client: ${clientType} = {`);
83
+ input.docs.forEach((entry, _index) => {
84
+ const memberName = toMemberName(entry.toolName);
85
+ const indexKey = toIndexKey(entry.toolName);
86
+ lines.push(` async ${memberName}(params: Parameters<${input.interfaceName}[${indexKey}]>[0]) {`);
87
+ lines.push(` const tool = proxy.${entry.methodName} as (args: Parameters<${input.interfaceName}[${indexKey}]>[0]) => Promise<unknown>;`);
88
+ lines.push(" const raw = await tool(params);");
89
+ lines.push(" return wrapCallResult(raw).callResult;");
90
+ lines.push(" },");
91
+ lines.push("");
92
+ });
93
+ lines.push(" async close() {");
94
+ lines.push(" if (ownsRuntime) {");
95
+ lines.push(` await runtime.close(${JSON.stringify(serverName)}).catch(() => {});`);
96
+ lines.push(" }");
97
+ lines.push(" },");
98
+ lines.push(" };");
99
+ lines.push(" return client;");
100
+ lines.push("}");
101
+ lines.push("");
102
+ return lines.join("\n");
103
+ }
104
+ function renderHeader(metadata) {
105
+ const lines = [];
106
+ const timestamp = metadata.generatedAt.toISOString();
107
+ lines.push(`// Generated on ${timestamp} by ${metadata.generatorLabel}`);
108
+ if (metadata.server.description) {
109
+ lines.push(`// Server: ${metadata.server.name} \u2014 ${metadata.server.description}`);
110
+ } else {
111
+ lines.push(`// Server: ${metadata.server.name}`);
112
+ }
113
+ const source = describeSource(metadata.server);
114
+ if (source) {
115
+ lines.push(`// Source: ${source}`);
116
+ }
117
+ const transport = describeTransport(metadata.server);
118
+ if (transport) {
119
+ lines.push(`// Transport: ${transport}`);
120
+ }
121
+ lines.push("");
122
+ return lines;
123
+ }
124
+ function renderDocComment(docLines, indent) {
125
+ if (!docLines || docLines.length === 0) {
126
+ return [];
127
+ }
128
+ return docLines.map((line) => `${indent}${line}`);
129
+ }
130
+ function toInterfaceSignature(signature, toolName, options) {
131
+ const trimmed = signature.trim();
132
+ const match = trimmed.match(/^function\s+([^(]+)\((.*)\)\s*(?::\s*([^;]+))?;?$/);
133
+ if (!match) {
134
+ return trimmed.replace(/^function\s+/, "");
135
+ }
136
+ const [, , params, returnTypeRaw] = match;
137
+ const returnType = (returnTypeRaw ?? "void").trim();
138
+ const finalReturn = options?.wrapInPromise ? `Promise<${returnType}>` : returnType;
139
+ return `${toMemberName(toolName)}(${params}): ${finalReturn};`;
140
+ }
141
+ var SAFE_IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
142
+ function toMemberName(name) {
143
+ return SAFE_IDENTIFIER.test(name) ? name : JSON.stringify(name);
144
+ }
145
+ function toIndexKey(name) {
146
+ return JSON.stringify(name);
147
+ }
148
+ function describeTransport(definition) {
149
+ if (definition.command.kind === "http") {
150
+ const url = definition.command.url instanceof URL ? definition.command.url.href : String(definition.command.url);
151
+ return `HTTP ${url}`;
152
+ }
153
+ if (definition.command.kind === "stdio") {
154
+ const cmd = [definition.command.command, ...definition.command.args ?? []].join(" ").trim();
155
+ return cmd.length > 0 ? `STDIO ${cmd}` : "STDIO";
156
+ }
157
+ return void 0;
158
+ }
159
+ function describeSource(definition) {
160
+ if (definition.source?.kind === "import") {
161
+ return path.normalize(definition.source.path);
162
+ }
163
+ if (definition.source?.kind === "local") {
164
+ return definition.source.path;
165
+ }
166
+ return void 0;
167
+ }
168
+
169
+ // node_modules/.pnpm/mcporter@0.12.3/node_modules/mcporter/dist/cli/emit-ts-command.js
170
+ async function handleEmitTs(runtime, args) {
171
+ const options = parseEmitTsArgs(args);
172
+ const definition = getServerDefinition(runtime, options.server);
173
+ const metadataEntries = await loadToolMetadata(runtime, options.server, {
174
+ includeSchema: true,
175
+ autoAuthorize: false
176
+ });
177
+ const generator = await readPackageMetadata();
178
+ const metadata = {
179
+ server: definition,
180
+ generatorLabel: `${generator.name}@${generator.version}`,
181
+ generatedAt: /* @__PURE__ */ new Date()
182
+ };
183
+ const docEntries = buildDocEntries(options.server, metadataEntries, options.includeOptional);
184
+ const interfaceName = buildInterfaceName(options.server);
185
+ if (options.mode === "types") {
186
+ const source = renderTypesModule({ interfaceName, docs: docEntries, metadata });
187
+ await writeFile(options.outPath, source);
188
+ if (options.format === "json") {
189
+ console.log(JSON.stringify({
190
+ mode: "types",
191
+ server: options.server,
192
+ outPath: options.outPath
193
+ }, null, 2));
194
+ } else {
195
+ console.log(`Emitted TypeScript definitions for ${options.server} \u2192 ${options.outPath}`);
196
+ }
197
+ return;
198
+ }
199
+ const typesOutPath = options.typesOutPath ?? deriveTypesOutPath(options.outPath);
200
+ const relativeImportPath = computeImportPath(options.outPath, typesOutPath);
201
+ const typesSource = renderTypesModule({ interfaceName, docs: docEntries, metadata });
202
+ const clientSource = renderClientModule({
203
+ interfaceName,
204
+ docs: docEntries,
205
+ metadata,
206
+ typesImportPath: relativeImportPath
207
+ });
208
+ await writeFile(typesOutPath, typesSource);
209
+ await writeFile(options.outPath, clientSource);
210
+ if (options.format === "json") {
211
+ console.log(JSON.stringify({
212
+ mode: "client",
213
+ server: options.server,
214
+ clientOutPath: options.outPath,
215
+ typesOutPath
216
+ }, null, 2));
217
+ } else {
218
+ console.log(`Emitted client + types for ${options.server} \u2192 ${options.outPath} / ${typesOutPath}`);
219
+ }
220
+ }
221
+ function printEmitTsHelp() {
222
+ console.error([
223
+ "Usage: mcporter emit-ts <server> --out <file> [flags]",
224
+ "",
225
+ "Flags:",
226
+ " --mode types|client Emit declarations only or client + declarations.",
227
+ " --out <path> Output .ts/.d.ts file.",
228
+ " --types-out <path> Declaration output path for --mode client.",
229
+ " --include-optional Include optional schema fields in signatures.",
230
+ " --json Print a JSON summary."
231
+ ].join("\n"));
232
+ }
233
+ function parseEmitTsArgs(args) {
234
+ const flags = {
235
+ mode: "types",
236
+ includeOptional: false,
237
+ format: "text"
238
+ };
239
+ const common = extractGeneratorFlags(args, { allowIncludeOptional: true });
240
+ if (common.includeOptional) {
241
+ flags.includeOptional = true;
242
+ }
243
+ flags.format = consumeOutputFormat(args, {
244
+ defaultFormat: "text",
245
+ allowed: ["text", "json"],
246
+ enableRawShortcut: false,
247
+ jsonShortcutFlag: "--json"
248
+ });
249
+ let index = 0;
250
+ while (index < args.length) {
251
+ const token = args[index];
252
+ if (!token) {
253
+ index += 1;
254
+ continue;
255
+ }
256
+ if (token === "--out") {
257
+ const value = args[index + 1];
258
+ if (!value) {
259
+ throw new Error("Flag '--out' requires a path.");
260
+ }
261
+ flags.outPath = value;
262
+ args.splice(index, 2);
263
+ continue;
264
+ }
265
+ if (token === "--types-out") {
266
+ const value = args[index + 1];
267
+ if (!value) {
268
+ throw new Error("Flag '--types-out' requires a path.");
269
+ }
270
+ flags.typesOutPath = value;
271
+ args.splice(index, 2);
272
+ continue;
273
+ }
274
+ if (token === "--mode") {
275
+ const value = args[index + 1];
276
+ if (value !== "types" && value !== "client") {
277
+ throw new Error("--mode must be 'types' or 'client'.");
278
+ }
279
+ flags.mode = value;
280
+ args.splice(index, 2);
281
+ continue;
282
+ }
283
+ if (token.startsWith("--")) {
284
+ throw new Error(`Unknown flag '${token}' for emit-ts.`);
285
+ }
286
+ index += 1;
287
+ }
288
+ const server = args.shift();
289
+ if (!server) {
290
+ throw new Error("Usage: mcporter emit-ts <server> --out <file> [--mode types|client]");
291
+ }
292
+ const outPath = flags.outPath;
293
+ if (!outPath) {
294
+ throw new Error("Flag '--out' is required for emit-ts.");
295
+ }
296
+ if (flags.mode === "client" && !outPath.endsWith(".ts")) {
297
+ throw new Error("--out should point to a .ts file when --mode client is used.");
298
+ }
299
+ if (flags.mode === "types" && !outPath.endsWith(".ts") && !outPath.endsWith(".d.ts")) {
300
+ throw new Error("--out should be a .ts or .d.ts file for --mode types.");
301
+ }
302
+ return {
303
+ server,
304
+ outPath: path2.resolve(outPath),
305
+ mode: flags.mode,
306
+ includeOptional: flags.includeOptional,
307
+ typesOutPath: flags.typesOutPath ? path2.resolve(flags.typesOutPath) : void 0,
308
+ format: flags.format
309
+ };
310
+ }
311
+ function getServerDefinition(runtime, selector) {
312
+ try {
313
+ return runtime.getDefinition(selector);
314
+ } catch (error) {
315
+ const resolved = resolveHttpServerName(runtime, selector);
316
+ if (resolved) {
317
+ return runtime.getDefinition(resolved);
318
+ }
319
+ if (error instanceof Error) {
320
+ throw new Error(error.message, { cause: error });
321
+ }
322
+ throw error;
323
+ }
324
+ }
325
+ function resolveHttpServerName(runtime, selector) {
326
+ const target = extractHttpServerTarget(selector);
327
+ if (!target) {
328
+ return void 0;
329
+ }
330
+ return findServerByHttpUrl(runtime.getDefinitions(), target);
331
+ }
332
+ function buildDocEntries(serverName, metadataEntries, includeOptional) {
333
+ return metadataEntries.map((entry) => {
334
+ const doc = buildToolDoc({
335
+ serverName,
336
+ toolName: entry.tool.name,
337
+ description: entry.tool.description,
338
+ outputSchema: entry.tool.outputSchema,
339
+ options: entry.options,
340
+ requiredOnly: !includeOptional,
341
+ colorize: false,
342
+ defaultReturnType: "CallResult"
343
+ });
344
+ return {
345
+ toolName: entry.tool.name,
346
+ methodName: entry.methodName,
347
+ doc
348
+ };
349
+ });
350
+ }
351
+ function buildInterfaceName(serverName) {
352
+ const cleaned = serverName.split(/[^A-Za-z0-9]+/).filter(Boolean).map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1)).join("");
353
+ const base = cleaned.length > 0 ? cleaned : "Server";
354
+ return `${base}Tools`;
355
+ }
356
+ function deriveTypesOutPath(tsPath) {
357
+ const dir = path2.dirname(tsPath);
358
+ const base = path2.basename(tsPath, path2.extname(tsPath));
359
+ return path2.join(dir, `${base}.d.ts`);
360
+ }
361
+ async function writeFile(targetPath, contents) {
362
+ await fs.mkdir(path2.dirname(targetPath), { recursive: true });
363
+ await fs.writeFile(targetPath, `${contents}
364
+ `, "utf8");
365
+ }
366
+ function computeImportPath(fromPath, typesPath) {
367
+ const fromDir = path2.dirname(fromPath);
368
+ const relative = path2.relative(fromDir, typesPath).replace(/\\/g, "/");
369
+ const withoutExt = relative.endsWith(".d.ts") ? relative.slice(0, -5) : relative.replace(/\.[^.]+$/, "");
370
+ if (withoutExt.startsWith(".")) {
371
+ return withoutExt;
372
+ }
373
+ return `./${withoutExt}`;
374
+ }
375
+ var __test = {
376
+ parseEmitTsArgs,
377
+ buildInterfaceName,
378
+ deriveTypesOutPath,
379
+ computeImportPath,
380
+ buildDocEntries
381
+ };
382
+ export {
383
+ __test,
384
+ handleEmitTs,
385
+ printEmitTsHelp
386
+ };