Skip to content

Commit b013147

Browse files
committed
Combining all percy tools
1 parent 2b6b325 commit b013147

File tree

7 files changed

+155
-113
lines changed

7 files changed

+155
-113
lines changed

src/server-factory.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const packageJson = require("../package.json");
88
import logger from "./logger.js";
99
import addSDKTools from "./tools/bstack-sdk.js";
1010
import addPercyTools from "./tools/percy-sdk.js";
11-
import addSimulatePercyChangeTool from "./tools/simulate-percy.js";
1211
import addBrowserLiveTools from "./tools/live.js";
1312
import addAccessibilityTools from "./tools/accessibility.js";
1413
import addTestManagementTools from "./tools/testmanagement.js";
@@ -17,8 +16,6 @@ import addFailureLogsTools from "./tools/get-failure-logs.js";
1716
import addAutomateTools from "./tools/automate.js";
1817
import addSelfHealTools from "./tools/selfheal.js";
1918
import addAppLiveTools from "./tools/applive.js";
20-
import addListTestFilesTool from "./tools/list-test-files.js";
21-
import addPercySnapshotTools from "./tools/add-percy-snapshots.js";
2219
import { setupOnInitialized } from "./oninitialized.js";
2320
import { BrowserStackConfig } from "./lib/types.js";
2421

@@ -53,16 +50,13 @@ export class BrowserStackMcpServer {
5350
addAccessibilityTools,
5451
addSDKTools,
5552
addPercyTools,
56-
addSimulatePercyChangeTool,
5753
addAppLiveTools,
5854
addBrowserLiveTools,
5955
addTestManagementTools,
6056
addAppAutomationTools,
6157
addFailureLogsTools,
6258
addAutomateTools,
6359
addSelfHealTools,
64-
addListTestFilesTool,
65-
addPercySnapshotTools,
6660
];
6761

