@browserstack/mcp-server 1.3.2-beta.1 → 1.3.2-beta.2

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 CHANGED
@@ -426,7 +426,7 @@ As of now we support 45 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`.
429
+ 18. `listSessions` — List the sessions in an Automate/App Automate build. Each record carries `sessionId`, `name`, `status`, `os`, `osVersion`, `browser`, `device`, `browserUrl` (dashboard link), and `videoUrl`, 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
430
  **Prompt example**
431
431
 
432
432
  ```text
@@ -444,7 +444,7 @@ As of now we support 45 tools.
444
444
  Get the Appium logs for App Automate session ID <session id>
445
445
  ```
446
446
 
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.
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) and `session_type`, resolved through the build's sessions when the build ran on Automate / App Automate.
448
448
  **Prompt example**
449
449
 
450
450
  ```text
@@ -643,7 +643,7 @@ As of now we support 45 tools.
643
643
  Get the latest build ID for build 'nightly-regression' in project 'Checkout Flow'
644
644
  ```
645
645
 
646
- 45. `listTestIds` — List test IDs from a BrowserStack Automate build, filtered by status (passed/failed/pending/skipped).
646
+ 45. `listTestIds` — List the tests in a BrowserStack build (Automate or App Automate) with each test's `status` and `session_id`, optionally filtered by status (passed/failed/pending/skipped). The `session_id` feeds `getFailureLogs` and `fetchAutomationScreenshots` directly.
647
647
  **Prompt example**
648
648
 
649
649
  ```text
@@ -2,15 +2,18 @@ export declare const SessionType: {
2
2
  readonly Automate: "automate";
3
3
  readonly AppAutomate: "app-automate";
4
4
  };
5
+ export declare const SessionVideoLogType: "video";
5
6
  export declare const AutomateLogType: {
6
7
  readonly NetworkLogs: "networkLogs";
7
8
  readonly SessionLogs: "sessionLogs";
8
9
  readonly ConsoleLogs: "consoleLogs";
10
+ readonly Video: "video";
9
11
  };
10
12
  export declare const AppAutomateLogType: {
11
13
  readonly DeviceLogs: "deviceLogs";
12
14
  readonly AppiumLogs: "appiumLogs";
13
15
  readonly CrashLogs: "crashLogs";
16
+ readonly Video: "video";
14
17
  };
15
18
  export type SessionType = (typeof SessionType)[keyof typeof SessionType];
16
19
  export type AutomateLogType = (typeof AutomateLogType)[keyof typeof AutomateLogType];
@@ -2,13 +2,16 @@ export const SessionType = {
2
2
  Automate: "automate",
3
3
  AppAutomate: "app-automate",
4
4
  };
5
+ export const SessionVideoLogType = "video";
5
6
  export const AutomateLogType = {
6
7
  NetworkLogs: "networkLogs",
7
8
  SessionLogs: "sessionLogs",
8
9
  ConsoleLogs: "consoleLogs",
10
+ Video: SessionVideoLogType,
9
11
  };
10
12
  export const AppAutomateLogType = {
11
13
  DeviceLogs: "deviceLogs",
12
14
  AppiumLogs: "appiumLogs",
13
15
  CrashLogs: "crashLogs",
16
+ Video: SessionVideoLogType,
14
17
  };
@@ -1,6 +1,10 @@
1
1
  import { SessionType } from "../../lib/constants.js";
2
2
  import { BrowserStackConfig } from "../../lib/types.js";
3
3
  export declare const DEFAULT_SESSION_LIST_LIMIT = 10;
