@browserstack/mcp-server 1.0.13 → 1.0.15

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.
Files changed (55) hide show
  1. package/README.md +22 -0
  2. package/dist/config.js +2 -6
  3. package/dist/index.js +29 -32
  4. package/dist/lib/api.js +3 -57
  5. package/dist/lib/constants.js +14 -0
  6. package/dist/lib/device-cache.js +32 -33
  7. package/dist/lib/error.js +3 -6
  8. package/dist/lib/fuzzy.js +1 -4
  9. package/dist/lib/inmemory-store.js +1 -0
  10. package/dist/lib/instrumentation.js +12 -18
  11. package/dist/lib/local.js +27 -35
  12. package/dist/lib/utils.js +29 -4
  13. package/dist/logger.js +4 -9
  14. package/dist/tools/accessibility.js +51 -21
  15. package/dist/tools/accessiblity-utils/report-fetcher.js +28 -0
  16. package/dist/tools/accessiblity-utils/report-parser.js +51 -0
  17. package/dist/tools/accessiblity-utils/scanner.js +80 -0
  18. package/dist/tools/appautomate-utils/appautomate.js +95 -0
  19. package/dist/tools/appautomate.js +116 -0
  20. package/dist/tools/applive-utils/fuzzy-search.js +3 -6
  21. package/dist/tools/applive-utils/start-session.js +14 -20
  22. package/dist/tools/applive-utils/upload-app.js +12 -51
  23. package/dist/tools/applive.js +18 -25
  24. package/dist/tools/automate-utils/fetch-screenshots.js +59 -0
  25. package/dist/tools/automate.js +44 -37
  26. package/dist/tools/bstack-sdk.js +14 -18
  27. package/dist/tools/failurelogs-utils/app-automate.js +88 -0
  28. package/dist/tools/failurelogs-utils/automate.js +97 -0
  29. package/dist/tools/getFailureLogs.js +173 -0
  30. package/dist/tools/live-utils/desktop-filter.js +8 -11
  31. package/dist/tools/live-utils/mobile-filter.js +7 -10
  32. package/dist/tools/live-utils/start-session.js +17 -23
  33. package/dist/tools/live-utils/types.js +2 -5
  34. package/dist/tools/live-utils/version-resolver.js +1 -4
  35. package/dist/tools/live.js +23 -29
  36. package/dist/tools/observability.js +12 -19
  37. package/dist/tools/sdk-utils/constants.js +3 -9
  38. package/dist/tools/sdk-utils/instructions.js +4 -9
  39. package/dist/tools/sdk-utils/types.js +1 -2
  40. package/dist/tools/testmanagement-utils/TCG-utils/api.js +259 -0
  41. package/dist/tools/testmanagement-utils/TCG-utils/config.js +5 -0
  42. package/dist/tools/testmanagement-utils/TCG-utils/helpers.js +53 -0
  43. package/dist/tools/testmanagement-utils/TCG-utils/types.js +8 -0
  44. package/dist/tools/testmanagement-utils/add-test-result.js +18 -25
  45. package/dist/tools/testmanagement-utils/create-project-folder.js +21 -28
  46. package/dist/tools/testmanagement-utils/create-testcase.js +30 -38
  47. package/dist/tools/testmanagement-utils/create-testrun.js +23 -30
  48. package/dist/tools/testmanagement-utils/list-testcases.js +16 -23
  49. package/dist/tools/testmanagement-utils/list-testruns.js +13 -20
  50. package/dist/tools/testmanagement-utils/testcase-from-file.js +42 -0
  51. package/dist/tools/testmanagement-utils/update-testrun.js +16 -23
  52. package/dist/tools/testmanagement-utils/upload-file.js +101 -0
  53. package/dist/tools/testmanagement.js +98 -61
  54. package/package.json +13 -7
  55. package/dist/tools/accessiblity-utils/accessibility.js +0 -82
@@ -1,28 +1,21 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.CreateTestRunSchema = void 0;
7
- exports.createTestRun = createTestRun;
8
- const axios_1 = __importDefault(require("axios"));
9
- const config_1 = __importDefault(require("../../config"));
10
- const zod_1 = require("zod");
11
- const error_1 = require("../../lib/error");
1
+ import axios from "axios";
2
+ import config from "../../config.js";
3
+ import { z } from "zod";
4
+ import { formatAxiosError } from "../../lib/error.js";
12
5
  /**
13
6
  * Schema for creating a test run.
14
7
  */
