1
1
import { trackMCP } from "../index.js" ;
2
2
import { BrowserStackConfig } from "../lib/types.js" ;
3
- import { fetchPercyChanges } from "./percy-change .js" ;
3
+ import { fetchPercyChanges } from "./review-agent .js" ;
4
4
import { addListTestFiles } from "./list-test-files.js" ;
5
5
import { runPercyScan } from "./run-percy-scan.js" ;
6
6
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js" ;
@@ -25,14 +25,14 @@ import {
25
25
FetchPercyChangesParamsShape ,
26
26
ManagePercyBuildApprovalParamsShape ,
27
27
} from "./sdk-utils/common/schema.js" ;
28
+ import { handleMCPError } from "../lib/utils.js" ;
28
29
29
30
export function registerPercyTools (
30
31
server : McpServer ,
31
32
config : BrowserStackConfig ,
32
33
) {
33
34
const tools : Record < string , any > = { } ;
34
35
35
- // Register setupPercyVisualTesting
36
36
tools . setupPercyVisualTesting = server . tool (
37
37
"setupPercyVisualTesting" ,
38
38
SETUP_PERCY_DESCRIPTION ,
@@ -46,26 +46,11 @@ export function registerPercyTools(
46
46
) ;
47
47
return setUpPercyHandler ( args , config ) ;
48
48
} catch ( error ) {
49
- trackMCP (
50
- "setupPercyVisualTesting" ,
51
- server . server . getClientVersion ( ) ! ,
52
- error ,
53
- config ,
54
- ) ;
55
- return {
56
- content : [
57
- {
58
- type : "text" ,
59
- text : error instanceof Error ? error . message : String ( error ) ,
60
- } ,
61
- ] ,
62
- isError : true ,
63
- } ;
49
+ return handleMCPError ( "setupPercyVisualTesting" , server , config , error ) ;
64
50
}
65
51
} ,
66
52
) ;
67
53
68
- // Register addPercySnapshotCommands
69
54
tools . addPercySnapshotCommands = server . tool (
70
55
"addPercySnapshotCommands" ,
71
56
PERCY_SNAPSHOT_COMMANDS_DESCRIPTION ,
@@ -79,26 +64,16 @@ export function registerPercyTools(
79
64
) ;
80
65
return await updateTestsWithPercyCommands ( args ) ;
81
66
} catch ( error ) {
82
- trackMCP (
67
+ return handleMCPError (
83
68
"addPercySnapshotCommands" ,
84
- server . server . getClientVersion ( ) ! ,
85
- error ,
69
+ server ,
86
70
config ,
71
+ error ,
87
72
) ;
88
- return {
89
- content : [
90
- {
91
- type : "text" ,
92
- text : error instanceof Error ? error . message : String ( error ) ,
93
- } ,
94
- ] ,
95
- isError : true ,
96
- } ;
97
73
}
98
74
} ,
99
75
) ;
100
76
101
- // Register listTestFiles
102
77
tools . listTestFiles = server . tool (
103
78
"listTestFiles" ,
104
79
LIST_TEST_FILES_DESCRIPTION ,
@@ -108,21 +83,7 @@ export function registerPercyTools(
108
83
trackMCP ( "listTestFiles" , server . server . getClientVersion ( ) ! , config ) ;
109
84
return addListTestFiles ( args ) ;
110
85
} catch ( error ) {
111
- trackMCP (
112
- "listTestFiles" ,
113
- server . server . getClientVersion ( ) ! ,
114
- error ,
115
- config ,
116
- ) ;
117
- return {
118
- content : [
119
- {
120
- type : "text" ,
121
- text : error instanceof Error ? error . message : String ( error ) ,
122
- } ,
123
- ] ,
124
- isError : true ,
125
- } ;
86
+ return handleMCPError ( "listTestFiles" , server , config , error ) ;
126
87
}
127
88
} ,
128
89
) ;
@@ -132,16 +93,30 @@ export function registerPercyTools(
132
93
"Run a Percy visual test scan. Example prompts : Run this Percy build/scan. Never run percy scan/build without this tool" ,
133
94
RunPercyScanParamsShape ,
134
95
async ( args ) => {
135
- return runPercyScan ( args , config ) ;
96
+ try {
97
+ trackMCP ( "runPercyScan" , server . server . getClientVersion ( ) ! , config ) ;
98
+ return runPercyScan ( args , config ) ;
99
+ } catch ( error ) {
100
+ return handleMCPError ( "runPercyScan" , server , config , error ) ;
101
+ }
136
102
} ,
137
103
) ;
138
104
139
105
tools . fetchPercyChanges = server . tool (
140
106
"fetchPercyChanges" ,
141
- "Retrieves and summarizes all visual changes detected by Percy between the latest and previous builds, helping quickly review what has changed in your project." ,
107
+ "Retrieves and summarizes all visual changes detected by Percy AI between the latest and previous builds, helping quickly review what has changed in your project." ,
142
108
FetchPercyChangesParamsShape ,
143
109
async ( args ) => {
144
- return await fetchPercyChanges ( args , config ) ;
110
+ try {
111
+ trackMCP (
112
+ "fetchPercyChanges" ,
113
+ server . server . getClientVersion ( ) ! ,
114
+ config ,
115
+ ) ;
116
+ return await fetchPercyChanges ( args , config ) ;
117
+ } catch ( error ) {
118
+ return handleMCPError ( "fetchPercyChanges" , server , config , error ) ;
119
+ }
145
120
} ,
146
121
) ;
147
122
@@ -150,7 +125,21 @@ export function registerPercyTools(
150
125
"Approve or reject a Percy build" ,
151
126
ManagePercyBuildApprovalParamsShape ,
152
127
async ( args ) => {
153
- return await approveOrDeclinePercyBuild ( args , config ) ;
128
+ try {
129
+ trackMCP (
130
+ "managePercyBuildApproval" ,
131
+ server . server . getClientVersion ( ) ! ,
132
+ config ,
133
+ ) ;
134
+ return await approveOrDeclinePercyBuild ( args , config ) ;
135
+ } catch ( error ) {
136
+ return handleMCPError (
137
+ "managePercyBuildApproval" ,
138
+ server ,
139
+ config ,
140
+ error ,
141
+ ) ;
142
+ }
154
143
} ,
155
144
) ;
156
145
0 commit comments