4
+ /** The REST session list returned 404: no Automate/App Automate build has this hashed id. */
5
+ export declare class UnknownBuildError extends Error {
6
+ constructor(message: string);
7
+ }
4
8
  export interface ListSessionIdsArgs {
5
9
  sessionType: SessionType;
6
10
  buildId: string;
@@ -17,6 +21,7 @@ export interface SessionIdRecord {
17
21
  browser?: string;
18
22
  device?: string | null;
19
23
  browserUrl?: string;
24
+ videoUrl?: string;
20
25
  }
21
26
  export declare function sessionsListUrl(sessionType: SessionType, buildId: string): string;
22
27
  export declare function mapSessionRecords(payload: unknown, statusFilter?: string): SessionIdRecord[];
@@ -2,6 +2,13 @@ import { SessionType } from "../../lib/constants.js";
2
2
  import { getBrowserStackAuth } from "../../lib/get-auth.js";
3
3
  import { apiClient } from "../../lib/apiClient.js";
4
4
  export const DEFAULT_SESSION_LIST_LIMIT = 10;
5
+ /** The REST session list returned 404: no Automate/App Automate build has this hashed id. */
6
+ export class UnknownBuildError extends Error {
7
+ constructor(message) {
8
+ super(message);
9
+ this.name = "UnknownBuildError";
10
+ }
11
+ }
5
12
  export function sessionsListUrl(sessionType, buildId) {
6
13
  const encodedBuildId = encodeURIComponent(buildId);
7
14
  switch (sessionType) {
@@ -41,6 +48,7 @@ export function mapSessionRecords(payload, statusFilter) {
41
48
  browser: session.browser,
42
49
  device: session.device,
43
50
  browserUrl: session.browser_url,
51
+ videoUrl: session.video_url,
44
52
  });
45
53
  }
46
54
  return records;
@@ -68,11 +76,10 @@ export async function listSessionIds(args, config) {
68
76
  });
69
77
  if (!response.ok) {
70
78
  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.");
79
+ throw new UnknownBuildError(`No ${args.sessionType} build found for id "${buildId}". ` +
80
+ "Pass the Automate/App Automate dashboard hashed build id or the " +
81
+ "observability build id from getBuildId / listBuildId, and check that " +
82
+ "sessionType matches the product the build ran on.");
76
83
  }
77
84
  throw new Error(`Failed to list sessions: ${response.status} ${response.statusText}`);
78
85
  }
