@browserstack/mcp-server 1.3.1 → 1.3.2-beta.1
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 +36 -29
- package/dist/tools/automate-utils/list-session-ids.d.ts +23 -0
- package/dist/tools/automate-utils/list-session-ids.js +80 -0
- package/dist/tools/automate.d.ts +7 -0
- package/dist/tools/automate.js +76 -0
- package/dist/tools/build-insights.js +16 -1
- package/dist/tools/failurelogs-utils/resolve-app-build-id.d.ts +2 -0
- package/dist/tools/failurelogs-utils/resolve-app-build-id.js +25 -0
- package/dist/tools/get-failure-logs.js +11 -6
- package/dist/tools/rca-agent-utils/get-failed-test-id.js +12 -0
- package/dist/tools/rca-agent-utils/types.d.ts +1 -0
- package/dist/tools/rca-agent.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -294,7 +294,7 @@ Select the “Installed” tab. Click the “Configure MCP Servers” button at
|
|
|
294
294
|
|
|
295
295
|
### 💡 List of BrowserStack MCP Tools
|
|
296
296
|
|
|
297
|
-
As of now we support
|
|
297
|
+
As of now we support 45 tools.
|
|
298
298
|
|
|
299
299
|
> **Remote MCP note:** Tools marked _(not available in Remote MCP)_ rely on local file/process state and are disabled in the multi-tenant [Remote MCP Server](#-remote-mcp-server). They are available in the local (npx) setup.
|
|
300
300
|
|
|
@@ -426,18 +426,25 @@ As of now we support 44 tools.
|
|
|
426
426
|
Get screenshots from Automate session ID abc123xyz for my desktop test run
|
|
427
427
|
```
|
|
428
428
|
|
|
429
|
+
18. `listSessions` — List the sessions in an Automate/App Automate build. Each record carries `sessionId`, `name`, `status`, `os`, `osVersion`, `browser`, `device`, and `browserUrl` (dashboard link), with optional `limit` / `offset` paging and a client-side `status` filter. Takes the **hashed** build ID from the dashboard URL — not the observability UUID returned by `getBuildId` / `listBuildId`; if you only have that UUID, use `hashed_id` from `fetchBuildInsights` when present. Returned `sessionId` values work with `getFailureLogs`, `fetchAutomationScreenshots`, and `fetchSelfHealedSelectors`.
|
|
430
|
+
**Prompt example**
|
|
431
|
+
|
|
432
|
+
```text
|
|
433
|
+
List sessions for Automate hashed build ID <hashed build id>
|
|
434
|
+
```
|
|
435
|
+
|
|
429
436
|
---
|
|
430
437
|
|
|
431
438
|
## 🔍 Observability
|
|
432
439
|
|
|
433
|
-
|
|
440
|
+
19. `getFailureLogs` — Retrieve error logs for Automate/App Automate sessions. App Automate log endpoints are build-scoped, so a hashed build ID is required there — pass one if you have it, otherwise it is resolved from the session automatically.
|
|
434
441
|
**Prompt example**
|
|
435
442
|
|
|
436
443
|
```text
|
|
437
|
-
Get the
|
|
444
|
+
Get the Appium logs for App Automate session ID <session id>
|
|
438
445
|
```
|
|
439
446
|
|
|
440
|
-
|
|
447
|
+
20. `fetchBuildInsights` — Fetch insights about a BrowserStack build by combining build details and quality-gate results. Includes `hashed_id` (the hashed build id `listSessions` takes) when the build payload reports one.
|
|
441
448
|
**Prompt example**
|
|
442
449
|
|
|
443
450
|
```text
|
|
@@ -448,7 +455,7 @@ As of now we support 44 tools.
|
|
|
448
455
|
|
|
449
456
|
## 📱 App Live
|
|
450
457
|
|
|
451
|
-
|
|
458
|
+
21. `runAppLiveSession` — Start a manual app testing session on a real device in the cloud.
|
|
452
459
|
**Prompt example**
|
|
453
460
|
|
|
454
461
|
```text
|
|
@@ -459,7 +466,7 @@ As of now we support 44 tools.
|
|
|
459
466
|
|
|
460
467
|
## 💻 Live
|
|
461
468
|
|
|
462
|
-
|
|
469
|
+
22. `runBrowserLiveSession` — Start a Live session for website testing on desktop or mobile browsers.
|
|
463
470
|
**Prompt example**
|
|
464
471
|
|
|
465
472
|
```text
|
|
@@ -470,21 +477,21 @@ As of now we support 44 tools.
|
|
|
470
477
|
|
|
471
478
|
## 📲 App Automate
|
|
472
479
|
|
|
473
|
-
|
|
480
|
+
23. `takeAppScreenshot` — Launch the app on a specified device and capture a quick verification screenshot to confirm your app has launched.
|
|
474
481
|
**Prompt example**
|
|
475
482
|
|
|
476
483
|
```text
|
|
477
484
|
Take a screenshot of my app on Google Pixel 6 with Android 12 while testing on App Automate. App file path: /Users/xyz/app-debug.apk
|
|
478
485
|
```
|
|
479
486
|
|
|
480
|
-
|
|
487
|
+
24. `runAppTestsOnBrowserStack` — Run pre-built native mobile test suites (Espresso/XCUITest) by direct upload of compiled .apk/.ipa test files.
|
|
481
488
|
**Prompt example**
|
|
482
489
|
|
|
483
490
|
```text
|
|
484
491
|
Run Espresso tests from /tests/checkout.zip on Galaxy S21 and Pixel 6 with Android 12. App path is /apps/beta-release.apk under project 'Checkout Flow'
|
|
485
492
|
```
|
|
486
493
|
|
|
487
|
-
|
|
494
|
+
25. `setupBrowserStackAppAutomateTests` — Set up BrowserStack App Automate SDK integration for Appium-based mobile app testing.
|
|
488
495
|
**Prompt example**
|
|
489
496
|
|
|
490
497
|
```text
|
|
@@ -495,35 +502,35 @@ As of now we support 44 tools.
|
|
|
495
502
|
|
|
496
503
|
## ♿ Accessibility
|
|
497
504
|
|
|
498
|
-
|
|
505
|
+
26. `accessibilityExpert` — Ask the A11y Expert (WCAG 2.0/2.1/2.2, mobile/web usability, best practices).
|
|
499
506
|
**Prompt example**
|
|
500
507
|
|
|
501
508
|
```text
|
|
502
509
|
What WCAG guidelines apply to form field error messages on mobile web?
|
|
503
510
|
```
|
|
504
511
|
|
|
505
|
-
|
|
512
|
+
27. `startAccessibilityScan` — Start a web accessibility scan and retrieve a local CSV report path.
|
|
506
513
|
**Prompt example**
|
|
507
514
|
|
|
508
515
|
```text
|
|
509
516
|
Run accessibility scan for "www.example.com"
|
|
510
517
|
```
|
|
511
518
|
|
|
512
|
-
|
|
519
|
+
28. `createAccessibilityAuthConfig` — Create an authentication configuration (form-based or basic) for accessibility scans behind a login.
|
|
513
520
|
**Prompt example**
|
|
514
521
|
|
|
515
522
|
```text
|
|
516
523
|
Create a basic-auth accessibility config named 'site-login' for https://www.example.com with username testuser and password <password>
|
|
517
524
|
```
|
|
518
525
|
|
|
519
|
-
|
|
526
|
+
29. `getAccessibilityAuthConfig` — Retrieve an existing accessibility authentication configuration by ID.
|
|
520
527
|
**Prompt example**
|
|
521
528
|
|
|
522
529
|
```text
|
|
523
530
|
Get accessibility auth config with ID <config-id>
|
|
524
531
|
```
|
|
525
532
|
|
|
526
|
-
|
|
533
|
+
30. `fetchAccessibilityIssues` — Fetch accessibility issues from a completed scan, with pagination support.
|
|
527
534
|
**Prompt example**
|
|
528
535
|
|
|
529
536
|
```text
|
|
@@ -534,49 +541,49 @@ As of now we support 44 tools.
|
|
|
534
541
|
|
|
535
542
|
## 🎨 Percy Visual Testing
|
|
536
543
|
|
|
537
|
-
|
|
544
|
+
31. `percyVisualTestIntegrationAgent` — Integrate Percy visual testing into a new project and demonstrate visual change detection with a step-by-step simulation.
|
|
538
545
|
**Prompt example**
|
|
539
546
|
|
|
540
547
|
```text
|
|
541
548
|
Integrate Percy for this project
|
|
542
549
|
```
|
|
543
550
|
|
|
544
|
-
|
|
551
|
+
32. `expandPercyVisualTesting` — Set up or expand Percy visual testing coverage for existing projects (Percy Web Standalone and Percy Automate).
|
|
545
552
|
**Prompt example**
|
|
546
553
|
|
|
547
554
|
```text
|
|
548
555
|
Expand Percy coverage for this project
|
|
549
556
|
```
|
|
550
557
|
|
|
551
|
-
|
|
558
|
+
33. `addPercySnapshotCommands` — Add Percy snapshot commands to the specified test files. _(not available in Remote MCP)_
|
|
552
559
|
**Prompt example**
|
|
553
560
|
|
|
554
561
|
```text
|
|
555
562
|
Add Percy snapshot commands to my Cypress test files
|
|
556
563
|
```
|
|
557
564
|
|
|
558
|
-
|
|
565
|
+
34. `listTestFiles` — List all test files for a given set of directories. _(not available in Remote MCP)_
|
|
559
566
|
**Prompt example**
|
|
560
567
|
|
|
561
568
|
```text
|
|
562
569
|
List the test files under my ./tests directory
|
|
563
570
|
```
|
|
564
571
|
|
|
565
|
-
|
|
572
|
+
35. `runPercyScan` — Run a Percy visual test scan. _(not available in Remote MCP)_
|
|
566
573
|
**Prompt example**
|
|
567
574
|
|
|
568
575
|
```text
|
|
569
576
|
Run this Percy build
|
|
570
577
|
```
|
|
571
578
|
|
|
572
|
-
|
|
579
|
+
36. `fetchPercyChanges` — Retrieve and summarize visual changes detected by Percy AI between the latest and previous builds.
|
|
573
580
|
**Prompt example**
|
|
574
581
|
|
|
575
582
|
```text
|
|
576
583
|
Summarize the visual changes Percy detected in my latest build
|
|
577
584
|
```
|
|
578
585
|
|
|
579
|
-
|
|
586
|
+
37. `managePercyBuildApproval` — Approve or reject a Percy build.
|
|
580
587
|
**Prompt example**
|
|
581
588
|
|
|
582
589
|
```text
|
|
@@ -587,56 +594,56 @@ As of now we support 44 tools.
|
|
|
587
594
|
|
|
588
595
|
## 🤖 BrowserStack AI Agents
|
|
589
596
|
|
|
590
|
-
|
|
597
|
+
38. `uploadProductRequirementFile` — Upload a PRD/screenshot/PDF and get a file mapping ID (used with `createTestCasesFromFile`). _(not available in Remote MCP)_
|
|
591
598
|
**Prompt example**
|
|
592
599
|
|
|
593
600
|
```text
|
|
594
601
|
Upload PRD from /Users/xyz/Desktop/login-flow.pdf and use BrowserStack AI to generate test cases
|
|
595
602
|
```
|
|
596
603
|
|
|
597
|
-
|
|
604
|
+
39. `createLCASteps` — Generate Low Code Automation (LCA) steps from a manual test case in Test Management.
|
|
598
605
|
**Prompt example**
|
|
599
606
|
|
|
600
607
|
```text
|
|
601
608
|
Convert the manual test case 'Add to Cart' in the 'Shopping App' project into LCA steps
|
|
602
609
|
```
|
|
603
610
|
|
|
604
|
-
|
|
611
|
+
40. `fetchSelfHealedSelectors` — Retrieve AI self-healed selectors (plus test source) to fix flaky tests caused by DOM changes.
|
|
605
612
|
**Prompt example**
|
|
606
613
|
|
|
607
614
|
```text
|
|
608
615
|
Fetch and fix flaky test selectors in Automate session ID session_9482 using MCP
|
|
609
616
|
```
|
|
610
617
|
|
|
611
|
-
|
|
618
|
+
41. `prepareSelfHealingPlan` — Build a self-healing edit plan that bundles locator pairs with test source for your LLM to apply. Does NOT modify files itself.
|
|
612
619
|
**Prompt example**
|
|
613
620
|
|
|
614
621
|
```text
|
|
615
622
|
Prepare a self-healing plan from the self-healed selectors for my build
|
|
616
623
|
```
|
|
617
624
|
|
|
618
|
-
|
|
625
|
+
42. `fetchRCA` — Fetch AI Root Cause Analysis for your failed Automate/App-Automate tests (by numeric test ID). Suggests fixes only; never auto-applies.
|
|
619
626
|
**Prompt example**
|
|
620
627
|
|
|
621
628
|
```text
|
|
622
629
|
Fetch the root cause analysis for failed test IDs 101 and 102 on BrowserStack
|
|
623
630
|
```
|
|
624
631
|
|
|
625
|
-
|
|
632
|
+
43. `getBuildId` — Get the BrowserStack build ID for a given project and build name, scoped to your builds.
|
|
626
633
|
**Prompt example**
|
|
627
634
|
|
|
628
635
|
```text
|
|
629
636
|
Get the build ID for build 'nightly-regression' in project 'Checkout Flow'
|
|
630
637
|
```
|
|
631
638
|
|
|
632
|
-
|
|
639
|
+
44. `listBuildId` — Get the latest build ID for a project and build name, across all users (no user filter).
|
|
633
640
|
**Prompt example**
|
|
634
641
|
|
|
635
642
|
```text
|
|
636
643
|
Get the latest build ID for build 'nightly-regression' in project 'Checkout Flow'
|
|
637
644
|
```
|
|
638
645
|
|
|
639
|
-
|
|
646
|
+
45. `listTestIds` — List test IDs from a BrowserStack Automate build, filtered by status (passed/failed/pending/skipped).
|
|
640
647
|
**Prompt example**
|
|
641
648
|
|
|
642
649
|
```text
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SessionType } from "../../lib/constants.js";
|
|
2
|
+
import { BrowserStackConfig } from "../../lib/types.js";
|
|
3
|
+
export declare const DEFAULT_SESSION_LIST_LIMIT = 10;
|
|
4
|
+
export interface ListSessionIdsArgs {
|
|
5
|
+
sessionType: SessionType;
|
|
6
|
+
buildId: string;
|
|
7
|
+
limit?: number;
|
|
8
|
+
offset?: number;
|
|
9
|
+
status?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface SessionIdRecord {
|
|
12
|
+
sessionId: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
status?: string;
|
|
15
|
+
os?: string;
|
|
16
|
+
osVersion?: string;
|
|
17
|
+
browser?: string;
|
|
18
|
+
device?: string | null;
|
|
19
|
+
browserUrl?: string;
|
|
20
|
+
}
|
|
21
|
+
export declare function sessionsListUrl(sessionType: SessionType, buildId: string): string;
|
|
22
|
+
export declare function mapSessionRecords(payload: unknown, statusFilter?: string): SessionIdRecord[];
|
|
23
|
+
export declare function listSessionIds(args: ListSessionIdsArgs, config: BrowserStackConfig): Promise<SessionIdRecord[]>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { SessionType } from "../../lib/constants.js";
|
|
2
|
+
import { getBrowserStackAuth } from "../../lib/get-auth.js";
|
|
3
|
+
import { apiClient } from "../../lib/apiClient.js";
|
|
4
|
+
export const DEFAULT_SESSION_LIST_LIMIT = 10;
|
|
5
|
+
export function sessionsListUrl(sessionType, buildId) {
|
|
6
|
+
const encodedBuildId = encodeURIComponent(buildId);
|
|
7
|
+
switch (sessionType) {
|
|
8
|
+
case SessionType.Automate:
|
|
9
|
+
return `https://api.browserstack.com/automate/builds/${encodedBuildId}/sessions.json`;
|
|
10
|
+
case SessionType.AppAutomate:
|
|
11
|
+
return `https://api-cloud.browserstack.com/app-automate/builds/${encodedBuildId}/sessions.json`;
|
|
12
|
+
default: {
|
|
13
|
+
const _exhaustive = sessionType;
|
|
14
|
+
throw new Error(`Unsupported session type: ${_exhaustive}`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function mapSessionRecords(payload, statusFilter) {
|
|
19
|
+
const items = Array.isArray(payload) ? payload : [];
|
|
20
|
+
const normalizedFilter = statusFilter?.trim().toLowerCase();
|
|
21
|
+
const records = [];
|
|
22
|
+
for (const item of items) {
|
|
23
|
+
const session = item?.automation_session;
|
|
24
|
+
if (!session) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
const sessionId = session.hashed_id?.trim();
|
|
28
|
+
if (!sessionId) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (normalizedFilter &&
|
|
32
|
+
(session.status ?? "").toLowerCase() !== normalizedFilter) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
records.push({
|
|
36
|
+
sessionId,
|
|
37
|
+
name: session.name,
|
|
38
|
+
status: session.status,
|
|
39
|
+
os: session.os,
|
|
40
|
+
osVersion: session.os_version,
|
|
41
|
+
browser: session.browser,
|
|
42
|
+
device: session.device,
|
|
43
|
+
browserUrl: session.browser_url,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return records;
|
|
47
|
+
}
|
|
48
|
+
export async function listSessionIds(args, config) {
|
|
49
|
+
const buildId = args.buildId.trim();
|
|
50
|
+
if (!buildId) {
|
|
51
|
+
throw new Error("Hashed Automate/App Automate build ID is required");
|
|
52
|
+
}
|
|
53
|
+
const authString = getBrowserStackAuth(config);
|
|
54
|
+
const auth = Buffer.from(authString).toString("base64");
|
|
55
|
+
const limit = args.limit ?? DEFAULT_SESSION_LIST_LIMIT;
|
|
56
|
+
const params = { limit };
|
|
57
|
+
if (args.offset !== undefined) {
|
|
58
|
+
params.offset = args.offset;
|
|
59
|
+
}
|
|
60
|
+
const response = await apiClient.get({
|
|
61
|
+
url: sessionsListUrl(args.sessionType, buildId),
|
|
62
|
+
headers: {
|
|
63
|
+
"Content-Type": "application/json",
|
|
64
|
+
Authorization: `Basic ${auth}`,
|
|
65
|
+
},
|
|
66
|
+
params,
|
|
67
|
+
raise_error: false,
|
|
68
|
+
});
|
|
69
|
+
if (!response.ok) {
|
|
70
|
+
if (response.status === 404) {
|
|
71
|
+
throw new Error(`Invalid hashed build ID "${buildId}" for ${args.sessionType}. ` +
|
|
72
|
+
"Use the Automate/App Automate dashboard hashed build id " +
|
|
73
|
+
"(same family as App Automate getFailureLogs buildId), not the " +
|
|
74
|
+
"observability UUID from getBuildId or listBuildId. " +
|
|
75
|
+
"If you only have an observability UUID, call fetchBuildInsights and use hashed_id when present.");
|
|
76
|
+
}
|
|
77
|
+
throw new Error(`Failed to list sessions: ${response.status} ${response.statusText}`);
|
|
78
|
+
}
|
|
79
|
+
return mapSessionRecords(response.data, args.status);
|
|
80
|
+
}
|
package/dist/tools/automate.d.ts
CHANGED
|
@@ -6,4 +6,11 @@ export declare function fetchAutomationScreenshotsTool(args: {
|
|
|
6
6
|
sessionId: string;
|
|
7
7
|
sessionType: SessionType;
|
|
8
8
|
}, config: BrowserStackConfig): Promise<CallToolResult>;
|
|
9
|
+
export declare function listSessionIdsTool(args: {
|
|
10
|
+
sessionType: SessionType;
|
|
11
|
+
buildId: string;
|
|
12
|
+
limit?: number;
|
|
13
|
+
offset?: number;
|
|
14
|
+
status?: string;
|
|
15
|
+
}, config: BrowserStackConfig): Promise<CallToolResult>;
|
|
9
16
|
export default function addAutomationTools(server: McpServer, config: BrowserStackConfig): Record<string, any>;
|
package/dist/tools/automate.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { fetchAutomationScreenshots } from "./automate-utils/fetch-screenshots.js";
|
|
3
|
+
import { DEFAULT_SESSION_LIST_LIMIT, listSessionIds, } from "./automate-utils/list-session-ids.js";
|
|
3
4
|
import { SessionType } from "../lib/constants.js";
|
|
4
5
|
import { trackMCP } from "../lib/instrumentation.js";
|
|
5
6
|
import logger from "../logger.js";
|
|
@@ -48,6 +49,33 @@ export async function fetchAutomationScreenshotsTool(args, config) {
|
|
|
48
49
|
};
|
|
49
50
|
}
|
|
50
51
|
}
|
|
52
|
+
export async function listSessionIdsTool(args, config) {
|
|
53
|
+
try {
|
|
54
|
+
const sessions = await listSessionIds(args, config);
|
|
55
|
+
if (sessions.length === 0) {
|
|
56
|
+
return {
|
|
57
|
+
content: [
|
|
58
|
+
{
|
|
59
|
+
type: "text",
|
|
60
|
+
text: "No sessions found for this hashed build ID.",
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
content: [
|
|
67
|
+
{
|
|
68
|
+
type: "text",
|
|
69
|
+
text: JSON.stringify(sessions, null, 2),
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
logger.error("Error listing session IDs", error);
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
51
79
|
//Registers the fetchAutomationScreenshots tool with the MCP server
|
|
52
80
|
export default function addAutomationTools(server, config) {
|
|
53
81
|
const tools = {};
|
|
@@ -83,5 +111,53 @@ export default function addAutomationTools(server, config) {
|
|
|
83
111
|
};
|
|
84
112
|
}
|
|
85
113
|
});
|
|
114
|
+
tools.listSessions = server.tool("listSessions", "List sessions for a hashed Automate/App Automate build: session IDs, status, OS, browser/device, dashboard URL.", {
|
|
115
|
+
sessionType: z
|
|
116
|
+
.enum([SessionType.Automate, SessionType.AppAutomate])
|
|
117
|
+
.describe("Type of BrowserStack session"),
|
|
118
|
+
buildId: z
|
|
119
|
+
.string()
|
|
120
|
+
.describe("Dashboard hashed build id or fetchBuildInsights hashed_id — not the getBuildId UUID."),
|
|
121
|
+
limit: z
|
|
122
|
+
.number()
|
|
123
|
+
.int()
|
|
124
|
+
.positive()
|
|
125
|
+
.optional()
|
|
126
|
+
.describe(`Max sessions to return. Defaults to ${DEFAULT_SESSION_LIST_LIMIT}.`),
|
|
127
|
+
offset: z
|
|
128
|
+
.number()
|
|
129
|
+
.int()
|
|
130
|
+
.min(0)
|
|
131
|
+
.optional()
|
|
132
|
+
.describe("Pagination offset for the REST session list."),
|
|
133
|
+
status: z
|
|
134
|
+
.string()
|
|
135
|
+
.optional()
|
|
136
|
+
.describe("Optional session status filter (e.g. done, running, error). Applied client-side."),
|
|
137
|
+
}, {
|
|
138
|
+
title: "List Sessions",
|
|
139
|
+
readOnlyHint: true,
|
|
140
|
+
openWorldHint: false,
|
|
141
|
+
destructiveHint: false,
|
|
142
|
+
idempotentHint: true,
|
|
143
|
+
}, async (args) => {
|
|
144
|
+
try {
|
|
145
|
+
trackMCP("listSessions", server.server.getClientVersion(), undefined, config);
|
|
146
|
+
return await listSessionIdsTool(args, config);
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
trackMCP("listSessions", server.server.getClientVersion(), error, config);
|
|
150
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
151
|
+
return {
|
|
152
|
+
content: [
|
|
153
|
+
{
|
|
154
|
+
type: "text",
|
|
155
|
+
text: `Error listing session IDs: ${errorMessage}`,
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
isError: true,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
});
|
|
86
162
|
return tools;
|
|
87
163
|
}
|
|
@@ -15,6 +15,7 @@ export async function fetchBuildInsightsTool(args, config) {
|
|
|
15
15
|
return null;
|
|
16
16
|
}),
|
|
17
17
|
]);
|
|
18
|
+
const hashed_id = extractHashedBuildId(buildData);
|
|
18
19
|
// Select useful fields for users
|
|
19
20
|
const insights = {
|
|
20
21
|
name: buildData.name,
|
|
@@ -33,6 +34,7 @@ export async function fetchBuildInsightsTool(args, config) {
|
|
|
33
34
|
commit_sha: buildData.vcs_info?.sha,
|
|
34
35
|
vcs_name: buildData.vcs_info?.name,
|
|
35
36
|
quality_gate_result: qualityData?.quality_gate_result,
|
|
37
|
+
...(hashed_id ? { hashed_id } : {}),
|
|
36
38
|
};
|
|
37
39
|
const qualityProfiles = qualityData?.quality_profiles?.map((profile) => ({
|
|
38
40
|
name: profile.name,
|
|
@@ -56,10 +58,23 @@ export async function fetchBuildInsightsTool(args, config) {
|
|
|
56
58
|
throw error;
|
|
57
59
|
}
|
|
58
60
|
}
|
|
61
|
+
function extractHashedBuildId(buildData) {
|
|
62
|
+
const candidates = [
|
|
63
|
+
buildData?.hashed_id,
|
|
64
|
+
buildData?.automate_hashed_id,
|
|
65
|
+
buildData?.hashedId,
|
|
66
|
+
];
|
|
67
|
+
for (const candidate of candidates) {
|
|
68
|
+
if (typeof candidate === "string" &&
|
|
69
|
+
/^[a-z0-9]{40}$/i.test(candidate.trim()))
|
|
70
|
+
return candidate.trim();
|
|
71
|
+
}
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
59
74
|
// Registers the fetchBuildInsights tool with the MCP server
|
|
60
75
|
export default function addBuildInsightsTools(server, config) {
|
|
61
76
|
const tools = {};
|
|
62
|
-
tools.fetchBuildInsights = server.tool("fetchBuildInsights", "
|
|
77
|
+
tools.fetchBuildInsights = server.tool("fetchBuildInsights", "Fetch build details and quality gate results. Includes hashed_id, the build id listSessions takes.", {
|
|
63
78
|
buildId: z.string().describe("The build UUID of the BrowserStack build"),
|
|
64
79
|
}, {
|
|
65
80
|
title: "Fetch Build Insights",
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { getBrowserStackAuth } from "../../lib/get-auth.js";
|
|
2
|
+
import { apiClient } from "../../lib/apiClient.js";
|
|
3
|
+
import logger from "../../logger.js";
|
|
4
|
+
export async function resolveAppAutomateBuildId(sessionId, config) {
|
|
5
|
+
const url = `https://api.browserstack.com/app-automate/sessions/${encodeURIComponent(sessionId)}.json`;
|
|
6
|
+
const authString = getBrowserStackAuth(config);
|
|
7
|
+
const auth = Buffer.from(authString).toString("base64");
|
|
8
|
+
const response = await apiClient.get({
|
|
9
|
+
url,
|
|
10
|
+
headers: {
|
|
11
|
+
"Content-Type": "application/json",
|
|
12
|
+
Authorization: `Basic ${auth}`,
|
|
13
|
+
},
|
|
14
|
+
raise_error: false,
|
|
15
|
+
});
|
|
16
|
+
if (!response.ok) {
|
|
17
|
+
logger.warn(`Could not resolve build id for app-automate session ${sessionId}: ${response.status}`);
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
const session = response.data?.automation_session;
|
|
21
|
+
const buildId = session?.build_hashed_id;
|
|
22
|
+
return typeof buildId === "string" && buildId.trim()
|
|
23
|
+
? buildId.trim()
|
|
24
|
+
: undefined;
|
|
25
|
+
}
|
|
@@ -2,6 +2,7 @@ import { z } from "zod";
|
|
|
2
2
|
import { trackMCP } from "../lib/instrumentation.js";
|
|
3
3
|
import { retrieveNetworkFailures, retrieveSessionFailures, retrieveConsoleFailures, } from "./failurelogs-utils/automate.js";
|
|
4
4
|
import { retrieveDeviceLogs, retrieveAppiumLogs, retrieveCrashLogs, } from "./failurelogs-utils/app-automate.js";
|
|
5
|
+
import { resolveAppAutomateBuildId } from "./failurelogs-utils/resolve-app-build-id.js";
|
|
5
6
|
import { AppAutomateLogType, AutomateLogType, SessionType, } from "../lib/constants.js";
|
|
6
7
|
// Main log fetcher function
|
|
7
8
|
export async function getFailureLogs(args, config) {
|
|
@@ -11,8 +12,12 @@ export async function getFailureLogs(args, config) {
|
|
|
11
12
|
if (!args.sessionId) {
|
|
12
13
|
throw new Error("Session ID is required");
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
let buildId = args.buildId;
|
|
16
|
+
if (args.sessionType === SessionType.AppAutomate && !buildId) {
|
|
17
|
+
buildId = await resolveAppAutomateBuildId(args.sessionId, config);
|
|
18
|
+
if (!buildId) {
|
|
19
|
+
throw new Error("Build ID is required for app-automate sessions");
|
|
20
|
+
}
|
|
16
21
|
}
|
|
17
22
|
// Validate log types and collect errors
|
|
18
23
|
validLogTypes = args.logTypes.filter((logType) => {
|
|
@@ -67,17 +72,17 @@ export async function getFailureLogs(args, config) {
|
|
|
67
72
|
break;
|
|
68
73
|
}
|
|
69
74
|
case AppAutomateLogType.DeviceLogs: {
|
|
70
|
-
response = await retrieveDeviceLogs(args.sessionId,
|
|
75
|
+
response = await retrieveDeviceLogs(args.sessionId, buildId, config);
|
|
71
76
|
results.push({ type: "text", text: response });
|
|
72
77
|
break;
|
|
73
78
|
}
|
|
74
79
|
case AppAutomateLogType.AppiumLogs: {
|
|
75
|
-
response = await retrieveAppiumLogs(args.sessionId,
|
|
80
|
+
response = await retrieveAppiumLogs(args.sessionId, buildId, config);
|
|
76
81
|
results.push({ type: "text", text: response });
|
|
77
82
|
break;
|
|
78
83
|
}
|
|
79
84
|
case AppAutomateLogType.CrashLogs: {
|
|
80
|
-
response = await retrieveCrashLogs(args.sessionId,
|
|
85
|
+
response = await retrieveCrashLogs(args.sessionId, buildId, config);
|
|
81
86
|
results.push({ type: "text", text: response });
|
|
82
87
|
break;
|
|
83
88
|
}
|
|
@@ -108,7 +113,7 @@ export default function registerGetFailureLogs(server, config) {
|
|
|
108
113
|
buildId: z
|
|
109
114
|
.string()
|
|
110
115
|
.optional()
|
|
111
|
-
.describe("
|
|
116
|
+
.describe("App Automate build ID. Optional — resolved from the session if omitted."),
|
|
112
117
|
logTypes: z
|
|
113
118
|
.array(z.enum([
|
|
114
119
|
AutomateLogType.NetworkLogs,
|
|
@@ -53,6 +53,16 @@ export async function getTestIds(buildId, authString, status, includeFailureDeta
|
|
|
53
53
|
throw error;
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* The test listing API serialises a missing BrowserStack session id as the
|
|
58
|
+
* literal string "null", so treat that (and blanks) as absent.
|
|
59
|
+
*/
|
|
60
|
+
function extractSessionId(rawSessionId) {
|
|
61
|
+
if (typeof rawSessionId !== "string")
|
|
62
|
+
return undefined;
|
|
63
|
+
const sessionId = rawSessionId.trim();
|
|
64
|
+
return sessionId && sessionId !== "null" ? sessionId : undefined;
|
|
65
|
+
}
|
|
56
66
|
export function extractTestIds(hierarchy, status, includeFailureDetail = false) {
|
|
57
67
|
let tests = [];
|
|
58
68
|
for (const node of hierarchy) {
|
|
@@ -63,10 +73,12 @@ export function extractTestIds(hierarchy, status, includeFailureDetail = false)
|
|
|
63
73
|
if (statusMatches && node.details?.observability_url) {
|
|
64
74
|
const idMatch = node.details.observability_url.match(/details=(\d+)/);
|
|
65
75
|
if (idMatch) {
|
|
76
|
+
const sessionId = extractSessionId(node.details.session_id);
|
|
66
77
|
const entry = {
|
|
67
78
|
test_id: idMatch[1],
|
|
68
79
|
test_name: node.display_name || `Test ${idMatch[1]}`,
|
|
69
80
|
status: nodeStatus,
|
|
81
|
+
...(sessionId && { session_id: sessionId }),
|
|
70
82
|
};
|
|
71
83
|
// Failure signatures only exist for failed tests; include when asked.
|
|
72
84
|
if (includeFailureDetail && nodeStatus === TestStatus.FAILED) {
|
package/dist/tools/rca-agent.js
CHANGED
|
@@ -175,7 +175,7 @@ export default function addRCATools(server, config) {
|
|
|
175
175
|
return handleMCPError("listBuildId", server, config, error);
|
|
176
176
|
}
|
|
177
177
|
});
|
|
178
|
-
tools.listTestIds = server.tool("listTestIds", "List all tests of a BrowserStack build (each with its status); optional status filter.", LIST_TEST_IDS_PARAMS, {
|
|
178
|
+
tools.listTestIds = server.tool("listTestIds", "List all tests of a BrowserStack build (each with its status and session id); optional status filter.", LIST_TEST_IDS_PARAMS, {
|
|
179
179
|
title: "List Test IDs",
|
|
180
180
|
readOnlyHint: true,
|
|
181
181
|
openWorldHint: false,
|