@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,612 @@
1
+ import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
+ import {
3
+ dumpActiveHandles
4
+ } from "./chunk-BTLAWHTA.js";
5
+ import {
6
+ CALL_HELP_ADHOC_SERVER_LINES,
7
+ CALL_HELP_ARGUMENT_LINES,
8
+ CALL_HELP_EXAMPLE_LINES,
9
+ CALL_HELP_RUNTIME_FLAG_LINES,
10
+ parseCallArguments
11
+ } from "./chunk-PIIYJR44.js";
12
+ import "./chunk-BV56DXPW.js";
13
+ import {
14
+ printCallOutput,
15
+ tailLogIfRequested
16
+ } from "./chunk-LNH5LAJD.js";
17
+ import "./chunk-UNKB4SBV.js";
18
+ import {
19
+ loadToolMetadata
20
+ } from "./chunk-IABRYROW.js";
21
+ import "./chunk-XANPGTLI.js";
22
+ import {
23
+ chooseClosestIdentifier,
24
+ normalizeIdentifier,
25
+ renderIdentifierResolutionMessages
26
+ } from "./chunk-BWHIA4PC.js";
27
+ import {
28
+ dimText,
29
+ redText,
30
+ yellowText
31
+ } from "./chunk-N46NEFAF.js";
32
+ import {
33
+ resolveCallTimeout,
34
+ withTimeout
35
+ } from "./chunk-BNV3TPE4.js";
36
+ import {
37
+ persistPreparedEphemeralServer,
38
+ prepareEphemeralServerTarget
39
+ } from "./chunk-WD6BOD24.js";
40
+ import "./chunk-TEUKFFQL.js";
41
+ import "./chunk-E22DYOW5.js";
42
+ import {
43
+ buildConnectionIssueEnvelope
44
+ } from "./chunk-SJCCBNZ4.js";
45
+ import "./chunk-LQQEYD76.js";
46
+ import {
47
+ looksLikeHttpUrl,
48
+ normalizeHttpUrlCandidate
49
+ } from "./chunk-M3TPODXI.js";
50
+ import "./chunk-YVZKMV5H.js";
51
+ import {
52
+ wrapCallResult
53
+ } from "./chunk-5QOSCSQB.js";
54
+ import "./chunk-6W5QFASN.js";
55
+ import "./chunk-2U4BSDC4.js";
56
+ import {
57
+ analyzeConnectionError
58
+ } from "./chunk-UKYNQGNE.js";
59
+ import "./chunk-P3PSC54P.js";
60
+ import "./chunk-2XL7MG7R.js";
61
+ import "./chunk-WQJZMCJN.js";
62
+ import "./chunk-ECIVB7P4.js";
63
+ import "./chunk-LS7PMWSR.js";
64
+ import "./chunk-D3MRAZ6H.js";
65
+ import "./chunk-LRKZP7DJ.js";
66
+
67
+ // node_modules/.pnpm/mcporter@0.12.3/node_modules/mcporter/dist/cli/image-output.js
68
+ import fs from "node:fs";
69
+ import path from "node:path";
70
+ function saveCallImagesIfRequested(wrapped, outputDir) {
71
+ if (!outputDir) {
72
+ return;
73
+ }
74
+ const images = wrapped.images();
75
+ if (!images || images.length === 0) {
76
+ return;
77
+ }
78
+ fs.mkdirSync(outputDir, { recursive: true });
79
+ const writtenPaths = [];
80
+ const timestamp = Date.now();
81
+ for (const [index, image] of images.entries()) {
82
+ const extension = extensionFromMimeType(image.mimeType);
83
+ const baseName = `mcp-image-${timestamp}-${index + 1}`;
84
+ const outputPath = resolveImageOutputPath(outputDir, baseName, extension);
85
+ fs.writeFileSync(outputPath, Buffer.from(image.data, "base64"));
86
+ writtenPaths.push(outputPath);
87
+ }
88
+ for (const outputPath of writtenPaths) {
89
+ console.error(`[mcporter] Saved image: ${outputPath}`);
90
+ }
91
+ }
92
+ function extensionFromMimeType(mimeType) {
93
+ if (!mimeType) {
94
+ return ".bin";
95
+ }
96
+ const normalized = mimeType.toLowerCase().split(";", 1)[0]?.trim() ?? "";
97
+ const mapping = {
98
+ "image/png": ".png",
99
+ "image/jpeg": ".jpg",
100
+ "image/jpg": ".jpg",
101
+ "image/webp": ".webp",
102
+ "image/gif": ".gif",
103
+ "image/svg+xml": ".svg",
104
+ "image/bmp": ".bmp",
105
+ "image/tiff": ".tiff",
106
+ "image/x-icon": ".ico"
107
+ };
108
+ return mapping[normalized] ?? ".bin";
109
+ }
110
+ function resolveImageOutputPath(outputDir, baseName, extension) {
111
+ let candidate = path.join(outputDir, `${baseName}${extension}`);
112
+ if (!fs.existsSync(candidate)) {
113
+ return candidate;
114
+ }
115
+ let suffix = 2;
116
+ while (true) {
117
+ candidate = path.join(outputDir, `${baseName}-${suffix}${extension}`);
118
+ if (!fs.existsSync(candidate)) {
119
+ return candidate;
120
+ }
121
+ suffix += 1;
122
+ }
123
+ }
124
+
125
+ // node_modules/.pnpm/mcporter@0.12.3/node_modules/mcporter/dist/cli/call-command.js
126
+ async function handleCall(runtime, args) {
127
+ let prepared;
128
+ try {
129
+ prepared = await prepareCallRequest(runtime, args);
130
+ if (!prepared) {
131
+ return;
132
+ }
133
+ const invocation = await invokePreparedCall(runtime, prepared);
134
+ if (!invocation) {
135
+ return;
136
+ }
137
+ renderCallResult(invocation.result, prepared.parsed);
138
+ } finally {
139
+ await persistPreparedEphemeralServer(runtime, prepared?.ephemeralTarget);
140
+ }
141
+ }
142
+ async function prepareCallRequest(runtime, args) {
143
+ const parsed = parseCallArguments(args);
144
+ const ephemeralTarget = await normalizeParsedCallArguments(runtime, parsed);
145
+ const { server, tool } = await resolveServerAndTool(runtime, parsed);
146
+ if (await maybeDescribeServer(runtime, server, tool, parsed.output, parsed.disableOAuth)) {
147
+ return void 0;
148
+ }
149
+ const timeoutMs = resolveCallTimeout(parsed.timeoutMs);
150
+ const hydratedArgs = await hydratePositionalArguments(runtime, server, tool, parsed.args, parsed.positionalArgs, parsed.disableOAuth);
151
+ const schemaAwareArgs = await enforceSchemaAwareArgumentTypes(runtime, server, tool, hydratedArgs, parsed.schemaStringCoercionCandidates, parsed.schemaArrayCoercionCandidates, timeoutMs, parsed.disableOAuth);
152
+ return {
153
+ parsed,
154
+ server,
155
+ tool,
156
+ hydratedArgs: schemaAwareArgs,
157
+ timeoutMs,
158
+ disableOAuth: parsed.disableOAuth,
159
+ ephemeralTarget
160
+ };
161
+ }
162
+ async function normalizeParsedCallArguments(runtime, parsed) {
163
+ let ephemeralSpec = parsed.ephemeral ? { ...parsed.ephemeral } : void 0;
164
+ const nameHints = [];
165
+ const absorbUrlCandidate = (value) => {
166
+ if (!value) {
167
+ return value;
168
+ }
169
+ const normalized = normalizeHttpUrlCandidate(value);
170
+ if (!normalized) {
171
+ return value;
172
+ }
173
+ if (!ephemeralSpec) {
174
+ ephemeralSpec = { httpUrl: normalized };
175
+ } else if (!ephemeralSpec.httpUrl) {
176
+ ephemeralSpec = { ...ephemeralSpec, httpUrl: normalized };
177
+ }
178
+ return void 0;
179
+ };
180
+ parsed.server = absorbUrlCandidate(parsed.server);
181
+ parsed.selector = absorbUrlCandidate(parsed.selector);
182
+ if (ephemeralSpec && parsed.server && !looksLikeHttpUrl(parsed.server)) {
183
+ nameHints.push(parsed.server);
184
+ parsed.server = void 0;
185
+ }
186
+ if (ephemeralSpec?.httpUrl && parsed.selector && !looksLikeHttpUrl(parsed.selector)) {
187
+ const selector = splitServerToolSelector(parsed.selector);
188
+ if (selector) {
189
+ if (!ephemeralSpec.name) {
190
+ nameHints.push(selector.server);
191
+ }
192
+ parsed.tool ??= selector.tool;
193
+ parsed.selector = void 0;
194
+ } else if (parsed.tool) {
195
+ if (!ephemeralSpec.name) {
196
+ nameHints.push(parsed.selector);
197
+ }
198
+ parsed.selector = void 0;
199
+ }
200
+ }
201
+ const prepared = await prepareEphemeralServerTarget({
202
+ runtime,
203
+ target: parsed.server,
204
+ ephemeral: ephemeralSpec,
205
+ nameHints,
206
+ reuseFromSpec: true
207
+ });
208
+ parsed.server = prepared.target;
209
+ if (!parsed.selector) {
210
+ parsed.selector = prepared.target;
211
+ }
212
+ return prepared;
213
+ }
214
+ async function resolveServerAndTool(runtime, parsed) {
215
+ const target = resolveCallTarget(parsed, { allowMissingTool: true });
216
+ const server = target.server;
217
+ let tool = target.tool;
218
+ if (!server) {
219
+ throw new Error("Missing server name. Provide it via <server>.<tool> or --server.");
220
+ }
221
+ if (!tool) {
222
+ tool = await inferSingleToolName(runtime, server, parsed.disableOAuth);
223
+ if (!tool) {
224
+ throw new Error("Missing tool name. Provide it via <server>.<tool> or --tool.");
225
+ }
226
+ }
227
+ return { server, tool };
228
+ }
229
+ async function invokePreparedCall(runtime, prepared) {
230
+ let invocation;
231
+ try {
232
+ invocation = await invokeWithAutoCorrection(runtime, prepared.server, prepared.tool, prepared.hydratedArgs, prepared.timeoutMs, prepared.parsed.output, prepared.disableOAuth);
233
+ } catch (error) {
234
+ const issue = maybeReportConnectionIssue(prepared.server, prepared.tool, error);
235
+ if (prepared.parsed.output === "json" || prepared.parsed.output === "raw") {
236
+ const payload = buildConnectionIssueEnvelope({ server: prepared.server, tool: prepared.tool, error, issue });
237
+ console.log(JSON.stringify(payload, null, 2));
238
+ process.exitCode = 1;
239
+ return void 0;
240
+ }
241
+ throw error;
242
+ }
243
+ return invocation;
244
+ }
245
+ function renderCallResult(result, parsed) {
246
+ const { callResult: wrapped } = wrapCallResult(result);
247
+ if (isErrorCallResult(result)) {
248
+ process.exitCode = 1;
249
+ }
250
+ printCallOutput(wrapped, result, parsed.output);
251
+ saveCallImagesIfRequested(wrapped, parsed.saveImagesDir);
252
+ tailLogIfRequested(result, parsed.tailLog);
253
+ dumpActiveHandles("after call (formatted result)");
254
+ }
255
+ function isErrorCallResult(result) {
256
+ return !!result && typeof result === "object" && result.isError === true;
257
+ }
258
+ function printCallHelp() {
259
+ const lines = [
260
+ "Usage: mcporter call <server.tool | url> [arguments] [flags]",
261
+ "",
262
+ "Selectors:",
263
+ " server.tool Use a configured server and tool (e.g., linear.list_issues).",
264
+ " https://host/mcp.tool Call a tool by full HTTP URL (auto-registers ad-hoc).",
265
+ " --server <name> Override the server name.",
266
+ " --tool <name> Override the tool name.",
267
+ "",
268
+ "Arguments:",
269
+ ...CALL_HELP_ARGUMENT_LINES,
270
+ "",
271
+ "Runtime flags:",
272
+ ...CALL_HELP_RUNTIME_FLAG_LINES,
273
+ "",
274
+ "Ad-hoc servers:",
275
+ ...CALL_HELP_ADHOC_SERVER_LINES,
276
+ "",
277
+ "Examples:",
278
+ ...CALL_HELP_EXAMPLE_LINES
279
+ ];
280
+ console.error(lines.join("\n"));
281
+ }
282
+ async function maybeDescribeServer(runtime, server, tool, outputFormat, disableOAuth) {
283
+ if (tool === "list_tools") {
284
+ console.log(dimText(`[mcporter] ${server}.list_tools is a shortcut for 'mcporter list ${server}'.`));
285
+ const listArgs2 = [server];
286
+ if (disableOAuth) {
287
+ listArgs2.push("--no-oauth");
288
+ }
289
+ if (outputFormat === "json") {
290
+ listArgs2.push("--json");
291
+ }
292
+ const { handleList: handleList2 } = await import("./list-command-2MEGGNFQ.js");
293
+ await handleList2(runtime, listArgs2);
294
+ return true;
295
+ }
296
+ if (tool !== "help") {
297
+ return false;
298
+ }
299
+ const tools = await runtime.listTools(server, { includeSchema: false, autoAuthorize: false, disableOAuth }).catch(() => void 0);
300
+ if (!tools) {
301
+ return false;
302
+ }
303
+ const hasHelpTool = tools.some((entry) => entry.name === "help");
304
+ if (hasHelpTool) {
305
+ return false;
306
+ }
307
+ console.log(dimText(`[mcporter] ${server} does not expose a 'help' tool; showing mcporter list output instead.`));
308
+ const listArgs = [server];
309
+ if (disableOAuth) {
310
+ listArgs.push("--no-oauth");
311
+ }
312
+ if (outputFormat === "json") {
313
+ listArgs.push("--json");
314
+ }
315
+ const { handleList } = await import("./list-command-2MEGGNFQ.js");
316
+ await handleList(runtime, listArgs);
317
+ return true;
318
+ }
319
+ function resolveCallTarget(parsed, options = {}) {
320
+ const selector = parsed.selector;
321
+ let server = parsed.server;
322
+ let tool = parsed.tool;
323
+ if (selector && !server && selector.includes(".")) {
324
+ const [left, right] = selector.split(".", 2);
325
+ server = left;
326
+ tool = right;
327
+ } else if (selector && !server) {
328
+ server = selector;
329
+ } else if (selector && !tool && selector !== server) {
330
+ tool = selector;
331
+ }
332
+ if (!server) {
333
+ throw new Error("Missing server name. Provide it via <server>.<tool> or --server.");
334
+ }
335
+ if (!tool && !options.allowMissingTool) {
336
+ throw new Error("Missing tool name. Provide it via <server>.<tool> or --tool.");
337
+ }
338
+ return { server, tool };
339
+ }
340
+ function splitServerToolSelector(selector) {
341
+ const dotIndex = selector.indexOf(".");
342
+ if (dotIndex <= 0 || dotIndex === selector.length - 1) {
343
+ return void 0;
344
+ }
345
+ return {
346
+ server: selector.slice(0, dotIndex),
347
+ tool: selector.slice(dotIndex + 1)
348
+ };
349
+ }
350
+ async function enforceSchemaAwareArgumentTypes(runtime, server, tool, args, stringCandidates, arrayCandidates, timeoutMs, disableOAuth) {
351
+ if ((!stringCandidates || Object.keys(stringCandidates).length === 0) && (!arrayCandidates || Object.keys(arrayCandidates).length === 0)) {
352
+ return args;
353
+ }
354
+ const tools = await withTimeout(loadToolMetadata(runtime, server, { includeSchema: true, disableOAuth }), timeoutMs).catch(() => void 0);
355
+ if (!tools) {
356
+ return args;
357
+ }
358
+ const toolInfo = tools.find((entry) => entry.tool.name === tool);
359
+ const schema = toolInfo?.tool.inputSchema;
360
+ if (!schema?.properties) {
361
+ return args;
362
+ }
363
+ let corrected;
364
+ for (const [key, rawValue] of Object.entries(stringCandidates ?? {})) {
365
+ if (typeof args[key] !== "number") {
366
+ continue;
367
+ }
368
+ if (!schemaAllowsString(schema.properties[key])) {
369
+ continue;
370
+ }
371
+ corrected ??= { ...args };
372
+ corrected[key] = rawValue;
373
+ }
374
+ for (const [key, rawValue] of Object.entries(arrayCandidates ?? {})) {
375
+ if (typeof args[key] !== "string") {
376
+ continue;
377
+ }
378
+ const descriptor = schema.properties[key];
379
+ if (!schemaAllowsArray(descriptor) || schemaAllowsString(descriptor)) {
380
+ continue;
381
+ }
382
+ corrected ??= { ...args };
383
+ corrected[key] = [rawValue];
384
+ }
385
+ return corrected ?? args;
386
+ }
387
+ function schemaAllowsString(descriptor) {
388
+ if (!descriptor || typeof descriptor !== "object") {
389
+ return false;
390
+ }
391
+ const record = descriptor;
392
+ const type = record.type;
393
+ if (type === "string") {
394
+ return true;
395
+ }
396
+ if (Array.isArray(type) && type.includes("string")) {
397
+ return true;
398
+ }
399
+ for (const key of ["anyOf", "oneOf", "allOf"]) {
400
+ const variants = record[key];
401
+ if (Array.isArray(variants) && variants.some(schemaAllowsString)) {
402
+ return true;
403
+ }
404
+ }
405
+ return false;
406
+ }
407
+ function schemaAllowsArray(descriptor) {
408
+ if (!descriptor || typeof descriptor !== "object") {
409
+ return false;
410
+ }
411
+ const record = descriptor;
412
+ const type = record.type;
413
+ if (type === "array") {
414
+ return true;
415
+ }
416
+ if (Array.isArray(type) && type.includes("array")) {
417
+ return true;
418
+ }
419
+ for (const key of ["anyOf", "oneOf", "allOf"]) {
420
+ const variants = record[key];
421
+ if (Array.isArray(variants) && variants.some(schemaAllowsArray)) {
422
+ return true;
423
+ }
424
+ }
425
+ return false;
426
+ }
427
+ async function hydratePositionalArguments(runtime, server, tool, namedArgs, positionalArgs, disableOAuth) {
428
+ if (!positionalArgs || positionalArgs.length === 0) {
429
+ return namedArgs;
430
+ }
431
+ const tools = await loadToolMetadata(runtime, server, { includeSchema: true, disableOAuth }).catch(() => void 0);
432
+ if (!tools) {
433
+ throw new Error("Unable to load tool metadata; name positional arguments explicitly.");
434
+ }
435
+ const toolInfo = tools.find((entry) => entry.tool.name === tool);
436
+ if (!toolInfo) {
437
+ throw new Error(`Unknown tool '${tool}' on server '${server}'. Double-check the name or run mcporter list ${server}.`);
438
+ }
439
+ if (!toolInfo.tool.inputSchema) {
440
+ throw new Error(`Tool '${tool}' does not expose an input schema; name positional arguments explicitly.`);
441
+ }
442
+ const options = toolInfo.options;
443
+ if (options.length === 0) {
444
+ throw new Error(`Tool '${tool}' has no declared parameters; remove positional arguments.`);
445
+ }
446
+ const remaining = options.filter((option) => !(option.property in namedArgs));
447
+ if (positionalArgs.length > remaining.length) {
448
+ throw new Error(`Too many positional arguments (${positionalArgs.length}) supplied; only ${remaining.length} parameter${remaining.length === 1 ? "" : "s"} remain on ${tool}.`);
449
+ }
450
+ const hydrated = { ...namedArgs };
451
+ positionalArgs.forEach((value, index) => {
452
+ const target = remaining[index];
453
+ if (!target) {
454
+ return;
455
+ }
456
+ hydrated[target.property] = value;
457
+ });
458
+ return hydrated;
459
+ }
460
+ async function inferSingleToolName(runtime, server, disableOAuth) {
461
+ const tools = await loadToolMetadata(runtime, server, { includeSchema: false, disableOAuth });
462
+ if (tools.length !== 1) {
463
+ return void 0;
464
+ }
465
+ const name = tools[0]?.tool.name;
466
+ if (!name) {
467
+ return void 0;
468
+ }
469
+ console.log(dimText(`[auto] ${server} exposes a single tool (${name}); using it.`));
470
+ return name;
471
+ }
472
+ async function invokeWithAutoCorrection(runtime, server, tool, args, timeoutMs, outputFormat, disableOAuth) {
473
+ return attemptCall(runtime, server, tool, args, timeoutMs, outputFormat, true, disableOAuth);
474
+ }
475
+ async function attemptCall(runtime, server, tool, args, timeoutMs, outputFormat, allowCorrection, disableOAuth) {
476
+ try {
477
+ const result = await withTimeout(runtime.callTool(server, tool, { args, timeoutMs, disableOAuth }), timeoutMs);
478
+ if (allowCorrection && isErrorCallResult(result)) {
479
+ const resolution = await maybeResolveToolName(runtime, server, tool, result, disableOAuth);
480
+ if (resolution) {
481
+ const retry = await maybeRetryResolvedTool(runtime, server, tool, args, timeoutMs, outputFormat, resolution, disableOAuth);
482
+ if (retry) {
483
+ return retry;
484
+ }
485
+ }
486
+ }
487
+ return { result, resolvedTool: tool };
488
+ } catch (error) {
489
+ if (error instanceof Error && error.message === "Timeout") {
490
+ const timeoutDisplay = `${timeoutMs}ms`;
491
+ await runtime.close(server).catch(() => {
492
+ });
493
+ throw new Error(`Call to ${server}.${tool} timed out after ${timeoutDisplay}. Override MCPORTER_CALL_TIMEOUT or pass --timeout to adjust.`, { cause: error });
494
+ }
495
+ if (!allowCorrection) {
496
+ throw error;
497
+ }
498
+ const resolution = await maybeResolveToolName(runtime, server, tool, error, disableOAuth);
499
+ if (!resolution) {
500
+ maybeReportConnectionIssue(server, tool, error);
501
+ throw error;
502
+ }
503
+ const retry = await maybeRetryResolvedTool(runtime, server, tool, args, timeoutMs, outputFormat, resolution, disableOAuth);
504
+ if (!retry) {
505
+ throw error;
506
+ }
507
+ return retry;
508
+ }
509
+ }
510
+ async function maybeRetryResolvedTool(runtime, server, tool, args, timeoutMs, outputFormat, resolution, disableOAuth) {
511
+ const messages = renderIdentifierResolutionMessages({
512
+ entity: "tool",
513
+ attempted: tool,
514
+ resolution,
515
+ scope: server
516
+ });
517
+ if (resolution.kind === "suggest") {
518
+ if (messages.suggest) {
519
+ console.error(dimText(messages.suggest));
520
+ }
521
+ return void 0;
522
+ }
523
+ if (messages.auto) {
524
+ const emitAutoMessage = outputFormat === "json" || outputFormat === "raw" ? console.error : console.log;
525
+ emitAutoMessage(dimText(messages.auto));
526
+ }
527
+ return attemptCall(runtime, server, resolution.value, args, timeoutMs, outputFormat, false, disableOAuth);
528
+ }
529
+ async function maybeResolveToolName(runtime, server, attemptedTool, error, disableOAuth) {
530
+ const missingName = extractMissingToolFromError(error);
531
+ if (!missingName) {
532
+ return void 0;
533
+ }
534
+ if (normalizeIdentifier(missingName) !== normalizeIdentifier(attemptedTool)) {
535
+ return void 0;
536
+ }
537
+ const tools = await loadToolMetadata(runtime, server, { includeSchema: false, disableOAuth }).catch(() => void 0);
538
+ if (!tools) {
539
+ return void 0;
540
+ }
541
+ const resolution = chooseClosestIdentifier(attemptedTool, tools.map((entry) => entry.tool.name));
542
+ if (!resolution) {
543
+ return void 0;
544
+ }
545
+ return resolution;
546
+ }
547
+ function extractMissingToolFromError(error) {
548
+ const message = extractErrorMessageText(error);
549
+ if (!message) {
550
+ return void 0;
551
+ }
552
+ const match = message.match(/Tool\s+([A-Za-z0-9._-]+)\s+not found/i) ?? message.match(/Unknown tool:?\s+([A-Za-z0-9._-]+)/i);
553
+ return match?.[1];
554
+ }
555
+ function extractErrorMessageText(value) {
556
+ if (value instanceof Error) {
557
+ return value.message;
558
+ }
559
+ if (typeof value === "string") {
560
+ return value;
561
+ }
562
+ if (!value || typeof value !== "object") {
563
+ return void 0;
564
+ }
565
+ const content = value.content;
566
+ if (!Array.isArray(content)) {
567
+ return void 0;
568
+ }
569
+ return content.map((entry) => entry && typeof entry === "object" && typeof entry.text === "string" ? entry.text : "").filter(Boolean).join("\n");
570
+ }
571
+ function maybeReportConnectionIssue(server, tool, error) {
572
+ const issue = analyzeConnectionError(error);
573
+ const detail = summarizeIssueMessage(issue.rawMessage);
574
+ if (issue.kind === "auth") {
575
+ const authCommand = `mcporter auth ${server}`;
576
+ const hint = `[mcporter] Authorization required for ${server}. Run '${authCommand}'.${detail ? ` (${detail})` : ""}`;
577
+ console.error(yellowText(hint));
578
+ return issue;
579
+ }
580
+ if (issue.kind === "offline") {
581
+ const hint = `[mcporter] ${server} appears offline${detail ? ` (${detail})` : ""}.`;
582
+ console.error(redText(hint));
583
+ return issue;
584
+ }
585
+ if (issue.kind === "http") {
586
+ const status = issue.statusCode ? `HTTP ${issue.statusCode}` : "an HTTP error";
587
+ const hint = `[mcporter] ${server}.${tool} responded with ${status}${detail ? ` (${detail})` : ""}.`;
588
+ console.error(dimText(hint));
589
+ return issue;
590
+ }
591
+ if (issue.kind === "stdio-exit") {
592
+ const exit = typeof issue.stdioExitCode === "number" ? `code ${issue.stdioExitCode}` : "an unknown status";
593
+ const signal = issue.stdioSignal ? ` (signal ${issue.stdioSignal})` : "";
594
+ const hint = `[mcporter] STDIO server for ${server} exited with ${exit}${signal}.`;
595
+ console.error(redText(hint));
596
+ }
597
+ return issue;
598
+ }
599
+ function summarizeIssueMessage(message) {
600
+ if (!message) {
601
+ return "";
602
+ }
603
+ const trimmed = message.trim();
604
+ if (trimmed.length <= 120) {
605
+ return trimmed;
606
+ }
607
+ return `${trimmed.slice(0, 117)}\u2026`;
608
+ }
609
+ export {
610
+ handleCall,
611
+ printCallHelp
612
+ };