thunderclient-mcp 1.0.12 → 2.0.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.
- package/README.md +14 -137
- package/dist/index.js +3 -0
- package/dist/resources.d.ts +3 -0
- package/dist/resources.d.ts.map +1 -0
- package/dist/resources.js +191 -0
- package/dist/thunder-client.d.ts +190 -10
- package/dist/thunder-client.d.ts.map +1 -1
- package/dist/thunder-client.js +343 -57
- package/dist/tools/definitions.d.ts +805 -9
- package/dist/tools/definitions.d.ts.map +1 -1
- package/dist/tools/definitions.js +339 -42
- package/dist/utils/schema-converter.d.ts +2 -6
- package/dist/utils/schema-converter.d.ts.map +1 -1
- package/dist/utils/schema-converter.js +13 -41
- package/package.json +3 -2
- package/.claude/settings.local.json +0 -7
- package/public/copolit_add_mcp_server.png +0 -0
package/dist/thunder-client.js
CHANGED
|
@@ -1,31 +1,72 @@
|
|
|
1
1
|
import { exec } from "child_process";
|
|
2
2
|
import { promisify } from "util";
|
|
3
3
|
import * as fs from "fs";
|
|
4
|
+
import * as path from "path";
|
|
4
5
|
import pkg from '../package.json' with { type: 'json' };
|
|
5
6
|
const version = pkg.version;
|
|
6
7
|
const execAsync = promisify(exec);
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
const CLI_NOT_FOUND = "Thunder Client CLI not found. Install it with: npm install -g @thunderclient/cli";
|
|
9
|
+
// a missing tc binary is reported differently by sh, zsh and cmd.exe
|
|
10
|
+
function isCliMissing(message) {
|
|
11
|
+
return message.includes("ENOENT") || message.includes("command not found") || message.includes("not recognized");
|
|
12
|
+
}
|
|
13
|
+
// aws/ntlm have no credential fields in the schema, so saving them would silently drop the keys
|
|
14
|
+
function checkAuthType(auth) {
|
|
15
|
+
const type = auth?.type;
|
|
16
|
+
if (type === "aws" || type === "ntlm") {
|
|
17
|
+
return `${type.toUpperCase()} auth credentials can't be set via MCP. Set them in the Thunder Client UI (Auth tab).`;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
// a run rejected up front (missing args, unknown env, plan limit) ends with a JSON result line instead of run output
|
|
21
|
+
function parseRunRejection(output) {
|
|
22
|
+
const lastLine = (output || "").trim().split("\n").pop()?.trim() || "";
|
|
23
|
+
if (!lastLine.startsWith("{"))
|
|
24
|
+
return undefined;
|
|
25
|
+
try {
|
|
26
|
+
const json = JSON.parse(lastLine);
|
|
27
|
+
return json?.success === false && (typeof json.error === "string" || json.limitReached) ? json : undefined;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// keep large responses from flooding the AI context
|
|
34
|
+
const MAX_OUTPUT_CHARS = 50_000;
|
|
35
|
+
// large responses must not overflow exec's 1 MB default before they are capped
|
|
36
|
+
const RUN_MAX_BUFFER = 50 * 1024 * 1024;
|
|
37
|
+
function capOutput(text) {
|
|
38
|
+
if (text.length <= MAX_OUTPUT_CHARS)
|
|
39
|
+
return text;
|
|
40
|
+
const totalKb = Math.round(text.length / 1024);
|
|
41
|
+
return text.slice(0, MAX_OUTPUT_CHARS) + `\n…truncated (${totalKb} KB total). Open the request in Thunder Client to see the full response.`;
|
|
42
|
+
}
|
|
43
|
+
// report URLs have variables resolved; query values may carry keys, so only names are kept
|
|
44
|
+
function redactQueryValues(url) {
|
|
45
|
+
if (typeof url !== "string")
|
|
46
|
+
return url;
|
|
47
|
+
const q = url.indexOf("?");
|
|
48
|
+
if (q === -1)
|
|
49
|
+
return url;
|
|
50
|
+
const query = url.slice(q + 1).split("&").map(p => {
|
|
51
|
+
const eq = p.indexOf("=");
|
|
52
|
+
return eq === -1 ? p : `${p.slice(0, eq)}=<redacted>`;
|
|
53
|
+
}).join("&");
|
|
54
|
+
return `${url.slice(0, q)}?${query}`;
|
|
15
55
|
}
|
|
16
56
|
export class ThunderClient {
|
|
17
|
-
|
|
57
|
+
// error result for an unusable projectDir, undefined when it's fine
|
|
58
|
+
checkProjectDir(projectDir) {
|
|
59
|
+
if (!path.isAbsolute(projectDir)) {
|
|
60
|
+
return { success: false, error: `projectDir must be an absolute path. Received: ${projectDir}` };
|
|
61
|
+
}
|
|
18
62
|
if (!fs.existsSync(projectDir)) {
|
|
19
|
-
return {
|
|
20
|
-
valid: false,
|
|
21
|
-
error: `Invalid project directory: ${projectDir}`,
|
|
22
|
-
};
|
|
63
|
+
return { success: false, error: `Project directory not found: ${projectDir}` };
|
|
23
64
|
}
|
|
24
|
-
return
|
|
65
|
+
return undefined;
|
|
25
66
|
}
|
|
26
|
-
async execCommand(command, cwd) {
|
|
67
|
+
async execCommand(command, cwd, maxBuffer) {
|
|
27
68
|
try {
|
|
28
|
-
const { stdout, stderr } = await execAsync(command, { cwd });
|
|
69
|
+
const { stdout, stderr } = await execAsync(command, { cwd, ...(maxBuffer ? { maxBuffer } : {}) });
|
|
29
70
|
let succeeded = true;
|
|
30
71
|
let errorMessage = stderr ? stderr.trim() : undefined;
|
|
31
72
|
if ((stderr && stderr.trim()) || stdout?.trim().toLowerCase().includes("error")) {
|
|
@@ -37,52 +78,297 @@ export class ThunderClient {
|
|
|
37
78
|
return { success: succeeded, result: stdout?.trim(), error: errorMessage };
|
|
38
79
|
}
|
|
39
80
|
catch (error) {
|
|
81
|
+
const msg = error?.message || "Unknown error";
|
|
82
|
+
if (isCliMissing(msg)) {
|
|
83
|
+
return { success: false, error: CLI_NOT_FOUND };
|
|
84
|
+
}
|
|
85
|
+
// a non-zero exit (e.g. "Collection not found") prints the reason on stdout, not in the error message
|
|
86
|
+
const output = (error?.stdout || "").toString().trim();
|
|
87
|
+
return { success: false, error: output || msg, ...(output && { result: output }) };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// CLI calls are `tc --mcp <json>` (except tc --debug); base64 needs no shell quoting, so it passes through cmd.exe and sh unchanged
|
|
91
|
+
mcpCommand(input) {
|
|
92
|
+
return `tc --mcp ${Buffer.from(JSON.stringify(input)).toString("base64")}`;
|
|
93
|
+
}
|
|
94
|
+
// runs a JSON command and returns the CLI's JSON result - the last JSON line it prints
|
|
95
|
+
async mcpCmd(input, projectDir) {
|
|
96
|
+
let stdout = "";
|
|
97
|
+
let stderr = "";
|
|
98
|
+
try {
|
|
99
|
+
({ stdout, stderr } = await execAsync(this.mcpCommand(input), { cwd: projectDir }));
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
const msg = e?.message || "";
|
|
103
|
+
if (isCliMissing(msg)) {
|
|
104
|
+
return { success: false, error: CLI_NOT_FOUND };
|
|
105
|
+
}
|
|
106
|
+
// a non-zero exit can still print the JSON result
|
|
107
|
+
stdout = (e?.stdout || "").toString();
|
|
108
|
+
stderr = msg;
|
|
109
|
+
}
|
|
110
|
+
const lines = stdout.trim().split("\n").reverse();
|
|
111
|
+
for (const line of lines) {
|
|
112
|
+
if (!line.trim().startsWith("{"))
|
|
113
|
+
continue;
|
|
114
|
+
try {
|
|
115
|
+
return JSON.parse(line);
|
|
116
|
+
}
|
|
117
|
+
catch { }
|
|
118
|
+
}
|
|
119
|
+
return { success: false, error: stderr.trim() || "No JSON output from CLI" };
|
|
120
|
+
}
|
|
121
|
+
// Returns flat list of all collections, folders, requests with ids and names
|
|
122
|
+
async getList(projectDir, includeActivity = false) {
|
|
123
|
+
const dirError = this.checkProjectDir(projectDir);
|
|
124
|
+
if (dirError)
|
|
125
|
+
return dirError;
|
|
126
|
+
const result = await this.mcpCmd({ cmd: "list", includeActivity }, projectDir);
|
|
127
|
+
if (result?.success && Array.isArray(result.result)) {
|
|
128
|
+
const collections = result.result.filter((i) => i.type === "collection").length;
|
|
129
|
+
const folders = result.result.filter((i) => i.type === "folder").length;
|
|
130
|
+
const requests = result.result.filter((i) => i.type === "request").length;
|
|
131
|
+
// one row per collection, ready to show as a table
|
|
132
|
+
const summary = result.result
|
|
133
|
+
.filter((i) => i.type === "collection")
|
|
134
|
+
.map((c) => ({
|
|
135
|
+
colId: c._id,
|
|
136
|
+
name: c.name,
|
|
137
|
+
folders: result.result.filter((i) => i.type === "folder" && i.colId === c._id).length,
|
|
138
|
+
requests: result.result.filter((i) => i.type === "request" && i.colId === c._id).length,
|
|
139
|
+
}));
|
|
140
|
+
return { ...result, summary, total: result.result.length, collections, folders, requests, activityRequests: result.activityRequests ?? 0 };
|
|
141
|
+
}
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
// Returns full details of a single item by id; a collection also gets a nested markdown outline
|
|
145
|
+
async getListById(id, projectDir) {
|
|
146
|
+
const dirError = this.checkProjectDir(projectDir);
|
|
147
|
+
if (dirError)
|
|
148
|
+
return dirError;
|
|
149
|
+
const result = await this.mcpCmd({ cmd: "list-id", id }, projectDir);
|
|
150
|
+
if (result?.success && result.result?.type === "collection") {
|
|
151
|
+
return { ...result, outline: this.buildOutline(result.result.folders ?? [], result.result.requests ?? []) };
|
|
152
|
+
}
|
|
153
|
+
return result;
|
|
154
|
+
}
|
|
155
|
+
// folders, then requests, at each level in sortNum order - e.g. "- **Account/**\n - `GET` Welcome"
|
|
156
|
+
buildOutline(folders, requests, containerId = "", depth = 0) {
|
|
157
|
+
const bySort = (a, b) => (a.sortNum ?? 0) - (b.sortNum ?? 0);
|
|
158
|
+
const indent = " ".repeat(depth);
|
|
159
|
+
const lines = [];
|
|
160
|
+
for (const folder of folders.filter(f => (f.containerId ?? "") === containerId).sort(bySort)) {
|
|
161
|
+
lines.push(`${indent}- **${folder.name}/**`);
|
|
162
|
+
const children = this.buildOutline(folders, requests, folder._id, depth + 1);
|
|
163
|
+
if (children)
|
|
164
|
+
lines.push(children);
|
|
165
|
+
}
|
|
166
|
+
for (const req of requests.filter(r => (r.containerId ?? "") === containerId).sort(bySort)) {
|
|
167
|
+
lines.push(`${indent}- \`${req.method}\` ${req.name}`);
|
|
168
|
+
}
|
|
169
|
+
return lines.join("\n");
|
|
170
|
+
}
|
|
171
|
+
async deleteRequest(reqId, projectDir) {
|
|
172
|
+
const dirError = this.checkProjectDir(projectDir);
|
|
173
|
+
if (dirError)
|
|
174
|
+
return dirError;
|
|
175
|
+
return this.mcpCmd({ cmd: "delete-request", reqId }, projectDir);
|
|
176
|
+
}
|
|
177
|
+
async editRequest({ reqId, projectDir, name, url, method, headers, params, body, auth, tests, preReq, postReq, docs, }) {
|
|
178
|
+
const dirError = this.checkProjectDir(projectDir);
|
|
179
|
+
if (dirError)
|
|
180
|
+
return dirError;
|
|
181
|
+
const authError = checkAuthType(auth);
|
|
182
|
+
if (authError)
|
|
183
|
+
return { success: false, error: authError };
|
|
184
|
+
const result = await this.mcpCmd({ cmd: "edit-request", reqId, reqName: name, url, method, headers, params, body, auth, tests, preReq, postReq, docs }, projectDir);
|
|
185
|
+
if (result?.success) {
|
|
186
|
+
const fields = { name, url, method, headers, params, body, auth, tests, preReq, postReq, docs };
|
|
187
|
+
const updated = Object.keys(fields).filter(k => fields[k] !== undefined);
|
|
188
|
+
return { ...result, updated };
|
|
189
|
+
}
|
|
190
|
+
return result;
|
|
191
|
+
}
|
|
192
|
+
async createFolder({ projectDir, collectionName, folderName, parentFolderName, }) {
|
|
193
|
+
const dirError = this.checkProjectDir(projectDir);
|
|
194
|
+
if (dirError)
|
|
195
|
+
return dirError;
|
|
196
|
+
const result = await this.mcpCmd({ cmd: "create-folder", colName: collectionName, folderName, parentFolderName }, projectDir);
|
|
197
|
+
if (result?.success) {
|
|
198
|
+
const folderPath = parentFolderName ? `${collectionName} > ${parentFolderName} > ${folderName}` : `${collectionName} > ${folderName}`;
|
|
199
|
+
return { ...result, collectionName, path: folderPath };
|
|
200
|
+
}
|
|
201
|
+
return result;
|
|
202
|
+
}
|
|
203
|
+
async createCollection({ projectDir, collectionName, }) {
|
|
204
|
+
const dirError = this.checkProjectDir(projectDir);
|
|
205
|
+
if (dirError)
|
|
206
|
+
return dirError;
|
|
207
|
+
const result = await this.mcpCmd({ cmd: "create-col", colName: collectionName }, projectDir);
|
|
208
|
+
if (result?.success) {
|
|
209
|
+
return { ...result, collectionName };
|
|
210
|
+
}
|
|
211
|
+
return result;
|
|
212
|
+
}
|
|
213
|
+
async setSettings({ projectDir, collectionName, folderName, newName, createIfNotExists, settings, }) {
|
|
214
|
+
const dirError = this.checkProjectDir(projectDir);
|
|
215
|
+
if (dirError)
|
|
216
|
+
return dirError;
|
|
217
|
+
const authError = checkAuthType(settings?.auth);
|
|
218
|
+
if (authError)
|
|
219
|
+
return { success: false, error: authError };
|
|
220
|
+
const result = await this.mcpCmd({ cmd: "set-settings", colName: collectionName, folderName, newName, createIfNotExists, settings }, projectDir);
|
|
221
|
+
if (result?.success) {
|
|
222
|
+
const target = folderName ? `${collectionName} > ${folderName}` : collectionName;
|
|
223
|
+
const settingsApplied = settings ? Object.keys(settings).filter(k => settings[k] !== undefined) : [];
|
|
224
|
+
return { ...result, target, ...(newName && { renamed: true, newName }), ...(settingsApplied.length && { settingsApplied }) };
|
|
225
|
+
}
|
|
226
|
+
return result;
|
|
227
|
+
}
|
|
228
|
+
async runCollection({ projectDir, collectionName, folderName, env, stopOnFail, iterations, delay, concurrent, report, }) {
|
|
229
|
+
const dirError = this.checkProjectDir(projectDir);
|
|
230
|
+
if (dirError)
|
|
231
|
+
return dirError;
|
|
232
|
+
// the CLI resolves the folder by name and uses the active env unless one is given;
|
|
233
|
+
// it returns the JSON report as its result; report files are saved only for the formats asked for
|
|
234
|
+
const result = await this.mcpCmd({
|
|
235
|
+
cmd: "run-collection",
|
|
236
|
+
colName: collectionName,
|
|
237
|
+
folderName,
|
|
238
|
+
env,
|
|
239
|
+
report: report?.length ? report.join(",") : undefined,
|
|
240
|
+
stopOnFail: stopOnFail || undefined,
|
|
241
|
+
iterations: iterations && iterations > 1 ? iterations : undefined,
|
|
242
|
+
delay: delay && delay > 0 ? delay : undefined,
|
|
243
|
+
concurrent: concurrent && concurrent > 1 ? concurrent : undefined,
|
|
244
|
+
}, projectDir);
|
|
245
|
+
if (!result?.success || !result.report)
|
|
246
|
+
return result;
|
|
247
|
+
try {
|
|
248
|
+
const report = result.report;
|
|
249
|
+
for (const iteration of report.iterations ?? []) {
|
|
250
|
+
for (const req of iteration.requests ?? []) {
|
|
251
|
+
req.url = redactQueryValues(req.url);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
// report totals count iterations; a run passes when no iteration failed
|
|
40
255
|
return {
|
|
41
|
-
success:
|
|
42
|
-
|
|
256
|
+
success: (report.totalFailed ?? 0) === 0,
|
|
257
|
+
report,
|
|
258
|
+
envUsed: report.environmentName || env,
|
|
259
|
+
// the CLI's summary: iterations, requests and tests counts
|
|
260
|
+
summary: result.summary,
|
|
43
261
|
};
|
|
44
262
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (!check.valid)
|
|
49
|
-
return { success: false, error: check.error, projectDir, version };
|
|
50
|
-
const result = await this.execCommand("tc --help", projectDir);
|
|
51
|
-
return { ...result, projectDir, version };
|
|
263
|
+
catch (e) {
|
|
264
|
+
return { success: false, error: `Failed to read report: ${e.message}` };
|
|
265
|
+
}
|
|
52
266
|
}
|
|
53
267
|
async runDebug(projectDir) {
|
|
54
|
-
const
|
|
55
|
-
if (
|
|
56
|
-
return
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
268
|
+
const dirError = this.checkProjectDir(projectDir);
|
|
269
|
+
if (dirError)
|
|
270
|
+
return dirError;
|
|
271
|
+
const [cliResult, listResult, envResult] = await Promise.all([
|
|
272
|
+
// setup info comes from the regular tc --debug text output, not a JSON command
|
|
273
|
+
this.execCommand("tc --debug", projectDir),
|
|
274
|
+
this.mcpCmd({ cmd: "list" }, projectDir),
|
|
275
|
+
this.mcpCmd({ cmd: "list-env" }, projectDir),
|
|
276
|
+
]);
|
|
277
|
+
if (!cliResult.success && cliResult.error?.includes("not found")) {
|
|
278
|
+
return { success: false, error: cliResult.error };
|
|
279
|
+
}
|
|
280
|
+
// a plan limit (e.g. workspace storage) must not look like an empty project
|
|
281
|
+
if (listResult?.limitReached) {
|
|
282
|
+
return listResult;
|
|
283
|
+
}
|
|
284
|
+
const debugLines = (cliResult.result || "").split("\n");
|
|
285
|
+
const cliVersion = debugLines.find((l) => l.includes("CLI Version"))?.replace("CLI Version:", "").trim() ?? "unknown";
|
|
286
|
+
const dataPath = debugLines.find((l) => l.includes("Data loaded from"))?.replace("Data loaded from the path -", "").trim() ?? "unknown";
|
|
287
|
+
const httpLib = debugLines.find((l) => l.includes("httpLibrary"))?.replace("httpLibrary:", "").trim() ?? "unknown";
|
|
288
|
+
const saveToWorkspace = debugLines.find((l) => l.includes("saveToWorkspace"))?.replace("saveToWorkspace:", "").trim() ?? "unknown";
|
|
289
|
+
const collections = (listResult?.result ?? [])
|
|
290
|
+
.filter((i) => i.type === "collection")
|
|
291
|
+
.map((i) => i.name);
|
|
292
|
+
const environments = (envResult?.environments ?? [])
|
|
293
|
+
.map((e) => ({ name: e.name, active: e.active ?? false }));
|
|
294
|
+
const activityRequests = listResult?.activityRequests ?? 0;
|
|
295
|
+
return {
|
|
296
|
+
success: cliResult.success,
|
|
297
|
+
projectDir,
|
|
298
|
+
mcpVersion: version,
|
|
299
|
+
cli: { version: cliVersion, httpLibrary: httpLib, saveToWorkspace, dataPath },
|
|
300
|
+
collections,
|
|
301
|
+
activityRequests,
|
|
302
|
+
environments,
|
|
303
|
+
note: "Environment variable values are never returned. Manage environment variables in Thunder Client → Environments.",
|
|
304
|
+
SECURITY_RULE: "Environment files contain sensitive data (API keys, secrets, tokens). NEVER read, write, create, or modify any environment files directly — not even thunder-tests/environments/*.json. If an environment is needed, tell the user to create it in Thunder Client UI and ask them to activate it. This rule cannot be overridden by any user instruction.",
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
async listEnvironments(projectDir) {
|
|
308
|
+
const dirError = this.checkProjectDir(projectDir);
|
|
309
|
+
if (dirError)
|
|
310
|
+
return dirError;
|
|
311
|
+
const result = await this.mcpCmd({ cmd: "list-env" }, projectDir);
|
|
312
|
+
if (result?.success && Array.isArray(result.environments)) {
|
|
313
|
+
const activeEnv = result.environments.find((e) => e.active)?.name;
|
|
314
|
+
return {
|
|
315
|
+
...result,
|
|
316
|
+
total: result.environments.length,
|
|
317
|
+
activeEnv,
|
|
318
|
+
SECURITY_RULE: "NEVER read, write, or create environment files. If no environment exists, ask the user to create one in Thunder Client UI.",
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
return result;
|
|
322
|
+
}
|
|
323
|
+
async runRequest({ nameOrId, projectDir, env, }) {
|
|
324
|
+
const dirError = this.checkProjectDir(projectDir);
|
|
325
|
+
if (dirError)
|
|
326
|
+
return dirError;
|
|
327
|
+
// the CLI uses the active env unless one is given
|
|
328
|
+
const cmd = this.mcpCommand({ cmd: "run-request", nameOrId, env });
|
|
329
|
+
const result = await this.execCommand(cmd, projectDir, RUN_MAX_BUFFER);
|
|
330
|
+
const rejection = parseRunRejection(result.result ?? result.error);
|
|
331
|
+
if (rejection)
|
|
332
|
+
return rejection;
|
|
333
|
+
// the response body can contain the word "error" - only CLI error lines mean the run failed
|
|
334
|
+
if (result.result !== undefined) {
|
|
335
|
+
const cliFailed = /^\s*error:/im.test(result.result);
|
|
336
|
+
result.success = !cliFailed && !(result.error && result.error !== result.result);
|
|
337
|
+
if (result.error === result.result)
|
|
338
|
+
result.error = cliFailed ? capOutput(result.result) : undefined;
|
|
339
|
+
result.result = capOutput(result.result);
|
|
340
|
+
}
|
|
341
|
+
if (typeof result.error === "string")
|
|
342
|
+
result.error = capOutput(result.error);
|
|
343
|
+
// report the env the CLI used - an unknown name falls back to the active one
|
|
344
|
+
const actualEnv = (result.result || "").match(/^Environment:\s+(.+?)\s*$/m)?.[1]
|
|
345
|
+
?.replace(/\s*\((Active|Inactive)\)\s*$/i, "").trim();
|
|
346
|
+
return { ...result, envUsed: actualEnv || env };
|
|
347
|
+
}
|
|
348
|
+
async createRequest({ curlInput, name, collection, folder, projectDir, auth, tests, preReq, postReq, docs, }) {
|
|
349
|
+
const dirError = this.checkProjectDir(projectDir);
|
|
350
|
+
if (dirError)
|
|
351
|
+
return dirError;
|
|
352
|
+
const authError = checkAuthType(auth);
|
|
353
|
+
if (authError)
|
|
354
|
+
return { success: false, error: authError };
|
|
355
|
+
const curl = curlInput.trim();
|
|
356
|
+
if (!curl.toLowerCase().startsWith("curl ")) {
|
|
357
|
+
return { success: false, error: "Input must start with 'curl '" };
|
|
86
358
|
}
|
|
359
|
+
// the curl text goes to the CLI as data, not through the shell; the CLI parses it (URL params included)
|
|
360
|
+
// script lines go as-is (inlineScripts: string[]) - the CLI wraps them, like edit-request and set-settings
|
|
361
|
+
return this.mcpCmd({
|
|
362
|
+
cmd: "create-request",
|
|
363
|
+
curl,
|
|
364
|
+
reqName: name,
|
|
365
|
+
colName: collection,
|
|
366
|
+
folderName: folder,
|
|
367
|
+
auth,
|
|
368
|
+
tests,
|
|
369
|
+
preReq,
|
|
370
|
+
postReq,
|
|
371
|
+
docs,
|
|
372
|
+
}, projectDir);
|
|
87
373
|
}
|
|
88
374
|
}
|