15
- exports.CreateTestRunSchema = zod_1.z.object({
16
- project_identifier: zod_1.z
8
+ export const CreateTestRunSchema = z.object({
9
+ project_identifier: z
17
10
  .string()
18
11
  .describe("Identifier of the project in which to create the test run."),
19
- test_run: zod_1.z.object({
20
- name: zod_1.z.string().describe("Name of the test run"),
21
- description: zod_1.z
12
+ test_run: z.object({
13
+ name: z.string().describe("Name of the test run"),
14
+ description: z
22
15
  .string()
23
16
  .optional()
24
17
  .describe("Brief information about the test run"),
25
- run_state: zod_1.z
18
+ run_state: z
26
19
  .enum([
27
20
  "new_run",
28
21
  "in_progress",
@@ -33,17 +26,17 @@ exports.CreateTestRunSchema = zod_1.z.object({
33
26
  ])
34
27
  .optional()
35
28
  .describe("State of the test run. One of new_run, in_progress, under_review, rejected, done, closed"),
36
- issues: zod_1.z.array(zod_1.z.string()).optional().describe("Linked issue IDs"),
37
- issue_tracker: zod_1.z
38
- .object({ name: zod_1.z.string(), host: zod_1.z.string().url() })
29
+ issues: z.array(z.string()).optional().describe("Linked issue IDs"),
30
+ issue_tracker: z
31
+ .object({ name: z.string(), host: z.string().url() })
39
32
  .optional()
40
33
  .describe("Issue tracker configuration"),
41
- test_cases: zod_1.z
42
- .array(zod_1.z.string())
34
+ test_cases: z
35
+ .array(z.string())
43
36
  .optional()
44
37
  .describe("List of test case IDs"),
45
- folder_ids: zod_1.z
46
- .array(zod_1.z.number())
38
+ folder_ids: z
39
+ .array(z.number())
47
40
  .optional()
48
41
  .describe("Folder IDs to include"),
49
42
  }),
@@ -51,7 +44,7 @@ exports.CreateTestRunSchema = zod_1.z.object({
51
44
  /**
52
45
  * Creates a test run via BrowserStack Test Management API.
53
46
  */
54
- async function createTestRun(rawArgs) {
47
+ export async function createTestRun(rawArgs) {
55
48
  try {
56
49
  const inputArgs = {
57
50
  ...rawArgs,
@@ -60,12 +53,12 @@ async function createTestRun(rawArgs) {
60
53
  include_all: false,
61
54
  },
62
55
  };
63
- const args = exports.CreateTestRunSchema.parse(inputArgs);
56
+ const args = CreateTestRunSchema.parse(inputArgs);
64
57
  const url = `https://test-management.browserstack.com/api/v2/projects/${encodeURIComponent(args.project_identifier)}/test-runs`;
65
- const response = await axios_1.default.post(url, { test_run: args.test_run }, {
58
+ const response = await axios.post(url, { test_run: args.test_run }, {
66
59
  auth: {
67
- username: config_1.default.browserstackUsername,
68
- password: config_1.default.browserstackAccessKey,
60
+ username: config.browserstackUsername,
61
+ password: config.browserstackAccessKey,
69
62
  },
70
63
  headers: { "Content-Type": "application/json" },
71
64
  });
@@ -85,6 +78,6 @@ async function createTestRun(rawArgs) {
85
78
  };
86
79
  }
87
80
  catch (err) {
88
- return (0, error_1.formatAxiosError)(err, "Failed to create test run");
81
+ return formatAxiosError(err, "Failed to create test run");
89
82
  }
90
83
  }
@@ -1,39 +1,32 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ListTestCasesSchema = void 0;
7
- exports.listTestCases = listTestCases;
8
- const axios_1 = __importDefault(require("axios"));
9
- const config_1 = __importDefault(require("../../config"));
10
- const zod_1 = require("zod");
11
- const error_1 = require("../../lib/error");
1
+ import axios from "axios";
2
+ import config from "../../config.js";
3
+ import { z } from "zod";
4
+ import { formatAxiosError } from "../../lib/error.js";
12
5
  /**
13
6
  * Schema for listing test cases with optional filters.
14
7
  */
15
- exports.ListTestCasesSchema = zod_1.z.object({
16
- project_identifier: zod_1.z
8
+ export const ListTestCasesSchema = z.object({
9
+ project_identifier: z
17
10
  .string()
18
- .describe("Identifier of the project to fetch test cases from. Example: PR-12345"),
19
- folder_id: zod_1.z
11
+ .describe("Identifier of the project to fetch test cases from. This id starts with a PR- and is followed by a number."),
12
+ folder_id: z
20
13
  .string()
21
14
  .optional()
22
15
  .describe("If provided, only return cases in this folder."),
23
- case_type: zod_1.z
16
+ case_type: z
24
17
  .string()
25
18
  .optional()
26
19
  .describe("Comma-separated list of case types (e.g. functional,regression)."),
27
- priority: zod_1.z
20
+ priority: z
28
21
  .string()
29
22
  .optional()
30
23
  .describe("Comma-separated list of priorities (e.g. critical,medium,low)."),
31
- p: zod_1.z.number().optional().describe("Page number."),
24
+ p: z.number().optional().describe("Page number."),
32
25
  });
33
26
  /**
34
27
  * Calls BrowserStack Test Management to list test cases with filters.
35
28
  */
36
- async function listTestCases(args) {
29
+ export async function listTestCases(args) {
37
30
  try {
38
31
  // Build query string
39
32
  const params = new URLSearchParams();
@@ -46,10 +39,10 @@ async function listTestCases(args) {
46
39
  if (args.p !== undefined)
47
40
  params.append("p", args.p.toString());
48
41
  const url = `https://test-management.browserstack.com/api/v2/projects/${encodeURIComponent(args.project_identifier)}/test-cases?${params.toString()}`;
49
- const resp = await axios_1.default.get(url, {
42
+ const resp = await axios.get(url, {
50
43
  auth: {
51
- username: config_1.default.browserstackUsername,
52
- password: config_1.default.browserstackAccessKey,
44
+ username: config.browserstackUsername,
45
+ password: config.browserstackAccessKey,
53
46
  },
54
47
  });
55
48
  const resp_data = resp.data;
@@ -85,6 +78,6 @@ async function listTestCases(args) {
85
78
  };
86
79
  }
87
80
  catch (err) {
88
- return (0, error_1.formatAxiosError)(err, "Failed to list test cases");
81
+ return formatAxiosError(err, "Failed to list test cases");
89
82
  }
90
83
  }
@@ -1,22 +1,15 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ListTestRunsSchema = void 0;
7
- exports.listTestRuns = listTestRuns;
8
- const axios_1 = __importDefault(require("axios"));
9
- const config_1 = __importDefault(require("../../config"));
10
- const zod_1 = require("zod");
11
- const error_1 = require("../../lib/error");
1
+ import axios from "axios";
2
+ import config from "../../config.js";
3
+ import { z } from "zod";
4
+ import { formatAxiosError } from "../../lib/error.js";
12
5
  /**
13
6
  * Schema for listing test runs with optional filters.
14
7
  */
15
- exports.ListTestRunsSchema = zod_1.z.object({
16
- project_identifier: zod_1.z
8
+ export const ListTestRunsSchema = z.object({
9
+ project_identifier: z
17
10
  .string()
18
- .describe("Identifier of the project to fetch test runs from (e.g., PR-12345)"),
19
- run_state: zod_1.z
11
+ .describe("Identifier of the project to fetch test runs from (usually starts with PR-)."),
12
+ run_state: z
20
13
  .string()
21
14
  .optional()
22
15
  .describe("Return all test runs with this state (comma-separated)"),
@@ -24,17 +17,17 @@ exports.ListTestRunsSchema = zod_1.z.object({
24
17
  /**
25
18
  * Fetches and formats the list of test runs for a project.
26
19
  */
27
- async function listTestRuns(args) {
20
+ export async function listTestRuns(args) {
28
21
  try {
29
22
  const params = new URLSearchParams();
30
23
  if (args.run_state) {
31
24
  params.set("run_state", args.run_state);
32
25
  }
33
26
  const url = `https://test-management.browserstack.com/api/v2/projects/${encodeURIComponent(args.project_identifier)}/test-runs?` + params.toString();
34
- const resp = await axios_1.default.get(url, {
27
+ const resp = await axios.get(url, {
35
28
  auth: {
36
- username: config_1.default.browserstackUsername,
37
- password: config_1.default.browserstackAccessKey,
29
+ username: config.browserstackUsername,
30
+ password: config.browserstackAccessKey,
38
31
  },
39
32
  });
40
33
  const data = resp.data;
@@ -63,6 +56,6 @@ async function listTestRuns(args) {
63
56
  };
64
57
  }
65
58
  catch (err) {
66
- return (0, error_1.formatAxiosError)(err, "Failed to list test runs");
59
+ return formatAxiosError(err, "Failed to list test runs");
67
60
  }
68
61
  }
@@ -0,0 +1,42 @@
1
+ import { fetchFormFields, triggerTestCaseGeneration, pollScenariosTestDetails, bulkCreateTestCases, } from "./TCG-utils/api.js";
2
+ import { buildDefaultFieldMaps, findBooleanFieldId, } from "./TCG-utils/helpers.js";
3
+ import { signedUrlMap } from "../../lib/inmemory-store.js";
4
+ import logger from "../../logger.js";
5
+ import { projectIdentifierToId } from "./TCG-utils/api.js";
6
+ export async function createTestCasesFromFile(args, context) {
7
+ logger.info(`createTestCasesFromFile called with projectId: ${args.projectReferenceId}, folderId: ${args.folderId}`);
8
+ if (args.projectReferenceId.startsWith("PR-")) {
9
+ args.projectReferenceId = await projectIdentifierToId(args.projectReferenceId);
10
+ }
11
+ const { default_fields, custom_fields } = await fetchFormFields(args.projectReferenceId);
12
+ const fieldMaps = buildDefaultFieldMaps(default_fields);
13
+ const booleanFieldId = findBooleanFieldId(custom_fields);
14
+ const documentObj = signedUrlMap.get(args.documentId);
15
+ if (!documentObj) {
16
+ return {
17
+ content: [
18
+ {
19
+ type: "text",
20
+ text: `Document with ID ${args.documentId} not found.`,
21
+ isError: true,
22
+ },
23
+ ],
24
+ isError: true,
25
+ };
26
+ }
27
+ const documentId = documentObj.fileId;
28
+ const document = documentObj.downloadUrl;
29
+ const source = "jira-on-prem";
30
+ const traceId = await triggerTestCaseGeneration(document, documentId, args.folderId, args.projectReferenceId, source);
31
+ const scenariosMap = await pollScenariosTestDetails(args, traceId, context, documentId, source);
32
+ const resultString = await bulkCreateTestCases(scenariosMap, args.projectReferenceId, args.folderId, fieldMaps, booleanFieldId, traceId, context, documentId);
33
+ signedUrlMap.delete(args.documentId);
34
+ return {
35
+ content: [
36
+ {
37
+ type: "text",
38
+ text: resultString,
39
+ },
40
+ ],
41
+ };
42
+ }
@@ -1,25 +1,18 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.UpdateTestRunSchema = void 0;
7
- exports.updateTestRun = updateTestRun;
8
- const axios_1 = __importDefault(require("axios"));
9
- const config_1 = __importDefault(require("../../config"));
10
- const zod_1 = require("zod");
11
- const error_1 = require("../../lib/error");
1
+ import axios from "axios";
2
+ import config from "../../config.js";
3
+ import { z } from "zod";
4
+ import { formatAxiosError } from "../../lib/error.js";
12
5
  /**
13
6
  * Schema for updating a test run with partial fields.
14
7
  */
15
- exports.UpdateTestRunSchema = zod_1.z.object({
16
- project_identifier: zod_1.z
8
+ export const UpdateTestRunSchema = z.object({
9
+ project_identifier: z
17
10
  .string()
18
- .describe("Project identifier (e.g., PR-12345)"),
19
- test_run_id: zod_1.z.string().describe("Test run identifier (e.g., TR-678)"),
20
- test_run: zod_1.z.object({
21
- name: zod_1.z.string().optional().describe("New name of the test run"),
22
- run_state: zod_1.z
11
+ .describe("Identifier of the project (Starts with 'PR-')"),
12
+ test_run_id: z.string().describe("Test run identifier (e.g., TR-678)"),
13
+ test_run: z.object({
14
+ name: z.string().optional().describe("New name of the test run"),
15
+ run_state: z
23
16
  .enum([
24
17
  "new_run",
25
18
  "in_progress",
@@ -35,14 +28,14 @@ exports.UpdateTestRunSchema = zod_1.z.object({
35
28
  /**
36
29
  * Partially updates an existing test run.
37
30
  */
38
- async function updateTestRun(args) {
31
+ export async function updateTestRun(args) {
39
32
  try {
40
33
  const body = { test_run: args.test_run };
41
34
  const url = `https://test-management.browserstack.com/api/v2/projects/${encodeURIComponent(args.project_identifier)}/test-runs/${encodeURIComponent(args.test_run_id)}/update`;
42
- const resp = await axios_1.default.patch(url, body, {
35
+ const resp = await axios.patch(url, body, {
43
36
  auth: {
44
- username: config_1.default.browserstackUsername,
45
- password: config_1.default.browserstackAccessKey,
37
+ username: config.browserstackUsername,
38
+ password: config.browserstackAccessKey,
46
39
  },
47
40
  });
48
41
  const data = resp.data;
@@ -69,6 +62,6 @@ async function updateTestRun(args) {
69
62
  };
70
63
  }
71
64
  catch (err) {
72
- return (0, error_1.formatAxiosError)(err, "Failed to update test run");
65
+ return formatAxiosError(err, "Failed to update test run");
73
66
  }
74
67
  }
@@ -0,0 +1,101 @@
1
+ import { z } from "zod";
2
+ import axios from "axios";
3
+ import FormData from "form-data";
4
+ import fs from "fs";
5
+ import path from "path";
6
+ import { v4 as uuidv4 } from "uuid";
7
+ import config from "../../config.js";
8
+ import { signedUrlMap } from "../../lib/inmemory-store.js";
9
+ import { projectIdentifierToId } from "./TCG-utils/api.js";
10
+ /**
11
+ * Schema for the upload file tool
12
+ */
13
+ export const UploadFileSchema = z.object({
14
+ project_identifier: z
15
+ .string()
16
+ .describe("ID of the project where the file should be uploaded. Do not assume it, always ask user for it."),
17
+ file_path: z
18
+ .string()
19
+ .describe("Full path to the file that should be uploaded"),
20
+ });
21
+ /**
22
+ * Uploads a file to BrowserStack Test Management and returns the signed URL.
23
+ */
24
+ export async function uploadFile(args) {
25
+ const { project_identifier, file_path } = args;
26
+ try {
27
+ // Validate file exists
28
+ if (!fs.existsSync(file_path)) {
29
+ return {
30
+ content: [
31
+ {
32
+ type: "text",
33
+ text: `File ${file_path} does not exist.`,
34
+ isError: true,
35
+ },
36
+ ],
37
+ isError: true,
38
+ };
39
+ }
40
+ // Get the project ID
41
+ const projectIdResponse = await projectIdentifierToId(project_identifier);
42
+ const formData = new FormData();
43
+ formData.append("attachments[]", fs.createReadStream(file_path));
44
+ const uploadUrl = `https://test-management.browserstack.com/api/v1/projects/${projectIdResponse}/generic/attachments/ai_uploads`;
45
+ const response = await axios.post(uploadUrl, formData, {
46
+ headers: {
47
+ ...formData.getHeaders(),
48
+ "API-TOKEN": `${config.browserstackUsername}:${config.browserstackAccessKey}`,
49
+ accept: "application/json, text/plain, */*",
50
+ },
51
+ });
52
+ if (response.status >= 200 &&
53
+ response.status < 300 &&
54
+ response.data.generic_attachment) {
55
+ const attachments = response.data.generic_attachment.map((attachment) => {
56
+ // Generate a unique ID for each attachment
57
+ const fileId = uuidv4();
58
+ // Store the download URL in the signedUrlMap
59
+ const data = {
60
+ fileId: attachment.id,
61
+ downloadUrl: attachment.download_url,
62
+ };
63
+ signedUrlMap.set(fileId, data);
64
+ return {
65
+ name: attachment.name,
66
+ documentID: fileId,
67
+ contentType: attachment.content_type,
68
+ size: attachment.size,
69
+ projectReferenceId: projectIdResponse,
70
+ };
71
+ });
72
+ return {
73
+ content: [
74
+ {
75
+ type: "text",
76
+ text: `Successfully uploaded ${path.basename(file_path)} to BrowserStack Test Management.`,
77
+ },
78
+ {
79
+ type: "text",
80
+ text: JSON.stringify(attachments, null, 2),
81
+ },
82
+ ],
83
+ };
84
+ }
85
+ else {
86
+ throw new Error(`Unexpected response: ${JSON.stringify(response.data)}`);
87
+ }
88
+ }
89
+ catch (error) {
90
+ return {
91
+ content: [
92
+ {
93
+ type: "text",
94
+ text: `Failed to upload file: ${error instanceof Error ? error.message : "Unknown error"}. Please check your credentials and try again.`,
95
+ isError: true,
96
+ },
97
+ ],
98
+ isError: true,
99
+ };
100
+ }
101
+ }