@@ -0,0 +1,30 @@
1
+ import { SessionType } from "../../lib/constants.js";
2
+ import { BrowserStackConfig } from "../../lib/types.js";
3
+ export declare function isObservabilityBuildUuid(id: string): boolean;
4
+ export declare function isHashedBuildId(id: string): boolean;
5
+ export declare function sessionDetailsUrl(sessionType: SessionType, sessionId: string): string;
6
+ /**
7
+ * Resolve the hashed build id that a session belongs to via the Automate /
8
+ * App Automate session detail endpoint. Returns undefined when the session
9
+ * cannot be fetched or does not report a build.
10
+ */
11
+ export declare function resolveBuildIdFromSession(sessionId: string, sessionType: SessionType, config: BrowserStackConfig): Promise<string | undefined>;
12
+ /**
13
+ * Find any BrowserStack session id attached to an observability build by
14
+ * walking its test runs. Returns undefined when no test reports a session
15
+ * (e.g. JUnit-uploaded builds that never ran on BrowserStack).
16
+ */
17
+ export declare function findSessionIdForObservabilityBuild(observabilityBuildId: string, config: BrowserStackConfig): Promise<string | undefined>;
18
+ export interface ResolvedHashedBuildId {
19
+ hashedBuildId: string;
20
+ sessionId: string;
21
+ sessionType: SessionType;
22
+ }
23
+ /**
24
+ * Convert an observability build UUID into the Automate / App Automate hashed
25
+ * build id in two deterministic API calls: pick any session of the build from
26
+ * its test runs, then read `build_hashed_id` from that session's details.
27
+ *
28
+ * When `sessionType` is omitted, Automate is tried first, then App Automate.
29
+ */
30
+ export declare function resolveHashedBuildId(observabilityBuildId: string, config: BrowserStackConfig, sessionType?: SessionType): Promise<ResolvedHashedBuildId>;
@@ -0,0 +1,124 @@
1
+ import { SessionType } from "../../lib/constants.js";
2
+ import { getBrowserStackAuth } from "../../lib/get-auth.js";
3
+ import { apiClient } from "../../lib/apiClient.js";
4
+ import logger from "../../logger.js";
5
+ import { getAutomationBaseUrl } from "../rca-agent-utils/constants.js";
6
+ import { extractTestIds } from "../rca-agent-utils/get-failed-test-id.js";
7
+ // Observability (Test Reporting & Analytics) build ids are usually UUIDs but
8
+ // some are 40-char hex, the same shape as Automate / App Automate "hashed ids".
9
+ // The two are never interchangeable, and the observability build API does not
10
+ // expose the hashed id. The deterministic bridge is any BrowserStack session that belongs to the
11
+ // build: the session detail endpoint reports its parent `build_hashed_id`.
12
+ const OBSERVABILITY_UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
13
+ const HASHED_BUILD_ID_RE = /^[a-f0-9]{40}$/i;
14
+ // Only the first session id is needed; most builds surface one on page one.
15
+ const MAX_TEST_RUN_PAGES = 5;
16
+ export function isObservabilityBuildUuid(id) {
17
+ return OBSERVABILITY_UUID_RE.test(id.trim());
18
+ }
19
+ export function isHashedBuildId(id) {
20
+ return HASHED_BUILD_ID_RE.test(id.trim());
21
+ }
22
+ export function sessionDetailsUrl(sessionType, sessionId) {
23
+ const encoded = encodeURIComponent(sessionId);
24
+ switch (sessionType) {
25
+ case SessionType.Automate:
26
+ return `https://api.browserstack.com/automate/sessions/${encoded}.json`;
27
+ case SessionType.AppAutomate:
28
+ return `https://api.browserstack.com/app-automate/sessions/${encoded}.json`;
29
+ default: {
30
+ const _exhaustive = sessionType;
31
+ throw new Error(`Unsupported session type: ${_exhaustive}`);
32
+ }
33
+ }
34
+ }
35
+ /**
36
+ * Resolve the hashed build id that a session belongs to via the Automate /
37
+ * App Automate session detail endpoint. Returns undefined when the session
38
+ * cannot be fetched or does not report a build.
39
+ */
40
+ export async function resolveBuildIdFromSession(sessionId, sessionType, config) {
41
+ const authString = getBrowserStackAuth(config);
42
+ const auth = Buffer.from(authString).toString("base64");
43
+ const response = await apiClient.get({
44
+ url: sessionDetailsUrl(sessionType, sessionId),
45
+ headers: {
46
+ "Content-Type": "application/json",
47
+ Authorization: `Basic ${auth}`,
48
+ },
49
+ raise_error: false,
50
+ });
51
+ if (!response.ok) {
52
+ logger.warn(`Could not resolve build id for ${sessionType} session ${sessionId}: ${response.status}`);
53
+ return undefined;
54
+ }
55
+ const session = response.data?.automation_session;
56
+ const buildId = session?.build_hashed_id;
57
+ return typeof buildId === "string" && buildId.trim()
58
+ ? buildId.trim()
59
+ : undefined;
60
+ }
61
+ /**
62
+ * Find any BrowserStack session id attached to an observability build by
63
+ * walking its test runs. Returns undefined when no test reports a session
64
+ * (e.g. JUnit-uploaded builds that never ran on BrowserStack).
65
+ */
66
+ export async function findSessionIdForObservabilityBuild(observabilityBuildId, config) {
67
+ const authString = getBrowserStackAuth(config);
68
+ const auth = Buffer.from(authString).toString("base64");
69
+ const baseUrl = `${getAutomationBaseUrl()}/ext/v1/builds/${encodeURIComponent(observabilityBuildId)}/testRuns`;
70
+ let nextPage;
71
+ for (let page = 0; page < MAX_TEST_RUN_PAGES; page++) {
72
+ const response = await apiClient.get({
73
+ url: baseUrl,
74
+ headers: {
75
+ "Content-Type": "application/json",
76
+ Authorization: `Basic ${auth}`,
77
+ },
78
+ ...(nextPage ? { params: { next_page: nextPage } } : {}),
79
+ raise_error: false,
80
+ });
81
+ if (!response.ok) {
82
+ throw new Error(`Failed to fetch test runs for observability build "${observabilityBuildId}": ` +
83
+ `${response.status} ${response.statusText}`);
84
+ }
85
+ const data = response.data;
86
+ const withSession = extractTestIds(data?.hierarchy ?? []).find((test) => test.session_id);
87
+ if (withSession?.session_id) {
88
+ return withSession.session_id;
89
+ }
90
+ if (!data?.pagination?.has_next || !data.pagination.next_page) {
91
+ return undefined;
92
+ }
93
+ nextPage = data.pagination.next_page;
94
+ }
95
+ logger.warn(`resolveHashedBuildId: no session id in first ${MAX_TEST_RUN_PAGES} pages of build ${observabilityBuildId}`);
96
+ return undefined;
97
+ }
98
+ /**
99
+ * Convert an observability build UUID into the Automate / App Automate hashed
100
+ * build id in two deterministic API calls: pick any session of the build from
101
+ * its test runs, then read `build_hashed_id` from that session's details.
102
+ *
103
+ * When `sessionType` is omitted, Automate is tried first, then App Automate.
104
+ */
105
+ export async function resolveHashedBuildId(observabilityBuildId, config, sessionType) {
106
+ const buildId = observabilityBuildId.trim();
107
+ const sessionId = await findSessionIdForObservabilityBuild(buildId, config);
108
+ if (!sessionId) {
109
+ throw new Error(`No BrowserStack sessions found for observability build "${buildId}". ` +
110
+ "Only builds that ran on Automate or App Automate have sessions to list; " +
111
+ "uploaded-report builds (e.g. JUnit) do not.");
112
+ }
113
+ const candidates = sessionType
114
+ ? [sessionType]
115
+ : [SessionType.Automate, SessionType.AppAutomate];
116
+ for (const candidate of candidates) {
117
+ const hashedBuildId = await resolveBuildIdFromSession(sessionId, candidate, config);
118
+ if (hashedBuildId) {
119
+ return { hashedBuildId, sessionId, sessionType: candidate };
120
+ }
121
+ }
122
+ throw new Error(`Could not resolve the hashed build id for observability build "${buildId}" ` +
123
+ `from session "${sessionId}" (tried: ${candidates.join(", ")}).`);
124
+ }
@@ -1,6 +1,7 @@
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
+ import { DEFAULT_SESSION_LIST_LIMIT, listSessionIds, UnknownBuildError, } from "./automate-utils/list-session-ids.js";
4
+ import { isObservabilityBuildUuid, resolveHashedBuildId, } from "./automate-utils/resolve-hashed-build-id.js";
4
5
  import { SessionType } from "../lib/constants.js";