6862
toolAdders.forEach((adder) => {

src/tools/add-percy-snapshots.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
21
import { testFilePathsMap } from "../lib/inmemory-store.js";
3-
import { UpdateTestFileWithInstructionsParams } from "./percy-snapshot-utils/constants.js";
42
import { updateFileAndStep } from "./percy-snapshot-utils/utils.js";
53
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
64
import { percyWebSetupInstructions } from "../tools/sdk-utils/percy-web/handler.js";
75

8-
async function updateTestsWithPercyCommands(args: {
6+
export async function updateTestsWithPercyCommands(args: {
97
uuid: string;
108
index: number;
119
}): Promise<CallToolResult> {
@@ -32,18 +30,3 @@ async function updateTestsWithPercyCommands(args: {
3230
content: result,
3331
};
3432
}
35-
36-
export default function addPercySnapshotTools(server: McpServer) {
37-
const tools: Record<string, any> = {};
38-
39-
tools.addPercySnapshotCommands = server.tool(
40-
"addPercySnapshotCommands",
41-
"Adds Percy snapshot commands to the specified test files.",
42-
UpdateTestFileWithInstructionsParams,
43-
async (args) => {
44-
return await updateTestsWithPercyCommands(args);
45-
},
46-
);
47-
48-
return tools;
49-
}

src/tools/list-test-files.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
21
import { listTestFiles } from "./percy-snapshot-utils/detect-test-files.js";
32
import { testFilePathsMap } from "../lib/inmemory-store.js";
43
import crypto from "crypto";
5-
import { ListTestFilesParamsShape } from "./percy-snapshot-utils/constants.js";
64
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
75

86
export async function addListTestFiles(args: any): Promise<CallToolResult> {
@@ -39,32 +37,3 @@ export async function addListTestFiles(args: any): Promise<CallToolResult> {
3937
],
4038
};
4139
}
42-
43-
export default function addListTestFilesTool(server: McpServer) {
44-
const tools: Record<string, any> = {};
45-
46-
tools.listTestFiles = server.tool(
47-
"listTestFiles",
48-
"Lists all test files for a given set of directories.",
49-
ListTestFilesParamsShape,
50-
async (args) => {
51-
try {
52-
return await addListTestFiles(args);
53-
} catch (error) {
54-
const errorMessage =
55-
error instanceof Error ? error.message : "Unknown error";
56-
return {
57-
content: [
58-
{
59-
type: "text",
60-
text: `Error during fetching self-heal suggestions: ${errorMessage}`,
61-
},
62-
],
63-
isError: true,
64-
};
65-
}
66-
},
67-
);
68-
69-
return tools;
70-
}

src/tools/percy-sdk.ts

Lines changed: 145 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,163 @@
11
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
22
import { BrowserStackConfig } from "../lib/types.js";
33
import { SetUpPercyParamsShape } from "./sdk-utils/common/schema.js";
4-
import { setUpPercyHandler } from "./sdk-utils/handler.js";
5-
import { SETUP_PERCY_DESCRIPTION } from "./sdk-utils/common/constants.js";
4+
import { updateTestsWithPercyCommands } from "./add-percy-snapshots.js";
5+
import { addListTestFiles } from "./list-test-files.js";
6+
import { trackMCP } from "../index.js";
7+
import {
8+
setUpPercyHandler,
9+
setUpSimulatePercyChangeHandler,
10+
} from "./sdk-utils/handler.js";
11+
import {
12+
SETUP_PERCY_DESCRIPTION,
13+
SIMULATE_PERCY_CHANGE_DESCRIPTION,
14+
LIST_TEST_FILES_DESCRIPTION,
15+
PERCY_SNAPSHOT_COMMANDS_DESCRIPTION,
16+
} from "./sdk-utils/common/constants.js";
17+
import {
18+
ListTestFilesParamsShape,
19+
UpdateTestFileWithInstructionsParams,
20+
} from "./percy-snapshot-utils/constants.js";
621

7-
export function registerPercySetupTool(
22+
export function registerPercyTools(
823
server: McpServer,
924
config: BrowserStackConfig,
1025
) {
1126
const tools: Record<string, any> = {};
27+
28+
// Register setupPercyVisualTesting
1229
tools.setupPercyVisualTesting = server.tool(
1330
"setupPercyVisualTesting",
1431
SETUP_PERCY_DESCRIPTION,
1532
SetUpPercyParamsShape,
1633
async (args) => {
17-
return setUpPercyHandler(args, config);
34+
try {
35+
trackMCP(
36+
"setupPercyVisualTesting",
37+
server.server.getClientVersion()!,
38+
config,
39+
);
40+
return setUpPercyHandler(args, config);
41+
} catch (error) {
42+
trackMCP(
43+
"setupPercyVisualTesting",
44+
server.server.getClientVersion()!,
45+
error,
46+
config,
47+
);
48+
return {
49+
content: [
50+
{
51+
type: "text",
52+
text: error instanceof Error ? error.message : String(error),
53+
},
54+
],
55+
isError: true,
56+
};
57+
}
58+
},
59+
);
60+
61+
// Register simulatePercyChange
62+
tools.simulatePercyChange = server.tool(
63+
"simulatePercyChange",
64+
SIMULATE_PERCY_CHANGE_DESCRIPTION,
65+
SetUpPercyParamsShape,
66+
async (args) => {
67+
try {
68+
trackMCP(
69+
"simulatePercyChange",
70+
server.server.getClientVersion()!,
71+
config,
72+
);
73+
return setUpSimulatePercyChangeHandler(args, config);
74+
} catch (error) {
75+
trackMCP(
76+
"simulatePercyChange",
77+
server.server.getClientVersion()!,
78+
error,
79+
config,
80+
);
81+
return {
82+
content: [
83+
{
84+
type: "text",
85+
text: error instanceof Error ? error.message : String(error),
86+
},
87+
],
88+
isError: true,
89+
};
90+
}
1891
},
1992
);
93+
94+
// Register addPercySnapshotCommands
95+
tools.addPercySnapshotCommands = server.tool(
96+
"addPercySnapshotCommands",
97+
PERCY_SNAPSHOT_COMMANDS_DESCRIPTION,
98+
UpdateTestFileWithInstructionsParams,
99+
async (args) => {
100+
try {
101+
trackMCP(
102+
"addPercySnapshotCommands",
103+
server.server.getClientVersion()!,
104+
config,
105+
);
106+
return await updateTestsWithPercyCommands(args);
107+
} catch (error) {
108+
trackMCP(
109+
"addPercySnapshotCommands",
110+
server.server.getClientVersion()!,
111+
error,
112+
config,
113+
);
114+
return {
115+
content: [
116+
{
117+
type: "text",
118+
text: error instanceof Error ? error.message : String(error),
119+
},
120+
],
121+
isError: true,
122+
};
123+
}
124+
},
125+
);
126+
127+
// Register listTestFiles
128+
tools.listTestFiles = server.tool(
129+
"listTestFiles",
130+
LIST_TEST_FILES_DESCRIPTION,
131+
ListTestFilesParamsShape,
132+
async (args) => {
133+
try {
134+
trackMCP(
135+
"listTestFiles",
136+
server.server.getClientVersion()!,
137+
config,
138+
);
139+
return addListTestFiles(args);
140+
} catch (error) {
141+
trackMCP(
142+
"listTestFiles",
143+
server.server.getClientVersion()!,
144+
error,
145+
config,
146+
);
147+
return {
148+
content: [
149+
{
150+
type: "text",
151+
text: error instanceof Error ? error.message : String(error),
152+
},
153+
],
154+
isError: true,
155+
};
156+
}
157+
},
158+
);
159+
20160
return tools;
21161
}
22162

23-
export default registerPercySetupTool;
163+
export default registerPercyTools;

src/tools/sdk-utils/common/constants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ export const IMPORTANT_SETUP_WARNING =
44
export const SETUP_PERCY_DESCRIPTION =
55
"Set up Percy visual testing for your project. This supports both Percy Web Standalone and Percy Automate.";
66

7+
export const LIST_TEST_FILES_DESCRIPTION =
8+
"Lists all test files for a given set of directories.";
9+
10+
export const PERCY_SNAPSHOT_COMMANDS_DESCRIPTION =
11+
"Adds Percy snapshot commands to the specified test files.";
12+
713
export const RUN_ON_BROWSERSTACK_DESCRIPTION =
814
"Set up and run automated web-based tests on BrowserStack using the BrowserStack SDK. Use this tool for functional or integration test setup on BrowserStack only. For any visual testing or Percy integration, use the dedicated Percy setup tool. Example prompts: run this test on browserstack; set up this project for browserstack.";
915

src/tools/sdk-utils/handler.ts

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,7 @@ export async function runTestsOnBrowserStackHandler(
3434
const result = runBstackSDKOnly(input, config);
3535
return await formatToolResult(result);
3636
} catch (error) {
37-
return {
38-
content: [
39-
{
40-
type: "text",
41-
text: getBootstrapFailedMessage(error, { config }),
42-
},
43-
],
44-
isError: true,
45-
};
37+
throw new Error(getBootstrapFailedMessage(error, { config }));
4638
}
4739
}
4840

@@ -171,18 +163,7 @@ export async function setUpPercyHandler(
171163
};
172164
}
173165
} catch (error) {
174-
return {
175-
content: [
176-
{
177-
type: "text",
178-
text: getBootstrapFailedMessage(error, {
179-
config,
180-
percyMode: (rawInput as any)?.integrationType,
181-
}),
182-
},
183-
],
184-
isError: true,
185-
};
166+
throw new Error(getBootstrapFailedMessage(error, { config }));
186167
}
187168
}
188169

@@ -218,14 +199,6 @@ export async function setUpSimulatePercyChangeHandler(
218199

219200
return percyInstruction;
220201
} catch (error) {
221-
return {
222-
content: [
223-
{
224-
type: "text",
225-
text: getBootstrapFailedMessage(error, { config }),
226-
},
227-
],
228-
isError: true,
229-
};
202+
throw new Error(getBootstrapFailedMessage(error, { config }));
230203
}
231204
}

src/tools/simulate-percy.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)