@qcentriq/mcp 0.3.0 → 0.4.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/LICENSE +202 -0
- package/README.md +24 -11
- package/dist/index.js +706 -728
- package/dist/index.js.map +1 -1
- package/package.json +12 -4
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { serveStdio } from "@modelcontextprotocol/server/stdio";
|
|
5
|
+
import { McpServer as McpServer2 } from "@modelcontextprotocol/server";
|
|
6
6
|
|
|
7
7
|
// src/config.ts
|
|
8
8
|
import { Command } from "commander";
|
|
@@ -39,13 +39,19 @@ var logger = {
|
|
|
39
39
|
var DEFAULT_BASE_URL = "https://api.qcentriq.com";
|
|
40
40
|
function loadConfig(argv = process.argv) {
|
|
41
41
|
const program = new Command();
|
|
42
|
-
program.name("qcentriq-mcp").description("QCentriq Model Context Protocol (MCP) Server for automated test discovery and execution").option("-k, --api-key <key>", "QCentriq API key (or QCENTRIQ_API_KEY env var)").option("-u, --base-url <url>", "QCentriq API base URL (or QCENTRIQ_BASE_URL env var)").option("-p, --project-id <id>", "Default QCentriq project UUID (or QCENTRIQ_PROJECT_ID env var)").option("-d, --debug", "Enable debug logging to stderr (or DEBUG/QCENTRIQ_DEBUG env var)").
|
|
42
|
+
program.name("qcentriq-mcp").description("QCentriq Model Context Protocol (MCP) Server for automated test discovery and execution").option("-k, --api-key <key>", "QCentriq API key (or QCENTRIQ_API_KEY env var)").option("-u, --base-url <url>", "QCentriq API base URL (or QCENTRIQ_BASE_URL env var)").option("-p, --project-id <id>", "Default QCentriq project UUID (or QCENTRIQ_PROJECT_ID env var)").option("-d, --debug", "Enable debug logging to stderr (or DEBUG/QCENTRIQ_DEBUG env var)").option(
|
|
43
|
+
"--require-upload-confirmation",
|
|
44
|
+
"Refuse uploads when the MCP client cannot show a confirmation prompt (or QCENTRIQ_REQUIRE_UPLOAD_CONFIRMATION=true)"
|
|
45
|
+
).allowUnknownOption(true).parse(argv);
|
|
43
46
|
const opts = program.opts();
|
|
44
47
|
const apiKey = opts.apiKey || process.env.QCENTRIQ_API_KEY || "";
|
|
45
48
|
const rawBaseUrl = opts.baseUrl || process.env.QCENTRIQ_BASE_URL || DEFAULT_BASE_URL;
|
|
46
49
|
const baseUrl = rawBaseUrl.replace(/\/+$/, "");
|
|
47
50
|
const defaultProjectId = opts.projectId || process.env.QCENTRIQ_PROJECT_ID;
|
|
48
51
|
const debug = Boolean(opts.debug || process.env.DEBUG || process.env.QCENTRIQ_DEBUG);
|
|
52
|
+
const requireUploadConfirmation = Boolean(
|
|
53
|
+
opts.requireUploadConfirmation || isTruthy(process.env.QCENTRIQ_REQUIRE_UPLOAD_CONFIRMATION)
|
|
54
|
+
);
|
|
49
55
|
if (debug) {
|
|
50
56
|
setDebugLogging(true);
|
|
51
57
|
}
|
|
@@ -59,9 +65,13 @@ function loadConfig(argv = process.argv) {
|
|
|
59
65
|
apiKey,
|
|
60
66
|
baseUrl,
|
|
61
67
|
defaultProjectId,
|
|
62
|
-
debug
|
|
68
|
+
debug,
|
|
69
|
+
requireUploadConfirmation
|
|
63
70
|
};
|
|
64
71
|
}
|
|
72
|
+
function isTruthy(value) {
|
|
73
|
+
return ["1", "true", "yes"].includes((value ?? "").trim().toLowerCase());
|
|
74
|
+
}
|
|
65
75
|
|
|
66
76
|
// src/utils/sanitizer.ts
|
|
67
77
|
var QCENTRIQ_KEY_REGEX = /qc_[0-9a-fA-F]{30,45}/g;
|
|
@@ -96,181 +106,104 @@ function sanitizePayload(value) {
|
|
|
96
106
|
}
|
|
97
107
|
|
|
98
108
|
// src/client/api.ts
|
|
109
|
+
var DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
|
|
110
|
+
async function readErrorDetail(res) {
|
|
111
|
+
let text;
|
|
112
|
+
try {
|
|
113
|
+
text = await res.text();
|
|
114
|
+
} catch {
|
|
115
|
+
return res.statusText;
|
|
116
|
+
}
|
|
117
|
+
if (!text) return res.statusText;
|
|
118
|
+
try {
|
|
119
|
+
const json = JSON.parse(text);
|
|
120
|
+
return json?.detail || JSON.stringify(json);
|
|
121
|
+
} catch {
|
|
122
|
+
return text;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
99
125
|
var QCentriqApiClient = class {
|
|
100
|
-
config;
|
|
101
126
|
constructor(config) {
|
|
102
127
|
this.config = config;
|
|
103
128
|
}
|
|
104
129
|
/**
|
|
105
|
-
*
|
|
130
|
+
* Authenticated GET against the QCentriq backend (/api/v1/mcp-client/...).
|
|
131
|
+
* Undefined and null params are left out of the query string.
|
|
106
132
|
*/
|
|
107
|
-
async request(
|
|
108
|
-
const
|
|
109
|
-
const url = new URL(`${this.config.baseUrl}/api/v1/mcp-client${cleanPath}`);
|
|
133
|
+
async request(path6, params = {}) {
|
|
134
|
+
const query = new URLSearchParams();
|
|
110
135
|
for (const [key, value] of Object.entries(params)) {
|
|
111
136
|
if (value !== void 0 && value !== null) {
|
|
112
|
-
|
|
137
|
+
query.set(key, String(value));
|
|
113
138
|
}
|
|
114
139
|
}
|
|
115
|
-
|
|
116
|
-
const res = await fetch(url.toString(), {
|
|
117
|
-
method: "GET",
|
|
118
|
-
headers: {
|
|
119
|
-
Authorization: `Bearer ${this.config.apiKey}`,
|
|
120
|
-
Accept: "application/json"
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
if (!res.ok) {
|
|
124
|
-
let errorDetail = res.statusText;
|
|
125
|
-
try {
|
|
126
|
-
const errorJson = await res.json();
|
|
127
|
-
errorDetail = errorJson?.detail || JSON.stringify(errorJson);
|
|
128
|
-
} catch {
|
|
129
|
-
const text = await res.text();
|
|
130
|
-
if (text) errorDetail = text;
|
|
131
|
-
}
|
|
132
|
-
throw new Error(`API error (${res.status}): ${errorDetail}`);
|
|
133
|
-
}
|
|
134
|
-
const data = await res.json();
|
|
135
|
-
return sanitizePayload(data);
|
|
140
|
+
return this.call("GET", path6, query);
|
|
136
141
|
}
|
|
137
|
-
/**
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const
|
|
145
|
-
const url = `${this.config.baseUrl}/api/v1/mcp-client${cleanPath}`;
|
|
142
|
+
/** Authenticated JSON write against the QCentriq backend. */
|
|
143
|
+
async send(method, path6, body) {
|
|
144
|
+
return this.call(method, path6, void 0, body);
|
|
145
|
+
}
|
|
146
|
+
async call(method, path6, query, body) {
|
|
147
|
+
const cleanPath = path6.startsWith("/") ? path6 : `/${path6}`;
|
|
148
|
+
const qs = query?.toString();
|
|
149
|
+
const url = `${this.config.baseUrl}/api/v1/mcp-client${cleanPath}${qs ? `?${qs}` : ""}`;
|
|
146
150
|
logger.debug(`[mcp-client] HTTP ${method} ${url}`);
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
body: JSON.stringify(body)
|
|
151
|
+
const headers = {
|
|
152
|
+
Authorization: `Bearer ${this.config.apiKey}`,
|
|
153
|
+
Accept: "application/json"
|
|
154
|
+
};
|
|
155
|
+
if (body) headers["Content-Type"] = "application/json";
|
|
156
|
+
const res = await this.fetchWithTimeout(method, cleanPath, url, {
|
|
157
|
+
headers,
|
|
158
|
+
body: body ? JSON.stringify(body) : void 0
|
|
155
159
|
});
|
|
156
160
|
if (!res.ok) {
|
|
157
|
-
|
|
158
|
-
try {
|
|
159
|
-
const errorJson = await res.json();
|
|
160
|
-
errorDetail = errorJson?.detail || JSON.stringify(errorJson);
|
|
161
|
-
} catch {
|
|
162
|
-
const text = await res.text();
|
|
163
|
-
if (text) errorDetail = text;
|
|
164
|
-
}
|
|
165
|
-
throw new Error(`API error (${res.status}): ${errorDetail}`);
|
|
161
|
+
throw new Error(`API error (${res.status}): ${await readErrorDetail(res)}`);
|
|
166
162
|
}
|
|
167
|
-
|
|
168
|
-
return sanitizePayload(data);
|
|
163
|
+
return sanitizePayload(await res.json());
|
|
169
164
|
}
|
|
170
165
|
/**
|
|
171
|
-
*
|
|
172
|
-
*
|
|
166
|
+
* Issue a request that is aborted after the configured timeout, reporting
|
|
167
|
+
* the timeout as such rather than as a bare AbortError.
|
|
173
168
|
*/
|
|
174
|
-
async
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
project_id,
|
|
182
|
-
group_id,
|
|
183
|
-
priority,
|
|
184
|
-
test_type,
|
|
185
|
-
status,
|
|
186
|
-
limit,
|
|
187
|
-
offset
|
|
188
|
-
});
|
|
189
|
-
break;
|
|
190
|
-
}
|
|
191
|
-
case "qcentriq_get_test": {
|
|
192
|
-
const { test_case_id, project_id } = args;
|
|
193
|
-
data = await this.request(`/tests/${test_case_id}`, { project_id });
|
|
194
|
-
break;
|
|
195
|
-
}
|
|
196
|
-
case "qcentriq_get_test_groups": {
|
|
197
|
-
const { project_id, group_id, limit, offset } = args;
|
|
198
|
-
data = await this.request("/groups", {
|
|
199
|
-
project_id,
|
|
200
|
-
group_id,
|
|
201
|
-
limit,
|
|
202
|
-
offset
|
|
203
|
-
});
|
|
204
|
-
break;
|
|
205
|
-
}
|
|
206
|
-
case "qcentriq_download_script": {
|
|
207
|
-
const { group_id, project_id, include_fixtures } = args;
|
|
208
|
-
data = await this.request(`/groups/${group_id}/script`, {
|
|
209
|
-
project_id,
|
|
210
|
-
include_fixtures
|
|
211
|
-
});
|
|
212
|
-
break;
|
|
213
|
-
}
|
|
214
|
-
case "qcentriq_get_environment": {
|
|
215
|
-
const { project_id, environment_id, environment_name } = args;
|
|
216
|
-
data = await this.request("/environment", {
|
|
217
|
-
project_id,
|
|
218
|
-
environment_id,
|
|
219
|
-
environment_name
|
|
220
|
-
});
|
|
221
|
-
break;
|
|
222
|
-
}
|
|
223
|
-
case "qcentriq_get_test_run_logs": {
|
|
224
|
-
const {
|
|
225
|
-
test_case_id,
|
|
226
|
-
project_id,
|
|
227
|
-
run_id,
|
|
228
|
-
status,
|
|
229
|
-
latest_only,
|
|
230
|
-
from_date,
|
|
231
|
-
to_date,
|
|
232
|
-
limit,
|
|
233
|
-
offset
|
|
234
|
-
} = args;
|
|
235
|
-
data = await this.request(`/tests/${test_case_id}/run-logs`, {
|
|
236
|
-
project_id,
|
|
237
|
-
run_id,
|
|
238
|
-
status,
|
|
239
|
-
latest_only,
|
|
240
|
-
from_date,
|
|
241
|
-
to_date,
|
|
242
|
-
limit,
|
|
243
|
-
offset
|
|
244
|
-
});
|
|
245
|
-
break;
|
|
169
|
+
async fetchWithTimeout(method, path6, url, init) {
|
|
170
|
+
const timeoutMs = this.config.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
171
|
+
try {
|
|
172
|
+
return await fetch(url, { ...init, method, signal: AbortSignal.timeout(timeoutMs) });
|
|
173
|
+
} catch (err) {
|
|
174
|
+
if (err?.name === "TimeoutError") {
|
|
175
|
+
throw new Error(`${method} ${path6} timed out after ${timeoutMs}ms`);
|
|
246
176
|
}
|
|
247
|
-
|
|
248
|
-
throw new Error(`Unknown tool: ${toolName}`);
|
|
177
|
+
throw err;
|
|
249
178
|
}
|
|
250
|
-
return {
|
|
251
|
-
content: [
|
|
252
|
-
{
|
|
253
|
-
type: "text",
|
|
254
|
-
text: JSON.stringify(data, null, 2)
|
|
255
|
-
}
|
|
256
|
-
]
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* Close client session on shutdown (no-op for stateless HTTP client).
|
|
261
|
-
*/
|
|
262
|
-
async close() {
|
|
263
179
|
}
|
|
264
180
|
};
|
|
265
181
|
|
|
266
182
|
// src/tools/list-tests.ts
|
|
267
183
|
import { z } from "zod";
|
|
184
|
+
|
|
185
|
+
// src/tools/results.ts
|
|
186
|
+
function jsonResult(data) {
|
|
187
|
+
return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
|
|
188
|
+
}
|
|
189
|
+
function errorResult(text) {
|
|
190
|
+
return { isError: true, content: [{ type: "text", text }] };
|
|
191
|
+
}
|
|
192
|
+
async function backendCall(tool, run) {
|
|
193
|
+
try {
|
|
194
|
+
return jsonResult(await run());
|
|
195
|
+
} catch (err) {
|
|
196
|
+
return errorResult(`Error in ${tool}: ${err.message}`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// src/tools/list-tests.ts
|
|
268
201
|
function registerListTestsTool(server, client, config) {
|
|
269
202
|
server.registerTool(
|
|
270
203
|
"qcentriq_list_tests",
|
|
271
204
|
{
|
|
272
205
|
description: "Discover and list automated test cases and test groups for a project with status, priority, and update dates. Test group script availability is indicated in test_groups. Blocked test cases have no script.",
|
|
273
|
-
inputSchema: {
|
|
206
|
+
inputSchema: z.object({
|
|
274
207
|
project_id: z.uuid().optional().describe("Optional project UUID (inferred from API key if omitted)."),
|
|
275
208
|
group_id: z.uuid().optional().describe("Optional test group UUID filter."),
|
|
276
209
|
priority: z.enum(["low", "medium", "high", "critical"]).optional().describe("Filter by priority."),
|
|
@@ -278,23 +211,12 @@ function registerListTestsTool(server, client, config) {
|
|
|
278
211
|
status: z.enum(["failed", "passed", "error", "never_run", "blocked", "active", "flaky"]).optional().describe("Filter by test status (e.g. 'failed' or 'blocked')."),
|
|
279
212
|
limit: z.number().int().min(1).max(100).default(50).describe("Max number of test cases to return (default 50)."),
|
|
280
213
|
offset: z.number().int().min(0).default(0).describe("Pagination offset.")
|
|
281
|
-
}
|
|
214
|
+
})
|
|
282
215
|
},
|
|
283
|
-
async (args) =>
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
...args,
|
|
288
|
-
project_id: projectId
|
|
289
|
-
});
|
|
290
|
-
return response;
|
|
291
|
-
} catch (err) {
|
|
292
|
-
return {
|
|
293
|
-
isError: true,
|
|
294
|
-
content: [{ type: "text", text: `Error in qcentriq_list_tests: ${err.message}` }]
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
}
|
|
216
|
+
async (args) => backendCall(
|
|
217
|
+
"qcentriq_list_tests",
|
|
218
|
+
() => client.request("/tests", { ...args, project_id: args.project_id || config.defaultProjectId })
|
|
219
|
+
)
|
|
298
220
|
);
|
|
299
221
|
}
|
|
300
222
|
|
|
@@ -305,26 +227,15 @@ function registerGetTestTool(server, client, config) {
|
|
|
305
227
|
"qcentriq_get_test",
|
|
306
228
|
{
|
|
307
229
|
description: "Retrieve detailed test case information including step definitions, preconditions, latest execution diagnostics, error stack traces, and parent test group script metadata.",
|
|
308
|
-
inputSchema: {
|
|
230
|
+
inputSchema: z2.object({
|
|
309
231
|
test_case_id: z2.uuid().describe("UUID of the target test case."),
|
|
310
232
|
project_id: z2.uuid().optional().describe("Optional project UUID (inferred from API key if omitted).")
|
|
311
|
-
}
|
|
233
|
+
})
|
|
312
234
|
},
|
|
313
|
-
async (
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
...args,
|
|
318
|
-
project_id: projectId
|
|
319
|
-
});
|
|
320
|
-
return response;
|
|
321
|
-
} catch (err) {
|
|
322
|
-
return {
|
|
323
|
-
isError: true,
|
|
324
|
-
content: [{ type: "text", text: `Error in qcentriq_get_test: ${err.message}` }]
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
|
-
}
|
|
235
|
+
async ({ test_case_id, ...query }) => backendCall(
|
|
236
|
+
"qcentriq_get_test",
|
|
237
|
+
() => client.request(`/tests/${test_case_id}`, { ...query, project_id: query.project_id || config.defaultProjectId })
|
|
238
|
+
)
|
|
328
239
|
);
|
|
329
240
|
}
|
|
330
241
|
|
|
@@ -335,97 +246,113 @@ function registerGetTestGroupsTool(server, client, config) {
|
|
|
335
246
|
"qcentriq_get_test_groups",
|
|
336
247
|
{
|
|
337
248
|
description: "Discover and inspect test groups for a project. Returns what each group is about (title, description), total/active/blocked test case counts, and whether a test script exists. Provide group_id to inspect member test cases.",
|
|
338
|
-
inputSchema: {
|
|
249
|
+
inputSchema: z3.object({
|
|
339
250
|
project_id: z3.uuid().optional().describe("Optional project UUID (inferred from API key if omitted)."),
|
|
340
251
|
group_id: z3.uuid().optional().describe("Optional test group UUID filter to inspect a specific group."),
|
|
341
252
|
limit: z3.number().int().min(1).max(100).default(50).describe("Max test groups to return (default 50)."),
|
|
342
253
|
offset: z3.number().int().min(0).default(0).describe("Pagination offset.")
|
|
343
|
-
}
|
|
254
|
+
})
|
|
255
|
+
},
|
|
256
|
+
async (args) => backendCall(
|
|
257
|
+
"qcentriq_get_test_groups",
|
|
258
|
+
() => client.request("/groups", { ...args, project_id: args.project_id || config.defaultProjectId })
|
|
259
|
+
)
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// src/tools/download-script.ts
|
|
264
|
+
import { z as z5 } from "zod";
|
|
265
|
+
|
|
266
|
+
// src/tools/save-script.ts
|
|
267
|
+
import { z as z4 } from "zod";
|
|
268
|
+
import * as fs from "fs/promises";
|
|
269
|
+
import * as path from "path";
|
|
270
|
+
var DEFAULT_SCRIPT_DIR = "./qcentriq_tests";
|
|
271
|
+
function registerSaveScriptTool(server) {
|
|
272
|
+
server.registerTool(
|
|
273
|
+
"qcentriq_save_script",
|
|
274
|
+
{
|
|
275
|
+
description: "Save downloaded Playwright Python test script and fixtures directly to the local workspace disk so they can be run or edited locally.",
|
|
276
|
+
inputSchema: z4.object({
|
|
277
|
+
file_name: z4.string().describe("Target filename (e.g. 'test_login.py')."),
|
|
278
|
+
content: z4.string().describe("Python test script source code."),
|
|
279
|
+
conftest_content: z4.string().optional().describe("Accompanying conftest.py source code if present."),
|
|
280
|
+
destination_dir: z4.string().default(DEFAULT_SCRIPT_DIR).describe(`Destination directory in the local workspace (default '${DEFAULT_SCRIPT_DIR}'). Kept separate from a project's own ./tests so an existing conftest.py is never overwritten.`)
|
|
281
|
+
})
|
|
344
282
|
},
|
|
345
283
|
async (args) => {
|
|
346
284
|
try {
|
|
347
|
-
const
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
285
|
+
const savedFiles = await saveScriptFiles(args.destination_dir ?? DEFAULT_SCRIPT_DIR, args.file_name, args.content, args.conftest_content);
|
|
286
|
+
return jsonResult({
|
|
287
|
+
status: "success",
|
|
288
|
+
message: `Successfully saved ${savedFiles.length} file(s) to ${path.dirname(savedFiles[0])}`,
|
|
289
|
+
saved_files: savedFiles
|
|
351
290
|
});
|
|
352
|
-
return response;
|
|
353
291
|
} catch (err) {
|
|
354
|
-
return {
|
|
355
|
-
isError: true,
|
|
356
|
-
content: [{ type: "text", text: `Error in qcentriq_get_test_groups: ${err.message}` }]
|
|
357
|
-
};
|
|
292
|
+
return errorResult(`Failed to save test script to disk: ${err.message}`);
|
|
358
293
|
}
|
|
359
294
|
}
|
|
360
295
|
);
|
|
361
296
|
}
|
|
297
|
+
async function saveScriptFiles(destinationDir, fileName, content, conftest) {
|
|
298
|
+
const safeFileName = path.basename(fileName);
|
|
299
|
+
if (!safeFileName || safeFileName === "." || safeFileName === "..") {
|
|
300
|
+
throw new Error(`Invalid file name: "${fileName}"`);
|
|
301
|
+
}
|
|
302
|
+
const targetDir = path.resolve(process.cwd(), destinationDir);
|
|
303
|
+
await fs.mkdir(targetDir, { recursive: true });
|
|
304
|
+
const scriptPath = path.join(targetDir, safeFileName);
|
|
305
|
+
await fs.writeFile(scriptPath, content, "utf-8");
|
|
306
|
+
logger.info(`Saved test script to: ${scriptPath}`);
|
|
307
|
+
const saved = [scriptPath];
|
|
308
|
+
if (conftest) {
|
|
309
|
+
const conftestPath = path.join(targetDir, "conftest.py");
|
|
310
|
+
await fs.writeFile(conftestPath, conftest, "utf-8");
|
|
311
|
+
logger.info(`Saved conftest.py to: ${conftestPath}`);
|
|
312
|
+
saved.push(conftestPath);
|
|
313
|
+
}
|
|
314
|
+
return saved;
|
|
315
|
+
}
|
|
362
316
|
|
|
363
317
|
// src/tools/download-script.ts
|
|
364
|
-
import { z as z4 } from "zod";
|
|
365
|
-
import * as fs from "fs/promises";
|
|
366
|
-
import * as path from "path";
|
|
367
318
|
function registerDownloadScriptTool(server, client, config) {
|
|
368
319
|
server.registerTool(
|
|
369
320
|
"qcentriq_download_script",
|
|
370
321
|
{
|
|
371
|
-
description:
|
|
372
|
-
inputSchema: {
|
|
373
|
-
group_id:
|
|
374
|
-
project_id:
|
|
375
|
-
include_fixtures:
|
|
376
|
-
save_to_disk:
|
|
377
|
-
destination_dir:
|
|
378
|
-
}
|
|
322
|
+
description: `Download test group script and accompanying fixture files (e.g. conftest.py) for local test execution and editing. By default the files are written to '${DEFAULT_SCRIPT_DIR}', the same directory qcentriq_save_script uses, and their paths are returned in saved_files.`,
|
|
323
|
+
inputSchema: z5.object({
|
|
324
|
+
group_id: z5.uuid().describe("UUID of the target test group."),
|
|
325
|
+
project_id: z5.uuid().optional().describe("Optional project UUID (inferred from API key if omitted)."),
|
|
326
|
+
include_fixtures: z5.boolean().default(true).describe("Whether to retrieve accompanying conftest.py / fixtures (default True)."),
|
|
327
|
+
save_to_disk: z5.boolean().default(true).describe("Saves the downloaded test script and fixtures to destination_dir (default True). Set false to only return the content."),
|
|
328
|
+
destination_dir: z5.string().default(DEFAULT_SCRIPT_DIR).describe(`Destination directory when save_to_disk is true (default '${DEFAULT_SCRIPT_DIR}'). Kept separate from a project's own ./tests so an existing conftest.py is never overwritten.`)
|
|
329
|
+
})
|
|
379
330
|
},
|
|
380
331
|
async (args) => {
|
|
332
|
+
let data;
|
|
381
333
|
try {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
group_id: args.group_id,
|
|
385
|
-
project_id: projectId,
|
|
334
|
+
data = await client.request(`/groups/${args.group_id}/script`, {
|
|
335
|
+
project_id: args.project_id || config.defaultProjectId,
|
|
386
336
|
include_fixtures: args.include_fixtures
|
|
387
337
|
});
|
|
388
|
-
if (args.save_to_disk && response && response.content) {
|
|
389
|
-
try {
|
|
390
|
-
const textItem = response.content.find((c) => c.type === "text");
|
|
391
|
-
if (textItem && textItem.text) {
|
|
392
|
-
const data = JSON.parse(textItem.text);
|
|
393
|
-
const targetDir = path.resolve(process.cwd(), args.destination_dir);
|
|
394
|
-
await fs.mkdir(targetDir, { recursive: true });
|
|
395
|
-
const savedFiles = [];
|
|
396
|
-
if (data.file_name && data.content) {
|
|
397
|
-
const safeFileName = path.basename(data.file_name);
|
|
398
|
-
if (!safeFileName || safeFileName === "." || safeFileName === "..") {
|
|
399
|
-
throw new Error(`Invalid file name returned: "${data.file_name}"`);
|
|
400
|
-
}
|
|
401
|
-
const scriptPath = path.join(targetDir, safeFileName);
|
|
402
|
-
if (!path.resolve(scriptPath).startsWith(targetDir)) {
|
|
403
|
-
throw new Error(`Path traversal detected in returned file name: "${data.file_name}"`);
|
|
404
|
-
}
|
|
405
|
-
await fs.writeFile(scriptPath, data.content, "utf-8");
|
|
406
|
-
savedFiles.push(scriptPath);
|
|
407
|
-
logger.info(`Saved test script to: ${scriptPath}`);
|
|
408
|
-
}
|
|
409
|
-
if (data.conftest_content) {
|
|
410
|
-
const conftestPath = path.join(targetDir, "conftest.py");
|
|
411
|
-
await fs.writeFile(conftestPath, data.conftest_content, "utf-8");
|
|
412
|
-
savedFiles.push(conftestPath);
|
|
413
|
-
logger.info(`Saved conftest.py to: ${conftestPath}`);
|
|
414
|
-
}
|
|
415
|
-
if (savedFiles.length > 0) {
|
|
416
|
-
data.saved_files = savedFiles;
|
|
417
|
-
textItem.text = JSON.stringify(data, null, 2);
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
} catch (writeErr) {
|
|
421
|
-
logger.warn(`Failed to write downloaded script to disk: ${writeErr.message}`);
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
return response;
|
|
425
338
|
} catch (err) {
|
|
339
|
+
return errorResult(`Error in qcentriq_download_script: ${err.message}`);
|
|
340
|
+
}
|
|
341
|
+
if (!args.save_to_disk || !data?.file_name || !data?.content) return jsonResult(data);
|
|
342
|
+
try {
|
|
343
|
+
data.saved_files = await saveScriptFiles(args.destination_dir, data.file_name, data.content, data.conftest_content);
|
|
344
|
+
return jsonResult(data);
|
|
345
|
+
} catch (writeErr) {
|
|
346
|
+
logger.warn(`Failed to write downloaded script to disk: ${writeErr.message}`);
|
|
426
347
|
return {
|
|
427
348
|
isError: true,
|
|
428
|
-
content: [
|
|
349
|
+
content: [
|
|
350
|
+
{
|
|
351
|
+
type: "text",
|
|
352
|
+
text: `The script was downloaded but could not be saved to "${args.destination_dir}": ${writeErr.message}. The downloaded content follows; save it with qcentriq_save_script.`
|
|
353
|
+
},
|
|
354
|
+
...jsonResult(data).content
|
|
355
|
+
]
|
|
429
356
|
};
|
|
430
357
|
}
|
|
431
358
|
}
|
|
@@ -433,80 +360,59 @@ function registerDownloadScriptTool(server, client, config) {
|
|
|
433
360
|
}
|
|
434
361
|
|
|
435
362
|
// src/tools/environment.ts
|
|
436
|
-
import { z as
|
|
363
|
+
import { z as z6 } from "zod";
|
|
437
364
|
function registerEnvironmentTool(server, client, config) {
|
|
438
365
|
server.registerTool(
|
|
439
366
|
"qcentriq_get_environment",
|
|
440
367
|
{
|
|
441
368
|
description: "Retrieve target test environment configuration, base URL (BASE_URL), environment variables, and required secret variable names for local test execution.",
|
|
442
|
-
inputSchema: {
|
|
443
|
-
project_id:
|
|
444
|
-
environment_id:
|
|
445
|
-
environment_name:
|
|
446
|
-
}
|
|
369
|
+
inputSchema: z6.object({
|
|
370
|
+
project_id: z6.uuid().optional().describe("Optional project UUID (inferred from API key if omitted)."),
|
|
371
|
+
environment_id: z6.uuid().optional().describe("Optional specific environment UUID."),
|
|
372
|
+
environment_name: z6.string().optional().describe("Optional environment name filter (e.g. 'staging', 'dev', 'production').")
|
|
373
|
+
})
|
|
447
374
|
},
|
|
448
|
-
async (args) =>
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
...args,
|
|
453
|
-
project_id: projectId
|
|
454
|
-
});
|
|
455
|
-
return response;
|
|
456
|
-
} catch (err) {
|
|
457
|
-
return {
|
|
458
|
-
isError: true,
|
|
459
|
-
content: [{ type: "text", text: `Error in qcentriq_get_environment: ${err.message}` }]
|
|
460
|
-
};
|
|
461
|
-
}
|
|
462
|
-
}
|
|
375
|
+
async (args) => backendCall(
|
|
376
|
+
"qcentriq_get_environment",
|
|
377
|
+
() => client.request("/environment", { ...args, project_id: args.project_id || config.defaultProjectId })
|
|
378
|
+
)
|
|
463
379
|
);
|
|
464
380
|
}
|
|
465
381
|
|
|
466
382
|
// src/tools/run-logs.ts
|
|
467
|
-
import { z as
|
|
383
|
+
import { z as z7 } from "zod";
|
|
468
384
|
function registerRunLogsTool(server, client, config) {
|
|
469
385
|
server.registerTool(
|
|
470
386
|
"qcentriq_get_test_run_logs",
|
|
471
387
|
{
|
|
472
388
|
description: "Retrieve execution history and logs for a test case: per-run status, timing, error message, stack trace, and raw output logs across runs.",
|
|
473
|
-
inputSchema: {
|
|
474
|
-
test_case_id:
|
|
475
|
-
project_id:
|
|
476
|
-
run_id:
|
|
477
|
-
status:
|
|
478
|
-
latest_only:
|
|
479
|
-
from_date:
|
|
480
|
-
to_date:
|
|
481
|
-
limit:
|
|
482
|
-
offset:
|
|
483
|
-
}
|
|
389
|
+
inputSchema: z7.object({
|
|
390
|
+
test_case_id: z7.uuid().describe("UUID of the target test case."),
|
|
391
|
+
project_id: z7.uuid().optional().describe("Optional project UUID (inferred from API key if omitted)."),
|
|
392
|
+
run_id: z7.uuid().optional().describe("Optional specific run UUID to fetch a single run's full log."),
|
|
393
|
+
status: z7.enum(["failed", "passed", "error"]).optional().describe("Filter by result status."),
|
|
394
|
+
latest_only: z7.boolean().default(false).describe("If True, returns only the most recent matching run."),
|
|
395
|
+
from_date: z7.string().optional().describe("Optional ISO-8601 start date filter."),
|
|
396
|
+
to_date: z7.string().optional().describe("Optional ISO-8601 end date filter."),
|
|
397
|
+
limit: z7.number().int().min(1).max(100).default(20).describe("Max runs to return."),
|
|
398
|
+
offset: z7.number().int().min(0).default(0).describe("Pagination offset.")
|
|
399
|
+
})
|
|
484
400
|
},
|
|
485
|
-
async (
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
...args,
|
|
490
|
-
project_id: projectId
|
|
491
|
-
});
|
|
492
|
-
return response;
|
|
493
|
-
} catch (err) {
|
|
494
|
-
return {
|
|
495
|
-
isError: true,
|
|
496
|
-
content: [{ type: "text", text: `Error in qcentriq_get_test_run_logs: ${err.message}` }]
|
|
497
|
-
};
|
|
498
|
-
}
|
|
499
|
-
}
|
|
401
|
+
async ({ test_case_id, ...query }) => backendCall(
|
|
402
|
+
"qcentriq_get_test_run_logs",
|
|
403
|
+
() => client.request(`/tests/${test_case_id}/run-logs`, { ...query, project_id: query.project_id || config.defaultProjectId })
|
|
404
|
+
)
|
|
500
405
|
);
|
|
501
406
|
}
|
|
502
407
|
|
|
503
408
|
// src/tools/authoring-guide.ts
|
|
409
|
+
import { z as z8 } from "zod";
|
|
504
410
|
function registerAuthoringGuideTool(server, client) {
|
|
505
411
|
server.registerTool(
|
|
506
412
|
"qcentriq_get_authoring_guide",
|
|
507
413
|
{
|
|
508
414
|
description: "Fetch the contract for authoring QCentriq test plans and scripts: the TaskPlan JSON schema, the ${VAR} environment-variable convention, the @allure.id rules a saved script is validated against, and the conftest fixtures a script may use. Call this before writing a plan or a test script \u2014 a script that violates the contract is rejected on save.",
|
|
509
|
-
inputSchema: {},
|
|
415
|
+
inputSchema: z8.object({}),
|
|
510
416
|
annotations: {
|
|
511
417
|
readOnlyHint: true,
|
|
512
418
|
destructiveHint: false,
|
|
@@ -530,413 +436,184 @@ function registerAuthoringGuideTool(server, client) {
|
|
|
530
436
|
);
|
|
531
437
|
}
|
|
532
438
|
|
|
533
|
-
// src/tools/create-plan.ts
|
|
534
|
-
import { z as z7 } from "zod";
|
|
535
|
-
function registerCreatePlanTool(server, client, config) {
|
|
536
|
-
server.registerTool(
|
|
537
|
-
"qcentriq_create_plan",
|
|
538
|
-
{
|
|
539
|
-
description: "Create test groups and test cases in QCentriq from a plan you authored. Call qcentriq_get_authoring_guide first \u2014 the plan must match the TaskPlan schema, and any value that exists as a project environment variable must be written as ${VAR_NAME} rather than inlined. Returns one UUID per created test case; each must appear exactly once as @allure.id('<case_id>') in the script you then save with qcentriq_save_group_script. Requires an API key with the 'test:write' scope.",
|
|
540
|
-
inputSchema: {
|
|
541
|
-
plan: z7.record(z7.string(), z7.any()).describe("The plan object, matching the TaskPlan schema from qcentriq_get_authoring_guide."),
|
|
542
|
-
project_id: z7.uuid().optional().describe("Optional project UUID (inferred from the API key if omitted).")
|
|
543
|
-
},
|
|
544
|
-
annotations: {
|
|
545
|
-
readOnlyHint: false,
|
|
546
|
-
destructiveHint: false,
|
|
547
|
-
// Creates new groups and cases; never modifies existing ones.
|
|
548
|
-
idempotentHint: false,
|
|
549
|
-
// Calling twice creates two plans.
|
|
550
|
-
openWorldHint: false
|
|
551
|
-
}
|
|
552
|
-
},
|
|
553
|
-
async (args) => {
|
|
554
|
-
try {
|
|
555
|
-
const data = await client.send("POST", "/plans", {
|
|
556
|
-
plan: args.plan,
|
|
557
|
-
project_id: args.project_id || config.defaultProjectId
|
|
558
|
-
});
|
|
559
|
-
return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
|
|
560
|
-
} catch (err) {
|
|
561
|
-
return {
|
|
562
|
-
isError: true,
|
|
563
|
-
content: [{ type: "text", text: `Error in qcentriq_create_plan: ${err.message}` }]
|
|
564
|
-
};
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
);
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
// src/tools/save-group-script.ts
|
|
571
|
-
import { z as z8 } from "zod";
|
|
572
|
-
function registerSaveGroupScriptTool(server, client, config) {
|
|
573
|
-
server.registerTool(
|
|
574
|
-
"qcentriq_save_group_script",
|
|
575
|
-
{
|
|
576
|
-
description: "Save a test script you wrote back to QCentriq so the cloud runner executes exactly what you ran locally. The script is validated before it is stored: valid Python, and every test case in the group present exactly once as @allure.id('<case_id>') \u2014 no duplicates, no ids from other groups. A rejection names the offending id or line so you can correct it. Pass expected_updated_at from the last download to turn a concurrent edit into a conflict rather than a lost update. conftest.py cannot be saved; QCentriq provides it. Requires the 'test:write' scope.",
|
|
577
|
-
inputSchema: {
|
|
578
|
-
group_id: z8.uuid().describe("UUID of the target test group."),
|
|
579
|
-
content: z8.string().describe("The Python test script source."),
|
|
580
|
-
project_id: z8.uuid().optional().describe("Optional project UUID (inferred from the API key if omitted)."),
|
|
581
|
-
filename: z8.string().optional().describe("Optional script filename; derived from the group title if omitted."),
|
|
582
|
-
fixtures: z8.array(z8.object({ file_name: z8.string(), content: z8.string() })).optional().describe("Companion files to store next to the script (page objects, test data). conftest.py is rejected."),
|
|
583
|
-
expected_updated_at: z8.string().optional().describe("ISO-8601 timestamp from the last download. Supply it to get a conflict instead of silently overwriting someone else's edit.")
|
|
584
|
-
},
|
|
585
|
-
annotations: {
|
|
586
|
-
readOnlyHint: false,
|
|
587
|
-
destructiveHint: true,
|
|
588
|
-
// Replaces the group's existing script.
|
|
589
|
-
idempotentHint: true,
|
|
590
|
-
// Saving the same content twice leaves the same state.
|
|
591
|
-
openWorldHint: false
|
|
592
|
-
}
|
|
593
|
-
},
|
|
594
|
-
async (args) => {
|
|
595
|
-
try {
|
|
596
|
-
const { group_id, ...rest } = args;
|
|
597
|
-
const data = await client.send("PUT", `/groups/${group_id}/script`, {
|
|
598
|
-
...rest,
|
|
599
|
-
project_id: args.project_id || config.defaultProjectId
|
|
600
|
-
});
|
|
601
|
-
return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
|
|
602
|
-
} catch (err) {
|
|
603
|
-
return {
|
|
604
|
-
isError: true,
|
|
605
|
-
content: [{ type: "text", text: `Error in qcentriq_save_group_script: ${err.message}` }]
|
|
606
|
-
};
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
);
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
// src/tools/local-run.ts
|
|
613
|
-
import { z as z9 } from "zod";
|
|
614
|
-
|
|
615
|
-
// src/local/runner.ts
|
|
616
|
-
import { spawn } from "child_process";
|
|
617
|
-
import * as path2 from "path";
|
|
618
|
-
function buildTestEnv(params) {
|
|
619
|
-
const env = {
|
|
620
|
-
...process.env,
|
|
621
|
-
...params.envVars || {}
|
|
622
|
-
};
|
|
623
|
-
if (params.baseUrl) {
|
|
624
|
-
env.BASE_URL = params.baseUrl;
|
|
625
|
-
}
|
|
626
|
-
if (params.browser) {
|
|
627
|
-
env.BROWSER = params.browser;
|
|
628
|
-
}
|
|
629
|
-
if (params.headless !== void 0) {
|
|
630
|
-
env.HEADLESS = params.headless ? "true" : "false";
|
|
631
|
-
}
|
|
632
|
-
if (params.groupId) {
|
|
633
|
-
env.QCAQ_TEST_GROUP_ID = params.groupId;
|
|
634
|
-
}
|
|
635
|
-
return env;
|
|
636
|
-
}
|
|
637
|
-
function resolvePytestCommand() {
|
|
638
|
-
if (process.env.VIRTUAL_ENV) {
|
|
639
|
-
const venvPytest = path2.join(process.env.VIRTUAL_ENV, "bin", "pytest");
|
|
640
|
-
return { cmd: venvPytest, baseArgs: [] };
|
|
641
|
-
}
|
|
642
|
-
return { cmd: "pytest", baseArgs: [] };
|
|
643
|
-
}
|
|
644
|
-
function killProcessTree(child) {
|
|
645
|
-
if (child.pid) {
|
|
646
|
-
try {
|
|
647
|
-
if (process.platform !== "win32") {
|
|
648
|
-
process.kill(-child.pid, "SIGKILL");
|
|
649
|
-
return;
|
|
650
|
-
}
|
|
651
|
-
} catch {
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
try {
|
|
655
|
-
child.kill("SIGKILL");
|
|
656
|
-
} catch {
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
async function runLocalPytest(params) {
|
|
660
|
-
const startTime = Date.now();
|
|
661
|
-
const cwd = params.workingDir ? path2.resolve(params.workingDir) : process.cwd();
|
|
662
|
-
const timeoutMs = (params.timeoutSeconds || 60) * 1e3;
|
|
663
|
-
const { cmd, baseArgs } = resolvePytestCommand();
|
|
664
|
-
const args = [...baseArgs, params.filePath];
|
|
665
|
-
if (params.testName) {
|
|
666
|
-
args.push("-k", params.testName);
|
|
667
|
-
}
|
|
668
|
-
if (params.extraArgs && params.extraArgs.length > 0) {
|
|
669
|
-
args.push(...params.extraArgs);
|
|
670
|
-
}
|
|
671
|
-
if (!args.includes("-v") && !args.includes("-vv")) {
|
|
672
|
-
args.push("-v");
|
|
673
|
-
}
|
|
674
|
-
const env = buildTestEnv(params);
|
|
675
|
-
const fullCommand = `${cmd} ${args.join(" ")}`;
|
|
676
|
-
logger.info(`Running local test command: ${fullCommand} in ${cwd}`);
|
|
677
|
-
return new Promise((resolve5) => {
|
|
678
|
-
let stdout = "";
|
|
679
|
-
let stderr = "";
|
|
680
|
-
let finished = false;
|
|
681
|
-
const child = spawn(cmd, args, {
|
|
682
|
-
cwd,
|
|
683
|
-
env,
|
|
684
|
-
detached: process.platform !== "win32",
|
|
685
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
686
|
-
});
|
|
687
|
-
const timer = setTimeout(() => {
|
|
688
|
-
if (!finished) {
|
|
689
|
-
finished = true;
|
|
690
|
-
killProcessTree(child);
|
|
691
|
-
resolve5({
|
|
692
|
-
passed: false,
|
|
693
|
-
exitCode: -1,
|
|
694
|
-
stdout,
|
|
695
|
-
stderr: stderr + `
|
|
696
|
-
[TIMEOUT] Test execution timed out after ${params.timeoutSeconds || 60} seconds.`,
|
|
697
|
-
durationMs: Date.now() - startTime,
|
|
698
|
-
command: fullCommand
|
|
699
|
-
});
|
|
700
|
-
}
|
|
701
|
-
}, timeoutMs);
|
|
702
|
-
child.stdout.on("data", (chunk) => {
|
|
703
|
-
stdout += chunk.toString();
|
|
704
|
-
});
|
|
705
|
-
child.stderr.on("data", (chunk) => {
|
|
706
|
-
stderr += chunk.toString();
|
|
707
|
-
});
|
|
708
|
-
child.on("error", (err) => {
|
|
709
|
-
if (finished) return;
|
|
710
|
-
finished = true;
|
|
711
|
-
clearTimeout(timer);
|
|
712
|
-
if (err.code === "ENOENT" && cmd !== "python3") {
|
|
713
|
-
logger.warn("pytest binary not found directly, falling back to python3 -m pytest...");
|
|
714
|
-
const fallbackChild = spawn("python3", ["-m", "pytest", ...args], {
|
|
715
|
-
cwd,
|
|
716
|
-
env,
|
|
717
|
-
detached: process.platform !== "win32",
|
|
718
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
719
|
-
});
|
|
720
|
-
let fbStdout = "";
|
|
721
|
-
let fbStderr = "";
|
|
722
|
-
let fbFinished = false;
|
|
723
|
-
const fbTimer = setTimeout(() => {
|
|
724
|
-
if (!fbFinished) {
|
|
725
|
-
fbFinished = true;
|
|
726
|
-
killProcessTree(fallbackChild);
|
|
727
|
-
resolve5({
|
|
728
|
-
passed: false,
|
|
729
|
-
exitCode: -1,
|
|
730
|
-
stdout: fbStdout,
|
|
731
|
-
stderr: fbStderr + `
|
|
732
|
-
[TIMEOUT] Test execution timed out after ${params.timeoutSeconds || 60} seconds.`,
|
|
733
|
-
durationMs: Date.now() - startTime,
|
|
734
|
-
command: `python3 -m pytest ${args.join(" ")}`
|
|
735
|
-
});
|
|
736
|
-
}
|
|
737
|
-
}, timeoutMs);
|
|
738
|
-
fallbackChild.stdout.on("data", (c) => fbStdout += c.toString());
|
|
739
|
-
fallbackChild.stderr.on("data", (c) => fbStderr += c.toString());
|
|
740
|
-
fallbackChild.on("close", (code) => {
|
|
741
|
-
if (fbFinished) return;
|
|
742
|
-
fbFinished = true;
|
|
743
|
-
clearTimeout(fbTimer);
|
|
744
|
-
resolve5({
|
|
745
|
-
passed: code === 0,
|
|
746
|
-
exitCode: code ?? -1,
|
|
747
|
-
stdout: fbStdout,
|
|
748
|
-
stderr: fbStderr,
|
|
749
|
-
durationMs: Date.now() - startTime,
|
|
750
|
-
command: `python3 -m pytest ${args.join(" ")}`
|
|
751
|
-
});
|
|
752
|
-
});
|
|
753
|
-
fallbackChild.on("error", (fbErr) => {
|
|
754
|
-
if (fbFinished) return;
|
|
755
|
-
fbFinished = true;
|
|
756
|
-
clearTimeout(fbTimer);
|
|
757
|
-
resolve5({
|
|
758
|
-
passed: false,
|
|
759
|
-
exitCode: -1,
|
|
760
|
-
stdout: "",
|
|
761
|
-
stderr: `Failed to execute pytest or python3 -m pytest: ${fbErr.message}. Ensure pytest is installed in your Python environment.`,
|
|
762
|
-
durationMs: Date.now() - startTime,
|
|
763
|
-
command: fullCommand
|
|
764
|
-
});
|
|
765
|
-
});
|
|
766
|
-
return;
|
|
767
|
-
}
|
|
768
|
-
resolve5({
|
|
769
|
-
passed: false,
|
|
770
|
-
exitCode: -1,
|
|
771
|
-
stdout,
|
|
772
|
-
stderr: `Failed to spawn process: ${err.message}. Ensure pytest is installed in your Python environment.`,
|
|
773
|
-
durationMs: Date.now() - startTime,
|
|
774
|
-
command: fullCommand
|
|
775
|
-
});
|
|
776
|
-
});
|
|
777
|
-
child.on("close", (code) => {
|
|
778
|
-
if (finished) return;
|
|
779
|
-
finished = true;
|
|
780
|
-
clearTimeout(timer);
|
|
781
|
-
const durationMs = Date.now() - startTime;
|
|
782
|
-
resolve5({
|
|
783
|
-
passed: code === 0,
|
|
784
|
-
exitCode: code ?? -1,
|
|
785
|
-
stdout,
|
|
786
|
-
stderr,
|
|
787
|
-
durationMs,
|
|
788
|
-
command: fullCommand
|
|
789
|
-
});
|
|
790
|
-
});
|
|
791
|
-
});
|
|
792
|
-
}
|
|
793
|
-
|
|
794
|
-
// src/tools/local-run.ts
|
|
795
|
-
function registerLocalRunTool(server) {
|
|
796
|
-
server.registerTool(
|
|
797
|
-
"qcentriq_run_local_test",
|
|
798
|
-
{
|
|
799
|
-
description: "Execute a downloaded Playwright/pytest test script locally in the developer's environment. Runs pytest as a local subprocess and returns stdout, stderr, exit code, and test diagnostics without using QCentriq cloud runners.",
|
|
800
|
-
inputSchema: {
|
|
801
|
-
file_path: z9.string().describe("Path to the local test file to run (e.g. 'tests/test_login.py')."),
|
|
802
|
-
test_name: z9.string().optional().describe("Optional specific test function name or expression to run (passed to pytest -k)."),
|
|
803
|
-
headless: z9.boolean().default(true).describe("Whether to run the browser in headless mode (default True). Set False to watch the browser execution live."),
|
|
804
|
-
browser: z9.enum(["chromium", "firefox", "webkit"]).default("chromium").describe("Browser engine to execute against (default 'chromium')."),
|
|
805
|
-
base_url: z9.url().optional().describe("Target application base URL (e.g. from qcentriq_get_environment). Injected as BASE_URL env var."),
|
|
806
|
-
group_id: z9.string().optional().describe("Test group UUID this script belongs to. Injected as QCAQ_TEST_GROUP_ID so the Allure results stay mappable back to the QCentriq group."),
|
|
807
|
-
env_vars: z9.record(z9.string(), z9.string()).optional().describe("Environment variables to inject into the local test process."),
|
|
808
|
-
extra_args: z9.array(z9.string()).optional().describe("Additional CLI arguments to pass to pytest (e.g. ['-s', '--alluredir=allure-results'])."),
|
|
809
|
-
timeout_seconds: z9.number().int().min(5).max(300).default(60).describe("Timeout in seconds for test execution (default 60)."),
|
|
810
|
-
working_dir: z9.string().optional().describe("Working directory to run pytest in (defaults to current project directory).")
|
|
811
|
-
}
|
|
812
|
-
},
|
|
813
|
-
async (args) => {
|
|
814
|
-
try {
|
|
815
|
-
const result = await runLocalPytest({
|
|
816
|
-
filePath: args.file_path,
|
|
817
|
-
testName: args.test_name,
|
|
818
|
-
headless: args.headless,
|
|
819
|
-
browser: args.browser,
|
|
820
|
-
baseUrl: args.base_url,
|
|
821
|
-
groupId: args.group_id,
|
|
822
|
-
envVars: args.env_vars,
|
|
823
|
-
extraArgs: args.extra_args,
|
|
824
|
-
timeoutSeconds: args.timeout_seconds,
|
|
825
|
-
workingDir: args.working_dir
|
|
826
|
-
});
|
|
827
|
-
const statusText = result.passed ? "PASSED" : "FAILED";
|
|
828
|
-
const summary = [
|
|
829
|
-
`Local Test Run Result: ${statusText} (exit code ${result.exitCode})`,
|
|
830
|
-
`Duration: ${(result.durationMs / 1e3).toFixed(2)}s`,
|
|
831
|
-
`Command: ${result.command}`,
|
|
832
|
-
"",
|
|
833
|
-
"--- STDOUT ---",
|
|
834
|
-
result.stdout || "(no stdout)",
|
|
835
|
-
"",
|
|
836
|
-
"--- STDERR ---",
|
|
837
|
-
result.stderr || "(no stderr)"
|
|
838
|
-
].join("\n");
|
|
839
|
-
return {
|
|
840
|
-
content: [
|
|
841
|
-
{
|
|
842
|
-
type: "text",
|
|
843
|
-
text: summary
|
|
844
|
-
}
|
|
845
|
-
],
|
|
846
|
-
isError: !result.passed
|
|
847
|
-
};
|
|
848
|
-
} catch (err) {
|
|
849
|
-
return {
|
|
850
|
-
isError: true,
|
|
851
|
-
content: [
|
|
852
|
-
{
|
|
853
|
-
type: "text",
|
|
854
|
-
text: `Error executing local test: ${err.message}`
|
|
855
|
-
}
|
|
856
|
-
]
|
|
857
|
-
};
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
);
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
// src/tools/save-script.ts
|
|
439
|
+
// src/tools/create-plan.ts
|
|
864
440
|
import { z as z10 } from "zod";
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
441
|
+
|
|
442
|
+
// src/tools/confirm-upload.ts
|
|
443
|
+
import {
|
|
444
|
+
CLIENT_CAPABILITIES_META_KEY,
|
|
445
|
+
inputRequired,
|
|
446
|
+
inputResponse,
|
|
447
|
+
acceptedContent
|
|
448
|
+
} from "@modelcontextprotocol/server";
|
|
449
|
+
import { z as z9 } from "zod";
|
|
450
|
+
var CONFIRM_KEY = "confirm_upload";
|
|
451
|
+
var ConfirmAnswer = z9.object({ confirm: z9.boolean() });
|
|
452
|
+
function confirmUpload(server, ctx, config, action, message) {
|
|
453
|
+
const response = inputResponse(ctx.mcpReq.inputResponses, CONFIRM_KEY);
|
|
454
|
+
if (response.kind === "elicit") {
|
|
455
|
+
const answer = acceptedContent(ctx.mcpReq.inputResponses, CONFIRM_KEY, ConfirmAnswer);
|
|
456
|
+
if (answer?.confirm === true) {
|
|
457
|
+
return { proceed: true };
|
|
458
|
+
}
|
|
459
|
+
return {
|
|
460
|
+
proceed: false,
|
|
461
|
+
result: {
|
|
462
|
+
content: [
|
|
463
|
+
{
|
|
464
|
+
type: "text",
|
|
465
|
+
text: `Upload declined: the user did not confirm ${action}, so nothing was sent to QCentriq. Do not retry unless the user asks you to.`
|
|
466
|
+
}
|
|
467
|
+
]
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
if (supportsFormElicitation(server, ctx)) {
|
|
472
|
+
return {
|
|
473
|
+
proceed: false,
|
|
474
|
+
result: inputRequired({
|
|
475
|
+
inputRequests: {
|
|
476
|
+
[CONFIRM_KEY]: inputRequired.elicit({
|
|
477
|
+
message,
|
|
478
|
+
requestedSchema: {
|
|
479
|
+
type: "object",
|
|
480
|
+
properties: {
|
|
481
|
+
confirm: { type: "boolean", title: "Upload to QCentriq", description: "Tick to upload." }
|
|
482
|
+
},
|
|
483
|
+
required: ["confirm"]
|
|
484
|
+
}
|
|
485
|
+
})
|
|
486
|
+
}
|
|
487
|
+
})
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
if (config.requireUploadConfirmation) {
|
|
491
|
+
return {
|
|
492
|
+
proceed: false,
|
|
493
|
+
result: {
|
|
494
|
+
isError: true,
|
|
495
|
+
content: [
|
|
496
|
+
{
|
|
497
|
+
type: "text",
|
|
498
|
+
text: `Upload refused: --require-upload-confirmation is set, but this MCP client cannot show a confirmation prompt, so ${action} was not sent to QCentriq. Use a client that supports elicitation, or remove the flag.`
|
|
499
|
+
}
|
|
500
|
+
]
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
logger.warn(`Client cannot show a confirmation prompt; uploading ${action} without one.`);
|
|
505
|
+
return { proceed: true };
|
|
506
|
+
}
|
|
507
|
+
function plural(count, noun) {
|
|
508
|
+
return `${count} ${noun}${count === 1 ? "" : "s"}`;
|
|
509
|
+
}
|
|
510
|
+
function supportsFormElicitation(server, ctx) {
|
|
511
|
+
const elicitation = clientCapabilities(server, ctx)?.elicitation;
|
|
512
|
+
if (!elicitation) return false;
|
|
513
|
+
return Boolean(elicitation.form) || !elicitation.url;
|
|
514
|
+
}
|
|
515
|
+
function clientCapabilities(server, ctx) {
|
|
516
|
+
const envelope = ctx.mcpReq.envelope;
|
|
517
|
+
const fromEnvelope = envelope?.[CLIENT_CAPABILITIES_META_KEY];
|
|
518
|
+
return fromEnvelope ?? server.server.getClientCapabilities();
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// src/tools/create-plan.ts
|
|
522
|
+
function registerCreatePlanTool(server, client, config) {
|
|
869
523
|
server.registerTool(
|
|
870
|
-
"
|
|
524
|
+
"qcentriq_create_plan",
|
|
871
525
|
{
|
|
872
|
-
description: "
|
|
873
|
-
inputSchema: {
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
526
|
+
description: "Create test groups and test cases in QCentriq from a plan you authored. Call qcentriq_get_authoring_guide first \u2014 the plan must match the TaskPlan schema, and any value that exists as a project environment variable must be written as ${VAR_NAME} rather than inlined. Returns one UUID per created test case; each must appear exactly once as @allure.id('<case_id>') in the script you then save with qcentriq_save_group_script. Requires an API key with the 'test:write' scope.",
|
|
527
|
+
inputSchema: z10.object({
|
|
528
|
+
plan: z10.record(z10.string(), z10.any()).describe("The plan object, matching the TaskPlan schema from qcentriq_get_authoring_guide."),
|
|
529
|
+
project_id: z10.uuid().optional().describe("Optional project UUID (inferred from the API key if omitted).")
|
|
530
|
+
}),
|
|
531
|
+
annotations: {
|
|
532
|
+
readOnlyHint: false,
|
|
533
|
+
destructiveHint: false,
|
|
534
|
+
// Creates new groups and cases; never modifies existing ones.
|
|
535
|
+
idempotentHint: false,
|
|
536
|
+
// Calling twice creates two plans.
|
|
537
|
+
openWorldHint: false
|
|
878
538
|
}
|
|
879
539
|
},
|
|
880
|
-
async (args) => {
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
throw new Error(`Invalid file name: "${args.file_name}"`);
|
|
888
|
-
}
|
|
889
|
-
const scriptPath = path3.join(targetDir, safeFileName);
|
|
890
|
-
if (!path3.resolve(scriptPath).startsWith(targetDir)) {
|
|
891
|
-
throw new Error(`Path traversal detected for file name: "${args.file_name}"`);
|
|
892
|
-
}
|
|
893
|
-
await fs2.writeFile(scriptPath, args.content, "utf-8");
|
|
894
|
-
savedFiles.push(scriptPath);
|
|
895
|
-
logger.info(`Saved test script to: ${scriptPath}`);
|
|
896
|
-
if (args.conftest_content) {
|
|
897
|
-
const conftestPath = path3.join(targetDir, "conftest.py");
|
|
898
|
-
await fs2.writeFile(conftestPath, args.conftest_content, "utf-8");
|
|
899
|
-
savedFiles.push(conftestPath);
|
|
900
|
-
logger.info(`Saved conftest.py to: ${conftestPath}`);
|
|
901
|
-
}
|
|
902
|
-
return {
|
|
903
|
-
content: [
|
|
904
|
-
{
|
|
905
|
-
type: "text",
|
|
906
|
-
text: JSON.stringify(
|
|
907
|
-
{
|
|
908
|
-
status: "success",
|
|
909
|
-
message: `Successfully saved ${savedFiles.length} file(s) to ${targetDir}`,
|
|
910
|
-
saved_files: savedFiles
|
|
911
|
-
},
|
|
912
|
-
null,
|
|
913
|
-
2
|
|
914
|
-
)
|
|
915
|
-
}
|
|
916
|
-
]
|
|
917
|
-
};
|
|
918
|
-
} catch (err) {
|
|
919
|
-
return {
|
|
920
|
-
isError: true,
|
|
921
|
-
content: [
|
|
922
|
-
{
|
|
923
|
-
type: "text",
|
|
924
|
-
text: `Failed to save test script to disk: ${err.message}`
|
|
925
|
-
}
|
|
926
|
-
]
|
|
927
|
-
};
|
|
928
|
-
}
|
|
540
|
+
async (args, ctx) => {
|
|
541
|
+
const gate = confirmUpload(server, ctx, config, "this test plan", describePlan(args.plan));
|
|
542
|
+
if (!gate.proceed) return gate.result;
|
|
543
|
+
return backendCall(
|
|
544
|
+
"qcentriq_create_plan",
|
|
545
|
+
() => client.send("POST", "/plans", { plan: args.plan, project_id: args.project_id || config.defaultProjectId })
|
|
546
|
+
);
|
|
929
547
|
}
|
|
930
548
|
);
|
|
931
549
|
}
|
|
550
|
+
function describePlan(plan) {
|
|
551
|
+
const tasks = Array.isArray(plan.tasks) ? plan.tasks : [];
|
|
552
|
+
const groups = tasks.map((task, i) => ({
|
|
553
|
+
name: typeof task?.name === "string" && task.name ? task.name : `Group ${i + 1}`,
|
|
554
|
+
cases: Array.isArray(task?.test_cases) ? task.test_cases.length : 0
|
|
555
|
+
}));
|
|
556
|
+
const cases = groups.reduce((sum, g) => sum + g.cases, 0);
|
|
557
|
+
const list = groups.map((g) => `${g.name} (${g.cases})`).join(", ");
|
|
558
|
+
return `Create ${plural(groups.length, "test group")} with ${plural(cases, "test case")} in QCentriq?` + (list ? ` Groups: ${list}.` : "");
|
|
559
|
+
}
|
|
932
560
|
|
|
933
|
-
// src/tools/
|
|
561
|
+
// src/tools/save-group-script.ts
|
|
934
562
|
import { z as z11 } from "zod";
|
|
935
563
|
|
|
564
|
+
// src/local/passing-runs.ts
|
|
565
|
+
import { createHash } from "crypto";
|
|
566
|
+
import * as fs2 from "fs/promises";
|
|
567
|
+
import * as path2 from "path";
|
|
568
|
+
var PassingRunLedger = class {
|
|
569
|
+
runs = /* @__PURE__ */ new Map();
|
|
570
|
+
record(content, run) {
|
|
571
|
+
this.runs.set(contentHash(content), run);
|
|
572
|
+
}
|
|
573
|
+
find(content) {
|
|
574
|
+
return this.runs.get(contentHash(content));
|
|
575
|
+
}
|
|
576
|
+
};
|
|
577
|
+
function contentHash(content) {
|
|
578
|
+
return createHash("sha256").update(content).digest("hex");
|
|
579
|
+
}
|
|
580
|
+
var NARROWING_FLAGS = ["-k", "-m", "--deselect", "--lf", "--last-failed", "--sw", "--stepwise", "--co", "--collect-only", "--setup-only", "--setup-plan", "--fixtures"];
|
|
581
|
+
function coversWholeFile(filePath, testName, extraArgs = []) {
|
|
582
|
+
if (testName || filePath.includes("::")) return false;
|
|
583
|
+
return !extraArgs.some(
|
|
584
|
+
(arg) => NARROWING_FLAGS.some((flag) => arg === flag || arg.startsWith(`${flag}=`) || /^-[a-z]$/.test(flag) && arg.startsWith(flag))
|
|
585
|
+
);
|
|
586
|
+
}
|
|
587
|
+
function reportsPassedTests(stdout) {
|
|
588
|
+
return /\b[1-9]\d* passed\b/.test(stdout);
|
|
589
|
+
}
|
|
590
|
+
async function fixtureMismatch(run, fixtures) {
|
|
591
|
+
for (const fixture of fixtures) {
|
|
592
|
+
const localPath = path2.resolve(run.dir, fixture.file_name);
|
|
593
|
+
if (path2.dirname(localPath) !== run.dir) {
|
|
594
|
+
return `companion file "${fixture.file_name}" is not a plain file name next to the script`;
|
|
595
|
+
}
|
|
596
|
+
let local;
|
|
597
|
+
let modifiedAt;
|
|
598
|
+
try {
|
|
599
|
+
[local, modifiedAt] = await Promise.all([fs2.readFile(localPath, "utf-8"), fs2.stat(localPath).then((s) => s.mtimeMs)]);
|
|
600
|
+
} catch {
|
|
601
|
+
return `companion file "${fixture.file_name}" was not next to the script (${run.dir}) when it passed`;
|
|
602
|
+
}
|
|
603
|
+
if (local !== fixture.content) {
|
|
604
|
+
return `companion file "${fixture.file_name}" differs from ${localPath}, which the passing run used`;
|
|
605
|
+
}
|
|
606
|
+
if (modifiedAt > run.startedAt) {
|
|
607
|
+
return `companion file "${fixture.file_name}" changed after the passing run`;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
return null;
|
|
611
|
+
}
|
|
612
|
+
|
|
936
613
|
// src/local/environment-setup.ts
|
|
937
|
-
import { spawn
|
|
614
|
+
import { spawn } from "child_process";
|
|
938
615
|
import * as fs3 from "fs/promises";
|
|
939
|
-
import * as
|
|
616
|
+
import * as path3 from "path";
|
|
940
617
|
var MANAGER_PRIORITY = ["uv", "poetry", "conda", "venv"];
|
|
941
618
|
var PROBE_TIMEOUT_MS = 5e3;
|
|
942
619
|
var DEFAULT_PYTHON_VERSION = "3.12";
|
|
@@ -955,23 +632,23 @@ function testDependencies(playwrightVersion, packages) {
|
|
|
955
632
|
return [...base, `playwright==${playwrightVersion}`].join(" ");
|
|
956
633
|
}
|
|
957
634
|
function probeCommand(cmd, args) {
|
|
958
|
-
return new Promise((
|
|
635
|
+
return new Promise((resolve6) => {
|
|
959
636
|
let output = "";
|
|
960
637
|
let settled = false;
|
|
961
638
|
const finish = (value) => {
|
|
962
639
|
if (settled) return;
|
|
963
640
|
settled = true;
|
|
964
641
|
clearTimeout(timer);
|
|
965
|
-
|
|
642
|
+
resolve6(value);
|
|
966
643
|
};
|
|
967
644
|
let child;
|
|
968
645
|
try {
|
|
969
|
-
child =
|
|
646
|
+
child = spawn(cmd, args, {
|
|
970
647
|
stdio: ["ignore", "pipe", "pipe"],
|
|
971
648
|
shell: process.platform === "win32"
|
|
972
649
|
});
|
|
973
650
|
} catch {
|
|
974
|
-
|
|
651
|
+
resolve6(null);
|
|
975
652
|
return;
|
|
976
653
|
}
|
|
977
654
|
const timer = setTimeout(() => {
|
|
@@ -1015,7 +692,7 @@ async function detectProjectFiles(workingDir) {
|
|
|
1015
692
|
];
|
|
1016
693
|
const found = [];
|
|
1017
694
|
for (const candidate of candidates) {
|
|
1018
|
-
if (await fileExists(
|
|
695
|
+
if (await fileExists(path3.join(workingDir, candidate))) {
|
|
1019
696
|
found.push(candidate);
|
|
1020
697
|
}
|
|
1021
698
|
}
|
|
@@ -1065,6 +742,16 @@ function buildUvSteps(ctx) {
|
|
|
1065
742
|
);
|
|
1066
743
|
return steps;
|
|
1067
744
|
}
|
|
745
|
+
function buildUvBootstrapSteps(ctx) {
|
|
746
|
+
return [
|
|
747
|
+
{
|
|
748
|
+
description: "Install uv, the recommended package manager. It also downloads Python, so nothing else needs to be installed first.",
|
|
749
|
+
command: ctx.isWindows ? UV_INSTALL_COMMANDS.windows : UV_INSTALL_COMMANDS.unix
|
|
750
|
+
},
|
|
751
|
+
{ description: "Open a new terminal so uv is on PATH, then confirm it is installed.", command: "uv --version" },
|
|
752
|
+
...buildUvSteps(ctx)
|
|
753
|
+
];
|
|
754
|
+
}
|
|
1068
755
|
function buildPoetrySteps(ctx) {
|
|
1069
756
|
const deps = testDependencies(ctx.playwrightVersion, ctx.packages);
|
|
1070
757
|
const steps = [
|
|
@@ -1131,12 +818,21 @@ var VERIFY_COMMANDS = {
|
|
|
1131
818
|
conda: "pytest --version",
|
|
1132
819
|
venv: "pytest --version"
|
|
1133
820
|
};
|
|
821
|
+
var UV_INSTALL_COMMANDS = {
|
|
822
|
+
unix: "curl -LsSf https://astral.sh/uv/install.sh | sh",
|
|
823
|
+
windows: 'powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"'
|
|
824
|
+
};
|
|
1134
825
|
var INSTALL_HINTS = {
|
|
1135
826
|
uv: "uv: https://docs.astral.sh/uv/getting-started/installation/",
|
|
1136
827
|
poetry: "poetry: https://python-poetry.org/docs/#installation",
|
|
1137
828
|
conda: "conda (miniconda): https://docs.conda.io/projects/miniconda/en/latest/",
|
|
1138
829
|
venv: "python3 with the venv module: https://www.python.org/downloads/"
|
|
1139
830
|
};
|
|
831
|
+
function installUvNotice(managers) {
|
|
832
|
+
if (managers.some((m) => m.available)) return null;
|
|
833
|
+
const command = process.platform === "win32" ? UV_INSTALL_COMMANDS.windows : UV_INSTALL_COMMANDS.unix;
|
|
834
|
+
return `No Python package manager (uv, poetry, conda or python3 with venv) was found on this machine. Ask the user to install uv first, the recommended option: \`${command}\` (see https://docs.astral.sh/uv/getting-started/installation/). Then call qcentriq_get_setup_instructions for the commands that create the test environment, and restart the MCP client from that environment.`;
|
|
835
|
+
}
|
|
1140
836
|
function detectActiveEnvironment() {
|
|
1141
837
|
if (process.env.VIRTUAL_ENV) {
|
|
1142
838
|
return `virtualenv: ${process.env.VIRTUAL_ENV}`;
|
|
@@ -1147,20 +843,21 @@ function detectActiveEnvironment() {
|
|
|
1147
843
|
return null;
|
|
1148
844
|
}
|
|
1149
845
|
async function buildEnvironmentSetupPlan(params = {}) {
|
|
1150
|
-
const workingDir = params.workingDir ?
|
|
846
|
+
const workingDir = params.workingDir ? path3.resolve(params.workingDir) : process.cwd();
|
|
1151
847
|
const [packageManagers, projectFiles] = await Promise.all([detectPackageManagers(), detectProjectFiles(workingDir)]);
|
|
1152
848
|
const availability = new Map(packageManagers.map((m) => [m.name, m.available]));
|
|
1153
849
|
const preferred = params.preferredManager;
|
|
1154
850
|
const notes = [];
|
|
1155
|
-
let
|
|
851
|
+
let installed;
|
|
1156
852
|
if (preferred && availability.get(preferred)) {
|
|
1157
|
-
|
|
853
|
+
installed = preferred;
|
|
1158
854
|
} else {
|
|
1159
855
|
if (preferred) {
|
|
1160
856
|
notes.push(`Requested package manager "${preferred}" was not found on PATH; falling back to the best available option.`);
|
|
1161
857
|
}
|
|
1162
|
-
|
|
858
|
+
installed = MANAGER_PRIORITY.find((name) => availability.get(name));
|
|
1163
859
|
}
|
|
860
|
+
const recommended = installed ?? "uv";
|
|
1164
861
|
const ctx = {
|
|
1165
862
|
workingDir,
|
|
1166
863
|
isWindows: process.platform === "win32",
|
|
@@ -1174,11 +871,9 @@ async function buildEnvironmentSetupPlan(params = {}) {
|
|
|
1174
871
|
if (activeEnvironment) {
|
|
1175
872
|
notes.push(`An environment is already active (${activeEnvironment}). Reuse it instead of creating a new one if it already has pytest and playwright installed.`);
|
|
1176
873
|
}
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
if (
|
|
1180
|
-
steps = STEP_BUILDERS[recommended](ctx);
|
|
1181
|
-
verifyCommand = VERIFY_COMMANDS[recommended];
|
|
874
|
+
const steps = installed ? STEP_BUILDERS[installed](ctx) : buildUvBootstrapSteps(ctx);
|
|
875
|
+
const verifyCommand = VERIFY_COMMANDS[recommended];
|
|
876
|
+
if (installed) {
|
|
1182
877
|
if (recommended !== "uv" && availability.get("uv")) {
|
|
1183
878
|
notes.push("uv is also available on this machine and is recommended over other package managers for faster, more reliable installs. Pass preferred_manager to override this choice.");
|
|
1184
879
|
}
|
|
@@ -1187,8 +882,8 @@ async function buildEnvironmentSetupPlan(params = {}) {
|
|
|
1187
882
|
notes.push(`Also available on this machine: ${alternatives.join(", ")}. Re-run this tool with preferred_manager to get instructions for one of them.`);
|
|
1188
883
|
}
|
|
1189
884
|
} else {
|
|
1190
|
-
notes.push("No supported Python package manager was found on PATH.
|
|
1191
|
-
for (const name of MANAGER_PRIORITY) {
|
|
885
|
+
notes.push("No supported Python package manager was found on PATH. The steps below install uv, the recommended option. To use a different tool instead, install one of the following and run this tool again:");
|
|
886
|
+
for (const name of MANAGER_PRIORITY.filter((name2) => name2 !== "uv")) {
|
|
1192
887
|
notes.push(` - ${INSTALL_HINTS[name]}`);
|
|
1193
888
|
}
|
|
1194
889
|
}
|
|
@@ -1196,7 +891,7 @@ async function buildEnvironmentSetupPlan(params = {}) {
|
|
|
1196
891
|
"Run these commands in a terminal from the working directory below \u2014 this tool returns instructions only and does not create the environment for you.",
|
|
1197
892
|
"qcentriq_run_local_test resolves pytest from the VIRTUAL_ENV the MCP server was launched with, then falls back to pytest on PATH. After creating a new environment, restart your MCP client (Claude Desktop, Cursor, ...) from an activated shell so local runs pick it up."
|
|
1198
893
|
);
|
|
1199
|
-
logger.debug(`Environment setup plan: recommended=${recommended
|
|
894
|
+
logger.debug(`Environment setup plan: recommended=${recommended}, project files=[${projectFiles.join(", ")}]`);
|
|
1200
895
|
return {
|
|
1201
896
|
working_dir: workingDir,
|
|
1202
897
|
package_managers: packageManagers,
|
|
@@ -1209,7 +904,289 @@ async function buildEnvironmentSetupPlan(params = {}) {
|
|
|
1209
904
|
};
|
|
1210
905
|
}
|
|
1211
906
|
|
|
907
|
+
// src/tools/save-group-script.ts
|
|
908
|
+
var ALLURE_ID = /@allure\.id\(\s*["'][^"']*["']\s*\)/g;
|
|
909
|
+
function registerSaveGroupScriptTool(server, client, config, passingRuns) {
|
|
910
|
+
server.registerTool(
|
|
911
|
+
"qcentriq_save_group_script",
|
|
912
|
+
{
|
|
913
|
+
description: "Save a test script you wrote back to QCentriq so the cloud runner executes exactly what you ran locally. Only a script that passed qcentriq_run_local_test as a whole file, with this exact content, is uploaded; each fixture must match the file next to it when it ran. The script is validated before it is stored: valid Python, and every test case in the group present exactly once as @allure.id('<case_id>') \u2014 no duplicates, no ids from other groups. A rejection names the offending id or line so you can correct it. Pass expected_updated_at from the last download to turn a concurrent edit into a conflict rather than a lost update. conftest.py cannot be saved; QCentriq provides it. Requires the 'test:write' scope.",
|
|
914
|
+
inputSchema: z11.object({
|
|
915
|
+
group_id: z11.uuid().describe("UUID of the target test group."),
|
|
916
|
+
content: z11.string().describe("The Python test script source."),
|
|
917
|
+
project_id: z11.uuid().optional().describe("Optional project UUID (inferred from the API key if omitted)."),
|
|
918
|
+
filename: z11.string().optional().describe("Optional script filename; derived from the group title if omitted."),
|
|
919
|
+
fixtures: z11.array(z11.object({ file_name: z11.string(), content: z11.string() })).optional().describe("Companion files to store next to the script (page objects, test data). conftest.py is rejected."),
|
|
920
|
+
expected_updated_at: z11.string().optional().describe("ISO-8601 timestamp from the last download. Supply it to get a conflict instead of silently overwriting someone else's edit.")
|
|
921
|
+
}),
|
|
922
|
+
annotations: {
|
|
923
|
+
readOnlyHint: false,
|
|
924
|
+
destructiveHint: true,
|
|
925
|
+
// Replaces the group's existing script.
|
|
926
|
+
idempotentHint: true,
|
|
927
|
+
// Saving the same content twice leaves the same state.
|
|
928
|
+
openWorldHint: false
|
|
929
|
+
}
|
|
930
|
+
},
|
|
931
|
+
async (args, ctx) => {
|
|
932
|
+
const untested = await untestedReason(passingRuns, args);
|
|
933
|
+
if (untested) return errorResult(untested);
|
|
934
|
+
const gate = confirmUpload(server, ctx, config, "this test script", describeUpload(args));
|
|
935
|
+
if (!gate.proceed) return gate.result;
|
|
936
|
+
const { group_id, ...body } = args;
|
|
937
|
+
return backendCall(
|
|
938
|
+
"qcentriq_save_group_script",
|
|
939
|
+
() => client.send("PUT", `/groups/${group_id}/script`, { ...body, project_id: body.project_id || config.defaultProjectId })
|
|
940
|
+
);
|
|
941
|
+
}
|
|
942
|
+
);
|
|
943
|
+
}
|
|
944
|
+
async function untestedReason(passingRuns, args) {
|
|
945
|
+
const run = passingRuns.find(args.content);
|
|
946
|
+
if (!run) {
|
|
947
|
+
const reason = "Upload refused: this script has not passed a local run, so nothing was sent to QCentriq. Save it to disk, run it with qcentriq_run_local_test on the whole file until it passes, then call this tool again with exactly that content.";
|
|
948
|
+
const notice = installUvNotice(await detectPackageManagers());
|
|
949
|
+
return notice ? `${reason}
|
|
950
|
+
|
|
951
|
+
${notice}` : reason;
|
|
952
|
+
}
|
|
953
|
+
const mismatch = await fixtureMismatch(run, args.fixtures ?? []);
|
|
954
|
+
if (mismatch) {
|
|
955
|
+
return `Upload refused: ${mismatch}, so nothing was sent to QCentriq. Re-run ${run.filePath} with qcentriq_run_local_test and upload the files exactly as they were when it passed.`;
|
|
956
|
+
}
|
|
957
|
+
return null;
|
|
958
|
+
}
|
|
959
|
+
function describeUpload(args) {
|
|
960
|
+
const cases = args.content.match(ALLURE_ID)?.length ?? 0;
|
|
961
|
+
const file = args.filename ? `"${args.filename}"` : "(named after the group)";
|
|
962
|
+
const fixtures = args.fixtures?.length ? ` plus ${plural(args.fixtures.length, "companion file")} (${args.fixtures.map((f) => f.file_name).join(", ")})` : "";
|
|
963
|
+
return `Upload test script ${file}${fixtures} to QCentriq test group ${args.group_id}? It contains ${plural(cases, "test case")} and replaces the group's current script.`;
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
// src/tools/local-run.ts
|
|
967
|
+
import { z as z12 } from "zod";
|
|
968
|
+
import * as fs4 from "fs/promises";
|
|
969
|
+
import * as path5 from "path";
|
|
970
|
+
|
|
971
|
+
// src/local/runner.ts
|
|
972
|
+
import { spawn as spawn2 } from "child_process";
|
|
973
|
+
import * as path4 from "path";
|
|
974
|
+
function buildTestEnv(params) {
|
|
975
|
+
const env = {
|
|
976
|
+
...process.env,
|
|
977
|
+
...params.envVars || {}
|
|
978
|
+
};
|
|
979
|
+
if (params.baseUrl) {
|
|
980
|
+
env.BASE_URL = params.baseUrl;
|
|
981
|
+
}
|
|
982
|
+
if (params.browser) {
|
|
983
|
+
env.BROWSER = params.browser;
|
|
984
|
+
}
|
|
985
|
+
if (params.headless !== void 0) {
|
|
986
|
+
env.HEADLESS = params.headless ? "true" : "false";
|
|
987
|
+
}
|
|
988
|
+
if (params.groupId) {
|
|
989
|
+
env.QCAQ_TEST_GROUP_ID = params.groupId;
|
|
990
|
+
}
|
|
991
|
+
return env;
|
|
992
|
+
}
|
|
993
|
+
function resolvePytestCommand() {
|
|
994
|
+
const venv = process.env.VIRTUAL_ENV;
|
|
995
|
+
if (!venv) return "pytest";
|
|
996
|
+
return process.platform === "win32" ? path4.join(venv, "Scripts", "pytest.exe") : path4.join(venv, "bin", "pytest");
|
|
997
|
+
}
|
|
998
|
+
function killProcessTree(child) {
|
|
999
|
+
if (child.pid && process.platform !== "win32") {
|
|
1000
|
+
try {
|
|
1001
|
+
process.kill(-child.pid, "SIGKILL");
|
|
1002
|
+
return;
|
|
1003
|
+
} catch {
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
try {
|
|
1007
|
+
child.kill("SIGKILL");
|
|
1008
|
+
} catch {
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
function attempt(cmd, args, cwd, env, timeoutMs) {
|
|
1012
|
+
return new Promise((resolve6) => {
|
|
1013
|
+
let stdout = "";
|
|
1014
|
+
let stderr = "";
|
|
1015
|
+
let settled = false;
|
|
1016
|
+
const settle = (result) => {
|
|
1017
|
+
if (settled) return;
|
|
1018
|
+
settled = true;
|
|
1019
|
+
clearTimeout(timer);
|
|
1020
|
+
resolve6(result);
|
|
1021
|
+
};
|
|
1022
|
+
const child = spawn2(cmd, args, {
|
|
1023
|
+
cwd,
|
|
1024
|
+
env,
|
|
1025
|
+
detached: process.platform !== "win32",
|
|
1026
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
1027
|
+
});
|
|
1028
|
+
const timer = setTimeout(() => {
|
|
1029
|
+
killProcessTree(child);
|
|
1030
|
+
settle({ launched: true, exitCode: -1, stdout, stderr, timedOut: true });
|
|
1031
|
+
}, timeoutMs);
|
|
1032
|
+
child.stdout?.on("data", (chunk) => stdout += chunk.toString());
|
|
1033
|
+
child.stderr?.on("data", (chunk) => stderr += chunk.toString());
|
|
1034
|
+
child.on("error", (error) => settle({ launched: false, error }));
|
|
1035
|
+
child.on("close", (code) => settle({ launched: true, exitCode: code ?? -1, stdout, stderr, timedOut: false }));
|
|
1036
|
+
});
|
|
1037
|
+
}
|
|
1038
|
+
async function runLocalPytest(params) {
|
|
1039
|
+
const startTime = Date.now();
|
|
1040
|
+
const cwd = params.workingDir ? path4.resolve(params.workingDir) : process.cwd();
|
|
1041
|
+
const timeoutSeconds = params.timeoutSeconds || 60;
|
|
1042
|
+
const args = [params.filePath];
|
|
1043
|
+
if (params.testName) {
|
|
1044
|
+
args.push("-k", params.testName);
|
|
1045
|
+
}
|
|
1046
|
+
if (params.extraArgs) {
|
|
1047
|
+
args.push(...params.extraArgs);
|
|
1048
|
+
}
|
|
1049
|
+
if (!args.includes("-v") && !args.includes("-vv")) {
|
|
1050
|
+
args.push("-v");
|
|
1051
|
+
}
|
|
1052
|
+
const env = buildTestEnv(params);
|
|
1053
|
+
const failure = (stderr, command, pytestMissing) => ({
|
|
1054
|
+
passed: false,
|
|
1055
|
+
exitCode: -1,
|
|
1056
|
+
stdout: "",
|
|
1057
|
+
stderr,
|
|
1058
|
+
durationMs: Date.now() - startTime,
|
|
1059
|
+
command,
|
|
1060
|
+
pytestMissing
|
|
1061
|
+
});
|
|
1062
|
+
let cmd = resolvePytestCommand();
|
|
1063
|
+
let cmdArgs = args;
|
|
1064
|
+
logger.info(`Running local test command: ${cmd} ${cmdArgs.join(" ")} in ${cwd}`);
|
|
1065
|
+
let outcome = await attempt(cmd, cmdArgs, cwd, env, timeoutSeconds * 1e3);
|
|
1066
|
+
if (!outcome.launched) {
|
|
1067
|
+
if (outcome.error.code !== "ENOENT") {
|
|
1068
|
+
return failure(`Failed to spawn process: ${outcome.error.message}. Ensure pytest is installed in your Python environment.`, `${cmd} ${cmdArgs.join(" ")}`, false);
|
|
1069
|
+
}
|
|
1070
|
+
logger.warn("pytest binary not found directly, falling back to python3 -m pytest...");
|
|
1071
|
+
const primary = `${cmd} ${cmdArgs.join(" ")}`;
|
|
1072
|
+
cmd = "python3";
|
|
1073
|
+
cmdArgs = ["-m", "pytest", ...args];
|
|
1074
|
+
outcome = await attempt(cmd, cmdArgs, cwd, env, timeoutSeconds * 1e3);
|
|
1075
|
+
if (!outcome.launched) {
|
|
1076
|
+
return failure(`Failed to execute pytest or python3 -m pytest: ${outcome.error.message}. Ensure pytest is installed in your Python environment.`, primary, true);
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
return {
|
|
1080
|
+
passed: !outcome.timedOut && outcome.exitCode === 0,
|
|
1081
|
+
exitCode: outcome.exitCode,
|
|
1082
|
+
stdout: outcome.stdout,
|
|
1083
|
+
stderr: outcome.timedOut ? `${outcome.stderr}
|
|
1084
|
+
[TIMEOUT] Test execution timed out after ${timeoutSeconds} seconds.` : outcome.stderr,
|
|
1085
|
+
durationMs: Date.now() - startTime,
|
|
1086
|
+
command: `${cmd} ${cmdArgs.join(" ")}`,
|
|
1087
|
+
pytestMissing: /No module named pytest/.test(outcome.stderr)
|
|
1088
|
+
};
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
// src/tools/local-run.ts
|
|
1092
|
+
function registerLocalRunTool(server, passingRuns) {
|
|
1093
|
+
server.registerTool(
|
|
1094
|
+
"qcentriq_run_local_test",
|
|
1095
|
+
{
|
|
1096
|
+
description: "Execute a downloaded Playwright/pytest test script locally in the developer's environment. Runs pytest as a local subprocess and returns stdout, stderr, exit code, and test diagnostics without using QCentriq cloud runners. A script must pass here, as a whole file (no test_name or other test filters), before qcentriq_save_group_script will upload it.",
|
|
1097
|
+
inputSchema: z12.object({
|
|
1098
|
+
file_path: z12.string().describe("Path to the local test file to run (e.g. 'tests/test_login.py')."),
|
|
1099
|
+
test_name: z12.string().optional().describe("Optional specific test function name or expression to run (passed to pytest -k)."),
|
|
1100
|
+
headless: z12.boolean().default(true).describe("Whether to run the browser in headless mode (default True). Set False to watch the browser execution live."),
|
|
1101
|
+
browser: z12.enum(["chromium", "firefox", "webkit"]).default("chromium").describe("Browser engine to execute against (default 'chromium')."),
|
|
1102
|
+
base_url: z12.url().optional().describe("Target application base URL (e.g. from qcentriq_get_environment). Injected as BASE_URL env var."),
|
|
1103
|
+
group_id: z12.string().optional().describe("Test group UUID this script belongs to. Injected as QCAQ_TEST_GROUP_ID so the Allure results stay mappable back to the QCentriq group."),
|
|
1104
|
+
env_vars: z12.record(z12.string(), z12.string()).optional().describe("Environment variables to inject into the local test process."),
|
|
1105
|
+
extra_args: z12.array(z12.string()).optional().describe("Additional CLI arguments to pass to pytest (e.g. ['-s', '--alluredir=allure-results'])."),
|
|
1106
|
+
timeout_seconds: z12.number().int().min(5).max(300).default(60).describe("Timeout in seconds for test execution (default 60)."),
|
|
1107
|
+
working_dir: z12.string().optional().describe("Working directory to run pytest in (defaults to current project directory).")
|
|
1108
|
+
})
|
|
1109
|
+
},
|
|
1110
|
+
async (args) => {
|
|
1111
|
+
try {
|
|
1112
|
+
const scriptPath = path5.resolve(args.working_dir ?? process.cwd(), args.file_path.split("::")[0]);
|
|
1113
|
+
const content = await fs4.readFile(scriptPath, "utf-8").catch(() => null);
|
|
1114
|
+
const startedAt = Date.now();
|
|
1115
|
+
const result = await runLocalPytest({
|
|
1116
|
+
filePath: args.file_path,
|
|
1117
|
+
testName: args.test_name,
|
|
1118
|
+
headless: args.headless,
|
|
1119
|
+
browser: args.browser,
|
|
1120
|
+
baseUrl: args.base_url,
|
|
1121
|
+
groupId: args.group_id,
|
|
1122
|
+
envVars: args.env_vars,
|
|
1123
|
+
extraArgs: args.extra_args,
|
|
1124
|
+
timeoutSeconds: args.timeout_seconds,
|
|
1125
|
+
workingDir: args.working_dir
|
|
1126
|
+
});
|
|
1127
|
+
const statusText = result.passed ? "PASSED" : "FAILED";
|
|
1128
|
+
const summary = [
|
|
1129
|
+
`Local Test Run Result: ${statusText} (exit code ${result.exitCode})`,
|
|
1130
|
+
`Duration: ${(result.durationMs / 1e3).toFixed(2)}s`,
|
|
1131
|
+
`Command: ${result.command}`,
|
|
1132
|
+
"",
|
|
1133
|
+
"--- STDOUT ---",
|
|
1134
|
+
result.stdout || "(no stdout)",
|
|
1135
|
+
"",
|
|
1136
|
+
"--- STDERR ---",
|
|
1137
|
+
result.stderr || "(no stderr)"
|
|
1138
|
+
];
|
|
1139
|
+
const next = await nextStep(result, args, content !== null);
|
|
1140
|
+
if (next.uploadable && content !== null) {
|
|
1141
|
+
passingRuns.record(content, { filePath: scriptPath, dir: path5.dirname(scriptPath), startedAt });
|
|
1142
|
+
}
|
|
1143
|
+
if (next.text) summary.push("", next.text);
|
|
1144
|
+
return {
|
|
1145
|
+
content: [
|
|
1146
|
+
{
|
|
1147
|
+
type: "text",
|
|
1148
|
+
text: summary.join("\n")
|
|
1149
|
+
}
|
|
1150
|
+
],
|
|
1151
|
+
isError: !result.passed
|
|
1152
|
+
};
|
|
1153
|
+
} catch (err) {
|
|
1154
|
+
return {
|
|
1155
|
+
isError: true,
|
|
1156
|
+
content: [
|
|
1157
|
+
{
|
|
1158
|
+
type: "text",
|
|
1159
|
+
text: `Error executing local test: ${err.message}`
|
|
1160
|
+
}
|
|
1161
|
+
]
|
|
1162
|
+
};
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
);
|
|
1166
|
+
}
|
|
1167
|
+
async function nextStep(result, args, scriptReadable) {
|
|
1168
|
+
if (result.pytestMissing) {
|
|
1169
|
+
const notice = installUvNotice(await detectPackageManagers());
|
|
1170
|
+
return {
|
|
1171
|
+
uploadable: false,
|
|
1172
|
+
text: notice ?? "pytest is not installed in the Python environment the MCP server runs with. Call qcentriq_get_setup_instructions for the commands that set one up."
|
|
1173
|
+
};
|
|
1174
|
+
}
|
|
1175
|
+
if (!result.passed) return { uploadable: false };
|
|
1176
|
+
if (!coversWholeFile(args.file_path, args.test_name, args.extra_args)) {
|
|
1177
|
+
return { uploadable: false, text: "Only part of the script ran. Run the whole file, without test_name or test filters, before uploading it with qcentriq_save_group_script." };
|
|
1178
|
+
}
|
|
1179
|
+
if (!scriptReadable) {
|
|
1180
|
+
return { uploadable: false, text: "file_path is not a readable script file, so this pass cannot qualify an upload. Run the single script file you intend to upload." };
|
|
1181
|
+
}
|
|
1182
|
+
if (!reportsPassedTests(result.stdout)) {
|
|
1183
|
+
return { uploadable: false, text: "No test actually passed (all skipped or none collected), so this script cannot be uploaded yet." };
|
|
1184
|
+
}
|
|
1185
|
+
return { uploadable: true, text: "This exact script passed locally and can now be uploaded with qcentriq_save_group_script." };
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1212
1188
|
// src/tools/setup-instructions.ts
|
|
1189
|
+
import { z as z13 } from "zod";
|
|
1213
1190
|
async function fetchRuntimeRequirements(client) {
|
|
1214
1191
|
if (!client) return {};
|
|
1215
1192
|
try {
|
|
@@ -1227,14 +1204,14 @@ function registerSetupInstructionsTool(server, client) {
|
|
|
1227
1204
|
server.registerTool(
|
|
1228
1205
|
"qcentriq_get_setup_instructions",
|
|
1229
1206
|
{
|
|
1230
|
-
description: "Check which Python package managers (uv, poetry, conda, or the stdlib venv module) are installed on the developer's machine and return step-by-step commands for creating an environment that can run QCentriq Playwright/pytest tests locally. Prefers uv when it is available. Returns instructions only \u2014 it does not create the environment.",
|
|
1231
|
-
inputSchema: {
|
|
1232
|
-
preferred_manager:
|
|
1233
|
-
working_dir:
|
|
1234
|
-
env_name:
|
|
1235
|
-
python_version:
|
|
1236
|
-
playwright_version:
|
|
1237
|
-
},
|
|
1207
|
+
description: "Check which Python package managers (uv, poetry, conda, or the stdlib venv module) are installed on the developer's machine and return step-by-step commands for creating an environment that can run QCentriq Playwright/pytest tests locally. Prefers uv when it is available; if no package manager is installed, the steps start by installing uv. Returns instructions only \u2014 it does not create the environment.",
|
|
1208
|
+
inputSchema: z13.object({
|
|
1209
|
+
preferred_manager: z13.enum(["uv", "poetry", "conda", "venv"]).optional().describe("Force instructions for a specific package manager. Falls back to the best available one if it is not installed."),
|
|
1210
|
+
working_dir: z13.string().optional().describe("Directory to inspect for pyproject.toml / lockfiles / requirements.txt (defaults to the current project directory)."),
|
|
1211
|
+
env_name: z13.string().default("qcentriq-tests").describe("Name for the created environment (used by conda, default 'qcentriq-tests')."),
|
|
1212
|
+
python_version: z13.string().default("3.12").describe("Python version to request when creating the environment (default '3.12', matching the QCentriq execution container)."),
|
|
1213
|
+
playwright_version: z13.string().optional().describe("Playwright version to pin when installing test dependencies. Defaults to the version the project's active execution image is built against, as reported by the backend.")
|
|
1214
|
+
}),
|
|
1238
1215
|
annotations: {
|
|
1239
1216
|
readOnlyHint: true,
|
|
1240
1217
|
// Only probes local package managers and project files; never mutates local or remote state.
|
|
@@ -1264,8 +1241,7 @@ function registerSetupInstructionsTool(server, client) {
|
|
|
1264
1241
|
type: "text",
|
|
1265
1242
|
text: JSON.stringify(plan, null, 2)
|
|
1266
1243
|
}
|
|
1267
|
-
]
|
|
1268
|
-
isError: plan.recommended_manager === null
|
|
1244
|
+
]
|
|
1269
1245
|
};
|
|
1270
1246
|
} catch (err) {
|
|
1271
1247
|
return {
|
|
@@ -1285,6 +1261,7 @@ function registerSetupInstructionsTool(server, client) {
|
|
|
1285
1261
|
// src/tools/index.ts
|
|
1286
1262
|
function registerAllTools(server, client, config) {
|
|
1287
1263
|
logger.debug("Registering QCentriq MCP tools...");
|
|
1264
|
+
const passingRuns = new PassingRunLedger();
|
|
1288
1265
|
registerListTestsTool(server, client, config);
|
|
1289
1266
|
registerGetTestTool(server, client, config);
|
|
1290
1267
|
registerGetTestGroupsTool(server, client, config);
|
|
@@ -1293,34 +1270,35 @@ function registerAllTools(server, client, config) {
|
|
|
1293
1270
|
registerRunLogsTool(server, client, config);
|
|
1294
1271
|
registerAuthoringGuideTool(server, client);
|
|
1295
1272
|
registerCreatePlanTool(server, client, config);
|
|
1296
|
-
registerSaveGroupScriptTool(server, client, config);
|
|
1273
|
+
registerSaveGroupScriptTool(server, client, config, passingRuns);
|
|
1297
1274
|
registerSaveScriptTool(server);
|
|
1298
|
-
registerLocalRunTool(server);
|
|
1275
|
+
registerLocalRunTool(server, passingRuns);
|
|
1299
1276
|
registerSetupInstructionsTool(server, client);
|
|
1300
|
-
logger.info("
|
|
1277
|
+
logger.info("Registered QCentriq MCP tools.");
|
|
1301
1278
|
}
|
|
1302
1279
|
|
|
1280
|
+
// src/version.ts
|
|
1281
|
+
import { createRequire } from "module";
|
|
1282
|
+
var PACKAGE_VERSION = createRequire(import.meta.url)("../package.json").version;
|
|
1283
|
+
|
|
1303
1284
|
// src/index.ts
|
|
1304
|
-
|
|
1285
|
+
function main() {
|
|
1305
1286
|
try {
|
|
1306
1287
|
const config = loadConfig(process.argv);
|
|
1307
1288
|
logger.info(`Starting QCentriq MCP Server against: ${config.baseUrl}`);
|
|
1308
1289
|
const apiClient = new QCentriqApiClient(config);
|
|
1309
|
-
const
|
|
1310
|
-
name: "@qcentriq/mcp",
|
|
1311
|
-
|
|
1290
|
+
const handle = serveStdio(() => {
|
|
1291
|
+
const server = new McpServer2({ name: "@qcentriq/mcp", version: PACKAGE_VERSION });
|
|
1292
|
+
registerAllTools(server, apiClient, config);
|
|
1293
|
+
return server;
|
|
1312
1294
|
});
|
|
1313
|
-
registerAllTools(server, apiClient, config);
|
|
1314
|
-
const transport = new StdioServerTransport();
|
|
1315
1295
|
const cleanup = async () => {
|
|
1316
1296
|
logger.info("Shutting down QCentriq MCP Server...");
|
|
1317
|
-
await
|
|
1318
|
-
await server.close();
|
|
1297
|
+
await handle.close();
|
|
1319
1298
|
process.exit(0);
|
|
1320
1299
|
};
|
|
1321
1300
|
process.on("SIGINT", cleanup);
|
|
1322
1301
|
process.on("SIGTERM", cleanup);
|
|
1323
|
-
await server.connect(transport);
|
|
1324
1302
|
logger.info("QCentriq MCP Server is running on stdio.");
|
|
1325
1303
|
} catch (err) {
|
|
1326
1304
|
logger.error("Fatal error during QCentriq MCP Server startup:", err.message);
|