5
6
  import { trackMCP } from "../lib/instrumentation.js";
6
7
  import logger from "../logger.js";
@@ -51,25 +52,51 @@ export async function fetchAutomationScreenshotsTool(args, config) {
51
52
  }
52
53
  export async function listSessionIdsTool(args, config) {
53
54
  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
- ],
55
+ // Accept the observability build id too. Observability ids are usually
56
+ // UUIDs but can also be 40-char hex like Automate hashed ids, so shape
57
+ // alone is not enough: try the REST list first and resolve on a miss.
58
+ const inputId = args.buildId.trim();
59
+ let buildId = inputId;
60
+ let resolvedNote;
61
+ const resolve = async () => {
62
+ const resolved = await resolveHashedBuildId(inputId, config, args.sessionType);
63
+ buildId = resolved.hashedBuildId;
64
+ resolvedNote = `Resolved observability build ${inputId} to hashed build id ${buildId}.`;
72
65
  };
66
+ let sessions;
67
+ if (isObservabilityBuildUuid(inputId)) {
68
+ await resolve();
69
+ sessions = await listSessionIds({ ...args, buildId }, config);
70
+ }
71
+ else {
72
+ try {
73
+ sessions = await listSessionIds({ ...args, buildId }, config);
74
+ }
75
+ catch (error) {
76
+ if (!(error instanceof UnknownBuildError))
77
+ throw error;
78
+ try {
79
+ await resolve();
80
+ }
81
+ catch (resolveError) {
82
+ logger.debug("listSessions: id is neither a known hashed build nor a resolvable observability build", resolveError);
83
+ throw error;
84
+ }
85
+ sessions = await listSessionIds({ ...args, buildId }, config);
86
+ }
87
+ }
88
+ const content = [
89
+ {
90
+ type: "text",
91
+ text: sessions.length === 0
92
+ ? "No sessions found for this hashed build ID."
93
+ : JSON.stringify(sessions, null, 2),
94
+ },
95
+ ];
96
+ if (resolvedNote) {
97
+ content.push({ type: "text", text: resolvedNote });
98
+ }
99
+ return { content };
73
100
  }
