@runtypelabs/cli 2.59.1 → 2.59.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-0x7UKC1U.js +17 -0
- package/dist/chunk-2ySxXtcg.js +418 -0
- package/dist/chunk-3An_BRHv.js +501 -0
- package/dist/chunk-6uTxgdiY.js +16218 -0
- package/dist/chunk-87nRnNRG.js +1363 -0
- package/dist/chunk-B3wo8uRx.js +322 -0
- package/dist/chunk-BGp3ZdBy.js +560 -0
- package/dist/chunk-BJQv9Elp.js +107 -0
- package/dist/chunk-BOpO6xE-.js +6053 -0
- package/dist/chunk-BQXXCL8B.js +102 -0
- package/dist/chunk-BV-8isOd.js +34 -0
- package/dist/chunk-BVMhjGVe.js +826 -0
- package/dist/chunk-BW2fg46T.js +141 -0
- package/dist/chunk-BWJdY5Ag.js +36 -0
- package/dist/chunk-BYJOrLhh.js +302 -0
- package/dist/chunk-BYab8EVL.js +127 -0
- package/dist/chunk-BfEKvp7h.js +82 -0
- package/dist/chunk-BhgLSfH6.js +1123 -0
- package/dist/chunk-BirUxTtH.js +296 -0
- package/dist/chunk-BmB6UVZ9.js +1559 -0
- package/dist/chunk-BnWhIqW1.js +109 -0
- package/dist/chunk-Bpfnfk0t.js +123 -0
- package/dist/chunk-BrhgdnM3.js +108 -0
- package/dist/chunk-Bt0XAgX5.js +327 -0
- package/dist/chunk-Bu0FJr6S.js +84 -0
- package/dist/chunk-BvEoKpN3.js +255 -0
- package/dist/chunk-BxNJgYbE.js +28 -0
- package/dist/chunk-C1OFhd7F.js +6131 -0
- package/dist/chunk-C7e7WwbU.js +331 -0
- package/dist/chunk-CDTYP6bN.js +558 -0
- package/dist/chunk-CGDQoqDC.js +24 -0
- package/dist/chunk-CJraEBVd.js +127 -0
- package/dist/chunk-CQrNhOtv.js +40 -0
- package/dist/chunk-CW6AzBH6.js +128 -0
- package/dist/chunk-CXgL4w-9.js +317 -0
- package/dist/chunk-CZrqoPyf.js +233 -0
- package/dist/chunk-CcFCyqbB.js +83 -0
- package/dist/chunk-CdaIvO-y.js +485 -0
- package/dist/chunk-CehSXtgK.js +624 -0
- package/dist/chunk-Ciqkop65.js +218 -0
- package/dist/chunk-CoAWdSiE.js +43 -0
- package/dist/chunk-Crb4y7t4.js +830 -0
- package/dist/chunk-CrlqIfmb.js +337 -0
- package/dist/chunk-Cs4pwCQ-.js +324 -0
- package/dist/chunk-CwM_9y01.js +519 -0
- package/dist/chunk-CyRbIJg8.js +440 -0
- package/dist/chunk-D0OHsyMy.js +212 -0
- package/dist/chunk-D3y2bURs.js +1347 -0
- package/dist/chunk-D4_mJk03.js +2338 -0
- package/dist/chunk-D6C8rned.js +578 -0
- package/dist/chunk-D9ZbUnks.js +11 -0
- package/dist/chunk-DEPmLshX.js +834 -0
- package/dist/chunk-DFj1UPB2.js +330 -0
- package/dist/chunk-DGdFdZVf.js +197 -0
- package/dist/chunk-DGv7X9S_.js +63 -0
- package/dist/chunk-DJQ47WYZ.js +664 -0
- package/dist/chunk-DJw3O61j.js +1974 -0
- package/dist/chunk-DK4FbWVK.js +100 -0
- package/dist/chunk-DPuofXMp.js +3907 -0
- package/dist/chunk-DSRYhUus.js +993 -0
- package/dist/chunk-DajZ9Eg4.js +299 -0
- package/dist/chunk-Df4dunvU.js +195 -0
- package/dist/chunk-DjNTPhfO.js +481 -0
- package/dist/chunk-Dn8eaJuu.js +1042 -0
- package/dist/chunk-DwDWqSxM.js +637 -0
- package/dist/chunk-Dz7cEtxl.js +84 -0
- package/dist/chunk-E_0bgjrS.js +359 -0
- package/dist/chunk-KPYN2vUp.js +776 -0
- package/dist/chunk-KcqPQJBi.js +86 -0
- package/dist/chunk-N9H0JnoG.js +349 -0
- package/dist/chunk-NONFcXkn.js +728 -0
- package/dist/chunk-PrFjcpmH.js +256 -0
- package/dist/chunk-QSfNYiw9.js +11 -0
- package/dist/chunk-R265bzj9.js +226 -0
- package/dist/chunk-X9V_r6jM.js +166 -0
- package/dist/chunk-ZBtPUtyA.js +55 -0
- package/dist/chunk-ZCTfmOs7.js +4939 -0
- package/dist/chunk-h6oavj0t.js +97 -0
- package/dist/chunk-i7DwkvvD.js +42 -0
- package/dist/chunk-mG-4eZ6S.js +203 -0
- package/dist/chunk-o0ygUbCf.js +313 -0
- package/dist/chunk-ucu5lrDZ.js +5715 -0
- package/dist/index.js +11367 -73789
- package/package.json +5 -5
|
@@ -0,0 +1,1559 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { F as getCliVersion } from "./index.js";
|
|
3
|
+
import { a as getApiVersion, c as getDevPlanOverride, i as getApiUrl } from "./chunk-BW2fg46T.js";
|
|
4
|
+
import { n as ensureAuth } from "./chunk-CJraEBVd.js";
|
|
5
|
+
import { a as printJson, i as printDetail } from "./chunk-CcFCyqbB.js";
|
|
6
|
+
import { Command, InvalidArgumentError } from "commander";
|
|
7
|
+
import chalk from "chalk";
|
|
8
|
+
import { readFile } from "node:fs/promises";
|
|
9
|
+
import { Client, StreamableHTTPClientTransport } from "@modelcontextprotocol/client";
|
|
10
|
+
// src/lib/mcp-client.ts
|
|
11
|
+
const CONNECT_TIMEOUT_MS = 1e4;
|
|
12
|
+
function parseHttpUrl(raw, label) {
|
|
13
|
+
let url;
|
|
14
|
+
try {
|
|
15
|
+
url = new URL(raw);
|
|
16
|
+
} catch {
|
|
17
|
+
throw new Error(`${label} must be a valid URL`);
|
|
18
|
+
}
|
|
19
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") throw new Error(`${label} must use http or https`);
|
|
20
|
+
return url;
|
|
21
|
+
}
|
|
22
|
+
function appendPath(baseUrl, ...segments) {
|
|
23
|
+
const url = parseHttpUrl(baseUrl, "RUNTYPE_API_URL");
|
|
24
|
+
url.pathname = `${url.pathname.replace(/\/+$/, "")}/${segments.map((segment) => segment.replace(/^\/+|\/+$/g, "")).join("/")}`;
|
|
25
|
+
url.search = "";
|
|
26
|
+
url.hash = "";
|
|
27
|
+
return url;
|
|
28
|
+
}
|
|
29
|
+
/** Resolve the selected first-party MCP endpoint without accepting arbitrary CLI URLs. */
|
|
30
|
+
function resolveMcpEndpoint(target, config) {
|
|
31
|
+
if (target === "standard") {
|
|
32
|
+
if (config.standardUrl) return parseHttpUrl(config.standardUrl, "RUNTYPE_MCP_URL");
|
|
33
|
+
return appendPath(config.apiUrl, config.apiVersion, "mcp", "protocol");
|
|
34
|
+
}
|
|
35
|
+
if (config.codeUrl) return parseHttpUrl(config.codeUrl, "RUNTYPE_CODE_MCP_URL");
|
|
36
|
+
const apiUrl = parseHttpUrl(config.apiUrl, "RUNTYPE_API_URL");
|
|
37
|
+
if (apiUrl.hostname === "api.runtype.com") return new URL("https://code.runtype.com/mcp");
|
|
38
|
+
if (apiUrl.hostname === "api.runtype-staging.com") return new URL("https://code.runtype-staging.com/mcp");
|
|
39
|
+
if (apiUrl.hostname === "localhost" || apiUrl.hostname === "127.0.0.1" || apiUrl.hostname === "[::1]") {
|
|
40
|
+
apiUrl.port = "2529";
|
|
41
|
+
apiUrl.pathname = "/mcp";
|
|
42
|
+
apiUrl.search = "";
|
|
43
|
+
apiUrl.hash = "";
|
|
44
|
+
return apiUrl;
|
|
45
|
+
}
|
|
46
|
+
throw new Error(`Cannot infer the Code Mode MCP endpoint from ${config.apiUrl}; set RUNTYPE_CODE_MCP_URL explicitly`);
|
|
47
|
+
}
|
|
48
|
+
function currentEndpointConfig() {
|
|
49
|
+
return {
|
|
50
|
+
apiUrl: getApiUrl(),
|
|
51
|
+
apiVersion: getApiVersion(),
|
|
52
|
+
standardUrl: process.env.RUNTYPE_MCP_URL,
|
|
53
|
+
codeUrl: process.env.RUNTYPE_CODE_MCP_URL
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/** Connect an authenticated, one-shot MCP client for a CLI operation. */
|
|
57
|
+
async function connectMcpClient(apiKey, target, options = {}) {
|
|
58
|
+
const endpoint = resolveMcpEndpoint(target, currentEndpointConfig());
|
|
59
|
+
const version = getCliVersion();
|
|
60
|
+
const devOverride = getDevPlanOverride();
|
|
61
|
+
const headers = {
|
|
62
|
+
Authorization: `Bearer ${apiKey}`,
|
|
63
|
+
"X-Runtype-Client": "cli",
|
|
64
|
+
"X-Runtype-CLI-Version": version,
|
|
65
|
+
"User-Agent": `runtype-cli/${version}`,
|
|
66
|
+
...devOverride ? { "X-Dev-Plan-Override": devOverride } : {}
|
|
67
|
+
};
|
|
68
|
+
const transport = new StreamableHTTPClientTransport(endpoint, {
|
|
69
|
+
requestInit: { headers },
|
|
70
|
+
...options.fetch ? { fetch: options.fetch } : {}
|
|
71
|
+
});
|
|
72
|
+
const client = new Client({
|
|
73
|
+
name: "runtype-cli",
|
|
74
|
+
version
|
|
75
|
+
}, {});
|
|
76
|
+
const connectPromise = client.connect(transport);
|
|
77
|
+
connectPromise.catch(() => void 0);
|
|
78
|
+
let timer;
|
|
79
|
+
const timeout = new Promise((_resolve, reject) => {
|
|
80
|
+
timer = setTimeout(() => {
|
|
81
|
+
reject(/* @__PURE__ */ new Error(`MCP connection timed out after ${CONNECT_TIMEOUT_MS}ms`));
|
|
82
|
+
}, CONNECT_TIMEOUT_MS);
|
|
83
|
+
});
|
|
84
|
+
try {
|
|
85
|
+
await Promise.race([connectPromise, timeout]);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
await client.close().catch(() => void 0);
|
|
88
|
+
throw error;
|
|
89
|
+
} finally {
|
|
90
|
+
if (timer) clearTimeout(timer);
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
client,
|
|
94
|
+
endpoint
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/** Collect every tools/list page while treating cursors as opaque values. */
|
|
98
|
+
async function listAllMcpTools(client, options) {
|
|
99
|
+
const tools = [];
|
|
100
|
+
const seenCursors = /* @__PURE__ */ new Set();
|
|
101
|
+
let cursor;
|
|
102
|
+
do {
|
|
103
|
+
const page = await client.listTools(cursor === void 0 ? void 0 : { cursor }, options);
|
|
104
|
+
tools.push(...page.tools);
|
|
105
|
+
const nextCursor = page.nextCursor;
|
|
106
|
+
if (nextCursor !== void 0) {
|
|
107
|
+
if (seenCursors.has(nextCursor)) throw new Error("MCP server returned a repeated tools/list cursor");
|
|
108
|
+
seenCursors.add(nextCursor);
|
|
109
|
+
}
|
|
110
|
+
cursor = nextCursor;
|
|
111
|
+
} while (cursor !== void 0);
|
|
112
|
+
return tools;
|
|
113
|
+
}
|
|
114
|
+
// ../mcp-cli/dist/chunk-Cx5MQp1B.mjs
|
|
115
|
+
const e$2 = {
|
|
116
|
+
Success: 0,
|
|
117
|
+
ToolError: 1,
|
|
118
|
+
Usage: 2,
|
|
119
|
+
Auth: 3,
|
|
120
|
+
Transport: 4,
|
|
121
|
+
InputRequired: 5,
|
|
122
|
+
WaitTimeout: 6,
|
|
123
|
+
Interrupted: 130
|
|
124
|
+
};
|
|
125
|
+
const t$2 = {
|
|
126
|
+
usage: e$2.Usage,
|
|
127
|
+
unknown_command: e$2.Usage,
|
|
128
|
+
unknown_flag: e$2.Usage,
|
|
129
|
+
invalid_value: e$2.Usage,
|
|
130
|
+
missing_argument: e$2.Usage,
|
|
131
|
+
confirmation_required: e$2.Usage,
|
|
132
|
+
config: e$2.Usage,
|
|
133
|
+
credential_conflict: e$2.Usage,
|
|
134
|
+
tool_error: e$2.ToolError,
|
|
135
|
+
auth_required: e$2.Auth,
|
|
136
|
+
auth_failed: e$2.Auth,
|
|
137
|
+
transport: e$2.Transport,
|
|
138
|
+
timeout: e$2.Transport,
|
|
139
|
+
protocol: e$2.Transport,
|
|
140
|
+
input_required: e$2.InputRequired,
|
|
141
|
+
input_rejected: e$2.Usage,
|
|
142
|
+
wait_timeout: e$2.WaitTimeout,
|
|
143
|
+
tasks_unsupported: e$2.Usage,
|
|
144
|
+
task_cancelled: e$2.ToolError,
|
|
145
|
+
interrupted: e$2.Interrupted,
|
|
146
|
+
plugin_error: e$2.ToolError,
|
|
147
|
+
internal: e$2.ToolError
|
|
148
|
+
};
|
|
149
|
+
var n$2 = class extends Error {
|
|
150
|
+
code;
|
|
151
|
+
hint;
|
|
152
|
+
details;
|
|
153
|
+
exitCode;
|
|
154
|
+
constructor(e, n, r, i) {
|
|
155
|
+
super(n), this.code = e, this.hint = r, this.details = i, this.name = `CliError`, this.exitCode = t$2[e];
|
|
156
|
+
}
|
|
157
|
+
toEnvelope() {
|
|
158
|
+
return { error: {
|
|
159
|
+
...this.details,
|
|
160
|
+
code: this.code,
|
|
161
|
+
message: this.message,
|
|
162
|
+
...this.hint ? { hint: this.hint } : {},
|
|
163
|
+
exitCode: this.exitCode
|
|
164
|
+
} };
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
// ../mcp-cli/dist/chunk-CQq_8FZL.mjs
|
|
168
|
+
function e$1(e) {
|
|
169
|
+
return e.replace(/([a-z0-9])([A-Z])/g, `$1-$2`).replace(/([A-Z]+)([A-Z][a-z])/g, `$1-$2`).replace(/[^A-Za-z0-9]+/g, `-`).replace(/^-+|-+$/g, ``).toLowerCase();
|
|
170
|
+
}
|
|
171
|
+
function t$1(e, t) {
|
|
172
|
+
if (e === t) return 0;
|
|
173
|
+
let n = Array.from({ length: t.length + 1 }, (e, t) => t);
|
|
174
|
+
for (let r = 1; r <= e.length; r += 1) {
|
|
175
|
+
let i = n[0];
|
|
176
|
+
n[0] = r;
|
|
177
|
+
for (let a = 1; a <= t.length; a += 1) {
|
|
178
|
+
let o = n[a];
|
|
179
|
+
n[a] = Math.min(n[a] + 1, n[a - 1] + 1, i + (e[r - 1] === t[a - 1] ? 0 : 1)), i = o;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return n[t.length];
|
|
183
|
+
}
|
|
184
|
+
function n$1(e, n, r = 3) {
|
|
185
|
+
let i = e.toLowerCase(), a = Math.max(2, Math.floor(i.length / 3)), o = [];
|
|
186
|
+
for (let e of new Set(n)) {
|
|
187
|
+
let n = e.toLowerCase(), r = n.startsWith(i) || i.startsWith(n) ? 1 : t$1(i, n);
|
|
188
|
+
r <= a && o.push([e, r]);
|
|
189
|
+
}
|
|
190
|
+
return o.sort((e, t) => e[1] - t[1] || e[0].localeCompare(t[0])).slice(0, r).map(([e]) => e);
|
|
191
|
+
}
|
|
192
|
+
// ../mcp-cli/dist/chunk-B4F-cgd0.mjs
|
|
193
|
+
function e(e, t) {
|
|
194
|
+
switch (e) {
|
|
195
|
+
case void 0:
|
|
196
|
+
case `auto`: return t.stdoutIsTTY ? `pretty` : `compact`;
|
|
197
|
+
default: return e;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
const t = /\u001b\[[0-9;?]*[ -/]*[@-~]|\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)|\u001b[@-Z\\-_]/g;
|
|
201
|
+
const n = /[\u0000-\u0008\u000b-\u001f\u007f-\u009f]/g;
|
|
202
|
+
function r(e) {
|
|
203
|
+
return e.replace(t, ``).replace(/\r\n/g, `
|
|
204
|
+
`).replace(n, ``);
|
|
205
|
+
}
|
|
206
|
+
function o(e) {
|
|
207
|
+
let t = e.endsWith(`==`) ? 2 : +!!e.endsWith(`=`);
|
|
208
|
+
return Math.max(0, Math.floor(e.length * 3 / 4) - t);
|
|
209
|
+
}
|
|
210
|
+
function s$1(e) {
|
|
211
|
+
return e < 1024 ? `${e} B` : e < 1048576 ? `${(e / 1024).toFixed(1)} KB` : `${(e / 1048576).toFixed(1)} MB`;
|
|
212
|
+
}
|
|
213
|
+
function c$1(e, t, n) {
|
|
214
|
+
let i = t.get(e);
|
|
215
|
+
switch (e.type) {
|
|
216
|
+
case `text`: return n ? String(e.text) : r(String(e.text));
|
|
217
|
+
case `image`:
|
|
218
|
+
case `audio`: {
|
|
219
|
+
let t = String(e.mimeType ?? `application/octet-stream`);
|
|
220
|
+
return i ? `[${e.type} ${t} saved to ${i.path}]` : `[${e.type} ${t}, ${s$1(o(String(e.data ?? ``)))}; use --save <dir> to write it]`;
|
|
221
|
+
}
|
|
222
|
+
case `resource_link`: return `${e.name ? `${r(String(e.name))}: ` : ``}${r(String(e.uri))}`;
|
|
223
|
+
case `resource`: {
|
|
224
|
+
let t = e.resource ?? {};
|
|
225
|
+
return typeof t.text == `string` ? n ? t.text : r(t.text) : i ? `[resource ${t.uri ?? ``} saved to ${i.path}]` : `[resource ${r(String(t.uri ?? ``))}${t.blob ? `, ${s$1(o(t.blob))}` : ``}]`;
|
|
226
|
+
}
|
|
227
|
+
default: return `[${r(String(e.type))} content]`;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
function l$1(e, t) {
|
|
231
|
+
return JSON.stringify(e) === JSON.stringify(t);
|
|
232
|
+
}
|
|
233
|
+
function u$1(e) {
|
|
234
|
+
let t = Array.isArray(e.content) ? e.content : [];
|
|
235
|
+
return e.structuredContent === void 0 ? t : t.filter((t) => {
|
|
236
|
+
if (t.type !== `text`) return !0;
|
|
237
|
+
try {
|
|
238
|
+
return !l$1(JSON.parse(String(t.text)), e.structuredContent);
|
|
239
|
+
} catch {
|
|
240
|
+
return !0;
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
function f$1(e) {
|
|
245
|
+
return typeof e == `object` && !!e && !Array.isArray(e) && Object.values(e).every((e) => typeof e != `object` || !e);
|
|
246
|
+
}
|
|
247
|
+
function p$2(e) {
|
|
248
|
+
let t = e.structuredContent, n = [];
|
|
249
|
+
t !== void 0 && (n.push(t), typeof t == `object` && t && n.push(...Object.values(t)));
|
|
250
|
+
for (let e of n) if (Array.isArray(e) && e.length > 0 && e.every(f$1)) return e;
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
253
|
+
function m$2(e) {
|
|
254
|
+
let t = [...new Set(e.flatMap((e) => Object.keys(e)))], n = (e) => e == null ? `` : r(String(e)).replace(/\n/g, ` `), i = t.map((t) => Math.max(t.length, ...e.map((e) => n(e[t]).length))), a = (e) => e.map((e, t) => e.padEnd(i[t])).join(` `).trimEnd();
|
|
255
|
+
return [a(t.map((e) => e.toUpperCase())), ...e.map((e) => a(t.map((t) => n(e[t]))))].join(`
|
|
256
|
+
`);
|
|
257
|
+
}
|
|
258
|
+
function h$2(e, t) {
|
|
259
|
+
let n = t.saved ?? /* @__PURE__ */ new Map();
|
|
260
|
+
switch (t.mode) {
|
|
261
|
+
case `json`: return JSON.stringify(e);
|
|
262
|
+
case `ndjson`: return JSON.stringify({
|
|
263
|
+
type: `result`,
|
|
264
|
+
result: e
|
|
265
|
+
});
|
|
266
|
+
case `table`: {
|
|
267
|
+
let n = p$2(e);
|
|
268
|
+
return n ? m$2(n) : h$2(e, {
|
|
269
|
+
...t,
|
|
270
|
+
mode: `pretty`
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
case `pretty`:
|
|
274
|
+
case `compact`:
|
|
275
|
+
if (e.structuredContent !== void 0) {
|
|
276
|
+
let r = t.mode === `pretty` ? JSON.stringify(e.structuredContent, null, 2) : JSON.stringify(e.structuredContent), i = u$1(e).map((e) => c$1(e, n, !1));
|
|
277
|
+
return t.mode === `pretty` && i.length > 0 ? [r, ...i].join(`
|
|
278
|
+
`) : r;
|
|
279
|
+
}
|
|
280
|
+
return u$1(e).map((e) => c$1(e, n, t.mode === `compact`)).join(`
|
|
281
|
+
`);
|
|
282
|
+
case `text`:
|
|
283
|
+
case `raw`: {
|
|
284
|
+
let r = u$1(e).map((e) => c$1(e, n, t.mode === `raw`));
|
|
285
|
+
return r.length === 0 && e.structuredContent !== void 0 ? JSON.stringify(e.structuredContent, null, t.mode === `text` ? 2 : void 0) : r.join(`
|
|
286
|
+
`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
// ../mcp-cli/dist/chunk-CMnHEuio.mjs
|
|
291
|
+
const i = /* @__PURE__ */ new Set([
|
|
292
|
+
`approvals`,
|
|
293
|
+
`auth`,
|
|
294
|
+
`call`,
|
|
295
|
+
`completion`,
|
|
296
|
+
`doctor`,
|
|
297
|
+
`help`,
|
|
298
|
+
`login`,
|
|
299
|
+
`logout`,
|
|
300
|
+
`resources`,
|
|
301
|
+
`resume`,
|
|
302
|
+
`schema`,
|
|
303
|
+
`skill`,
|
|
304
|
+
`tasks`,
|
|
305
|
+
`tools`,
|
|
306
|
+
`version`,
|
|
307
|
+
`whoami`,
|
|
308
|
+
`__complete`
|
|
309
|
+
]);
|
|
310
|
+
[...i];
|
|
311
|
+
function s(e) {
|
|
312
|
+
return e.split(/\s+/).filter(Boolean);
|
|
313
|
+
}
|
|
314
|
+
function c(e, t) {
|
|
315
|
+
if (t?.group || t?.name) {
|
|
316
|
+
let n = t.group ? s(t.group) : [], r = t.name ?? (e.name.includes(`.`) ? e.name.split(`.`).filter(Boolean).at(-1) ?? e.name : e.name);
|
|
317
|
+
return [...n, r];
|
|
318
|
+
}
|
|
319
|
+
if (e.name.includes(`.`)) {
|
|
320
|
+
let t = e.name.split(`.`).filter(Boolean);
|
|
321
|
+
if (t.length > 0) return t;
|
|
322
|
+
}
|
|
323
|
+
return [e.name];
|
|
324
|
+
}
|
|
325
|
+
const l = (e) => e.join(`\0`);
|
|
326
|
+
function u(e, t = {}, r = i) {
|
|
327
|
+
let a = [], o = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map(), d = (e, t, n) => {
|
|
328
|
+
if (t.length === 0 || t.some((e) => e === ``)) return;
|
|
329
|
+
let r = u.get(l(t)) ?? [];
|
|
330
|
+
r.push({
|
|
331
|
+
entry: e,
|
|
332
|
+
priority: n
|
|
333
|
+
}), u.set(l(t), r);
|
|
334
|
+
}, f = /* @__PURE__ */ new Map();
|
|
335
|
+
for (let r of e) {
|
|
336
|
+
if (o.has(r.name)) continue;
|
|
337
|
+
let e = Object.prototype.hasOwnProperty.call(t, r.name) ? t[r.name] : void 0, i = c(r, e), l = {
|
|
338
|
+
tool: e?.description ? {
|
|
339
|
+
...r,
|
|
340
|
+
description: e.description
|
|
341
|
+
} : r,
|
|
342
|
+
path: i,
|
|
343
|
+
aliases: [],
|
|
344
|
+
hidden: e?.hidden === !0,
|
|
345
|
+
callOnly: !1,
|
|
346
|
+
override: e
|
|
347
|
+
};
|
|
348
|
+
a.push(l), o.set(r.name, l);
|
|
349
|
+
let u = [
|
|
350
|
+
{
|
|
351
|
+
path: [r.name],
|
|
352
|
+
priority: 0
|
|
353
|
+
},
|
|
354
|
+
{
|
|
355
|
+
path: i,
|
|
356
|
+
priority: 1
|
|
357
|
+
},
|
|
358
|
+
...(e?.aliases ?? []).map((e) => ({
|
|
359
|
+
path: s(e),
|
|
360
|
+
priority: 2
|
|
361
|
+
})),
|
|
362
|
+
{
|
|
363
|
+
path: i.map(e$1),
|
|
364
|
+
priority: 3
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
path: [e$1(r.name)],
|
|
368
|
+
priority: 3
|
|
369
|
+
}
|
|
370
|
+
];
|
|
371
|
+
f.set(l, u);
|
|
372
|
+
for (let e of u) d(l, e.path, e.priority);
|
|
373
|
+
}
|
|
374
|
+
let p = { children: /* @__PURE__ */ new Map() }, m = /* @__PURE__ */ new Map();
|
|
375
|
+
for (let [e, t] of f) {
|
|
376
|
+
let n = /* @__PURE__ */ new Set();
|
|
377
|
+
for (let { path: i } of t) {
|
|
378
|
+
let t = l(i);
|
|
379
|
+
if (n.has(t) || i.length === 0 || (n.add(t), r.has(i[0]))) continue;
|
|
380
|
+
let a = u.get(t) ?? [], o = Math.min(...a.map((e) => e.priority)), s = a.filter((e) => e.priority === o), c = new Set(s.map((e) => e.entry));
|
|
381
|
+
if (c.size !== 1 || !c.has(e)) continue;
|
|
382
|
+
let d = p;
|
|
383
|
+
for (let e of i) {
|
|
384
|
+
let t = d.children.get(e);
|
|
385
|
+
t || (t = { children: /* @__PURE__ */ new Map() }, d.children.set(e, t)), d = t;
|
|
386
|
+
}
|
|
387
|
+
d.entry = e;
|
|
388
|
+
let f = m.get(e) ?? [];
|
|
389
|
+
f.push(i), m.set(e, f);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
for (let e of a) {
|
|
393
|
+
let t = m.get(e) ?? [], n = l(e.path), r = t.find((e) => l(e) === n) ?? t[0];
|
|
394
|
+
r ? (e.path = r, e.aliases = t.filter((e) => l(e) !== l(r))) : e.callOnly = !0;
|
|
395
|
+
}
|
|
396
|
+
let h = (e) => {
|
|
397
|
+
let t = p;
|
|
398
|
+
for (let n of e) if (t = t?.children.get(n), !t) return;
|
|
399
|
+
return t;
|
|
400
|
+
};
|
|
401
|
+
return {
|
|
402
|
+
entries: a,
|
|
403
|
+
byToolName: o,
|
|
404
|
+
resolve(e) {
|
|
405
|
+
let t = p, n = { kind: `none` }, r = [];
|
|
406
|
+
for (let [i, a] of e.entries()) {
|
|
407
|
+
let e = t.children.get(a);
|
|
408
|
+
if (!e) break;
|
|
409
|
+
t = e, r.push(a), t.entry && (n = {
|
|
410
|
+
kind: `tool`,
|
|
411
|
+
entry: t.entry,
|
|
412
|
+
consumed: i + 1
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
return n.kind === `tool` ? n : r.length > 0 ? {
|
|
416
|
+
kind: `group`,
|
|
417
|
+
path: r,
|
|
418
|
+
children: [...t.children.keys()].sort()
|
|
419
|
+
} : n;
|
|
420
|
+
},
|
|
421
|
+
topLevelWords() {
|
|
422
|
+
return [...p.children.keys()].sort();
|
|
423
|
+
},
|
|
424
|
+
childrenOf(e) {
|
|
425
|
+
return [...h(e)?.children.keys() ?? []].sort();
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
function d(e) {
|
|
430
|
+
return typeof e == `object` && !!e && !Array.isArray(e);
|
|
431
|
+
}
|
|
432
|
+
function f(e) {
|
|
433
|
+
return decodeURIComponent(e).replace(/~1/g, `/`).replace(/~0/g, `~`);
|
|
434
|
+
}
|
|
435
|
+
function p$1(e, t) {
|
|
436
|
+
if (t === `#`) return e;
|
|
437
|
+
if (!t.startsWith(`#/`)) return;
|
|
438
|
+
let n = e;
|
|
439
|
+
for (let e of t.slice(2).split(`/`)) {
|
|
440
|
+
if (!d(n)) return;
|
|
441
|
+
n = n[f(e)];
|
|
442
|
+
}
|
|
443
|
+
return d(n) ? n : void 0;
|
|
444
|
+
}
|
|
445
|
+
var m$1 = class extends Error {};
|
|
446
|
+
function h$1(e, t, n, r) {
|
|
447
|
+
if (n.length > 32) throw new m$1();
|
|
448
|
+
let i = t;
|
|
449
|
+
if (typeof i.$ref == `string`) {
|
|
450
|
+
let t = i.$ref;
|
|
451
|
+
if (n.includes(t)) throw new m$1();
|
|
452
|
+
let a = p$1(e, t);
|
|
453
|
+
if (!a) return {
|
|
454
|
+
...i,
|
|
455
|
+
$ref: void 0
|
|
456
|
+
};
|
|
457
|
+
r.add(t);
|
|
458
|
+
let { $ref: o, ...s } = i;
|
|
459
|
+
i = {
|
|
460
|
+
...h$1(e, a, [...n, t], r),
|
|
461
|
+
...s
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
if (Array.isArray(i.allOf)) {
|
|
465
|
+
let { allOf: t, ...a } = i, o = {};
|
|
466
|
+
for (let i of t) d(i) && (o = g$1(o, h$1(e, i, n, r)));
|
|
467
|
+
i = g$1(o, a);
|
|
468
|
+
}
|
|
469
|
+
return i;
|
|
470
|
+
}
|
|
471
|
+
function g$1(e, t) {
|
|
472
|
+
let n = {
|
|
473
|
+
...e,
|
|
474
|
+
...t
|
|
475
|
+
};
|
|
476
|
+
(d(e.properties) || d(t.properties)) && (n.properties = {
|
|
477
|
+
...d(e.properties) ? e.properties : {},
|
|
478
|
+
...d(t.properties) ? t.properties : {}
|
|
479
|
+
});
|
|
480
|
+
let r = [...Array.isArray(e.required) ? e.required : [], ...Array.isArray(t.required) ? t.required : []];
|
|
481
|
+
return r.length > 0 && (n.required = [...new Set(r)]), n;
|
|
482
|
+
}
|
|
483
|
+
function _$1(e, t, n = []) {
|
|
484
|
+
let r = /* @__PURE__ */ new Set();
|
|
485
|
+
try {
|
|
486
|
+
return {
|
|
487
|
+
schema: h$1(e, t, n, r),
|
|
488
|
+
recursive: !1,
|
|
489
|
+
ancestors: [...n, ...r]
|
|
490
|
+
};
|
|
491
|
+
} catch (e) {
|
|
492
|
+
if (e instanceof m$1) return {
|
|
493
|
+
schema: t,
|
|
494
|
+
recursive: !0,
|
|
495
|
+
ancestors: n
|
|
496
|
+
};
|
|
497
|
+
throw e;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
function v$1(e) {
|
|
501
|
+
return typeof e.type == `string` ? [e.type] : Array.isArray(e.type) ? e.type.filter((e) => typeof e == `string`) : [];
|
|
502
|
+
}
|
|
503
|
+
function ee(e) {
|
|
504
|
+
return e.contentEncoding === `base64` || e.format === `binary` || e.format === `byte` || typeof e.contentMediaType == `string`;
|
|
505
|
+
}
|
|
506
|
+
function y$1(e) {
|
|
507
|
+
return d(e) && (e.type === `null` || Array.isArray(e.type) && e.type.length === 1 && e.type[0] === `null`);
|
|
508
|
+
}
|
|
509
|
+
function b$1(e, t, n) {
|
|
510
|
+
return {
|
|
511
|
+
kind: t,
|
|
512
|
+
schema: e,
|
|
513
|
+
nullable: n,
|
|
514
|
+
description: typeof e.description == `string` ? e.description : void 0,
|
|
515
|
+
defaultValue: e.default,
|
|
516
|
+
hasDefault: Object.prototype.hasOwnProperty.call(e, `default`),
|
|
517
|
+
deprecated: e.deprecated === !0,
|
|
518
|
+
readOnly: e.readOnly === !0,
|
|
519
|
+
format: typeof e.format == `string` ? e.format : void 0
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
const x$1 = [
|
|
523
|
+
`integer`,
|
|
524
|
+
`number`,
|
|
525
|
+
`boolean`,
|
|
526
|
+
`string`
|
|
527
|
+
];
|
|
528
|
+
function S$1(e) {
|
|
529
|
+
if (e.kind === `integer` || e.kind === `number` || e.kind === `boolean` || e.kind === `string`) return e.kind;
|
|
530
|
+
if (e.kind === `binary`) return `string`;
|
|
531
|
+
if (e.kind === `enum` || e.kind === `const`) {
|
|
532
|
+
let t = e.kind === `enum` ? e.enumValues ?? [] : [e.constValue];
|
|
533
|
+
if (t.every((e) => typeof e == `string`)) return `string`;
|
|
534
|
+
if (t.every((e) => Number.isInteger(e))) return `integer`;
|
|
535
|
+
if (t.every((e) => typeof e == `number`)) return `number`;
|
|
536
|
+
if (t.every((e) => typeof e == `boolean`)) return `boolean`;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
function C$1(e, t, n = []) {
|
|
540
|
+
let { schema: r, recursive: i, ancestors: a } = _$1(e, t, n);
|
|
541
|
+
if (i) return b$1(r, `json`, !1);
|
|
542
|
+
let o = r.nullable === !0, s = v$1(r);
|
|
543
|
+
s.includes(`null`) && (o = !0);
|
|
544
|
+
let c = s.filter((e) => e !== `null`);
|
|
545
|
+
if (Object.prototype.hasOwnProperty.call(r, `const`)) return {
|
|
546
|
+
...b$1(r, `const`, o),
|
|
547
|
+
constValue: r.const
|
|
548
|
+
};
|
|
549
|
+
if (Array.isArray(r.enum)) {
|
|
550
|
+
let e = r.enum.filter((e) => e !== null);
|
|
551
|
+
return e.length !== r.enum.length && (o = !0), {
|
|
552
|
+
...b$1(r, `enum`, o),
|
|
553
|
+
enumValues: e
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
let l = Array.isArray(r.anyOf) ? r.anyOf : Array.isArray(r.oneOf) ? r.oneOf : void 0;
|
|
557
|
+
if (l) {
|
|
558
|
+
let t = l.filter((e) => !y$1(e));
|
|
559
|
+
t.length !== l.length && (o = !0);
|
|
560
|
+
let n = t.filter(d).map((t) => C$1(e, t, a)), i = {
|
|
561
|
+
...r,
|
|
562
|
+
anyOf: void 0,
|
|
563
|
+
oneOf: void 0
|
|
564
|
+
};
|
|
565
|
+
if (n.length === 1) {
|
|
566
|
+
let e = n[0];
|
|
567
|
+
return {
|
|
568
|
+
...e,
|
|
569
|
+
nullable: o || e.nullable,
|
|
570
|
+
description: typeof r.description == `string` ? r.description : e.description,
|
|
571
|
+
hasDefault: e.hasDefault || Object.prototype.hasOwnProperty.call(r, `default`),
|
|
572
|
+
defaultValue: r.default ?? e.defaultValue,
|
|
573
|
+
deprecated: r.deprecated === !0 || e.deprecated
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
let s = n.map(S$1);
|
|
577
|
+
if (n.length > 0 && s.every((e) => e !== void 0)) {
|
|
578
|
+
let e = x$1.filter((e) => s.includes(e));
|
|
579
|
+
return {
|
|
580
|
+
...b$1(i, `scalar-union`, o),
|
|
581
|
+
unionKinds: e
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
return b$1(i, `json`, o);
|
|
585
|
+
}
|
|
586
|
+
if (c.length > 1) {
|
|
587
|
+
let e = x$1.filter((e) => c.includes(e));
|
|
588
|
+
return e.length === c.length ? {
|
|
589
|
+
...b$1(r, `scalar-union`, o),
|
|
590
|
+
unionKinds: e
|
|
591
|
+
} : b$1(r, `json`, o);
|
|
592
|
+
}
|
|
593
|
+
switch (c[0] ?? (d(r.properties) || d(r.additionalProperties) ? `object` : void 0)) {
|
|
594
|
+
case `string`: return b$1(r, ee(r) ? `binary` : `string`, o);
|
|
595
|
+
case `integer`: return b$1(r, `integer`, o);
|
|
596
|
+
case `number`: return b$1(r, `number`, o);
|
|
597
|
+
case `boolean`: return b$1(r, `boolean`, o);
|
|
598
|
+
case `array`: {
|
|
599
|
+
let t = C$1(e, d(r.items) ? r.items : {}, a);
|
|
600
|
+
return S$1(t) !== void 0 || t.kind === `scalar-union` ? {
|
|
601
|
+
...b$1(r, `scalar-array`, o),
|
|
602
|
+
item: t
|
|
603
|
+
} : {
|
|
604
|
+
...b$1(r, `object-array`, o),
|
|
605
|
+
item: t
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
case `object`:
|
|
609
|
+
if (!(d(r.properties) && Object.keys(r.properties).length > 0) && d(r.additionalProperties)) {
|
|
610
|
+
let t = C$1(e, r.additionalProperties, a);
|
|
611
|
+
if (S$1(t) !== void 0 || t.kind === `scalar-union`) return {
|
|
612
|
+
...b$1(r, `map`, o),
|
|
613
|
+
item: t
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
return b$1(r, `object`, o);
|
|
617
|
+
default: return b$1(r, `any`, o);
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
function te(e) {
|
|
621
|
+
let { schema: t, recursive: n } = _$1(e, e);
|
|
622
|
+
if (n) return null;
|
|
623
|
+
let r = v$1(t);
|
|
624
|
+
if (!(r.includes(`object`) || r.length === 0 && (d(t.properties) || Object.keys(t).length === 0))) return null;
|
|
625
|
+
let i = Object.create(null);
|
|
626
|
+
if (d(t.properties)) for (let [e, n] of Object.entries(t.properties)) d(n) && (i[e] = n);
|
|
627
|
+
return {
|
|
628
|
+
properties: i,
|
|
629
|
+
required: Array.isArray(t.required) ? t.required.filter((e) => typeof e == `string` && Object.hasOwn(i, e)) : []
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
function ne(e, t) {
|
|
633
|
+
let n = (Array.isArray(t.anyOf) ? t.anyOf : Array.isArray(t.oneOf) ? t.oneOf : []).filter((e) => d(e) && !y$1(e));
|
|
634
|
+
return n.length === 1 ? _$1(e, n[0]).schema : t;
|
|
635
|
+
}
|
|
636
|
+
function re(e, t) {
|
|
637
|
+
let n = e;
|
|
638
|
+
for (let r of t) {
|
|
639
|
+
let { schema: t, recursive: i } = _$1(e, n);
|
|
640
|
+
if (i) return;
|
|
641
|
+
let a = ne(e, t);
|
|
642
|
+
if (r === `[]`) {
|
|
643
|
+
if (!d(a.items)) return;
|
|
644
|
+
n = a.items;
|
|
645
|
+
} else if (d(a.properties) && d(a.properties[r])) n = a.properties[r];
|
|
646
|
+
else if (d(a.additionalProperties)) n = a.additionalProperties;
|
|
647
|
+
else return;
|
|
648
|
+
}
|
|
649
|
+
return C$1(e, n);
|
|
650
|
+
}
|
|
651
|
+
const w$1 = /* @__PURE__ */ new Set(/* @__PURE__ */ `answers.approvals.approve.approve-all.color.deny.detach.dry-run.example.field.help.help-all.input.json.json-body.jsonl.max-output.no-color.no-input.output.profile.raw-field.raw-strings.save.stream.timeout.token.verbose.wait.yes`.split(`.`));
|
|
652
|
+
function ie(e) {
|
|
653
|
+
return e.kind === `string` || e.kind === `enum` || e.kind === `binary`;
|
|
654
|
+
}
|
|
655
|
+
function T$1(e, t) {
|
|
656
|
+
let r = e.inputSchema ?? {}, i = te(r);
|
|
657
|
+
if (!i) return {
|
|
658
|
+
tool: e,
|
|
659
|
+
bodyOnly: !0,
|
|
660
|
+
flags: [],
|
|
661
|
+
byFlag: /* @__PURE__ */ new Map(),
|
|
662
|
+
byWire: /* @__PURE__ */ new Map(),
|
|
663
|
+
positionals: [],
|
|
664
|
+
constFields: {},
|
|
665
|
+
defaults: {},
|
|
666
|
+
required: []
|
|
667
|
+
};
|
|
668
|
+
let a = {}, o = { ...t?.defaults }, s = [], c = /* @__PURE__ */ new Set(), l = /* @__PURE__ */ new Map();
|
|
669
|
+
for (let e of Object.keys(i.properties)) l.set(e$1(e), (l.get(e$1(e)) ?? 0) + 1);
|
|
670
|
+
for (let [e, t] of Object.entries(i.properties)) {
|
|
671
|
+
let u = C$1(r, t);
|
|
672
|
+
if (u.readOnly) continue;
|
|
673
|
+
if (u.kind === `const`) {
|
|
674
|
+
E$1(a, e, u.constValue);
|
|
675
|
+
continue;
|
|
676
|
+
}
|
|
677
|
+
let d = e$1(e) || e, f = d;
|
|
678
|
+
if (w$1.has(f) || (l.get(d) ?? 0) > 1 || c.has(f)) for (f = `arg-${d}`, (c.has(f) || (l.get(d) ?? 0) > 1) && (f = `arg-${e}`); c.has(f);) f = `arg-${f}`;
|
|
679
|
+
c.add(f);
|
|
680
|
+
let p = i.required.includes(e);
|
|
681
|
+
p && u.hasDefault && !Object.hasOwn(o, e) && E$1(o, e, u.defaultValue), s.push({
|
|
682
|
+
wire: e,
|
|
683
|
+
flag: f,
|
|
684
|
+
field: u,
|
|
685
|
+
required: p && !Object.hasOwn(o, e),
|
|
686
|
+
hidden: u.deprecated
|
|
687
|
+
});
|
|
688
|
+
}
|
|
689
|
+
let u = new Map(s.map((e) => [e.wire, e])), d = [];
|
|
690
|
+
if (t?.positional && t.positional.length > 0) d = t.positional.map((e) => u.get(e)).filter((e) => e !== void 0 && ie(e.field));
|
|
691
|
+
else {
|
|
692
|
+
let e = s.filter((e) => e.required);
|
|
693
|
+
e.length === 1 && e[0].field.kind === `string` && (d = e);
|
|
694
|
+
}
|
|
695
|
+
return d.forEach((e, t) => {
|
|
696
|
+
e.position = t;
|
|
697
|
+
}), {
|
|
698
|
+
tool: e,
|
|
699
|
+
bodyOnly: !1,
|
|
700
|
+
flags: s,
|
|
701
|
+
byFlag: new Map(s.map((e) => [e.flag, e])),
|
|
702
|
+
byWire: u,
|
|
703
|
+
positionals: d,
|
|
704
|
+
constFields: a,
|
|
705
|
+
defaults: o,
|
|
706
|
+
required: s.filter((e) => e.required).map((e) => e.wire)
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
function E$1(e, t, n) {
|
|
710
|
+
Object.defineProperty(e, t, {
|
|
711
|
+
value: n,
|
|
712
|
+
enumerable: !0,
|
|
713
|
+
configurable: !0,
|
|
714
|
+
writable: !0
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
function D$1(e) {
|
|
718
|
+
return e?.startsWith(`\0`) === !0;
|
|
719
|
+
}
|
|
720
|
+
function O$1(t, n) {
|
|
721
|
+
let r = n.slice(1), i = t.startsWith(`--`) ? `${t}=${r}` : `${t}${r}`;
|
|
722
|
+
return new n$2(`usage`, `${t} needs a value, but the word after it, ${r}, is a global flag`, `Write ${i} to pass it as the value, or put ${r} after the value`);
|
|
723
|
+
}
|
|
724
|
+
const k$1 = /* @__PURE__ */ new Set([
|
|
725
|
+
`auto`,
|
|
726
|
+
`json`,
|
|
727
|
+
`text`,
|
|
728
|
+
`raw`,
|
|
729
|
+
`ndjson`,
|
|
730
|
+
`table`
|
|
731
|
+
]);
|
|
732
|
+
const A$1 = /* @__PURE__ */ new Set([
|
|
733
|
+
`output`,
|
|
734
|
+
`timeout`,
|
|
735
|
+
`save`,
|
|
736
|
+
`input`,
|
|
737
|
+
`json-body`,
|
|
738
|
+
`field`,
|
|
739
|
+
`raw-field`,
|
|
740
|
+
`max-output`,
|
|
741
|
+
`approve`,
|
|
742
|
+
`deny`,
|
|
743
|
+
`approvals`,
|
|
744
|
+
`answers`,
|
|
745
|
+
`wait`,
|
|
746
|
+
`stream`
|
|
747
|
+
]);
|
|
748
|
+
const j$1 = /* @__PURE__ */ new Set([
|
|
749
|
+
`auto`,
|
|
750
|
+
`raw`,
|
|
751
|
+
`off`
|
|
752
|
+
]);
|
|
753
|
+
const M$1 = /* @__PURE__ */ new Set([
|
|
754
|
+
`prompt`,
|
|
755
|
+
`fail`,
|
|
756
|
+
`deny`
|
|
757
|
+
]);
|
|
758
|
+
const oe = {
|
|
759
|
+
h: `help`,
|
|
760
|
+
o: `output`,
|
|
761
|
+
y: `yes`,
|
|
762
|
+
f: `raw-field`,
|
|
763
|
+
F: `field`
|
|
764
|
+
};
|
|
765
|
+
function N$1(e) {
|
|
766
|
+
return e.field.kind === `scalar-array` || e.field.kind === `object-array` || e.field.kind === `map`;
|
|
767
|
+
}
|
|
768
|
+
function P$1(t, n) {
|
|
769
|
+
let r = /^(\d+(?:\.\d+)?)(ms|s|m|h)?$/.exec(t.trim());
|
|
770
|
+
if (!r) throw new n$2(`invalid_value`, `${n} expects a duration such as 30000, 30s or 5m`);
|
|
771
|
+
let i = Number(r[1]), a = r[2] ?? `ms`, o = Math.round(i * (a === `h` ? 36e5 : a === `m` ? 6e4 : a === `s` ? 1e3 : 1));
|
|
772
|
+
if (o <= 0) throw new n$2(`invalid_value`, `${n} must be greater than zero`);
|
|
773
|
+
return o;
|
|
774
|
+
}
|
|
775
|
+
function se(t) {
|
|
776
|
+
if (t === `0` || t === `none` || t === `unlimited`) return null;
|
|
777
|
+
if (!/^\d+$/.test(t)) throw new n$2(`invalid_value`, `--max-output expects a character count, or 0 for unlimited`);
|
|
778
|
+
return Number(t);
|
|
779
|
+
}
|
|
780
|
+
function ce(t, n) {
|
|
781
|
+
let r = {
|
|
782
|
+
help: !1,
|
|
783
|
+
helpAll: !1,
|
|
784
|
+
dryRun: !1,
|
|
785
|
+
example: !1,
|
|
786
|
+
detach: !1,
|
|
787
|
+
yes: !1,
|
|
788
|
+
fields: [],
|
|
789
|
+
rawFields: [],
|
|
790
|
+
rawStrings: !1,
|
|
791
|
+
approve: [],
|
|
792
|
+
deny: [],
|
|
793
|
+
approveAll: !1
|
|
794
|
+
}, i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), o = [], s = /* @__PURE__ */ new Set(), c = (t, n) => {
|
|
795
|
+
if (t === `field`) return void r.fields.push(n);
|
|
796
|
+
if (t === `raw-field`) return void r.rawFields.push(n);
|
|
797
|
+
if (t === `approve` || t === `deny`) {
|
|
798
|
+
if (n.trim() === ``) throw new n$2(`invalid_value`, `--${t} needs a tool name`);
|
|
799
|
+
r[t].push(n);
|
|
800
|
+
} else {
|
|
801
|
+
if (s.has(t)) throw new n$2(`usage`, `--${t} was given more than once`);
|
|
802
|
+
switch (s.add(t), t) {
|
|
803
|
+
case `output`:
|
|
804
|
+
if (!k$1.has(n)) throw new n$2(`invalid_value`, `--output must be one of ${[...k$1].join(`, `)}`);
|
|
805
|
+
r.output = F(r.output, n);
|
|
806
|
+
return;
|
|
807
|
+
case `timeout`:
|
|
808
|
+
r.timeoutMs = P$1(n, `--timeout`);
|
|
809
|
+
return;
|
|
810
|
+
case `save`:
|
|
811
|
+
r.save = n;
|
|
812
|
+
return;
|
|
813
|
+
case `input`:
|
|
814
|
+
r.input = n;
|
|
815
|
+
return;
|
|
816
|
+
case `json-body`:
|
|
817
|
+
r.jsonBody = n;
|
|
818
|
+
return;
|
|
819
|
+
case `max-output`:
|
|
820
|
+
r.maxOutput = se(n);
|
|
821
|
+
return;
|
|
822
|
+
case `approvals`:
|
|
823
|
+
if (!M$1.has(n)) throw new n$2(`invalid_value`, `--approvals must be prompt, fail or deny`);
|
|
824
|
+
r.approvals = n;
|
|
825
|
+
return;
|
|
826
|
+
case `answers`:
|
|
827
|
+
r.answers = n;
|
|
828
|
+
return;
|
|
829
|
+
case `wait`:
|
|
830
|
+
r.wait = n;
|
|
831
|
+
return;
|
|
832
|
+
case `stream`:
|
|
833
|
+
if (!j$1.has(n)) throw new n$2(`invalid_value`, `--stream must be auto, raw or off`);
|
|
834
|
+
r.stream = n;
|
|
835
|
+
return;
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
}, l = (e) => {
|
|
839
|
+
switch (e) {
|
|
840
|
+
case `help`: return r.help = !0, !0;
|
|
841
|
+
case `help-all`: return r.helpAll = !0, !0;
|
|
842
|
+
case `json`: return r.output = F(r.output, `json`), !0;
|
|
843
|
+
case `jsonl`: return r.output = F(r.output, `ndjson`), !0;
|
|
844
|
+
case `dry-run`: return r.dryRun = !0, !0;
|
|
845
|
+
case `example`: return r.example = !0, !0;
|
|
846
|
+
case `detach`: return r.detach = !0, !0;
|
|
847
|
+
case `yes`: return r.yes = !0, !0;
|
|
848
|
+
case `raw-strings`: return r.rawStrings = !0, !0;
|
|
849
|
+
case `approve-all`: return r.approveAll = !0, !0;
|
|
850
|
+
default: return !1;
|
|
851
|
+
}
|
|
852
|
+
}, u = (t, n) => {
|
|
853
|
+
let r = i.get(t) ?? [];
|
|
854
|
+
if (r.length > 0 && !N$1(t)) throw new n$2(`usage`, `--${t.flag} was given more than once`, le(t));
|
|
855
|
+
r.push(n), i.set(t, r);
|
|
856
|
+
}, d = (t, n) => {
|
|
857
|
+
if (a.has(t)) throw new n$2(`usage`, `--${t.flag} was given more than once`);
|
|
858
|
+
a.set(t, n);
|
|
859
|
+
};
|
|
860
|
+
for (let r = 0; r < t.length; r += 1) {
|
|
861
|
+
let i = t[r];
|
|
862
|
+
if (!D$1(i)) {
|
|
863
|
+
if (i === `--`) {
|
|
864
|
+
o.push(...t.slice(r + 1));
|
|
865
|
+
break;
|
|
866
|
+
}
|
|
867
|
+
if (i.startsWith(`--`) && i.length > 2) {
|
|
868
|
+
let a = i.indexOf(`=`), o = a === -1 ? i.slice(2) : i.slice(2, a), s = a === -1 ? void 0 : i.slice(a + 1), f = () => {
|
|
869
|
+
if (s !== void 0) return s;
|
|
870
|
+
if (D$1(t[r + 1])) throw O$1(i, t[r + 1]);
|
|
871
|
+
if (r + 1 >= t.length) throw new n$2(`missing_argument`, `--${o} needs a value`);
|
|
872
|
+
return r += 1, t[r];
|
|
873
|
+
}, p = n.byFlag.get(o);
|
|
874
|
+
if (p) {
|
|
875
|
+
p.field.kind === `boolean` ? d(p, s === void 0 || I(s, `--${o}`)) : u(p, f());
|
|
876
|
+
continue;
|
|
877
|
+
}
|
|
878
|
+
if (o.startsWith(`no-`)) {
|
|
879
|
+
let t = n.byFlag.get(o.slice(3));
|
|
880
|
+
if (t && t.field.kind === `boolean`) {
|
|
881
|
+
if (s !== void 0) throw new n$2(`usage`, `--${o} takes no value; use --${t.flag}=${s}`);
|
|
882
|
+
d(t, !1);
|
|
883
|
+
continue;
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
if (A$1.has(o)) {
|
|
887
|
+
c(o, f());
|
|
888
|
+
continue;
|
|
889
|
+
}
|
|
890
|
+
if (s === void 0 && l(o)) continue;
|
|
891
|
+
throw L(o, n);
|
|
892
|
+
}
|
|
893
|
+
if (i.startsWith(`-`) && i.length > 1 && !/^-\d/.test(i)) {
|
|
894
|
+
let a = i.slice(1, 2), o = oe[a];
|
|
895
|
+
if (!o) throw L(i.slice(1), n);
|
|
896
|
+
let s = i.slice(2);
|
|
897
|
+
if (A$1.has(o)) {
|
|
898
|
+
let n = s;
|
|
899
|
+
if (n === ``) {
|
|
900
|
+
if (D$1(t[r + 1])) throw O$1(i, t[r + 1]);
|
|
901
|
+
if (r + 1 >= t.length) throw new n$2(`missing_argument`, `-${a} needs a value`);
|
|
902
|
+
r += 1, n = t[r];
|
|
903
|
+
}
|
|
904
|
+
c(o, n);
|
|
905
|
+
} else {
|
|
906
|
+
if (s !== ``) throw L(i.slice(1), n);
|
|
907
|
+
l(o);
|
|
908
|
+
}
|
|
909
|
+
} else o.push(i);
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
return {
|
|
913
|
+
reserved: r,
|
|
914
|
+
values: i,
|
|
915
|
+
booleans: a,
|
|
916
|
+
positionals: o
|
|
917
|
+
};
|
|
918
|
+
}
|
|
919
|
+
function F(t, n) {
|
|
920
|
+
if (t && t !== n) throw new n$2(`usage`, `Choose one output format: --json, --jsonl or --output`);
|
|
921
|
+
return n;
|
|
922
|
+
}
|
|
923
|
+
function le(e) {
|
|
924
|
+
return e.field.kind === `object` || e.field.kind === `json` ? `Pass one JSON value to --${e.flag}, or use -F ${e.wire}[key]=value` : void 0;
|
|
925
|
+
}
|
|
926
|
+
function I(t, n) {
|
|
927
|
+
let r = t.trim().toLowerCase();
|
|
928
|
+
if (r === `true`) return !0;
|
|
929
|
+
if (r === `false`) return !1;
|
|
930
|
+
throw new n$2(`invalid_value`, `${n} expects true or false, got ${JSON.stringify(t)}`);
|
|
931
|
+
}
|
|
932
|
+
function L(n, r) {
|
|
933
|
+
let a = n$1(n, [...r.flags.filter((e) => !e.hidden).map((e) => e.flag), ...w$1]);
|
|
934
|
+
return new n$2(`unknown_flag`, `Unknown flag --${n} for ${r.tool.name}`, a.length > 0 ? `Did you mean ${a.map((e) => `--${e}`).join(`, `)}?` : `Run with --help to list flags`);
|
|
935
|
+
}
|
|
936
|
+
function R(e) {
|
|
937
|
+
if (!e) return ``;
|
|
938
|
+
let t = r(e).trim().split(`
|
|
939
|
+
`, 1)[0], n = /^(.+?[.!?])(\s|$)/.exec(t);
|
|
940
|
+
return (n ? n[1] : t).trim();
|
|
941
|
+
}
|
|
942
|
+
function z(e) {
|
|
943
|
+
let t = e.annotations ?? {}, n = [];
|
|
944
|
+
return t.readOnlyHint && n.push(`read-only`), t.destructiveHint && n.push(`destructive`), t.idempotentHint && n.push(`idempotent`), t.openWorldHint && n.push(`open-world`), n;
|
|
945
|
+
}
|
|
946
|
+
function B(e, t, n = 0) {
|
|
947
|
+
switch (e.kind) {
|
|
948
|
+
case `string`: return `string`;
|
|
949
|
+
case `binary`: return `base64`;
|
|
950
|
+
case `enum`: return (e.enumValues ?? []).map((e) => JSON.stringify(e)).join(` | `);
|
|
951
|
+
case `const`: return JSON.stringify(e.constValue);
|
|
952
|
+
case `integer`:
|
|
953
|
+
case `number`: return `number`;
|
|
954
|
+
case `boolean`: return `boolean`;
|
|
955
|
+
case `scalar-union`: return (e.unionKinds ?? []).map((e) => e === `integer` ? `number` : e).filter((e, t, n) => n.indexOf(e) === t).join(` | `);
|
|
956
|
+
case `scalar-array`: return `${V(B(e.item ?? e, t, n))}[]`;
|
|
957
|
+
case `object-array`: return `${H(e.item?.schema ?? {}, t, n)}[]`;
|
|
958
|
+
case `map`: return `Record<string, ${B(e.item ?? e, t, n)}>`;
|
|
959
|
+
case `object`: return H(e.schema, t, n);
|
|
960
|
+
case `json`:
|
|
961
|
+
case `any`: return `unknown`;
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
function V(e) {
|
|
965
|
+
return e.includes(` | `) ? `(${e})` : e;
|
|
966
|
+
}
|
|
967
|
+
function H(e, t, n = 0) {
|
|
968
|
+
let r = e.properties;
|
|
969
|
+
if (n > 1 || typeof r != `object` || !r) return `object`;
|
|
970
|
+
let i = Array.isArray(e.required) ? e.required : [], a = Object.entries(r).map(([e, r]) => {
|
|
971
|
+
let a = C$1(t, r), o = B(a, t, n + 1);
|
|
972
|
+
return `${e}${i.includes(e) ? `` : `?`}: ${o}${a.nullable ? ` | null` : ``}`;
|
|
973
|
+
});
|
|
974
|
+
return a.length > 0 ? `{ ${a.join(`; `)} }` : `object`;
|
|
975
|
+
}
|
|
976
|
+
function U(e) {
|
|
977
|
+
let t = e.inputSchema ?? {}, n = T$1(e);
|
|
978
|
+
if (n.bodyOnly) return r(`${e.name}(body: unknown)`);
|
|
979
|
+
let i = n.flags.filter((e) => !e.hidden).map((e) => `${e.wire}${e.required ? `` : `?`}: ${B(e.field, t)}${e.field.nullable ? ` | null` : ``}`);
|
|
980
|
+
return r(`${e.name}(${i.length > 0 ? `{ ${i.join(`; `)} }` : ``})`);
|
|
981
|
+
}
|
|
982
|
+
function W(e) {
|
|
983
|
+
return e.callOnly ? `call ${e.tool.name}` : e.path.join(` `);
|
|
984
|
+
}
|
|
985
|
+
function Z(e, t = !1) {
|
|
986
|
+
return e.entries.filter((e) => t || !e.hidden).map((e) => ({
|
|
987
|
+
command: W(e),
|
|
988
|
+
tool: e.tool.name,
|
|
989
|
+
summary: R(e.tool.description),
|
|
990
|
+
badges: z(e.tool)
|
|
991
|
+
})).sort((e, t) => e.command.localeCompare(t.command));
|
|
992
|
+
}
|
|
993
|
+
function Q(e) {
|
|
994
|
+
if (e.length === 0) return `No tools.
|
|
995
|
+
`;
|
|
996
|
+
let t = Math.min(40, Math.max(...e.map((e) => e.command.length)));
|
|
997
|
+
return r(`${e.map((e) => ` ${e.command.padEnd(t)} ${e.summary}${e.badges.length > 0 ? ` [${e.badges.join(`, `)}]` : ``}`.trimEnd()).join(`
|
|
998
|
+
`)}\n`);
|
|
999
|
+
}
|
|
1000
|
+
[...[
|
|
1001
|
+
[`login`, `Sign in (browser, --device for a code to approve elsewhere, or --with-token for an API key)`],
|
|
1002
|
+
[`logout`, `Sign out: revoke the session on the server and remove it here`],
|
|
1003
|
+
[`auth status`, `Show who is signed in and which credential is in use`],
|
|
1004
|
+
[`auth token`, `Print the current token`],
|
|
1005
|
+
[`tools`, `List tools (--search <q>, --refresh, --json)`],
|
|
1006
|
+
[`schema <tool>`, `Print a tool's input and output schemas`],
|
|
1007
|
+
[`call <tool>`, `Call a tool by its exact name`],
|
|
1008
|
+
[`resume <id>`, `Answer a paused call (an approval or other input) and print its result`],
|
|
1009
|
+
[`tasks get <id>`, `Print a task's status, or its result once it has finished`],
|
|
1010
|
+
[`tasks watch <id>`, `Follow a task (from --detach or --wait) until it finishes`],
|
|
1011
|
+
[`tasks answer <id>`, `Answer a task waiting for approval or input, then follow it`],
|
|
1012
|
+
[`tasks cancel <id>`, `Ask the server to cancel a task`],
|
|
1013
|
+
[`completion <shell>`, `Print a bash, zsh or fish completion script`],
|
|
1014
|
+
[`skill install`, `Write a SKILL.md for coding agents`],
|
|
1015
|
+
[`doctor`, `Check node, credentials and the server`],
|
|
1016
|
+
[`version`, `Print the version`]
|
|
1017
|
+
].slice(0, 13)];
|
|
1018
|
+
// ../mcp-cli/dist/chunk-Bc2e_4bO.mjs
|
|
1019
|
+
var p = class extends n$2 {};
|
|
1020
|
+
function m(e) {
|
|
1021
|
+
return typeof e == `object` && !!e && !Array.isArray(e);
|
|
1022
|
+
}
|
|
1023
|
+
function h(e, t) {
|
|
1024
|
+
try {
|
|
1025
|
+
return JSON.parse(e);
|
|
1026
|
+
} catch {
|
|
1027
|
+
throw new p(`invalid_value`, `${t} is not valid JSON`);
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
function g(e) {
|
|
1031
|
+
if (Array.isArray(e)) return e.map(g);
|
|
1032
|
+
if (m(e)) {
|
|
1033
|
+
let t = {};
|
|
1034
|
+
for (let [r, i] of Object.entries(e)) E$1(t, r, g(i));
|
|
1035
|
+
return t;
|
|
1036
|
+
}
|
|
1037
|
+
return e;
|
|
1038
|
+
}
|
|
1039
|
+
function _(e, t) {
|
|
1040
|
+
let r = {};
|
|
1041
|
+
for (let [t, i] of Object.entries(e)) E$1(r, t, i);
|
|
1042
|
+
for (let [e, i] of Object.entries(t)) {
|
|
1043
|
+
let t = Object.prototype.hasOwnProperty.call(r, e) ? r[e] : void 0;
|
|
1044
|
+
E$1(r, e, m(t) && m(i) ? _(t, i) : i);
|
|
1045
|
+
}
|
|
1046
|
+
return r;
|
|
1047
|
+
}
|
|
1048
|
+
async function v(t, n, r) {
|
|
1049
|
+
let i = t.slice(1);
|
|
1050
|
+
if (i === ``) throw new p(`invalid_value`, `${r}: @ must be followed by a path, or - for stdin`);
|
|
1051
|
+
if (i === `-`) return n.readStdin();
|
|
1052
|
+
try {
|
|
1053
|
+
return await n.readFile(i);
|
|
1054
|
+
} catch (t) {
|
|
1055
|
+
throw new n$2(`invalid_value`, `${r}: cannot read ${i} (${t instanceof Error && `code` in t ? String(t.code) : `unreadable`})`);
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
function y(e, t, n) {
|
|
1059
|
+
switch (e) {
|
|
1060
|
+
case `string`: return t;
|
|
1061
|
+
case `integer`: {
|
|
1062
|
+
let e = t.trim(), r = Number(e);
|
|
1063
|
+
if (!/^[+-]?\d+$/.test(e) || !Number.isSafeInteger(r)) throw new p(`invalid_value`, `${n} expects an integer, got ${JSON.stringify(t)}`);
|
|
1064
|
+
return r;
|
|
1065
|
+
}
|
|
1066
|
+
case `number`: {
|
|
1067
|
+
let e = Number(t.trim());
|
|
1068
|
+
if (t.trim() === `` || !Number.isFinite(e)) throw new p(`invalid_value`, `${n} expects a number, got ${JSON.stringify(t)}`);
|
|
1069
|
+
return e;
|
|
1070
|
+
}
|
|
1071
|
+
case `boolean`: {
|
|
1072
|
+
let e = t.trim().toLowerCase();
|
|
1073
|
+
if (e === `true`) return !0;
|
|
1074
|
+
if (e === `false`) return !1;
|
|
1075
|
+
throw new p(`invalid_value`, `${n} expects true or false, got ${JSON.stringify(t)}`);
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
function b(e, t, n) {
|
|
1080
|
+
for (let r of e) try {
|
|
1081
|
+
return y(r, t, n);
|
|
1082
|
+
} catch {
|
|
1083
|
+
continue;
|
|
1084
|
+
}
|
|
1085
|
+
throw new p(`invalid_value`, `${n} expects ${e.join(` or `)}, got ${JSON.stringify(t)}`);
|
|
1086
|
+
}
|
|
1087
|
+
function x(e, t, n) {
|
|
1088
|
+
let r = e.enumValues ?? [], i = r.find((e) => (typeof e == `string` ? e : JSON.stringify(e)) === t);
|
|
1089
|
+
if (i === void 0 && !r.includes(t)) throw new p(`invalid_value`, `${n} must be one of ${r.map((e) => typeof e == `string` ? e : JSON.stringify(e)).join(`, `)}`);
|
|
1090
|
+
return i ?? t;
|
|
1091
|
+
}
|
|
1092
|
+
async function S(e, t, n) {
|
|
1093
|
+
return e.startsWith(`@@`) ? e.slice(1) : e.startsWith(`@`) ? (await v(e, t, n)).toString(`utf8`) : e;
|
|
1094
|
+
}
|
|
1095
|
+
async function C(e, t, n, r) {
|
|
1096
|
+
switch (e.kind) {
|
|
1097
|
+
case `string`: return t;
|
|
1098
|
+
case `binary`: return t.startsWith(`@@`) ? t.slice(1) : t.startsWith(`@`) ? (await v(t, r, n)).toString(`base64`) : t;
|
|
1099
|
+
case `enum`: return x(e, t, n);
|
|
1100
|
+
case `integer`:
|
|
1101
|
+
case `number`:
|
|
1102
|
+
case `boolean`: return y(e.kind, t, n);
|
|
1103
|
+
case `scalar-union`: return b(e.unionKinds ?? [`string`], t, n);
|
|
1104
|
+
case `const`: return e.constValue;
|
|
1105
|
+
case `object`:
|
|
1106
|
+
case `object-array`:
|
|
1107
|
+
case `json`: {
|
|
1108
|
+
let i = g(h(await S(t, r, n), n));
|
|
1109
|
+
if (e.kind === `object` && !m(i)) throw new p(`invalid_value`, `${n} expects a JSON object`);
|
|
1110
|
+
return i;
|
|
1111
|
+
}
|
|
1112
|
+
case `any`: {
|
|
1113
|
+
let e = await S(t, r, n);
|
|
1114
|
+
try {
|
|
1115
|
+
return g(JSON.parse(e));
|
|
1116
|
+
} catch {
|
|
1117
|
+
return e;
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
case `scalar-array`:
|
|
1121
|
+
case `map`: return C(e.item ?? {
|
|
1122
|
+
...e,
|
|
1123
|
+
kind: `any`
|
|
1124
|
+
}, t, n, r);
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
async function w(t, r, i) {
|
|
1128
|
+
let a = `--${t.flag}`, o = t.field;
|
|
1129
|
+
if (o.kind === `scalar-array`) {
|
|
1130
|
+
let e = o.item ?? o, t = [];
|
|
1131
|
+
for (let n of r) if (r.length === 1 && n.trimStart().startsWith(`[`)) {
|
|
1132
|
+
let r = h(n, a);
|
|
1133
|
+
if (!Array.isArray(r)) throw new p(`invalid_value`, `${a} expects a JSON array`);
|
|
1134
|
+
for (let n of r) t.push(typeof n == `string` ? await C(e, n, a, i) : n);
|
|
1135
|
+
} else t.push(await C(e, n, a, i));
|
|
1136
|
+
return t;
|
|
1137
|
+
}
|
|
1138
|
+
if (o.kind === `object-array`) {
|
|
1139
|
+
let e = [];
|
|
1140
|
+
for (let t of r) {
|
|
1141
|
+
let n = await C({
|
|
1142
|
+
...o,
|
|
1143
|
+
kind: `json`
|
|
1144
|
+
}, t, a, i);
|
|
1145
|
+
Array.isArray(n) ? e.push(...n) : e.push(n);
|
|
1146
|
+
}
|
|
1147
|
+
return e;
|
|
1148
|
+
}
|
|
1149
|
+
if (o.kind === `map`) {
|
|
1150
|
+
let t = {};
|
|
1151
|
+
for (let s of r) {
|
|
1152
|
+
let r = s.indexOf(`=`);
|
|
1153
|
+
if (r <= 0) throw new p(`invalid_value`, `${a} expects key=value`);
|
|
1154
|
+
let c = s.slice(0, r);
|
|
1155
|
+
if (Object.prototype.hasOwnProperty.call(t, c)) throw new n$2(`usage`, `${a} sets ${c} more than once`);
|
|
1156
|
+
E$1(t, c, await C(o.item ?? o, s.slice(r + 1), `${a} ${c}`, i));
|
|
1157
|
+
}
|
|
1158
|
+
return t;
|
|
1159
|
+
}
|
|
1160
|
+
return C(o, r[0], a, i);
|
|
1161
|
+
}
|
|
1162
|
+
function T(t, n) {
|
|
1163
|
+
let r = n ? `-F` : `-f`, i = t.indexOf(`=`);
|
|
1164
|
+
if (i === -1 && /^[^[\]=]+(?:\[[^[\]]+\])*\[\]$/.test(t)) return {
|
|
1165
|
+
...T(`${t}=`, n),
|
|
1166
|
+
empty: !0
|
|
1167
|
+
};
|
|
1168
|
+
if (i <= 0) throw new n$2(`usage`, `${r} expects key=value, got ${JSON.stringify(t)}`);
|
|
1169
|
+
let a = t.slice(0, i), o = /^([^[\]]+)((?:\[[^[\]]*\])*)$/.exec(a);
|
|
1170
|
+
if (!o) throw new n$2(`usage`, `${r} key ${JSON.stringify(a)} is malformed`);
|
|
1171
|
+
let s = [o[1]], c = !1, l = [...o[2].matchAll(/\[([^[\]]*)\]/g)].map((e) => e[1]);
|
|
1172
|
+
for (let [t, n] of l.entries()) if (n === ``) {
|
|
1173
|
+
if (t !== l.length - 1) throw new n$2(`usage`, `${r} supports [] only at the end of a key`);
|
|
1174
|
+
c = !0;
|
|
1175
|
+
} else s.push(n);
|
|
1176
|
+
return {
|
|
1177
|
+
path: s,
|
|
1178
|
+
append: c,
|
|
1179
|
+
raw: t.slice(i + 1),
|
|
1180
|
+
typed: n
|
|
1181
|
+
};
|
|
1182
|
+
}
|
|
1183
|
+
async function E(e, n, r, i) {
|
|
1184
|
+
let a = `${e.typed ? `-F` : `-f`} ${e.path.join(`.`)}`;
|
|
1185
|
+
if (!e.typed || r) return e.raw;
|
|
1186
|
+
let s = re(n, e.append ? [...e.path, `[]`] : e.path), c = e.raw;
|
|
1187
|
+
if (c.startsWith(`@@`)) c = c.slice(1);
|
|
1188
|
+
else if (c.startsWith(`@`)) {
|
|
1189
|
+
let e = await v(c, i, a);
|
|
1190
|
+
if (s?.kind === `binary`) return e.toString(`base64`);
|
|
1191
|
+
if (c = e.toString(`utf8`), s && (s.kind === `string` || s.kind === `enum`)) return c;
|
|
1192
|
+
}
|
|
1193
|
+
if (c === `null`) return null;
|
|
1194
|
+
let l = D(c);
|
|
1195
|
+
return typeof l.value == `string` ? s?.kind === `enum` ? x(s, l.value, a) : l.value : s && (s.kind === `string` || s.kind === `binary`) ? c : s?.kind === `enum` ? x(s, c, a) : l.ok ? l.value : c;
|
|
1196
|
+
}
|
|
1197
|
+
function D(e) {
|
|
1198
|
+
try {
|
|
1199
|
+
return {
|
|
1200
|
+
ok: !0,
|
|
1201
|
+
value: g(JSON.parse(e))
|
|
1202
|
+
};
|
|
1203
|
+
} catch {
|
|
1204
|
+
return { ok: !1 };
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
function O(t, r, i) {
|
|
1208
|
+
let a = t;
|
|
1209
|
+
for (let t of r.path.slice(0, -1)) {
|
|
1210
|
+
let i = Object.prototype.hasOwnProperty.call(a, t) ? a[t] : void 0;
|
|
1211
|
+
if (i === void 0) {
|
|
1212
|
+
let e = {};
|
|
1213
|
+
E$1(a, t, e), a = e;
|
|
1214
|
+
} else if (m(i)) a = i;
|
|
1215
|
+
else throw new n$2(`usage`, `-F ${r.path.join(`.`)} conflicts with a non-object value`);
|
|
1216
|
+
}
|
|
1217
|
+
let o = r.path[r.path.length - 1];
|
|
1218
|
+
if (r.append) {
|
|
1219
|
+
let t = Object.prototype.hasOwnProperty.call(a, o) ? a[o] : void 0, s = r.empty ? [] : [i];
|
|
1220
|
+
if (t === void 0) E$1(a, o, s);
|
|
1221
|
+
else if (Array.isArray(t)) t.push(...s);
|
|
1222
|
+
else throw new n$2(`usage`, `-F ${o}[] conflicts with a non-array value`);
|
|
1223
|
+
} else {
|
|
1224
|
+
if (Object.prototype.hasOwnProperty.call(a, o)) throw new n$2(`usage`, `${r.path.join(`.`)} is set more than once by -f/-F`);
|
|
1225
|
+
E$1(a, o, i);
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
async function k(e, t) {
|
|
1229
|
+
let n = typeof e == `string` ? e : e.toString(`utf8`);
|
|
1230
|
+
if (n.trim() !== ``) return g(h(n, t));
|
|
1231
|
+
}
|
|
1232
|
+
function A(e, t) {
|
|
1233
|
+
if (t !== `@-`) return !1;
|
|
1234
|
+
switch (e.kind) {
|
|
1235
|
+
case `binary`:
|
|
1236
|
+
case `object`:
|
|
1237
|
+
case `object-array`:
|
|
1238
|
+
case `json`:
|
|
1239
|
+
case `any`: return !0;
|
|
1240
|
+
case `scalar-array`:
|
|
1241
|
+
case `map`: return A(e.item ?? {
|
|
1242
|
+
...e,
|
|
1243
|
+
kind: `any`
|
|
1244
|
+
}, t);
|
|
1245
|
+
default: return !1;
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
function j(e, t) {
|
|
1249
|
+
let { field: n } = e;
|
|
1250
|
+
if (n.kind === `map`) return t.some((e) => e.indexOf(`=`) > 0 && A(n, e.slice(e.indexOf(`=`) + 1)));
|
|
1251
|
+
if (n.kind === `scalar-array` && t.length === 1 && t[0].trimStart().startsWith(`[`)) try {
|
|
1252
|
+
let e = JSON.parse(t[0]);
|
|
1253
|
+
return Array.isArray(e) && e.some((e) => typeof e == `string` && A(n, e));
|
|
1254
|
+
} catch {
|
|
1255
|
+
return !1;
|
|
1256
|
+
}
|
|
1257
|
+
return t.some((e) => A(n, e));
|
|
1258
|
+
}
|
|
1259
|
+
function M(e, t) {
|
|
1260
|
+
let { reserved: n } = e;
|
|
1261
|
+
if (n.input === `-` || !n.rawStrings && n.fields.some((e) => e.slice(e.indexOf(`=`) + 1) === `@-`) || e.positionals.some((e, n) => t.positionals[n] !== void 0 && A(t.positionals[n].field, e))) return !0;
|
|
1262
|
+
for (let [t, n] of e.values) if (j(t, n)) return !0;
|
|
1263
|
+
return !1;
|
|
1264
|
+
}
|
|
1265
|
+
function N(e, t) {
|
|
1266
|
+
return e.reserved.answers === `-` || M(e, t);
|
|
1267
|
+
}
|
|
1268
|
+
async function P(t, r, i) {
|
|
1269
|
+
let { reserved: a } = r;
|
|
1270
|
+
if (a.input !== void 0 && a.jsonBody !== void 0) throw new n$2(`usage`, `Use only one of --input and --json-body`);
|
|
1271
|
+
let o, s = !1;
|
|
1272
|
+
if (a.jsonBody !== void 0) o = await k(a.jsonBody, `--json-body`);
|
|
1273
|
+
else if (a.input !== void 0) o = await k(a.input === `-` ? await i.readStdin() : await v(`@${a.input}`, i, `--input`), a.input === `-` ? `stdin` : a.input);
|
|
1274
|
+
else if (!i.noInput && !N(r, t) && i.stdinIsPipedData()) {
|
|
1275
|
+
let e = await i.readStdin();
|
|
1276
|
+
e.length > 0 && (o = await k(e, `stdin`), s = o !== void 0);
|
|
1277
|
+
}
|
|
1278
|
+
let c = r.values.size > 0 || r.booleans.size > 0 || r.positionals.length > 0, l = a.fields.length > 0 || a.rawFields.length > 0;
|
|
1279
|
+
if (t.bodyOnly) {
|
|
1280
|
+
if (c || l) throw new n$2(`usage`, `${t.tool.name} takes its arguments as one JSON value`, `Use --json-body, --input <file|-> or pipe JSON on stdin`);
|
|
1281
|
+
return {
|
|
1282
|
+
args: o === void 0 ? {} : o,
|
|
1283
|
+
usedAutoStdin: s
|
|
1284
|
+
};
|
|
1285
|
+
}
|
|
1286
|
+
if (o !== void 0 && !m(o)) throw new n$2(`invalid_value`, `The arguments body must be a JSON object`);
|
|
1287
|
+
let u = o ?? {};
|
|
1288
|
+
if (l) {
|
|
1289
|
+
let e = {}, n = t.tool.inputSchema ?? {}, r = [...a.rawFields.map((e) => T(e, !1)), ...a.fields.map((e) => T(e, !0))];
|
|
1290
|
+
for (let o of r) {
|
|
1291
|
+
let r = o.path[0], s = t.byWire.has(r) ? r : t.byFlag.get(r)?.wire ?? r, c = {
|
|
1292
|
+
...o,
|
|
1293
|
+
path: [s, ...o.path.slice(1)]
|
|
1294
|
+
};
|
|
1295
|
+
O(e, c, c.empty ? void 0 : await E(c, n, a.rawStrings, i));
|
|
1296
|
+
}
|
|
1297
|
+
u = _(u, e);
|
|
1298
|
+
}
|
|
1299
|
+
let d = {};
|
|
1300
|
+
if (r.positionals.length > t.positionals.length) {
|
|
1301
|
+
let n = r.positionals.slice(t.positionals.length);
|
|
1302
|
+
throw new n$2(`usage`, `Unexpected argument${n.length > 1 ? `s` : ``}: ${n.map((e) => JSON.stringify(e)).join(` `)}`, t.positionals.length === 0 ? `Pass values as --flags; run with --help to list them` : void 0);
|
|
1303
|
+
}
|
|
1304
|
+
for (let [a, o] of r.positionals.entries()) {
|
|
1305
|
+
let s = t.positionals[a], c = r.values.get(s);
|
|
1306
|
+
if (c && c.some((e) => e !== o)) throw new n$2(`usage`, `${s.wire} was given both positionally and as --${s.flag}, with different values`);
|
|
1307
|
+
E$1(d, s.wire, await C(s.field, o, s.wire, i));
|
|
1308
|
+
}
|
|
1309
|
+
for (let [e, t] of r.values) E$1(d, e.wire, await w(e, t, i));
|
|
1310
|
+
for (let [e, t] of r.booleans) E$1(d, e.wire, t);
|
|
1311
|
+
u = _(u, d);
|
|
1312
|
+
for (let [e, r] of [...Object.entries(t.constFields), ...Object.entries(t.defaults)]) Object.prototype.hasOwnProperty.call(u, e) || E$1(u, e, structuredClone(r));
|
|
1313
|
+
let f = t.required.filter((e) => !Object.prototype.hasOwnProperty.call(u, e));
|
|
1314
|
+
if (f.length > 0) {
|
|
1315
|
+
let e = f.map((e) => {
|
|
1316
|
+
let n = t.byWire.get(e);
|
|
1317
|
+
return n?.position === void 0 ? `--${n?.flag ?? e}` : `<${n.flag}>`;
|
|
1318
|
+
});
|
|
1319
|
+
throw new p(`missing_argument`, `Missing required ${e.length > 1 ? `arguments` : `argument`}: ${e.join(`, `)}`, `Run with --help for usage`);
|
|
1320
|
+
}
|
|
1321
|
+
return {
|
|
1322
|
+
args: u,
|
|
1323
|
+
usedAutoStdin: s
|
|
1324
|
+
};
|
|
1325
|
+
}
|
|
1326
|
+
// src/lib/mcp-input.ts
|
|
1327
|
+
const SCHEMALESS = {
|
|
1328
|
+
name: "tool",
|
|
1329
|
+
inputSchema: { type: "object" }
|
|
1330
|
+
};
|
|
1331
|
+
function toMcpCliArgv(options) {
|
|
1332
|
+
return [
|
|
1333
|
+
...(options.rawField ?? []).flatMap((value) => ["-f", value]),
|
|
1334
|
+
...(options.field ?? []).flatMap((value) => ["-F", value]),
|
|
1335
|
+
...options.jsonBody !== void 0 ? ["--json-body", options.jsonBody] : [],
|
|
1336
|
+
...options.input !== void 0 ? ["--input", options.input] : []
|
|
1337
|
+
];
|
|
1338
|
+
}
|
|
1339
|
+
/** Whether resolving these arguments will consume the process stdin stream; the parser that reads it decides. */
|
|
1340
|
+
function usesMcpStdin(options) {
|
|
1341
|
+
const spec = T$1(SCHEMALESS);
|
|
1342
|
+
try {
|
|
1343
|
+
return N(ce(toMcpCliArgv(options), spec), spec);
|
|
1344
|
+
} catch {
|
|
1345
|
+
return false;
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
/** `-F` is the only input whose meaning depends on the tool's schema. */
|
|
1349
|
+
function needsMcpToolSchema(options) {
|
|
1350
|
+
return (options.field ?? []).length > 0;
|
|
1351
|
+
}
|
|
1352
|
+
async function readStream(stream) {
|
|
1353
|
+
const chunks = [];
|
|
1354
|
+
for await (const chunk of stream) chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
|
|
1355
|
+
return Buffer.concat(chunks);
|
|
1356
|
+
}
|
|
1357
|
+
/**
|
|
1358
|
+
* Builds tools/call arguments with the `@runtypelabs/mcp-cli` input layer: `--input`/`--json-body`,
|
|
1359
|
+
* then `-f`/`-F` deep-merged over it. Given the tool, `-F id=123` stays a string for a string field.
|
|
1360
|
+
*/
|
|
1361
|
+
async function resolveMcpArguments(options, dependencies = {}) {
|
|
1362
|
+
let stdinPromise;
|
|
1363
|
+
const deps = {
|
|
1364
|
+
readFile: (path) => readFile(path),
|
|
1365
|
+
readStdin: () => {
|
|
1366
|
+
stdinPromise ??= readStream(process.stdin);
|
|
1367
|
+
return stdinPromise;
|
|
1368
|
+
},
|
|
1369
|
+
...dependencies
|
|
1370
|
+
};
|
|
1371
|
+
const toolSpec = T$1(deps.tool ?? SCHEMALESS);
|
|
1372
|
+
const spec = toolSpec.bodyOnly ? T$1(SCHEMALESS) : {
|
|
1373
|
+
...toolSpec,
|
|
1374
|
+
required: [],
|
|
1375
|
+
positionals: []
|
|
1376
|
+
};
|
|
1377
|
+
const { args } = await P(spec, ce(toMcpCliArgv(options), spec), {
|
|
1378
|
+
readFile: deps.readFile,
|
|
1379
|
+
readStdin: deps.readStdin,
|
|
1380
|
+
stdinIsPipedData: () => false,
|
|
1381
|
+
noInput: true
|
|
1382
|
+
});
|
|
1383
|
+
return args;
|
|
1384
|
+
}
|
|
1385
|
+
// src/commands/mcp.ts
|
|
1386
|
+
const defaultDependencies = {
|
|
1387
|
+
ensureAuth,
|
|
1388
|
+
connect: connectMcpClient,
|
|
1389
|
+
resolveArguments: (options, tool) => resolveMcpArguments(options, { tool }),
|
|
1390
|
+
setExitCode: (code) => {
|
|
1391
|
+
process.exitCode = code;
|
|
1392
|
+
}
|
|
1393
|
+
};
|
|
1394
|
+
const DEFAULT_TOOL_TIMEOUT_MS = 93e4;
|
|
1395
|
+
const TOOL_SCHEMA_LOOKUP_TIMEOUT_MS = 1e4;
|
|
1396
|
+
/** Listing for `-F` must not make the SDK enforce `outputSchema`, which a call without `-F` never does. */
|
|
1397
|
+
function withoutOutputSchema(tool) {
|
|
1398
|
+
const { outputSchema: _outputSchema, ...definition } = tool;
|
|
1399
|
+
return definition;
|
|
1400
|
+
}
|
|
1401
|
+
function collectField(value, previous) {
|
|
1402
|
+
return previous.concat(value);
|
|
1403
|
+
}
|
|
1404
|
+
function parseServer(value) {
|
|
1405
|
+
if (value === "standard" || value === "code") return value;
|
|
1406
|
+
throw new InvalidArgumentError("Allowed values are \"standard\" and \"code\"");
|
|
1407
|
+
}
|
|
1408
|
+
function parsePositiveInteger(value) {
|
|
1409
|
+
const parsed = Number(value);
|
|
1410
|
+
if (!Number.isSafeInteger(parsed) || parsed <= 0) throw new InvalidArgumentError("Timeout must be a positive integer in milliseconds");
|
|
1411
|
+
return parsed;
|
|
1412
|
+
}
|
|
1413
|
+
function addCommonOptions(command) {
|
|
1414
|
+
return command.option("--server <server>", "Runtype MCP server to use: standard or code", parseServer, "standard").option("--json", "Output the complete MCP result as JSON");
|
|
1415
|
+
}
|
|
1416
|
+
function errorMessage(error) {
|
|
1417
|
+
return error instanceof Error ? error.message : String(error);
|
|
1418
|
+
}
|
|
1419
|
+
async function withMcpClient(options, dependencies, operation, authOptions) {
|
|
1420
|
+
const apiKey = await dependencies.ensureAuth(authOptions);
|
|
1421
|
+
if (!apiKey) {
|
|
1422
|
+
dependencies.setExitCode(1);
|
|
1423
|
+
return;
|
|
1424
|
+
}
|
|
1425
|
+
const { client } = await dependencies.connect(apiKey, options.server);
|
|
1426
|
+
try {
|
|
1427
|
+
await operation(client);
|
|
1428
|
+
} finally {
|
|
1429
|
+
await client.close().catch(() => void 0);
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
function printTools(tools, target) {
|
|
1433
|
+
if (tools.length === 0) {
|
|
1434
|
+
console.log(chalk.gray("No MCP tools found"));
|
|
1435
|
+
return;
|
|
1436
|
+
}
|
|
1437
|
+
const label = target === "code" ? "Code Mode MCP Tools" : "MCP Tools";
|
|
1438
|
+
console.log(chalk.cyan(`${label}:`));
|
|
1439
|
+
const rows = Z(u(tools), true).map((row) => ({
|
|
1440
|
+
...row,
|
|
1441
|
+
command: row.tool
|
|
1442
|
+
}));
|
|
1443
|
+
process.stdout.write(Q(rows));
|
|
1444
|
+
console.log(chalk.dim(`\n Total: ${tools.length} tools`));
|
|
1445
|
+
}
|
|
1446
|
+
function printTool(tool) {
|
|
1447
|
+
printDetail("MCP Tool", [
|
|
1448
|
+
{
|
|
1449
|
+
label: "Name",
|
|
1450
|
+
value: tool.name
|
|
1451
|
+
},
|
|
1452
|
+
{
|
|
1453
|
+
label: "Title",
|
|
1454
|
+
value: tool.title
|
|
1455
|
+
},
|
|
1456
|
+
{
|
|
1457
|
+
label: "Description",
|
|
1458
|
+
value: tool.description
|
|
1459
|
+
},
|
|
1460
|
+
{
|
|
1461
|
+
label: "Signature",
|
|
1462
|
+
value: U(tool)
|
|
1463
|
+
},
|
|
1464
|
+
{
|
|
1465
|
+
label: "Hints",
|
|
1466
|
+
value: z(tool).join(", ") || void 0
|
|
1467
|
+
},
|
|
1468
|
+
{
|
|
1469
|
+
label: "Input Schema",
|
|
1470
|
+
value: tool.inputSchema
|
|
1471
|
+
},
|
|
1472
|
+
{
|
|
1473
|
+
label: "Output Schema",
|
|
1474
|
+
value: tool.outputSchema
|
|
1475
|
+
},
|
|
1476
|
+
{
|
|
1477
|
+
label: "Annotations",
|
|
1478
|
+
value: tool.annotations
|
|
1479
|
+
},
|
|
1480
|
+
{
|
|
1481
|
+
label: "Execution",
|
|
1482
|
+
value: tool.execution
|
|
1483
|
+
}
|
|
1484
|
+
]);
|
|
1485
|
+
}
|
|
1486
|
+
function printCallResult(result, json) {
|
|
1487
|
+
if (json) {
|
|
1488
|
+
printJson(result);
|
|
1489
|
+
return;
|
|
1490
|
+
}
|
|
1491
|
+
const textOnly = result.content.length > 0 && result.content.every((block) => block.type === "text");
|
|
1492
|
+
if (result.structuredContent !== void 0 || textOnly) {
|
|
1493
|
+
const mode = e(void 0, { stdoutIsTTY: process.stdout.isTTY === true });
|
|
1494
|
+
console.log(h$2(result, { mode }));
|
|
1495
|
+
return;
|
|
1496
|
+
}
|
|
1497
|
+
printJson(result);
|
|
1498
|
+
}
|
|
1499
|
+
function createMcpCommand(overrides = {}) {
|
|
1500
|
+
const dependencies = {
|
|
1501
|
+
...defaultDependencies,
|
|
1502
|
+
...overrides
|
|
1503
|
+
};
|
|
1504
|
+
const command = new Command("mcp").description("Discover and call tools on the Runtype MCP servers");
|
|
1505
|
+
addCommonOptions(command.command("tools").description("List dynamically exposed MCP tools")).action(async (options) => {
|
|
1506
|
+
try {
|
|
1507
|
+
await withMcpClient(options, dependencies, async (client) => {
|
|
1508
|
+
const tools = await listAllMcpTools(client);
|
|
1509
|
+
if (options.json) printJson({ tools });
|
|
1510
|
+
else printTools(tools, options.server);
|
|
1511
|
+
});
|
|
1512
|
+
} catch (error) {
|
|
1513
|
+
console.error(chalk.red(`Failed to list MCP tools: ${errorMessage(error)}`));
|
|
1514
|
+
dependencies.setExitCode(1);
|
|
1515
|
+
}
|
|
1516
|
+
});
|
|
1517
|
+
addCommonOptions(command.command("inspect <name>").description("Show a tool and its current schemas")).action(async (name, options) => {
|
|
1518
|
+
try {
|
|
1519
|
+
await withMcpClient(options, dependencies, async (client) => {
|
|
1520
|
+
const tool = (await listAllMcpTools(client)).find((candidate) => candidate.name === name);
|
|
1521
|
+
if (!tool) throw new Error(`MCP tool "${name}" was not found`);
|
|
1522
|
+
if (options.json) printJson(tool);
|
|
1523
|
+
else printTool(tool);
|
|
1524
|
+
});
|
|
1525
|
+
} catch (error) {
|
|
1526
|
+
console.error(chalk.red(`Failed to inspect MCP tool: ${errorMessage(error)}`));
|
|
1527
|
+
dependencies.setExitCode(1);
|
|
1528
|
+
}
|
|
1529
|
+
});
|
|
1530
|
+
addCommonOptions(command.command("call <name>").description("Call any MCP tool by name without local registration").option("-f, --raw-field <key=value>", "Add a string argument", collectField, []).option("-F, --field <key=value>", "Add a JSON-typed argument; use @<path> or @- to read its value", collectField, []).option("--json-body <json>", "Use an inline JSON object as the tool arguments").option("--input <file>", "Read the tool arguments JSON object from a file or - for stdin").option("--timeout <ms>", "Maximum time to wait for the tool result in milliseconds", parsePositiveInteger, DEFAULT_TOOL_TIMEOUT_MS)).action(async (name, options) => {
|
|
1531
|
+
try {
|
|
1532
|
+
await withMcpClient(options, dependencies, async (client) => {
|
|
1533
|
+
const tool = needsMcpToolSchema(options) ? (await listAllMcpTools(client, { timeout: TOOL_SCHEMA_LOOKUP_TIMEOUT_MS }).catch(() => [])).find((item) => item.name === name) : void 0;
|
|
1534
|
+
const args = await dependencies.resolveArguments(options, tool);
|
|
1535
|
+
const result = await client.callTool({
|
|
1536
|
+
name,
|
|
1537
|
+
arguments: args
|
|
1538
|
+
}, {
|
|
1539
|
+
timeout: options.timeout,
|
|
1540
|
+
...tool ? { toolDefinition: withoutOutputSchema(tool) } : {}
|
|
1541
|
+
});
|
|
1542
|
+
if (!("content" in result) || !Array.isArray(result.content)) throw new Error("Task-augmented MCP tool results are not supported by this command");
|
|
1543
|
+
const callResult = result;
|
|
1544
|
+
printCallResult(callResult, options.json);
|
|
1545
|
+
if (callResult.isError) dependencies.setExitCode(1);
|
|
1546
|
+
}, usesMcpStdin(options) ? {
|
|
1547
|
+
interactive: false,
|
|
1548
|
+
exitOnFailure: false
|
|
1549
|
+
} : void 0);
|
|
1550
|
+
} catch (error) {
|
|
1551
|
+
console.error(chalk.red(`MCP tool call failed: ${errorMessage(error)}`));
|
|
1552
|
+
dependencies.setExitCode(1);
|
|
1553
|
+
}
|
|
1554
|
+
});
|
|
1555
|
+
return command;
|
|
1556
|
+
}
|
|
1557
|
+
const mcpCommand = createMcpCommand();
|
|
1558
|
+
export { mcpCommand };
|
|
1559
|
+
|