Skip to content

Commit 82cc762

Browse files
committed
refactor: Move parameter definitions to constants for RCA tools
1 parent 2e84e81 commit 82cc762

File tree

2 files changed

+41
-33
lines changed

2 files changed

+41
-33
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { z } from "zod";
2+
import { TestStatus } from "./types.js";
3+
4+
export const FETCH_RCA_PARAMS = {
5+
testId: z
6+
.array(z.string())
7+
.max(3)
8+
.describe(
9+
"Array of test IDs to fetch RCA data for (maximum 3 IDs). If not provided, use the listTestIds tool get all failed testcases. If more than 3 IDs are provided, only the first 3 will be processed."
10+
),
11+
};
12+
13+
export const GET_BUILD_ID_PARAMS = {
14+
projectName: z
15+
.string()
16+
.describe(
17+
"The Browserstack project name used while creation of test run. Check browserstack.yml or similar project configuration files. If found extract it and provide to user, IF not found or unsure, prompt the user for this value. Do not make assumptions"
18+
),
19+
buildName: z
20+
.string()
21+
.describe(
22+
"The Browserstack build name used while creation of test run. Check browserstack.yml or similar project configuration files. If found extract it and provide to user, IF not found or unsure, prompt the user for this value. Do not make assumptions"
23+
),
24+
};
25+
26+
export const LIST_TEST_IDS_PARAMS = {
27+
buildId: z
28+
.string()
29+
.describe(
30+
"The Browserstack Build ID of the test run. If not known, use the getBuildId tool to fetch it using project and build name"
31+
),
32+
status: z
33+
.nativeEnum(TestStatus)
34+
.describe(
35+
"Filter tests by status. If not provided, all tests are returned. Example for RCA usecase always use failed status"
36+
),
37+
};

src/tools/rca-agent.ts

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2-
import { z } from "zod";
2+
import { FETCH_RCA_PARAMS, GET_BUILD_ID_PARAMS, LIST_TEST_IDS_PARAMS } from "./rca-agent-utils/constants.js";
33
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
44
import logger from "../logger.js";
55
import { BrowserStackConfig } from "../lib/types.js";
@@ -127,14 +127,7 @@ export default function addRCATools(
127127
tools.fetchRCA = server.tool(
128128
"fetchRCA",
129129
"Retrieves AI-RCA (Root Cause Analysis) data for a BrowserStack Automate and App-Automate session and provides insights into test failures.",
130-
{
131-
testId: z
132-
.array(z.string())
133-
.max(3)
134-
.describe(
135-
"Array of test IDs to fetch RCA data for (maximum 3 IDs). If not provided, use the listTestIds tool get all failed testcases. If more than 3 IDs are provided, only the first 3 will be processed.",
136-
),
137-
},
130+
FETCH_RCA_PARAMS,
138131
async (args) => {
139132
try {
140133
return await fetchRCADataTool(args, config);
@@ -156,18 +149,7 @@ export default function addRCATools(
156149
tools.getBuildId = server.tool(
157150
"getBuildId",
158151
"Get the BrowserStack build ID for a given project and build name.",
159-
{
160-
projectName: z
161-
.string()
162-
.describe(
163-
"The Browserstack project name used while creation of test run. Check browserstack.yml or similar project configuration files. If found extract it and provide to user, IF not found or unsure, prompt the user for this value. Do not make assumptions",
164-
),
165-
buildName: z
166-
.string()
167-
.describe(
168-
"The Browserstack build name used while creation of test run. Check browserstack.yml or similar project configuration files. If found extract it and provide to user, IF not found or unsure, prompt the user for this value. Do not make assumptions",
169-
),
170-
},
152+
GET_BUILD_ID_PARAMS,
171153
async (args) => {
172154
try {
173155
return await getBuildIdTool(args, config);
@@ -189,18 +171,7 @@ export default function addRCATools(
189171
tools.listTestIds = server.tool(
190172
"listTestIds",
191173
"List test IDs from a BrowserStack Automate build, optionally filtered by status",
192-
{
193-
buildId: z
194-
.string()
195-
.describe(
196-
"The Browserstack Build ID of the test run. If not known, use the getBuildId tool to fetch it using project and build name",
197-
),
198-
status: z
199-
.nativeEnum(TestStatus)
200-
.describe(
201-
"Filter tests by status. If not provided, all tests are returned. Example for RCA usecase always use failed status",
202-
),
203-
},
174+
LIST_TEST_IDS_PARAMS,
204175
async (args) => {
205176
try {
206177
return await listTestIdsTool(args, config);

0 commit comments

Comments
 (0)