@testingbot/mcp-server 1.0.2 → 1.1.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 +162 -12
- package/dist/lib/app-automate-client.d.ts +201 -0
- package/dist/lib/app-automate-client.d.ts.map +1 -0
- package/dist/lib/app-automate-client.js +179 -0
- package/dist/lib/app-automate-client.js.map +1 -0
- package/dist/server-factory.d.ts.map +1 -1
- package/dist/server-factory.js +4 -0
- package/dist/server-factory.js.map +1 -1
- package/dist/tools/app-automate.d.ts +3 -0
- package/dist/tools/app-automate.d.ts.map +1 -0
- package/dist/tools/app-automate.js +250 -0
- package/dist/tools/app-automate.js.map +1 -0
- package/dist/tools/maestro.d.ts +3 -0
- package/dist/tools/maestro.d.ts.map +1 -0
- package/dist/tools/maestro.js +625 -0
- package/dist/tools/maestro.js.map +1 -0
- package/dist/tools/project.d.ts +2 -2
- package/dist/tools/project.d.ts.map +1 -1
- package/dist/tools/project.js +133 -1
- package/dist/tools/project.js.map +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,625 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import { zipSync } from "fflate";
|
|
5
|
+
import { handleMCPError } from "../lib/utils.js";
|
|
6
|
+
import { AppAutomateClient, } from "../lib/app-automate-client.js";
|
|
7
|
+
import logger from "../lib/logger.js";
|
|
8
|
+
const ALLOWED_APP_EXTENSIONS = new Set([".apk", ".aab", ".ipa", ".zip"]);
|
|
9
|
+
function validateAppPath(input) {
|
|
10
|
+
const resolved = path.resolve(input);
|
|
11
|
+
const ext = path.extname(resolved).toLowerCase();
|
|
12
|
+
if (!ALLOWED_APP_EXTENSIONS.has(ext)) {
|
|
13
|
+
throw new Error(`Only ${[...ALLOWED_APP_EXTENSIONS].join(", ")} files may be uploaded (got "${ext || "no extension"}")`);
|
|
14
|
+
}
|
|
15
|
+
let stat;
|
|
16
|
+
try {
|
|
17
|
+
stat = fs.statSync(resolved);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
throw new Error(`File not found or not readable: ${resolved}`);
|
|
21
|
+
}
|
|
22
|
+
if (!stat.isFile()) {
|
|
23
|
+
throw new Error(`Path is not a regular file: ${resolved}`);
|
|
24
|
+
}
|
|
25
|
+
return resolved;
|
|
26
|
+
}
|
|
27
|
+
// Collect all .yaml/.yml files under a directory (recursively), preserving
|
|
28
|
+
// relative paths so runFlow/runScript references between flows keep working.
|
|
29
|
+
function collectYamlFiles(dir, baseDir, out) {
|
|
30
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
31
|
+
const full = path.join(dir, entry.name);
|
|
32
|
+
if (entry.isDirectory()) {
|
|
33
|
+
collectYamlFiles(full, baseDir, out);
|
|
34
|
+
}
|
|
35
|
+
else if (entry.isFile() && /\.ya?ml$/i.test(entry.name)) {
|
|
36
|
+
out[path.relative(baseDir, full).split(path.sep).join("/")] = fs.readFileSync(full);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function buildFlowsZip(args) {
|
|
41
|
+
if (args.flows && args.flows.length > 0) {
|
|
42
|
+
const files = {};
|
|
43
|
+
for (const flow of args.flows) {
|
|
44
|
+
const name = flow.fileName.replace(/\\/g, "/").replace(/^\/+/, "");
|
|
45
|
+
if (name.includes("..") || !/\.ya?ml$/i.test(name)) {
|
|
46
|
+
throw new Error(`Invalid flow file name "${flow.fileName}" — must be a relative .yaml/.yml path`);
|
|
47
|
+
}
|
|
48
|
+
files[name] = new TextEncoder().encode(flow.content);
|
|
49
|
+
}
|
|
50
|
+
return Buffer.from(zipSync(files));
|
|
51
|
+
}
|
|
52
|
+
if (!args.flowsPath) {
|
|
53
|
+
throw new Error("Provide either flowsPath (a directory or .zip) or inline flows");
|
|
54
|
+
}
|
|
55
|
+
const resolved = path.resolve(args.flowsPath);
|
|
56
|
+
const stat = fs.statSync(resolved);
|
|
57
|
+
if (stat.isFile()) {
|
|
58
|
+
if (path.extname(resolved).toLowerCase() !== ".zip") {
|
|
59
|
+
throw new Error("flowsPath must be a directory of YAML flows or a .zip file");
|
|
60
|
+
}
|
|
61
|
+
return fs.readFileSync(resolved);
|
|
62
|
+
}
|
|
63
|
+
const files = {};
|
|
64
|
+
collectYamlFiles(resolved, resolved, files);
|
|
65
|
+
if (Object.keys(files).length === 0) {
|
|
66
|
+
throw new Error(`No .yaml/.yml flow files found in ${resolved}`);
|
|
67
|
+
}
|
|
68
|
+
return Buffer.from(zipSync(files));
|
|
69
|
+
}
|
|
70
|
+
function formatRun(run) {
|
|
71
|
+
let out = `### Run ${run.id} — ${run.status}\n`;
|
|
72
|
+
const env = run.environment;
|
|
73
|
+
const caps = run.capabilities;
|
|
74
|
+
const device = env?.device || caps?.deviceName || "unknown device";
|
|
75
|
+
const version = env?.version || caps?.version || "";
|
|
76
|
+
out += `- **Device**: ${device}${version ? ` (${caps?.platformName || ""} ${version})` : ""}\n`;
|
|
77
|
+
if (run.error_messages && run.error_messages.length > 0) {
|
|
78
|
+
out += `- **Errors**: ${run.error_messages.join("; ")}\n`;
|
|
79
|
+
}
|
|
80
|
+
const flows = run.flows || [];
|
|
81
|
+
if (flows.length > 0) {
|
|
82
|
+
// Failures first so agents see what needs attention without scrolling.
|
|
83
|
+
const sorted = [...flows].sort((a, b) => Number(a.status !== "FAILED") - Number(b.status !== "FAILED"));
|
|
84
|
+
out += `- **Flows** (${flows.length}):\n`;
|
|
85
|
+
for (const flow of sorted) {
|
|
86
|
+
out += ` - ${flow.name} [id ${flow.id}]: ${flow.status}`;
|
|
87
|
+
if (flow.error_messages && flow.error_messages.length > 0) {
|
|
88
|
+
out += ` — ${flow.error_messages.join("; ")}`;
|
|
89
|
+
}
|
|
90
|
+
if (flow.status === "FAILED" && flow.assets?.video) {
|
|
91
|
+
out += ` (video: ${flow.assets.video})`;
|
|
92
|
+
}
|
|
93
|
+
out += "\n";
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return out;
|
|
97
|
+
}
|
|
98
|
+
// Static syntax reference served by the maestroCheatSheet tool. Kept in-code
|
|
99
|
+
// (not fetched) so it works offline and costs one cheap call for agents
|
|
100
|
+
// writing flow YAML.
|
|
101
|
+
const MAESTRO_CHEAT_SHEET = `## Maestro Flow Cheat Sheet
|
|
102
|
+
|
|
103
|
+
A flow file is YAML: a header, \`---\`, then a list of commands.
|
|
104
|
+
|
|
105
|
+
\`\`\`yaml
|
|
106
|
+
appId: com.example.app # required: bundle id / package name
|
|
107
|
+
name: Checkout happy path # optional
|
|
108
|
+
tags: [smoke, checkout] # optional, filter with includeTags/excludeTags
|
|
109
|
+
env:
|
|
110
|
+
USERNAME: default-value # overridable per run via runMaestroTest env
|
|
111
|
+
---
|
|
112
|
+
- launchApp
|
|
113
|
+
- tapOn: "Log in" # matches visible text (regex supported)
|
|
114
|
+
- tapOn:
|
|
115
|
+
id: "login_button" # matches accessibility/resource id
|
|
116
|
+
- inputText: \${USERNAME}
|
|
117
|
+
- pressKey: Enter
|
|
118
|
+
- assertVisible: "Welcome"
|
|
119
|
+
- assertNotVisible: "Error"
|
|
120
|
+
- takeScreenshot: after-login # named screenshot
|
|
121
|
+
\`\`\`
|
|
122
|
+
|
|
123
|
+
### Common commands
|
|
124
|
+
- \`launchApp\` / \`launchApp: { clearState: true }\` / \`stopApp\` / \`killApp\`
|
|
125
|
+
- \`tapOn\`, \`doubleTapOn\`, \`longPressOn\` — by text, \`id\`, \`point: 50%,50%\`, or \`index\`
|
|
126
|
+
- \`inputText: "..."\`, \`inputRandomEmail\`, \`inputRandomPersonName\`, \`eraseText\`
|
|
127
|
+
- \`copyTextFrom: { id: "..." }\` then \`pasteText\`
|
|
128
|
+
- \`scroll\`, \`scrollUntilVisible: { element: { text: "..." }, direction: DOWN }\`
|
|
129
|
+
- \`swipe: { direction: LEFT }\` or with \`start\`/\`end\` points
|
|
130
|
+
- \`back\` (Android), \`hideKeyboard\`, \`pressKey: Home|Enter|Back\`
|
|
131
|
+
- \`openLink: https://example.com\` (deep links supported)
|
|
132
|
+
- \`waitForAnimationToEnd\`, \`extendedWaitUntil: { visible: { text: "..." }, timeout: 10000 }\`
|
|
133
|
+
- \`assertVisible\` / \`assertNotVisible\` / \`assertTrue: \${output.x == 'y'}\`
|
|
134
|
+
- \`runFlow: subflow.yaml\` (compose flows), \`runFlow: { when: { visible: "..." }, file: ... }\` (conditional)
|
|
135
|
+
- \`runScript: script.js\` (JavaScript, results in \`output\`), \`evalScript: \${...}\`
|
|
136
|
+
- \`repeat: { times: 3, commands: [...] }\`
|
|
137
|
+
- \`setLocation: { latitude: 50.8, longitude: 4.4 }\`, \`travel\` (GPS route)
|
|
138
|
+
- \`addMedia: ["./receipt.png"]\` (push files to the device gallery)
|
|
139
|
+
|
|
140
|
+
### Selectors
|
|
141
|
+
\`\`\`yaml
|
|
142
|
+
- tapOn:
|
|
143
|
+
text: "Buy" # visible text or content-desc (regex ok: "Buy|Purchase")
|
|
144
|
+
id: "buy_btn" # resource-id (Android) / accessibility id (iOS)
|
|
145
|
+
index: 0 # when multiple matches
|
|
146
|
+
enabled: true
|
|
147
|
+
optional: true # don't fail the flow if not found
|
|
148
|
+
retryTapIfNoChange: false
|
|
149
|
+
\`\`\`
|
|
150
|
+
|
|
151
|
+
### Running on TestingBot
|
|
152
|
+
1. \`uploadMaestroApp\` (.apk/.aab/.ipa) → projectId
|
|
153
|
+
2. \`uploadMaestroFlows\` (directory, zip, or inline YAML — subflows keep relative paths)
|
|
154
|
+
3. \`runMaestroTest\` — pick device (wildcards like "Pixel [8-9]"), \`realDevice: true\` for physical devices, \`env\` to override flow env vars, \`shardSplit\` for parallelism
|
|
155
|
+
4. \`getMaestroRunStatus\` → \`getMaestroFlowDetails\` (errors, screenshots, video) → fix → \`retryMaestroRun\`
|
|
156
|
+
|
|
157
|
+
Full command reference: https://docs.maestro.dev/api-reference/commands`;
|
|
158
|
+
export default function addMaestroTools(server, _testingBotApi, config) {
|
|
159
|
+
const tools = {};
|
|
160
|
+
// Lazily constructed so tb_login (which mutates config) is picked up.
|
|
161
|
+
const client = () => new AppAutomateClient(config);
|
|
162
|
+
tools.maestroCheatSheet = server.tool("maestroCheatSheet", "Get a Maestro flow YAML syntax reference: file structure, commands, selectors, and the TestingBot run workflow. Call this before writing or fixing Maestro flows.", {}, async () => {
|
|
163
|
+
return { content: [{ type: "text", text: MAESTRO_CHEAT_SHEET }] };
|
|
164
|
+
});
|
|
165
|
+
tools.uploadMaestroApp = server.tool("uploadMaestroApp", "Upload a mobile app (APK, AAB, IPA, or zipped .app) for Maestro testing on TestingBot. Skips the upload if the same binary was uploaded before. Returns a projectId used by uploadMaestroFlows and runMaestroTest.", {
|
|
166
|
+
localFilePath: z.string().describe("Local path to the .apk, .aab, .ipa or .zip app file"),
|
|
167
|
+
}, async (args) => {
|
|
168
|
+
try {
|
|
169
|
+
const safePath = validateAppPath(args.localFilePath);
|
|
170
|
+
logger.info({ path: safePath }, "Uploading Maestro app");
|
|
171
|
+
const checksum = await AppAutomateClient.md5Checksum(safePath);
|
|
172
|
+
const existingId = await client().findAppByChecksum(checksum);
|
|
173
|
+
if (existingId) {
|
|
174
|
+
return {
|
|
175
|
+
content: [
|
|
176
|
+
{
|
|
177
|
+
type: "text",
|
|
178
|
+
text: `App already uploaded — reusing it.\n\n**Project ID**: ${existingId}\n\nNext: upload flows with uploadMaestroFlows, then start a run with runMaestroTest.`,
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
const result = await client().uploadApp(safePath);
|
|
184
|
+
return {
|
|
185
|
+
content: [
|
|
186
|
+
{
|
|
187
|
+
type: "text",
|
|
188
|
+
text: `App uploaded successfully!\n\n**Project ID**: ${result.id}\n\nNext: upload flows with uploadMaestroFlows, then start a run with runMaestroTest.`,
|
|
189
|
+
},
|
|
190
|
+
],
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
return handleMCPError("uploadMaestroApp", error);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
tools.uploadMaestroFlows = server.tool("uploadMaestroFlows", "Upload Maestro flow YAML files for a project. Accepts a local directory (all .yaml/.yml files, preserving structure), a pre-built .zip, or inline flow content. Replaces any previously uploaded flows for the project.", {
|
|
198
|
+
projectId: z
|
|
199
|
+
.union([z.number(), z.string().transform(Number)])
|
|
200
|
+
.pipe(z.number().int().positive())
|
|
201
|
+
.describe("Project ID returned by uploadMaestroApp"),
|
|
202
|
+
flowsPath: z
|
|
203
|
+
.string()
|
|
204
|
+
.optional()
|
|
205
|
+
.describe("Local path to a directory containing flow YAML files, or to a .zip of flows"),
|
|
206
|
+
flows: z
|
|
207
|
+
.array(z.object({
|
|
208
|
+
fileName: z
|
|
209
|
+
.string()
|
|
210
|
+
.describe("Relative file name, e.g. login.yaml or flows/checkout.yaml"),
|
|
211
|
+
content: z.string().describe("The Maestro flow YAML content"),
|
|
212
|
+
}))
|
|
213
|
+
.optional()
|
|
214
|
+
.describe("Inline flow files to upload instead of flowsPath"),
|
|
215
|
+
}, async (args) => {
|
|
216
|
+
try {
|
|
217
|
+
const zipBuffer = buildFlowsZip(args);
|
|
218
|
+
logger.info({ projectId: args.projectId, bytes: zipBuffer.length }, "Uploading Maestro flows");
|
|
219
|
+
await client().uploadFlowsZip(Number(args.projectId), zipBuffer, "flows.zip");
|
|
220
|
+
return {
|
|
221
|
+
content: [
|
|
222
|
+
{
|
|
223
|
+
type: "text",
|
|
224
|
+
text: `Flows uploaded successfully for project ${args.projectId}.\n\nNext: start a run with runMaestroTest.`,
|
|
225
|
+
},
|
|
226
|
+
],
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
catch (error) {
|
|
230
|
+
return handleMCPError("uploadMaestroFlows", error);
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
tools.runMaestroTest = server.tool("runMaestroTest", "Start a Maestro test run on a TestingBot device. Returns immediately with the run ID — it does NOT wait for completion. Poll with getMaestroRunStatus, then fetch getMaestroRunResults once completed.", {
|
|
234
|
+
projectId: z
|
|
235
|
+
.union([z.number(), z.string().transform(Number)])
|
|
236
|
+
.pipe(z.number().int().positive())
|
|
237
|
+
.describe("Project ID returned by uploadMaestroApp"),
|
|
238
|
+
platformName: z.enum(["Android", "iOS"]).describe("Mobile platform to run on"),
|
|
239
|
+
deviceName: z
|
|
240
|
+
.string()
|
|
241
|
+
.optional()
|
|
242
|
+
.describe('Device name, supports wildcards/regex (e.g. "Pixel 8", "iPhone 1[4-6]", "*"). Default: any device'),
|
|
243
|
+
version: z.string().optional().describe('OS version (e.g. "14")'),
|
|
244
|
+
realDevice: z
|
|
245
|
+
.boolean()
|
|
246
|
+
.optional()
|
|
247
|
+
.default(false)
|
|
248
|
+
.describe("Run on a physical device instead of an emulator/simulator (required for .ipa apps)"),
|
|
249
|
+
name: z
|
|
250
|
+
.string()
|
|
251
|
+
.optional()
|
|
252
|
+
.describe("A name for this test run, shown in the TestingBot dashboard"),
|
|
253
|
+
env: z
|
|
254
|
+
.record(z.string())
|
|
255
|
+
.optional()
|
|
256
|
+
.describe("Environment variables passed to the Maestro flows"),
|
|
257
|
+
includeTags: z
|
|
258
|
+
.array(z.string())
|
|
259
|
+
.optional()
|
|
260
|
+
.describe("Only run flows with these Maestro tags"),
|
|
261
|
+
excludeTags: z.array(z.string()).optional().describe("Skip flows with these Maestro tags"),
|
|
262
|
+
shardSplit: z
|
|
263
|
+
.union([z.number(), z.string().transform(Number)])
|
|
264
|
+
.pipe(z.number().int().min(1).max(10))
|
|
265
|
+
.optional()
|
|
266
|
+
.describe("Split flows across this many parallel devices"),
|
|
267
|
+
otherApps: z
|
|
268
|
+
.array(z.string().regex(/^(tb|https?):\/\//, "Must be a tb:// or http(s):// URL"))
|
|
269
|
+
.max(4)
|
|
270
|
+
.optional()
|
|
271
|
+
.describe("Up to 4 companion app URLs (tb:// from uploadMaestroCompanionApp, or http(s)://) installed alongside the app under test"),
|
|
272
|
+
}, async (args) => {
|
|
273
|
+
try {
|
|
274
|
+
const projectId = Number(args.projectId);
|
|
275
|
+
const capabilities = {
|
|
276
|
+
deviceName: args.deviceName || "*",
|
|
277
|
+
platformName: args.platformName,
|
|
278
|
+
};
|
|
279
|
+
if (args.version)
|
|
280
|
+
capabilities.version = args.version;
|
|
281
|
+
if (args.name)
|
|
282
|
+
capabilities.name = args.name;
|
|
283
|
+
if (args.realDevice)
|
|
284
|
+
capabilities.realDevice = "true";
|
|
285
|
+
const maestroOptions = {};
|
|
286
|
+
if (args.env && Object.keys(args.env).length > 0)
|
|
287
|
+
maestroOptions.env = args.env;
|
|
288
|
+
if (args.includeTags?.length)
|
|
289
|
+
maestroOptions.includeTags = args.includeTags;
|
|
290
|
+
if (args.excludeTags?.length)
|
|
291
|
+
maestroOptions.excludeTags = args.excludeTags;
|
|
292
|
+
logger.info({ projectId, capabilities }, "Starting Maestro run");
|
|
293
|
+
const started = await client().startRun(projectId, capabilities, maestroOptions, args.shardSplit, args.otherApps);
|
|
294
|
+
const runs = started.runs || [];
|
|
295
|
+
const runList = runs
|
|
296
|
+
.map((run) => `- Run **${run.id}**${run.flows?.length ? ` (${run.flows.length} flow${run.flows.length === 1 ? "" : "s"})` : ""}`)
|
|
297
|
+
.join("\n");
|
|
298
|
+
return {
|
|
299
|
+
content: [
|
|
300
|
+
{
|
|
301
|
+
type: "text",
|
|
302
|
+
text: `Maestro run started on project ${projectId} (running asynchronously).\n\n${runList || "Run queued; IDs not yet available."}\n\n` +
|
|
303
|
+
`Poll progress with getMaestroRunStatus (every 10-15 seconds), then fetch getMaestroRunResults when completed.`,
|
|
304
|
+
},
|
|
305
|
+
],
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
catch (error) {
|
|
309
|
+
return handleMCPError("runMaestroTest", error);
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
tools.getMaestroRunStatus = server.tool("getMaestroRunStatus", "Get the status of Maestro run(s) for a project. Omit runId to list all runs of the latest execution. Statuses: WAITING, READY (running), DONE, FAILED, CANCELLED.", {
|
|
313
|
+
projectId: z
|
|
314
|
+
.union([z.number(), z.string().transform(Number)])
|
|
315
|
+
.pipe(z.number().int().positive())
|
|
316
|
+
.describe("Project ID"),
|
|
317
|
+
runId: z
|
|
318
|
+
.union([z.number(), z.string().transform(Number)])
|
|
319
|
+
.pipe(z.number().int().positive())
|
|
320
|
+
.optional()
|
|
321
|
+
.describe("Specific run ID to inspect"),
|
|
322
|
+
}, async (args) => {
|
|
323
|
+
try {
|
|
324
|
+
const projectId = Number(args.projectId);
|
|
325
|
+
if (args.runId) {
|
|
326
|
+
const run = await client().getRun(projectId, Number(args.runId));
|
|
327
|
+
const done = run.completed
|
|
328
|
+
? "\n\nRun is complete — fetch getMaestroRunResults for the full report."
|
|
329
|
+
: "";
|
|
330
|
+
return {
|
|
331
|
+
content: [
|
|
332
|
+
{
|
|
333
|
+
type: "text",
|
|
334
|
+
text: `## Maestro Run Status (project ${projectId})\n\n${formatRun(run)}${done}`,
|
|
335
|
+
},
|
|
336
|
+
],
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
const status = await client().getProjectStatus(projectId);
|
|
340
|
+
let out = `## Maestro Runs (project ${projectId}) — ${status.completed ? "completed" : "in progress"}\n\n`;
|
|
341
|
+
for (const run of status.runs || []) {
|
|
342
|
+
out += formatRun(run) + "\n";
|
|
343
|
+
}
|
|
344
|
+
return { content: [{ type: "text", text: out }] };
|
|
345
|
+
}
|
|
346
|
+
catch (error) {
|
|
347
|
+
return handleMCPError("getMaestroRunStatus", error);
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
tools.getMaestroRunResults = server.tool("getMaestroRunResults", "Get the final results of a completed Maestro run: per-flow outcomes (failures first, with error messages and video links) plus the JUnit XML report.", {
|
|
351
|
+
projectId: z
|
|
352
|
+
.union([z.number(), z.string().transform(Number)])
|
|
353
|
+
.pipe(z.number().int().positive())
|
|
354
|
+
.describe("Project ID"),
|
|
355
|
+
runId: z
|
|
356
|
+
.union([z.number(), z.string().transform(Number)])
|
|
357
|
+
.pipe(z.number().int().positive())
|
|
358
|
+
.describe("Run ID"),
|
|
359
|
+
}, async (args) => {
|
|
360
|
+
try {
|
|
361
|
+
const projectId = Number(args.projectId);
|
|
362
|
+
const runId = Number(args.runId);
|
|
363
|
+
const run = await client().getRun(projectId, runId);
|
|
364
|
+
let junit = "";
|
|
365
|
+
try {
|
|
366
|
+
junit = await client().getJunitReport(projectId, runId);
|
|
367
|
+
}
|
|
368
|
+
catch {
|
|
369
|
+
junit = "(JUnit report not available yet)";
|
|
370
|
+
}
|
|
371
|
+
const outcome = run.status === "DONE" && run.success
|
|
372
|
+
? "PASSED ✅"
|
|
373
|
+
: run.status === "FAILED" || !run.success
|
|
374
|
+
? "FAILED ❌"
|
|
375
|
+
: run.status;
|
|
376
|
+
const text = `## Maestro Run ${runId} Results — ${outcome}\n\n${formatRun(run)}\n` +
|
|
377
|
+
`### JUnit Report\n\n\`\`\`xml\n${junit}\n\`\`\``;
|
|
378
|
+
return { content: [{ type: "text", text }] };
|
|
379
|
+
}
|
|
380
|
+
catch (error) {
|
|
381
|
+
return handleMCPError("getMaestroRunResults", error);
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
tools.uploadMaestroCompanionApp = server.tool("uploadMaestroCompanionApp", "Upload a companion app (.apk/.aab/.ipa) that should be installed alongside the app under test in a Maestro run. Returns a tb:// app URL to pass in runMaestroTest's otherApps parameter (max 4 per run).", {
|
|
385
|
+
localFilePath: z.string().describe("Local path to the companion .apk, .aab, .ipa or .zip"),
|
|
386
|
+
}, async (args) => {
|
|
387
|
+
try {
|
|
388
|
+
const safePath = validateAppPath(args.localFilePath);
|
|
389
|
+
logger.info({ path: safePath }, "Uploading Maestro companion app");
|
|
390
|
+
const result = await client().uploadOtherApp(safePath);
|
|
391
|
+
return {
|
|
392
|
+
content: [
|
|
393
|
+
{
|
|
394
|
+
type: "text",
|
|
395
|
+
text: `Companion app uploaded successfully!\n\n**App URL**: ${result.app_url}\n\nPass this URL in runMaestroTest's otherApps parameter to install it alongside the app under test.`,
|
|
396
|
+
},
|
|
397
|
+
],
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
catch (error) {
|
|
401
|
+
return handleMCPError("uploadMaestroCompanionApp", error);
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
tools.listMaestroProjects = server.tool("listMaestroProjects", "List Maestro projects on the account (newest first): app details, flow names, and run IDs. Use this to find an existing projectId instead of re-uploading an app.", {
|
|
405
|
+
offset: z
|
|
406
|
+
.union([z.number(), z.string().transform(Number)])
|
|
407
|
+
.pipe(z.number().min(0))
|
|
408
|
+
.optional()
|
|
409
|
+
.default(0)
|
|
410
|
+
.describe("Offset for pagination (default: 0)"),
|
|
411
|
+
count: z
|
|
412
|
+
.union([z.number(), z.string().transform(Number)])
|
|
413
|
+
.pipe(z.number().min(1).max(100))
|
|
414
|
+
.optional()
|
|
415
|
+
.default(10)
|
|
416
|
+
.describe("Number of projects to retrieve (default: 10, max: 100)"),
|
|
417
|
+
}, async (args) => {
|
|
418
|
+
try {
|
|
419
|
+
const offset = Number(args.offset ?? 0);
|
|
420
|
+
const count = Number(args.count ?? 10);
|
|
421
|
+
const result = await client().listProjects(offset, count);
|
|
422
|
+
const projects = result.data || [];
|
|
423
|
+
let out = `## Maestro Projects (${projects.length} of ${result.meta?.total ?? "?"}, offset ${offset})\n\n`;
|
|
424
|
+
if (projects.length === 0) {
|
|
425
|
+
out += "No Maestro projects found.\n";
|
|
426
|
+
}
|
|
427
|
+
for (const project of projects) {
|
|
428
|
+
out += `### Project ${project.id}${project.name ? ` — ${project.name}` : ""} (${project.completed ? "completed" : "in progress"})\n`;
|
|
429
|
+
if (project.app?.bundle_id) {
|
|
430
|
+
out += `- **App**: ${project.app.bundle_id}${project.app.app_version ? ` v${project.app.app_version}` : ""}\n`;
|
|
431
|
+
}
|
|
432
|
+
if (project.flows?.length) {
|
|
433
|
+
out += `- **Flows**: ${project.flows.map((f) => f.name || `#${f.id}`).join(", ")}\n`;
|
|
434
|
+
}
|
|
435
|
+
if (project.runs?.length) {
|
|
436
|
+
out += `- **Run IDs**: ${project.runs.join(", ")}\n`;
|
|
437
|
+
}
|
|
438
|
+
if (project.created_at) {
|
|
439
|
+
out += `- **Created**: ${project.created_at}\n`;
|
|
440
|
+
}
|
|
441
|
+
out += "\n";
|
|
442
|
+
}
|
|
443
|
+
return { content: [{ type: "text", text: out }] };
|
|
444
|
+
}
|
|
445
|
+
catch (error) {
|
|
446
|
+
return handleMCPError("listMaestroProjects", error);
|
|
447
|
+
}
|
|
448
|
+
});
|
|
449
|
+
tools.listMaestroRuns = server.tool("listMaestroRuns", "List Maestro runs across all projects (newest first), or look up runs by their build/run name. Returns projectId + runId pairs for use with getMaestroRunStatus and getMaestroRunResults.", {
|
|
450
|
+
buildName: z
|
|
451
|
+
.string()
|
|
452
|
+
.optional()
|
|
453
|
+
.describe("Look up runs with this exact run name instead of listing all runs"),
|
|
454
|
+
offset: z
|
|
455
|
+
.union([z.number(), z.string().transform(Number)])
|
|
456
|
+
.pipe(z.number().min(0))
|
|
457
|
+
.optional()
|
|
458
|
+
.default(0)
|
|
459
|
+
.describe("Offset for pagination (default: 0; ignored with buildName)"),
|
|
460
|
+
count: z
|
|
461
|
+
.union([z.number(), z.string().transform(Number)])
|
|
462
|
+
.pipe(z.number().min(1).max(100))
|
|
463
|
+
.optional()
|
|
464
|
+
.default(10)
|
|
465
|
+
.describe("Number of runs to retrieve (default: 10, max: 100; ignored with buildName)"),
|
|
466
|
+
}, async (args) => {
|
|
467
|
+
try {
|
|
468
|
+
let runs;
|
|
469
|
+
let heading;
|
|
470
|
+
if (args.buildName) {
|
|
471
|
+
const result = await client().findRunsByBuildName(args.buildName);
|
|
472
|
+
runs = result.data || [];
|
|
473
|
+
heading = `## Maestro Runs named "${args.buildName}" (${runs.length})\n\n`;
|
|
474
|
+
}
|
|
475
|
+
else {
|
|
476
|
+
const offset = Number(args.offset ?? 0);
|
|
477
|
+
const count = Number(args.count ?? 10);
|
|
478
|
+
const result = await client().listRuns(offset, count);
|
|
479
|
+
runs = result.data || [];
|
|
480
|
+
heading = `## Maestro Runs (${runs.length} of ${result.meta?.total ?? "?"}, offset ${offset})\n\n`;
|
|
481
|
+
}
|
|
482
|
+
let out = heading;
|
|
483
|
+
if (runs.length === 0) {
|
|
484
|
+
out += "No Maestro runs found.\n";
|
|
485
|
+
}
|
|
486
|
+
for (const run of runs) {
|
|
487
|
+
const caps = run.capabilities;
|
|
488
|
+
const outcome = run.status === "DONE" && run.success
|
|
489
|
+
? "PASSED"
|
|
490
|
+
: run.status === "FAILED" || (run.status === "DONE" && !run.success)
|
|
491
|
+
? "FAILED"
|
|
492
|
+
: run.status;
|
|
493
|
+
out += `- Run **${run.id}** (project ${run.project_id})${run.name ? ` "${run.name}"` : ""} — ${outcome}`;
|
|
494
|
+
if (caps?.deviceName)
|
|
495
|
+
out += ` on ${caps.deviceName}`;
|
|
496
|
+
if (run.created_at)
|
|
497
|
+
out += `, started ${run.created_at}`;
|
|
498
|
+
out += "\n";
|
|
499
|
+
}
|
|
500
|
+
out +=
|
|
501
|
+
"\nUse getMaestroRunStatus / getMaestroRunResults with a projectId + runId for details.";
|
|
502
|
+
return { content: [{ type: "text", text: out }] };
|
|
503
|
+
}
|
|
504
|
+
catch (error) {
|
|
505
|
+
return handleMCPError("listMaestroRuns", error);
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
tools.getMaestroFlowDetails = server.tool("getMaestroFlowDetails", "Get the detailed result of a single Maestro flow: error messages, step-level JUnit report, and links to the video, screenshots, and device logs. Use this to diagnose why a flow failed before fixing it and calling retryMaestroRun.", {
|
|
509
|
+
projectId: z
|
|
510
|
+
.union([z.number(), z.string().transform(Number)])
|
|
511
|
+
.pipe(z.number().int().positive())
|
|
512
|
+
.describe("Project ID"),
|
|
513
|
+
runId: z
|
|
514
|
+
.union([z.number(), z.string().transform(Number)])
|
|
515
|
+
.pipe(z.number().int().positive())
|
|
516
|
+
.describe("Run ID"),
|
|
517
|
+
flowId: z
|
|
518
|
+
.union([z.number(), z.string().transform(Number)])
|
|
519
|
+
.pipe(z.number().int().positive())
|
|
520
|
+
.describe("Flow ID (from getMaestroRunStatus output)"),
|
|
521
|
+
}, async (args) => {
|
|
522
|
+
try {
|
|
523
|
+
const flow = await client().getFlowResult(Number(args.projectId), Number(args.runId), Number(args.flowId));
|
|
524
|
+
const outcome = flow.status === "DONE" && flow.success
|
|
525
|
+
? "PASSED ✅"
|
|
526
|
+
: flow.status === "FAILED" || flow.success === 0
|
|
527
|
+
? "FAILED ❌"
|
|
528
|
+
: flow.status;
|
|
529
|
+
let text = `## Flow "${flow.name}" (id ${flow.id}) — ${outcome}\n\n`;
|
|
530
|
+
if (flow.error_messages?.length) {
|
|
531
|
+
text += `### Errors\n${flow.error_messages.map((m) => `- ${m}`).join("\n")}\n\n`;
|
|
532
|
+
}
|
|
533
|
+
if (flow.test?.environment?.name) {
|
|
534
|
+
const env = flow.test.environment;
|
|
535
|
+
text += `- **Device**: ${env.name}${env.version ? ` (${env.version})` : ""}\n`;
|
|
536
|
+
}
|
|
537
|
+
if (flow.test?.sessionId) {
|
|
538
|
+
text += `- **Session ID**: ${flow.test.sessionId}\n`;
|
|
539
|
+
}
|
|
540
|
+
if (flow.completed_at) {
|
|
541
|
+
text += `- **Completed**: ${flow.completed_at}\n`;
|
|
542
|
+
}
|
|
543
|
+
if (flow.assets) {
|
|
544
|
+
text += `\n### Assets\n`;
|
|
545
|
+
if (flow.assets.video)
|
|
546
|
+
text += `- **Video**: ${flow.assets.video}\n`;
|
|
547
|
+
if (flow.assets.screenshots?.length) {
|
|
548
|
+
text += flow.assets.screenshots.map((s) => `- **Screenshot**: ${s}`).join("\n") + "\n";
|
|
549
|
+
}
|
|
550
|
+
if (flow.assets.logs) {
|
|
551
|
+
text += `- **Logs**: ${typeof flow.assets.logs === "string"
|
|
552
|
+
? flow.assets.logs
|
|
553
|
+
: JSON.stringify(flow.assets.logs)}\n`;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
else if (flow.assets_synced === false) {
|
|
557
|
+
text += `\nAssets (video/screenshots/logs) are still syncing — check again shortly.\n`;
|
|
558
|
+
}
|
|
559
|
+
if (flow.report) {
|
|
560
|
+
text += `\n### Step Report\n\n\`\`\`xml\n${flow.report}\n\`\`\``;
|
|
561
|
+
}
|
|
562
|
+
return { content: [{ type: "text", text }] };
|
|
563
|
+
}
|
|
564
|
+
catch (error) {
|
|
565
|
+
return handleMCPError("getMaestroFlowDetails", error);
|
|
566
|
+
}
|
|
567
|
+
});
|
|
568
|
+
tools.cancelMaestroRun = server.tool("cancelMaestroRun", "Cancel a running Maestro run.", {
|
|
569
|
+
projectId: z
|
|
570
|
+
.union([z.number(), z.string().transform(Number)])
|
|
571
|
+
.pipe(z.number().int().positive())
|
|
572
|
+
.describe("Project ID"),
|
|
573
|
+
runId: z
|
|
574
|
+
.union([z.number(), z.string().transform(Number)])
|
|
575
|
+
.pipe(z.number().int().positive())
|
|
576
|
+
.describe("Run ID to cancel"),
|
|
577
|
+
}, async (args) => {
|
|
578
|
+
try {
|
|
579
|
+
await client().cancelRun(Number(args.projectId), Number(args.runId));
|
|
580
|
+
return { content: [{ type: "text", text: `Maestro run ${args.runId} cancelled.` }] };
|
|
581
|
+
}
|
|
582
|
+
catch (error) {
|
|
583
|
+
return handleMCPError("cancelMaestroRun", error);
|
|
584
|
+
}
|
|
585
|
+
});
|
|
586
|
+
tools.retryMaestroRun = server.tool("retryMaestroRun", "Retry a Maestro run, or a single failed flow within it when flowId is given.", {
|
|
587
|
+
projectId: z
|
|
588
|
+
.union([z.number(), z.string().transform(Number)])
|
|
589
|
+
.pipe(z.number().int().positive())
|
|
590
|
+
.describe("Project ID"),
|
|
591
|
+
runId: z
|
|
592
|
+
.union([z.number(), z.string().transform(Number)])
|
|
593
|
+
.pipe(z.number().int().positive())
|
|
594
|
+
.describe("Run ID to retry"),
|
|
595
|
+
flowId: z
|
|
596
|
+
.union([z.number(), z.string().transform(Number)])
|
|
597
|
+
.pipe(z.number().int().positive())
|
|
598
|
+
.optional()
|
|
599
|
+
.describe("Retry only this flow (from getMaestroRunStatus output)"),
|
|
600
|
+
}, async (args) => {
|
|
601
|
+
try {
|
|
602
|
+
const projectId = Number(args.projectId);
|
|
603
|
+
const runId = Number(args.runId);
|
|
604
|
+
if (args.flowId) {
|
|
605
|
+
await client().retryFlow(projectId, runId, Number(args.flowId));
|
|
606
|
+
}
|
|
607
|
+
else {
|
|
608
|
+
await client().retryRun(projectId, runId);
|
|
609
|
+
}
|
|
610
|
+
return {
|
|
611
|
+
content: [
|
|
612
|
+
{
|
|
613
|
+
type: "text",
|
|
614
|
+
text: `Retry queued for ${args.flowId ? `flow ${args.flowId} of ` : ""}run ${runId}. Poll with getMaestroRunStatus.`,
|
|
615
|
+
},
|
|
616
|
+
],
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
catch (error) {
|
|
620
|
+
return handleMCPError("retryMaestroRun", error);
|
|
621
|
+
}
|
|
622
|
+
});
|
|
623
|
+
return tools;
|
|
624
|
+
}
|
|
625
|
+
//# sourceMappingURL=maestro.js.map
|