@qcentriq/mcp 0.1.0 → 0.3.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 +165 -39
- package/dist/index.js +715 -165
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -63,10 +63,6 @@ function loadConfig(argv = process.argv) {
|
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
// src/client/api.ts
|
|
67
|
-
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
68
|
-
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
69
|
-
|
|
70
66
|
// src/utils/sanitizer.ts
|
|
71
67
|
var QCENTRIQ_KEY_REGEX = /qc_[0-9a-fA-F]{30,45}/g;
|
|
72
68
|
var BEARER_TOKEN_REGEX = /Bearer\s+ey[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+/=]*/g;
|
|
@@ -102,121 +98,187 @@ function sanitizePayload(value) {
|
|
|
102
98
|
// src/client/api.ts
|
|
103
99
|
var QCentriqApiClient = class {
|
|
104
100
|
config;
|
|
105
|
-
mcpClient = null;
|
|
106
|
-
mcpTransport = null;
|
|
107
|
-
isConnecting = false;
|
|
108
|
-
connectPromise = null;
|
|
109
101
|
constructor(config) {
|
|
110
102
|
this.config = config;
|
|
111
103
|
}
|
|
112
104
|
/**
|
|
113
|
-
*
|
|
114
|
-
* All QCentriq backend operations are handled via this single SSE connection.
|
|
105
|
+
* Make an authenticated HTTP request to the QCentriq backend (/api/v1/mcp-client/...).
|
|
115
106
|
*/
|
|
116
|
-
async
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
107
|
+
async request(path5, params = {}) {
|
|
108
|
+
const cleanPath = path5.startsWith("/") ? path5 : `/${path5}`;
|
|
109
|
+
const url = new URL(`${this.config.baseUrl}/api/v1/mcp-client${cleanPath}`);
|
|
110
|
+
for (const [key, value] of Object.entries(params)) {
|
|
111
|
+
if (value !== void 0 && value !== null) {
|
|
112
|
+
url.searchParams.set(key, String(value));
|
|
113
|
+
}
|
|
123
114
|
}
|
|
124
|
-
|
|
125
|
-
|
|
115
|
+
logger.debug(`[mcp-client] HTTP GET ${url.toString()}`);
|
|
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;
|
|
126
125
|
try {
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
this.mcpClient = new Client(
|
|
138
|
-
{
|
|
139
|
-
name: "qcentriq-mcp-cli",
|
|
140
|
-
version: "1.0.0"
|
|
141
|
-
},
|
|
142
|
-
{
|
|
143
|
-
capabilities: {}
|
|
144
|
-
}
|
|
145
|
-
);
|
|
146
|
-
await this.mcpClient.connect(this.mcpTransport);
|
|
147
|
-
logger.info("Connected to QCentriq backend /api/v1/mcp/sse successfully.");
|
|
148
|
-
} catch (err) {
|
|
149
|
-
logger.error(`Failed to connect to QCentriq MCP SSE: ${err.message}`);
|
|
150
|
-
this.mcpClient = null;
|
|
151
|
-
this.mcpTransport = null;
|
|
152
|
-
throw new Error(`Could not connect to QCentriq MCP endpoint: ${err.message}`);
|
|
153
|
-
} finally {
|
|
154
|
-
this.isConnecting = false;
|
|
155
|
-
}
|
|
156
|
-
})();
|
|
157
|
-
await this.connectPromise;
|
|
158
|
-
if (!this.mcpClient) {
|
|
159
|
-
throw new Error("Failed to initialize MCP client.");
|
|
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}`);
|
|
160
133
|
}
|
|
161
|
-
|
|
134
|
+
const data = await res.json();
|
|
135
|
+
return sanitizePayload(data);
|
|
162
136
|
}
|
|
163
137
|
/**
|
|
164
|
-
*
|
|
138
|
+
* Make an authenticated write request to the QCentriq backend.
|
|
139
|
+
*
|
|
140
|
+
* Separate from `request`, which is GET-only: a write must never be retried
|
|
141
|
+
* or cached the way a read can be.
|
|
165
142
|
*/
|
|
166
|
-
async
|
|
167
|
-
const
|
|
168
|
-
const
|
|
169
|
-
|
|
143
|
+
async send(method, path5, body) {
|
|
144
|
+
const cleanPath = path5.startsWith("/") ? path5 : `/${path5}`;
|
|
145
|
+
const url = `${this.config.baseUrl}/api/v1/mcp-client${cleanPath}`;
|
|
146
|
+
logger.debug(`[mcp-client] HTTP ${method} ${url}`);
|
|
147
|
+
const res = await fetch(url, {
|
|
148
|
+
method,
|
|
149
|
+
headers: {
|
|
150
|
+
Authorization: `Bearer ${this.config.apiKey}`,
|
|
151
|
+
Accept: "application/json",
|
|
152
|
+
"Content-Type": "application/json"
|
|
153
|
+
},
|
|
154
|
+
body: JSON.stringify(body)
|
|
155
|
+
});
|
|
156
|
+
if (!res.ok) {
|
|
157
|
+
let errorDetail = res.statusText;
|
|
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}`);
|
|
166
|
+
}
|
|
167
|
+
const data = await res.json();
|
|
168
|
+
return sanitizePayload(data);
|
|
170
169
|
}
|
|
171
170
|
/**
|
|
172
|
-
* Invoke
|
|
171
|
+
* Invoke remote tool via /api/v1/mcp-client REST endpoints and wrap
|
|
172
|
+
* response in standard MCP CallToolResult format.
|
|
173
173
|
*/
|
|
174
174
|
async callRemoteTool(toolName, args) {
|
|
175
|
-
const client = await this.ensureMcpConnected();
|
|
176
175
|
logger.debug(`Invoking remote tool "${toolName}" with arguments:`, args);
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
176
|
+
let data;
|
|
177
|
+
switch (toolName) {
|
|
178
|
+
case "qcentriq_list_tests": {
|
|
179
|
+
const { project_id, group_id, priority, test_type, status, limit, offset } = args;
|
|
180
|
+
data = await this.request("/tests", {
|
|
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;
|
|
246
|
+
}
|
|
247
|
+
default:
|
|
248
|
+
throw new Error(`Unknown tool: ${toolName}`);
|
|
190
249
|
}
|
|
250
|
+
return {
|
|
251
|
+
content: [
|
|
252
|
+
{
|
|
253
|
+
type: "text",
|
|
254
|
+
text: JSON.stringify(data, null, 2)
|
|
255
|
+
}
|
|
256
|
+
]
|
|
257
|
+
};
|
|
191
258
|
}
|
|
192
259
|
/**
|
|
193
|
-
* Close
|
|
260
|
+
* Close client session on shutdown (no-op for stateless HTTP client).
|
|
194
261
|
*/
|
|
195
262
|
async close() {
|
|
196
|
-
if (this.mcpClient) {
|
|
197
|
-
try {
|
|
198
|
-
await this.mcpClient.close();
|
|
199
|
-
} catch {
|
|
200
|
-
}
|
|
201
|
-
this.mcpClient = null;
|
|
202
|
-
this.mcpTransport = null;
|
|
203
|
-
}
|
|
204
263
|
}
|
|
205
264
|
};
|
|
206
265
|
|
|
207
266
|
// src/tools/list-tests.ts
|
|
208
267
|
import { z } from "zod";
|
|
209
268
|
function registerListTestsTool(server, client, config) {
|
|
210
|
-
server.
|
|
269
|
+
server.registerTool(
|
|
211
270
|
"qcentriq_list_tests",
|
|
212
|
-
"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.",
|
|
213
271
|
{
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
272
|
+
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: {
|
|
274
|
+
project_id: z.uuid().optional().describe("Optional project UUID (inferred from API key if omitted)."),
|
|
275
|
+
group_id: z.uuid().optional().describe("Optional test group UUID filter."),
|
|
276
|
+
priority: z.enum(["low", "medium", "high", "critical"]).optional().describe("Filter by priority."),
|
|
277
|
+
test_type: z.enum(["web", "api", "mobile"]).optional().describe("Filter by test type."),
|
|
278
|
+
status: z.enum(["failed", "passed", "error", "never_run", "blocked", "active", "flaky"]).optional().describe("Filter by test status (e.g. 'failed' or 'blocked')."),
|
|
279
|
+
limit: z.number().int().min(1).max(100).default(50).describe("Max number of test cases to return (default 50)."),
|
|
280
|
+
offset: z.number().int().min(0).default(0).describe("Pagination offset.")
|
|
281
|
+
}
|
|
220
282
|
},
|
|
221
283
|
async (args) => {
|
|
222
284
|
try {
|
|
@@ -239,12 +301,14 @@ function registerListTestsTool(server, client, config) {
|
|
|
239
301
|
// src/tools/get-test.ts
|
|
240
302
|
import { z as z2 } from "zod";
|
|
241
303
|
function registerGetTestTool(server, client, config) {
|
|
242
|
-
server.
|
|
304
|
+
server.registerTool(
|
|
243
305
|
"qcentriq_get_test",
|
|
244
|
-
"Retrieve detailed test case information including step definitions, preconditions, latest execution diagnostics, error stack traces, and parent test group script metadata.",
|
|
245
306
|
{
|
|
246
|
-
|
|
247
|
-
|
|
307
|
+
description: "Retrieve detailed test case information including step definitions, preconditions, latest execution diagnostics, error stack traces, and parent test group script metadata.",
|
|
308
|
+
inputSchema: {
|
|
309
|
+
test_case_id: z2.uuid().describe("UUID of the target test case."),
|
|
310
|
+
project_id: z2.uuid().optional().describe("Optional project UUID (inferred from API key if omitted).")
|
|
311
|
+
}
|
|
248
312
|
},
|
|
249
313
|
async (args) => {
|
|
250
314
|
try {
|
|
@@ -267,14 +331,16 @@ function registerGetTestTool(server, client, config) {
|
|
|
267
331
|
// src/tools/get-groups.ts
|
|
268
332
|
import { z as z3 } from "zod";
|
|
269
333
|
function registerGetTestGroupsTool(server, client, config) {
|
|
270
|
-
server.
|
|
334
|
+
server.registerTool(
|
|
271
335
|
"qcentriq_get_test_groups",
|
|
272
|
-
"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.",
|
|
273
336
|
{
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
337
|
+
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: {
|
|
339
|
+
project_id: z3.uuid().optional().describe("Optional project UUID (inferred from API key if omitted)."),
|
|
340
|
+
group_id: z3.uuid().optional().describe("Optional test group UUID filter to inspect a specific group."),
|
|
341
|
+
limit: z3.number().int().min(1).max(100).default(50).describe("Max test groups to return (default 50)."),
|
|
342
|
+
offset: z3.number().int().min(0).default(0).describe("Pagination offset.")
|
|
343
|
+
}
|
|
278
344
|
},
|
|
279
345
|
async (args) => {
|
|
280
346
|
try {
|
|
@@ -299,15 +365,17 @@ import { z as z4 } from "zod";
|
|
|
299
365
|
import * as fs from "fs/promises";
|
|
300
366
|
import * as path from "path";
|
|
301
367
|
function registerDownloadScriptTool(server, client, config) {
|
|
302
|
-
server.
|
|
368
|
+
server.registerTool(
|
|
303
369
|
"qcentriq_download_script",
|
|
304
|
-
"Download test group script and accompanying fixture files (e.g. conftest.py) for local test execution and editing. Optionally writes files directly to the local filesystem.",
|
|
305
370
|
{
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
371
|
+
description: "Download test group script and accompanying fixture files (e.g. conftest.py) for local test execution and editing. Optionally writes files directly to the local filesystem.",
|
|
372
|
+
inputSchema: {
|
|
373
|
+
group_id: z4.uuid().describe("UUID of the target test group."),
|
|
374
|
+
project_id: z4.uuid().optional().describe("Optional project UUID (inferred from API key if omitted)."),
|
|
375
|
+
include_fixtures: z4.boolean().default(true).describe("Whether to retrieve accompanying conftest.py / fixtures (default True)."),
|
|
376
|
+
save_to_disk: z4.boolean().default(false).describe("If true, saves the downloaded test script and fixtures directly to the local filesystem."),
|
|
377
|
+
destination_dir: z4.string().default("./tests").describe("Destination directory when save_to_disk is true (defaults to ./tests).")
|
|
378
|
+
}
|
|
311
379
|
},
|
|
312
380
|
async (args) => {
|
|
313
381
|
try {
|
|
@@ -367,14 +435,15 @@ function registerDownloadScriptTool(server, client, config) {
|
|
|
367
435
|
// src/tools/environment.ts
|
|
368
436
|
import { z as z5 } from "zod";
|
|
369
437
|
function registerEnvironmentTool(server, client, config) {
|
|
370
|
-
server.
|
|
438
|
+
server.registerTool(
|
|
371
439
|
"qcentriq_get_environment",
|
|
372
|
-
"Retrieve target test environment configuration, base URL (BASE_URL), environment variables, and secrets for local test execution.",
|
|
373
440
|
{
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
441
|
+
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: z5.uuid().optional().describe("Optional project UUID (inferred from API key if omitted)."),
|
|
444
|
+
environment_id: z5.uuid().optional().describe("Optional specific environment UUID."),
|
|
445
|
+
environment_name: z5.string().optional().describe("Optional environment name filter (e.g. 'staging', 'dev', 'production').")
|
|
446
|
+
}
|
|
378
447
|
},
|
|
379
448
|
async (args) => {
|
|
380
449
|
try {
|
|
@@ -397,19 +466,21 @@ function registerEnvironmentTool(server, client, config) {
|
|
|
397
466
|
// src/tools/run-logs.ts
|
|
398
467
|
import { z as z6 } from "zod";
|
|
399
468
|
function registerRunLogsTool(server, client, config) {
|
|
400
|
-
server.
|
|
469
|
+
server.registerTool(
|
|
401
470
|
"qcentriq_get_test_run_logs",
|
|
402
|
-
"Retrieve execution history and logs for a test case: per-run status, timing, error message, stack trace, and raw output logs across runs.",
|
|
403
471
|
{
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
472
|
+
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: z6.uuid().describe("UUID of the target test case."),
|
|
475
|
+
project_id: z6.uuid().optional().describe("Optional project UUID (inferred from API key if omitted)."),
|
|
476
|
+
run_id: z6.uuid().optional().describe("Optional specific run UUID to fetch a single run's full log."),
|
|
477
|
+
status: z6.enum(["failed", "passed", "error"]).optional().describe("Filter by result status."),
|
|
478
|
+
latest_only: z6.boolean().default(false).describe("If True, returns only the most recent matching run."),
|
|
479
|
+
from_date: z6.string().optional().describe("Optional ISO-8601 start date filter."),
|
|
480
|
+
to_date: z6.string().optional().describe("Optional ISO-8601 end date filter."),
|
|
481
|
+
limit: z6.number().int().min(1).max(100).default(20).describe("Max runs to return."),
|
|
482
|
+
offset: z6.number().int().min(0).default(0).describe("Pagination offset.")
|
|
483
|
+
}
|
|
413
484
|
},
|
|
414
485
|
async (args) => {
|
|
415
486
|
try {
|
|
@@ -429,12 +500,140 @@ function registerRunLogsTool(server, client, config) {
|
|
|
429
500
|
);
|
|
430
501
|
}
|
|
431
502
|
|
|
432
|
-
// src/tools/
|
|
503
|
+
// src/tools/authoring-guide.ts
|
|
504
|
+
function registerAuthoringGuideTool(server, client) {
|
|
505
|
+
server.registerTool(
|
|
506
|
+
"qcentriq_get_authoring_guide",
|
|
507
|
+
{
|
|
508
|
+
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: {},
|
|
510
|
+
annotations: {
|
|
511
|
+
readOnlyHint: true,
|
|
512
|
+
destructiveHint: false,
|
|
513
|
+
idempotentHint: true,
|
|
514
|
+
openWorldHint: false
|
|
515
|
+
}
|
|
516
|
+
},
|
|
517
|
+
async () => {
|
|
518
|
+
try {
|
|
519
|
+
const guide = await client.request("/authoring-guide");
|
|
520
|
+
return {
|
|
521
|
+
content: [{ type: "text", text: JSON.stringify(guide, null, 2) }]
|
|
522
|
+
};
|
|
523
|
+
} catch (err) {
|
|
524
|
+
return {
|
|
525
|
+
isError: true,
|
|
526
|
+
content: [{ type: "text", text: `Error fetching the authoring guide: ${err.message}` }]
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
// src/tools/create-plan.ts
|
|
433
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";
|
|
434
614
|
|
|
435
615
|
// src/local/runner.ts
|
|
436
616
|
import { spawn } from "child_process";
|
|
437
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
|
+
}
|
|
438
637
|
function resolvePytestCommand() {
|
|
439
638
|
if (process.env.VIRTUAL_ENV) {
|
|
440
639
|
const venvPytest = path2.join(process.env.VIRTUAL_ENV, "bin", "pytest");
|
|
@@ -472,22 +671,10 @@ async function runLocalPytest(params) {
|
|
|
472
671
|
if (!args.includes("-v") && !args.includes("-vv")) {
|
|
473
672
|
args.push("-v");
|
|
474
673
|
}
|
|
475
|
-
const env =
|
|
476
|
-
...process.env,
|
|
477
|
-
...params.envVars || {}
|
|
478
|
-
};
|
|
479
|
-
if (params.baseUrl) {
|
|
480
|
-
env.BASE_URL = params.baseUrl;
|
|
481
|
-
}
|
|
482
|
-
if (params.browser) {
|
|
483
|
-
env.BROWSER = params.browser;
|
|
484
|
-
}
|
|
485
|
-
if (params.headless !== void 0) {
|
|
486
|
-
env.HEADLESS = params.headless ? "true" : "false";
|
|
487
|
-
}
|
|
674
|
+
const env = buildTestEnv(params);
|
|
488
675
|
const fullCommand = `${cmd} ${args.join(" ")}`;
|
|
489
676
|
logger.info(`Running local test command: ${fullCommand} in ${cwd}`);
|
|
490
|
-
return new Promise((
|
|
677
|
+
return new Promise((resolve5) => {
|
|
491
678
|
let stdout = "";
|
|
492
679
|
let stderr = "";
|
|
493
680
|
let finished = false;
|
|
@@ -501,7 +688,7 @@ async function runLocalPytest(params) {
|
|
|
501
688
|
if (!finished) {
|
|
502
689
|
finished = true;
|
|
503
690
|
killProcessTree(child);
|
|
504
|
-
|
|
691
|
+
resolve5({
|
|
505
692
|
passed: false,
|
|
506
693
|
exitCode: -1,
|
|
507
694
|
stdout,
|
|
@@ -537,7 +724,7 @@ async function runLocalPytest(params) {
|
|
|
537
724
|
if (!fbFinished) {
|
|
538
725
|
fbFinished = true;
|
|
539
726
|
killProcessTree(fallbackChild);
|
|
540
|
-
|
|
727
|
+
resolve5({
|
|
541
728
|
passed: false,
|
|
542
729
|
exitCode: -1,
|
|
543
730
|
stdout: fbStdout,
|
|
@@ -554,7 +741,7 @@ async function runLocalPytest(params) {
|
|
|
554
741
|
if (fbFinished) return;
|
|
555
742
|
fbFinished = true;
|
|
556
743
|
clearTimeout(fbTimer);
|
|
557
|
-
|
|
744
|
+
resolve5({
|
|
558
745
|
passed: code === 0,
|
|
559
746
|
exitCode: code ?? -1,
|
|
560
747
|
stdout: fbStdout,
|
|
@@ -567,7 +754,7 @@ async function runLocalPytest(params) {
|
|
|
567
754
|
if (fbFinished) return;
|
|
568
755
|
fbFinished = true;
|
|
569
756
|
clearTimeout(fbTimer);
|
|
570
|
-
|
|
757
|
+
resolve5({
|
|
571
758
|
passed: false,
|
|
572
759
|
exitCode: -1,
|
|
573
760
|
stdout: "",
|
|
@@ -578,7 +765,7 @@ async function runLocalPytest(params) {
|
|
|
578
765
|
});
|
|
579
766
|
return;
|
|
580
767
|
}
|
|
581
|
-
|
|
768
|
+
resolve5({
|
|
582
769
|
passed: false,
|
|
583
770
|
exitCode: -1,
|
|
584
771
|
stdout,
|
|
@@ -592,7 +779,7 @@ async function runLocalPytest(params) {
|
|
|
592
779
|
finished = true;
|
|
593
780
|
clearTimeout(timer);
|
|
594
781
|
const durationMs = Date.now() - startTime;
|
|
595
|
-
|
|
782
|
+
resolve5({
|
|
596
783
|
passed: code === 0,
|
|
597
784
|
exitCode: code ?? -1,
|
|
598
785
|
stdout,
|
|
@@ -606,19 +793,22 @@ async function runLocalPytest(params) {
|
|
|
606
793
|
|
|
607
794
|
// src/tools/local-run.ts
|
|
608
795
|
function registerLocalRunTool(server) {
|
|
609
|
-
server.
|
|
796
|
+
server.registerTool(
|
|
610
797
|
"qcentriq_run_local_test",
|
|
611
|
-
"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.",
|
|
612
798
|
{
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
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
|
+
}
|
|
622
812
|
},
|
|
623
813
|
async (args) => {
|
|
624
814
|
try {
|
|
@@ -628,6 +818,7 @@ function registerLocalRunTool(server) {
|
|
|
628
818
|
headless: args.headless,
|
|
629
819
|
browser: args.browser,
|
|
630
820
|
baseUrl: args.base_url,
|
|
821
|
+
groupId: args.group_id,
|
|
631
822
|
envVars: args.env_vars,
|
|
632
823
|
extraArgs: args.extra_args,
|
|
633
824
|
timeoutSeconds: args.timeout_seconds,
|
|
@@ -670,22 +861,25 @@ function registerLocalRunTool(server) {
|
|
|
670
861
|
}
|
|
671
862
|
|
|
672
863
|
// src/tools/save-script.ts
|
|
673
|
-
import { z as
|
|
864
|
+
import { z as z10 } from "zod";
|
|
674
865
|
import * as fs2 from "fs/promises";
|
|
675
866
|
import * as path3 from "path";
|
|
867
|
+
var DEFAULT_SCRIPT_DIR = "./qcentriq_tests";
|
|
676
868
|
function registerSaveScriptTool(server) {
|
|
677
|
-
server.
|
|
869
|
+
server.registerTool(
|
|
678
870
|
"qcentriq_save_script",
|
|
679
|
-
"Save downloaded Playwright Python test script and fixtures directly to the local workspace disk so they can be run or edited locally.",
|
|
680
871
|
{
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
872
|
+
description: "Save downloaded Playwright Python test script and fixtures directly to the local workspace disk so they can be run or edited locally.",
|
|
873
|
+
inputSchema: {
|
|
874
|
+
file_name: z10.string().describe("Target filename (e.g. 'test_login.py')."),
|
|
875
|
+
content: z10.string().describe("Python test script source code."),
|
|
876
|
+
conftest_content: z10.string().optional().describe("Accompanying conftest.py source code if present."),
|
|
877
|
+
destination_dir: z10.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.`)
|
|
878
|
+
}
|
|
685
879
|
},
|
|
686
880
|
async (args) => {
|
|
687
881
|
try {
|
|
688
|
-
const targetDir = path3.resolve(process.cwd(), args.destination_dir);
|
|
882
|
+
const targetDir = path3.resolve(process.cwd(), args.destination_dir ?? DEFAULT_SCRIPT_DIR);
|
|
689
883
|
await fs2.mkdir(targetDir, { recursive: true });
|
|
690
884
|
const savedFiles = [];
|
|
691
885
|
const safeFileName = path3.basename(args.file_name);
|
|
@@ -736,6 +930,358 @@ function registerSaveScriptTool(server) {
|
|
|
736
930
|
);
|
|
737
931
|
}
|
|
738
932
|
|
|
933
|
+
// src/tools/setup-instructions.ts
|
|
934
|
+
import { z as z11 } from "zod";
|
|
935
|
+
|
|
936
|
+
// src/local/environment-setup.ts
|
|
937
|
+
import { spawn as spawn2 } from "child_process";
|
|
938
|
+
import * as fs3 from "fs/promises";
|
|
939
|
+
import * as path4 from "path";
|
|
940
|
+
var MANAGER_PRIORITY = ["uv", "poetry", "conda", "venv"];
|
|
941
|
+
var PROBE_TIMEOUT_MS = 5e3;
|
|
942
|
+
var DEFAULT_PYTHON_VERSION = "3.12";
|
|
943
|
+
var DEFAULT_PLAYWRIGHT_VERSION = "1.56.0";
|
|
944
|
+
var FALLBACK_TEST_PACKAGES = [
|
|
945
|
+
"pytest",
|
|
946
|
+
"pytest-playwright",
|
|
947
|
+
"allure-pytest",
|
|
948
|
+
"httpx",
|
|
949
|
+
"nest-asyncio",
|
|
950
|
+
"pytest-playwright-visual-snapshot",
|
|
951
|
+
"Pillow"
|
|
952
|
+
];
|
|
953
|
+
function testDependencies(playwrightVersion, packages) {
|
|
954
|
+
const base = packages && packages.length > 0 ? packages : FALLBACK_TEST_PACKAGES;
|
|
955
|
+
return [...base, `playwright==${playwrightVersion}`].join(" ");
|
|
956
|
+
}
|
|
957
|
+
function probeCommand(cmd, args) {
|
|
958
|
+
return new Promise((resolve5) => {
|
|
959
|
+
let output = "";
|
|
960
|
+
let settled = false;
|
|
961
|
+
const finish = (value) => {
|
|
962
|
+
if (settled) return;
|
|
963
|
+
settled = true;
|
|
964
|
+
clearTimeout(timer);
|
|
965
|
+
resolve5(value);
|
|
966
|
+
};
|
|
967
|
+
let child;
|
|
968
|
+
try {
|
|
969
|
+
child = spawn2(cmd, args, {
|
|
970
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
971
|
+
shell: process.platform === "win32"
|
|
972
|
+
});
|
|
973
|
+
} catch {
|
|
974
|
+
resolve5(null);
|
|
975
|
+
return;
|
|
976
|
+
}
|
|
977
|
+
const timer = setTimeout(() => {
|
|
978
|
+
try {
|
|
979
|
+
child.kill("SIGKILL");
|
|
980
|
+
} catch {
|
|
981
|
+
}
|
|
982
|
+
finish(null);
|
|
983
|
+
}, PROBE_TIMEOUT_MS);
|
|
984
|
+
child.stdout?.on("data", (chunk) => output += chunk.toString());
|
|
985
|
+
child.stderr?.on("data", (chunk) => output += chunk.toString());
|
|
986
|
+
child.on("error", () => finish(null));
|
|
987
|
+
child.on("close", (code) => finish(code === 0 ? output.trim().split("\n")[0].trim() || "unknown" : null));
|
|
988
|
+
});
|
|
989
|
+
}
|
|
990
|
+
async function probePython() {
|
|
991
|
+
for (const bin of ["python3", "python"]) {
|
|
992
|
+
const version = await probeCommand(bin, ["-c", "import venv, sys; print(sys.version.split()[0])"]);
|
|
993
|
+
if (version) {
|
|
994
|
+
return { bin, version };
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
return null;
|
|
998
|
+
}
|
|
999
|
+
async function fileExists(filePath) {
|
|
1000
|
+
try {
|
|
1001
|
+
await fs3.access(filePath);
|
|
1002
|
+
return true;
|
|
1003
|
+
} catch {
|
|
1004
|
+
return false;
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
async function detectProjectFiles(workingDir) {
|
|
1008
|
+
const candidates = [
|
|
1009
|
+
"pyproject.toml",
|
|
1010
|
+
"uv.lock",
|
|
1011
|
+
"poetry.lock",
|
|
1012
|
+
"requirements.txt",
|
|
1013
|
+
"environment.yml",
|
|
1014
|
+
"environment.yaml"
|
|
1015
|
+
];
|
|
1016
|
+
const found = [];
|
|
1017
|
+
for (const candidate of candidates) {
|
|
1018
|
+
if (await fileExists(path4.join(workingDir, candidate))) {
|
|
1019
|
+
found.push(candidate);
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
return found;
|
|
1023
|
+
}
|
|
1024
|
+
async function detectPackageManagers() {
|
|
1025
|
+
const [uv, poetry, conda, python] = await Promise.all([
|
|
1026
|
+
probeCommand("uv", ["--version"]),
|
|
1027
|
+
probeCommand("poetry", ["--version"]),
|
|
1028
|
+
probeCommand("conda", ["--version"]),
|
|
1029
|
+
probePython()
|
|
1030
|
+
]);
|
|
1031
|
+
return [
|
|
1032
|
+
{ name: "uv", available: Boolean(uv), version: uv ?? void 0, probe_command: "uv --version" },
|
|
1033
|
+
{ name: "poetry", available: Boolean(poetry), version: poetry ?? void 0, probe_command: "poetry --version" },
|
|
1034
|
+
{ name: "conda", available: Boolean(conda), version: conda ?? void 0, probe_command: "conda --version" },
|
|
1035
|
+
{
|
|
1036
|
+
name: "venv",
|
|
1037
|
+
available: Boolean(python),
|
|
1038
|
+
version: python ? `${python.bin} ${python.version}` : void 0,
|
|
1039
|
+
probe_command: "python3 -m venv"
|
|
1040
|
+
}
|
|
1041
|
+
];
|
|
1042
|
+
}
|
|
1043
|
+
function activateCommand(ctx) {
|
|
1044
|
+
return ctx.isWindows ? ".venv\\Scripts\\activate" : "source .venv/bin/activate";
|
|
1045
|
+
}
|
|
1046
|
+
function buildUvSteps(ctx) {
|
|
1047
|
+
const deps = testDependencies(ctx.playwrightVersion, ctx.packages);
|
|
1048
|
+
if (ctx.projectFiles.includes("uv.lock")) {
|
|
1049
|
+
return [
|
|
1050
|
+
{ description: "Install the project's locked dependencies into a uv-managed virtualenv.", command: "uv sync" },
|
|
1051
|
+
{ description: "Add the QCentriq test dependencies if they are not already in pyproject.toml.", command: `uv add --dev ${deps}` },
|
|
1052
|
+
{ description: "Download the Playwright browser binaries.", command: "uv run playwright install chromium" }
|
|
1053
|
+
];
|
|
1054
|
+
}
|
|
1055
|
+
const steps = [
|
|
1056
|
+
{ description: "Create a virtual environment in .venv.", command: `uv venv .venv --python ${ctx.pythonVersion}` },
|
|
1057
|
+
{ description: "Activate the virtual environment.", command: activateCommand(ctx) }
|
|
1058
|
+
];
|
|
1059
|
+
if (ctx.projectFiles.includes("requirements.txt")) {
|
|
1060
|
+
steps.push({ description: "Install the project's existing dependencies.", command: "uv pip install -r requirements.txt" });
|
|
1061
|
+
}
|
|
1062
|
+
steps.push(
|
|
1063
|
+
{ description: "Install the QCentriq test dependencies (pytest, Playwright, Allure, and fixtures).", command: `uv pip install ${deps}` },
|
|
1064
|
+
{ description: "Download the Playwright browser binaries.", command: "playwright install chromium" }
|
|
1065
|
+
);
|
|
1066
|
+
return steps;
|
|
1067
|
+
}
|
|
1068
|
+
function buildPoetrySteps(ctx) {
|
|
1069
|
+
const deps = testDependencies(ctx.playwrightVersion, ctx.packages);
|
|
1070
|
+
const steps = [
|
|
1071
|
+
{
|
|
1072
|
+
description: "Keep the virtualenv inside the project so qcentriq_run_local_test can find it.",
|
|
1073
|
+
command: "poetry config virtualenvs.in-project true"
|
|
1074
|
+
}
|
|
1075
|
+
];
|
|
1076
|
+
if (!ctx.projectFiles.includes("pyproject.toml")) {
|
|
1077
|
+
steps.push({
|
|
1078
|
+
description: "Initialize a pyproject.toml for this test project.",
|
|
1079
|
+
command: `poetry init --no-interaction --python ">=${ctx.pythonVersion}"`
|
|
1080
|
+
});
|
|
1081
|
+
}
|
|
1082
|
+
steps.push(
|
|
1083
|
+
{ description: "Add the QCentriq test dependencies (pytest, Playwright, Allure, and fixtures) as dev dependencies.", command: `poetry add --group dev ${deps}` },
|
|
1084
|
+
{ description: "Install the environment.", command: "poetry install" },
|
|
1085
|
+
{ description: "Download the Playwright browser binaries.", command: "poetry run playwright install chromium" },
|
|
1086
|
+
{ description: "Activate the environment for your shell session.", command: activateCommand(ctx) }
|
|
1087
|
+
);
|
|
1088
|
+
return steps;
|
|
1089
|
+
}
|
|
1090
|
+
function buildCondaSteps(ctx) {
|
|
1091
|
+
const deps = testDependencies(ctx.playwrightVersion, ctx.packages);
|
|
1092
|
+
const envFile = ctx.projectFiles.find((f) => f === "environment.yml" || f === "environment.yaml");
|
|
1093
|
+
const steps = envFile ? [{ description: "Create the conda environment from the project's environment file.", command: `conda env create -f ${envFile}` }] : [
|
|
1094
|
+
{
|
|
1095
|
+
description: "Create a dedicated conda environment for QCentriq tests.",
|
|
1096
|
+
command: `conda create -n ${ctx.envName} python=${ctx.pythonVersion} -y`
|
|
1097
|
+
}
|
|
1098
|
+
];
|
|
1099
|
+
steps.push(
|
|
1100
|
+
{ description: "Activate the conda environment.", command: `conda activate ${ctx.envName}` },
|
|
1101
|
+
{ description: "Install the QCentriq test dependencies (pytest, Playwright, Allure, and fixtures).", command: `pip install ${deps}` },
|
|
1102
|
+
{ description: "Download the Playwright browser binaries.", command: "playwright install chromium" }
|
|
1103
|
+
);
|
|
1104
|
+
return steps;
|
|
1105
|
+
}
|
|
1106
|
+
function buildVenvSteps(ctx) {
|
|
1107
|
+
const deps = testDependencies(ctx.playwrightVersion, ctx.packages);
|
|
1108
|
+
const steps = [
|
|
1109
|
+
{ description: "Create a virtual environment in .venv.", command: "python3 -m venv .venv" },
|
|
1110
|
+
{ description: "Activate the virtual environment.", command: activateCommand(ctx) },
|
|
1111
|
+
{ description: "Upgrade pip inside the environment.", command: "python -m pip install --upgrade pip" }
|
|
1112
|
+
];
|
|
1113
|
+
if (ctx.projectFiles.includes("requirements.txt")) {
|
|
1114
|
+
steps.push({ description: "Install the project's existing dependencies.", command: "pip install -r requirements.txt" });
|
|
1115
|
+
}
|
|
1116
|
+
steps.push(
|
|
1117
|
+
{ description: "Install the QCentriq test dependencies (pytest, Playwright, Allure, and fixtures).", command: `pip install ${deps}` },
|
|
1118
|
+
{ description: "Download the Playwright browser binaries.", command: "playwright install chromium" }
|
|
1119
|
+
);
|
|
1120
|
+
return steps;
|
|
1121
|
+
}
|
|
1122
|
+
var STEP_BUILDERS = {
|
|
1123
|
+
uv: buildUvSteps,
|
|
1124
|
+
poetry: buildPoetrySteps,
|
|
1125
|
+
conda: buildCondaSteps,
|
|
1126
|
+
venv: buildVenvSteps
|
|
1127
|
+
};
|
|
1128
|
+
var VERIFY_COMMANDS = {
|
|
1129
|
+
uv: "pytest --version",
|
|
1130
|
+
poetry: "poetry run pytest --version",
|
|
1131
|
+
conda: "pytest --version",
|
|
1132
|
+
venv: "pytest --version"
|
|
1133
|
+
};
|
|
1134
|
+
var INSTALL_HINTS = {
|
|
1135
|
+
uv: "uv: https://docs.astral.sh/uv/getting-started/installation/",
|
|
1136
|
+
poetry: "poetry: https://python-poetry.org/docs/#installation",
|
|
1137
|
+
conda: "conda (miniconda): https://docs.conda.io/projects/miniconda/en/latest/",
|
|
1138
|
+
venv: "python3 with the venv module: https://www.python.org/downloads/"
|
|
1139
|
+
};
|
|
1140
|
+
function detectActiveEnvironment() {
|
|
1141
|
+
if (process.env.VIRTUAL_ENV) {
|
|
1142
|
+
return `virtualenv: ${process.env.VIRTUAL_ENV}`;
|
|
1143
|
+
}
|
|
1144
|
+
if (process.env.CONDA_DEFAULT_ENV) {
|
|
1145
|
+
return `conda: ${process.env.CONDA_DEFAULT_ENV}`;
|
|
1146
|
+
}
|
|
1147
|
+
return null;
|
|
1148
|
+
}
|
|
1149
|
+
async function buildEnvironmentSetupPlan(params = {}) {
|
|
1150
|
+
const workingDir = params.workingDir ? path4.resolve(params.workingDir) : process.cwd();
|
|
1151
|
+
const [packageManagers, projectFiles] = await Promise.all([detectPackageManagers(), detectProjectFiles(workingDir)]);
|
|
1152
|
+
const availability = new Map(packageManagers.map((m) => [m.name, m.available]));
|
|
1153
|
+
const preferred = params.preferredManager;
|
|
1154
|
+
const notes = [];
|
|
1155
|
+
let recommended = null;
|
|
1156
|
+
if (preferred && availability.get(preferred)) {
|
|
1157
|
+
recommended = preferred;
|
|
1158
|
+
} else {
|
|
1159
|
+
if (preferred) {
|
|
1160
|
+
notes.push(`Requested package manager "${preferred}" was not found on PATH; falling back to the best available option.`);
|
|
1161
|
+
}
|
|
1162
|
+
recommended = MANAGER_PRIORITY.find((name) => availability.get(name)) ?? null;
|
|
1163
|
+
}
|
|
1164
|
+
const ctx = {
|
|
1165
|
+
workingDir,
|
|
1166
|
+
isWindows: process.platform === "win32",
|
|
1167
|
+
envName: params.envName || "qcentriq-tests",
|
|
1168
|
+
pythonVersion: params.pythonVersion || DEFAULT_PYTHON_VERSION,
|
|
1169
|
+
playwrightVersion: params.playwrightVersion || DEFAULT_PLAYWRIGHT_VERSION,
|
|
1170
|
+
packages: params.packages,
|
|
1171
|
+
projectFiles
|
|
1172
|
+
};
|
|
1173
|
+
const activeEnvironment = detectActiveEnvironment();
|
|
1174
|
+
if (activeEnvironment) {
|
|
1175
|
+
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
|
+
}
|
|
1177
|
+
let steps = [];
|
|
1178
|
+
let verifyCommand = null;
|
|
1179
|
+
if (recommended) {
|
|
1180
|
+
steps = STEP_BUILDERS[recommended](ctx);
|
|
1181
|
+
verifyCommand = VERIFY_COMMANDS[recommended];
|
|
1182
|
+
if (recommended !== "uv" && availability.get("uv")) {
|
|
1183
|
+
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
|
+
}
|
|
1185
|
+
const alternatives = MANAGER_PRIORITY.filter((name) => name !== recommended && availability.get(name));
|
|
1186
|
+
if (alternatives.length > 0) {
|
|
1187
|
+
notes.push(`Also available on this machine: ${alternatives.join(", ")}. Re-run this tool with preferred_manager to get instructions for one of them.`);
|
|
1188
|
+
}
|
|
1189
|
+
} else {
|
|
1190
|
+
notes.push("No supported Python package manager was found on PATH. Install one of the following, then run this tool again:");
|
|
1191
|
+
for (const name of MANAGER_PRIORITY) {
|
|
1192
|
+
notes.push(` - ${INSTALL_HINTS[name]}`);
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
notes.push(
|
|
1196
|
+
"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
|
+
"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
|
+
);
|
|
1199
|
+
logger.debug(`Environment setup plan: recommended=${recommended ?? "none"}, project files=[${projectFiles.join(", ")}]`);
|
|
1200
|
+
return {
|
|
1201
|
+
working_dir: workingDir,
|
|
1202
|
+
package_managers: packageManagers,
|
|
1203
|
+
recommended_manager: recommended,
|
|
1204
|
+
active_environment: activeEnvironment,
|
|
1205
|
+
detected_project_files: projectFiles,
|
|
1206
|
+
steps,
|
|
1207
|
+
verify_command: verifyCommand,
|
|
1208
|
+
notes
|
|
1209
|
+
};
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
// src/tools/setup-instructions.ts
|
|
1213
|
+
async function fetchRuntimeRequirements(client) {
|
|
1214
|
+
if (!client) return {};
|
|
1215
|
+
try {
|
|
1216
|
+
const res = await client.request("/runtime-requirements");
|
|
1217
|
+
return {
|
|
1218
|
+
packages: Array.isArray(res?.packages) ? res.packages : void 0,
|
|
1219
|
+
playwright_version: typeof res?.playwright_version === "string" ? res.playwright_version : void 0
|
|
1220
|
+
};
|
|
1221
|
+
} catch (err) {
|
|
1222
|
+
logger.warn(`Could not fetch runtime requirements from the backend, using the bundled list: ${err.message}`);
|
|
1223
|
+
return {};
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
function registerSetupInstructionsTool(server, client) {
|
|
1227
|
+
server.registerTool(
|
|
1228
|
+
"qcentriq_get_setup_instructions",
|
|
1229
|
+
{
|
|
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: z11.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."),
|
|
1233
|
+
working_dir: z11.string().optional().describe("Directory to inspect for pyproject.toml / lockfiles / requirements.txt (defaults to the current project directory)."),
|
|
1234
|
+
env_name: z11.string().default("qcentriq-tests").describe("Name for the created environment (used by conda, default 'qcentriq-tests')."),
|
|
1235
|
+
python_version: z11.string().default("3.12").describe("Python version to request when creating the environment (default '3.12', matching the QCentriq execution container)."),
|
|
1236
|
+
playwright_version: z11.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.")
|
|
1237
|
+
},
|
|
1238
|
+
annotations: {
|
|
1239
|
+
readOnlyHint: true,
|
|
1240
|
+
// Only probes local package managers and project files; never mutates local or remote state.
|
|
1241
|
+
destructiveHint: false,
|
|
1242
|
+
idempotentHint: false,
|
|
1243
|
+
// Machine state (installed tooling) can change between calls.
|
|
1244
|
+
openWorldHint: false
|
|
1245
|
+
// Fixed set of local package managers, not open-ended.
|
|
1246
|
+
}
|
|
1247
|
+
},
|
|
1248
|
+
async (args) => {
|
|
1249
|
+
try {
|
|
1250
|
+
const runtime = await fetchRuntimeRequirements(client);
|
|
1251
|
+
const plan = await buildEnvironmentSetupPlan({
|
|
1252
|
+
preferredManager: args.preferred_manager,
|
|
1253
|
+
workingDir: args.working_dir,
|
|
1254
|
+
envName: args.env_name,
|
|
1255
|
+
pythonVersion: args.python_version,
|
|
1256
|
+
// An explicitly requested pin wins; otherwise use whatever the
|
|
1257
|
+
// project's active execution image is built against.
|
|
1258
|
+
playwrightVersion: args.playwright_version ?? runtime.playwright_version,
|
|
1259
|
+
packages: runtime.packages
|
|
1260
|
+
});
|
|
1261
|
+
return {
|
|
1262
|
+
content: [
|
|
1263
|
+
{
|
|
1264
|
+
type: "text",
|
|
1265
|
+
text: JSON.stringify(plan, null, 2)
|
|
1266
|
+
}
|
|
1267
|
+
],
|
|
1268
|
+
isError: plan.recommended_manager === null
|
|
1269
|
+
};
|
|
1270
|
+
} catch (err) {
|
|
1271
|
+
return {
|
|
1272
|
+
isError: true,
|
|
1273
|
+
content: [
|
|
1274
|
+
{
|
|
1275
|
+
type: "text",
|
|
1276
|
+
text: `Error in qcentriq_get_setup_instructions: ${err.message}`
|
|
1277
|
+
}
|
|
1278
|
+
]
|
|
1279
|
+
};
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
);
|
|
1283
|
+
}
|
|
1284
|
+
|
|
739
1285
|
// src/tools/index.ts
|
|
740
1286
|
function registerAllTools(server, client, config) {
|
|
741
1287
|
logger.debug("Registering QCentriq MCP tools...");
|
|
@@ -745,9 +1291,13 @@ function registerAllTools(server, client, config) {
|
|
|
745
1291
|
registerDownloadScriptTool(server, client, config);
|
|
746
1292
|
registerEnvironmentTool(server, client, config);
|
|
747
1293
|
registerRunLogsTool(server, client, config);
|
|
1294
|
+
registerAuthoringGuideTool(server, client);
|
|
1295
|
+
registerCreatePlanTool(server, client, config);
|
|
1296
|
+
registerSaveGroupScriptTool(server, client, config);
|
|
748
1297
|
registerSaveScriptTool(server);
|
|
749
1298
|
registerLocalRunTool(server);
|
|
750
|
-
|
|
1299
|
+
registerSetupInstructionsTool(server, client);
|
|
1300
|
+
logger.info("Successfully registered 12 QCentriq MCP tools (7 remote discovery + 2 authoring + 3 local client execution).");
|
|
751
1301
|
}
|
|
752
1302
|
|
|
753
1303
|
// src/index.ts
|