74
101
  catch (error) {
75
102
  logger.error("Error listing session IDs", error);
@@ -79,7 +106,7 @@ export async function listSessionIdsTool(args, config) {
79
106
  //Registers the fetchAutomationScreenshots tool with the MCP server
80
107
  export default function addAutomationTools(server, config) {
81
108
  const tools = {};
82
- tools.fetchAutomationScreenshots = server.tool("fetchAutomationScreenshots", "Fetch and process screenshots from a BrowserStack Automate session", {
109
+ tools.fetchAutomationScreenshots = server.tool("fetchAutomationScreenshots", "Fetch screenshots captured during an Automate/App Automate session.", {
83
110
  sessionId: z
84
111
  .string()
85
112
  .describe("The BrowserStack session ID to fetch screenshots from"),
@@ -117,7 +144,7 @@ export default function addAutomationTools(server, config) {
117
144
  .describe("Type of BrowserStack session"),
118
145
  buildId: z
119
146
  .string()
120
- .describe("Dashboard hashed build id or fetchBuildInsights hashed_id not the getBuildId UUID."),
147
+ .describe("Hashed build id from the dashboard, or the observability build id from getBuildId."),
121
148
  limit: z
122
149
  .number()
123
150
  .int()
@@ -2,6 +2,7 @@ import { z } from "zod";
2
2
  import logger from "../logger.js";
3
3
  import { fetchFromBrowserStackAPI, handleMCPError } from "../lib/utils.js";
4
4
  import { trackMCP } from "../lib/instrumentation.js";
5
+ import { resolveHashedBuildId } from "./automate-utils/resolve-hashed-build-id.js";
5
6
  // Tool function that fetches build insights from two APIs
6
7
  export async function fetchBuildInsightsTool(args, config) {
7
8
  try {
@@ -15,7 +16,7 @@ export async function fetchBuildInsightsTool(args, config) {
15
16
  return null;
16
17
  }),
17
18
  ]);
18
- const hashed_id = extractHashedBuildId(buildData);
19
+ const { hashed_id, session_type } = await resolveInsightsHashedId(args.buildId, buildData, config);
19
20
  // Select useful fields for users
20
21
  const insights = {
21
22
  name: buildData.name,
@@ -35,6 +36,7 @@ export async function fetchBuildInsightsTool(args, config) {
35
36
  vcs_name: buildData.vcs_info?.name,
36
37
  quality_gate_result: qualityData?.quality_gate_result,
37
38
  ...(hashed_id ? { hashed_id } : {}),
39
+ ...(session_type ? { session_type } : {}),
38
40
  };
39
41
  const qualityProfiles = qualityData?.quality_profiles?.map((profile) => ({
40
42
  name: profile.name,
@@ -58,6 +60,28 @@ export async function fetchBuildInsightsTool(args, config) {
58
60
  throw error;
59
61
  }
60
62
  }
63
+ /**
64
+ * The observability build payload does not carry the Automate hashed build id
65
+ * today. Prefer it if the API ever adds one; otherwise resolve it through any
66
+ * session of the build (two deterministic REST calls). Never blocks insights.
67
+ */
68
+ async function resolveInsightsHashedId(observabilityBuildId, buildData, config) {
69
+ const direct = extractHashedBuildId(buildData);
70
+ if (direct) {
71
+ return { hashed_id: direct };
72
+ }
73
+ try {
74
+ const resolved = await resolveHashedBuildId(observabilityBuildId, config);
75
+ return {
76
+ hashed_id: resolved.hashedBuildId,
77
+ session_type: resolved.sessionType,
78
+ };
79
+ }
80
+ catch (error) {
81
+ logger.warn("Could not resolve hashed build id for build insights", error);
82
+ return {};
83
+ }
84
+ }
61
85
  function extractHashedBuildId(buildData) {
62
86
  const candidates = [
63
87
  buildData?.hashed_id,
@@ -74,7 +98,7 @@ function extractHashedBuildId(buildData) {
74
98
  // Registers the fetchBuildInsights tool with the MCP server
75
99
  export default function addBuildInsightsTools(server, config) {
76
100
  const tools = {};
77
- tools.fetchBuildInsights = server.tool("fetchBuildInsights", "Fetch build details and quality gate results. Includes hashed_id, the build id listSessions takes.", {
101
+ tools.fetchBuildInsights = server.tool("fetchBuildInsights", "Fetch build details and quality gate results. Includes hashed_id and session_type for listSessions.", {
78
102
  buildId: z.string().describe("The build UUID of the BrowserStack build"),
79
103
  }, {
80
104
  title: "Fetch Build Insights",
@@ -1,25 +1,5 @@
1
- import { getBrowserStackAuth } from "../../lib/get-auth.js";
2
- import { apiClient } from "../../lib/apiClient.js";
3
- import logger from "../../logger.js";
1
+ import { SessionType } from "../../lib/constants.js";
2
+ import { resolveBuildIdFromSession } from "../automate-utils/resolve-hashed-build-id.js";
4
3
  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;
4
+ return resolveBuildIdFromSession(sessionId, SessionType.AppAutomate, config);
25
5
  }
@@ -0,0 +1,3 @@
1
+ import { BrowserStackConfig } from "../../lib/types.js";
2
+ import { SessionType } from "../../lib/constants.js";
3
+ export declare function retrieveSessionVideo(sessionId: string, sessionType: SessionType, config: BrowserStackConfig): Promise<string>;
@@ -0,0 +1,25 @@
1
+ import { getBrowserStackAuth } from "../../lib/get-auth.js";
2
+ import { apiClient } from "../../lib/apiClient.js";
3
+ import { SessionType } from "../../lib/constants.js";
4
+ import { validateLogResponse } from "./utils.js";
5
+ export async function retrieveSessionVideo(sessionId, sessionType, config) {
6
+ const product = sessionType === SessionType.AppAutomate ? "app-automate" : "automate";
7
+ const url = `https://api.browserstack.com/${product}/sessions/${encodeURIComponent(sessionId)}.json`;
8
+ const authString = getBrowserStackAuth(config);
9
+ const auth = Buffer.from(authString).toString("base64");
10
+ const response = await apiClient.get({
11
+ url,
12
+ headers: {
13
+ "Content-Type": "application/json",
14
+ Authorization: `Basic ${auth}`,
15
+ },
16
+ raise_error: false,
17
+ });
18
+ const validationError = validateLogResponse(response, "session video");
19
+ if (validationError)
20
+ return validationError.message;
21
+ const videoUrl = response.data?.automation_session?.video_url;
22
+ return typeof videoUrl === "string" && videoUrl.trim()
23
+ ? `Session video: ${videoUrl.trim()}`
24
+ : "No session video available for this session";
25
+ }
@@ -3,7 +3,8 @@ 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
5
  import { resolveAppAutomateBuildId } from "./failurelogs-utils/resolve-app-build-id.js";
6
- import { AppAutomateLogType, AutomateLogType, SessionType, } from "../lib/constants.js";
6
+ import { retrieveSessionVideo } from "./failurelogs-utils/video.js";
7
+ import { AppAutomateLogType, AutomateLogType, SessionType, SessionVideoLogType, } from "../lib/constants.js";
7
8
  // Main log fetcher function
8
9
  export async function getFailureLogs(args, config) {
9
10
  const results = [];
@@ -12,21 +13,16 @@ export async function getFailureLogs(args, config) {
12
13
  if (!args.sessionId) {
13
14
  throw new Error("Session ID is required");
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
- }
21
- }
22
16
  // Validate log types and collect errors
23
17
  validLogTypes = args.logTypes.filter((logType) => {
24
18
  const isAutomate = Object.values(AutomateLogType).includes(logType);
25
19
  const isAppAutomate = Object.values(AppAutomateLogType).includes(logType);
26
20
  if (!isAutomate && !isAppAutomate) {
27
21
  errors.push(`Invalid log type '${logType}'. Valid log types are: ${[
28
- ...Object.values(AutomateLogType),
29
- ...Object.values(AppAutomateLogType),
22
+ ...new Set([
23
+ ...Object.values(AutomateLogType),
24
+ ...Object.values(AppAutomateLogType),
25
+ ]),
30
26
  ].join(", ")}`);
31
27
  return false;
32
28
  }
@@ -51,11 +47,26 @@ export async function getFailureLogs(args, config) {
51
47
  isError: true,
52
48
  };
53
49
  }
50
+ let buildId = args.buildId;
51
+ const needsBuildId = validLogTypes.some((logType) => logType !== SessionVideoLogType);
52
+ if (args.sessionType === SessionType.AppAutomate &&
53
+ needsBuildId &&
54
+ !buildId) {
55
+ buildId = await resolveAppAutomateBuildId(args.sessionId, config);
56
+ if (!buildId) {
57
+ throw new Error("Build ID is required for app-automate sessions");
58
+ }
59
+ }
54
60
  let response;
55
61
  // eslint-disable-next-line no-useless-catch
56
62
  try {
57
63
  for (const logType of validLogTypes) {
58
64
  switch (logType) {
65
+ case SessionVideoLogType: {
66
+ response = await retrieveSessionVideo(args.sessionId, args.sessionType, config);
67
+ results.push({ type: "text", text: response });
68
+ break;
69
+ }
59
70
  case AutomateLogType.NetworkLogs: {
60
71
  response = await retrieveNetworkFailures(args.sessionId, config);
61
72
  results.push({ type: "text", text: response });
@@ -103,7 +114,7 @@ export async function getFailureLogs(args, config) {
103
114
  // Register tool with the MCP server
104
115
  export default function registerGetFailureLogs(server, config) {
105
116
  const tools = {};
106
- tools.getFailureLogs = server.tool("getFailureLogs", "Fetch various types of logs from a BrowserStack session. Supports both automate and app-automate sessions.", {
117
+ tools.getFailureLogs = server.tool("getFailureLogs", "Fetch logs, or the session video URL, for an Automate/App Automate session.", {
107
118
  sessionType: z
108
119
  .enum([SessionType.Automate, SessionType.AppAutomate])
109
120
  .describe("Type of BrowserStack session. Must be explicitly provided by the user."),
@@ -122,6 +133,7 @@ export default function registerGetFailureLogs(server, config) {
122
133
  AppAutomateLogType.DeviceLogs,
123
134
  AppAutomateLogType.AppiumLogs,
124
135
  AppAutomateLogType.CrashLogs,
136
+ SessionVideoLogType,
125
137
  ]))
126
138
  .describe("The types of logs to fetch."),
127
139
  }, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@browserstack/mcp-server",
3
- "version": "1.3.2-beta.1",
3
+ "version": "1.3.2-beta.2",
4
4
  "description": "BrowserStack's Official MCP Server",
5
5
  "mcpName": "io.github.browserstack/mcp-server",
6
6
  "main": "dist/index.js",