Skip to content

Commit 40588dd

Browse files
feat: add fetchAccessibilityIssues function with pagination support
1 parent 4a51c67 commit 40588dd

File tree

1 file changed

+107
-4
lines changed

1 file changed

+107
-4
lines changed

src/tools/accessibility.ts

Lines changed: 107 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,64 @@ async function executeAccessibilityRAG(
137137
}
138138
}
139139

140+
async function executeFetchAccessibilityIssues(
141+
args: { scanId: string; scanRunId: string; nextPage?: number },
142+
server: McpServer,
143+
config: BrowserStackConfig,
144+
): Promise<CallToolResult> {
145+
try {
146+
trackMCP(
147+
"fetchAccessibilityIssues",
148+
server.server.getClientVersion()!,
149+
undefined,
150+
config,
151+
);
152+
return await fetchAccessibilityIssues(
153+
args.scanId,
154+
args.scanRunId,
155+
config,
156+
args.nextPage,
157+
);
158+
} catch (error) {
159+
return handleMCPError("fetchAccessibilityIssues", server, config, error);
160+
}
161+
}
162+
163+
async function fetchAccessibilityIssues(
164+
scanId: string,
165+
scanRunId: string,
166+
config: BrowserStackConfig,
167+
nextPage = 0,
168+
): Promise<CallToolResult> {
169+
const reportFetcher = await initializeReportFetcher(config);
170+
const reportLink = await reportFetcher.getReportLink(scanId, scanRunId);
171+
172+
const { records, page_length, total_issues, next_page } =
173+
await parseAccessibilityReportFromCSV(reportLink, { nextPage });
174+
175+
const currentlyShown =
176+
nextPage === 0
177+
? page_length
178+
: Math.floor(nextPage / JSON.stringify(records[0] || {}).length) +
179+
page_length;
180+
const remainingIssues = total_issues - currentlyShown;
181+
182+
const messages = [
183+
`📊 Retrieved ${page_length} accessibility issues (Total: ${total_issues})`,
184+
`Issues: ${JSON.stringify(records, null, 2)}`,
185+
];
186+
187+
if (next_page !== null) {
188+
messages.push(
189+
`📄 ${remainingIssues} more issues available. Use fetchAccessibilityIssues with nextPage: ${next_page} to get the next batch.`,
190+
);
191+
} else {
192+
messages.push(`✅ All issues retrieved.`);
193+
}
194+
195+
return createSuccessResponse(messages);
196+
}
197+
140198
async function executeAccessibilityScan(
141199
args: { name: string; pageURL: string; authConfigId?: number },
142200
context: ScanProgressContext,
@@ -283,12 +341,26 @@ function createScanSuccessResponse(
283341
totalIssues: number,
284342
pageLength: number,
285343
records: any[],
344+
scanId: string,
345+
scanRunId: string,
346+
reportUrl: string,
347+
nextPage: number | null,
286348
): CallToolResult {
287-
return createSuccessResponse([
349+
const messages = [
288350
`✅ Accessibility scan "${name}" completed. check the BrowserStack dashboard for more details [https://scanner.browserstack.com/site-scanner/scan-details/${name}].`,
351+
`Scan ID: ${scanId} and Scan Run ID: ${scanRunId}`,
352+
`You can also download the full report from the following link: ${reportUrl}`,
289353
`We found ${totalIssues} issues. Below are the details of the ${pageLength} most critical issues.`,
290354
`Scan results: ${JSON.stringify(records, null, 2)}`,
291-
]);
355+
];
356+
357+
if (nextPage !== null) {
358+
messages.push(
359+
`📄 More issues available. Use fetchAccessibilityIssues tool with scanId: "${scanId}", scanRunId: "${scanRunId}", and nextPage: ${nextPage} to get the next batch.`,
360+
);
361+
}
362+
363+
return createSuccessResponse(messages);
292364
}
293365

294366
async function runAccessibilityScan(
@@ -314,10 +386,19 @@ async function runAccessibilityScan(
314386
const reportFetcher = await initializeReportFetcher(config);
315387
const reportLink = await reportFetcher.getReportLink(scanId, scanRunId);
316388

317-
const { records, page_length, total_issues } =
389+
const { records, page_length, total_issues, next_page } =
318390
await parseAccessibilityReportFromCSV(reportLink);
319391

320-
return createScanSuccessResponse(name, total_issues, page_length, records);
392+
return createScanSuccessResponse(
393+
name,
394+
total_issues,
395+
page_length,
396+
records,
397+
scanId,
398+
scanRunId,
399+
reportLink,
400+
next_page,
401+
);
321402
}
322403

323404
export default function addAccessibilityTools(
@@ -403,5 +484,27 @@ export default function addAccessibilityTools(
403484
},
404485
);
405486

487+
tools.fetchAccessibilityIssues = server.tool(
488+
"fetchAccessibilityIssues",
489+
"Fetch accessibility issues from a completed scan with pagination support. Use nextPage parameter to get subsequent pages of results.",
490+
{
491+
scanId: z
492+
.string()
493+
.describe("The scan ID from a completed accessibility scan"),
494+
scanRunId: z
495+
.string()
496+
.describe("The scan run ID from a completed accessibility scan"),
497+
nextPage: z
498+
.number()
499+
.optional()
500+
.describe(
501+
"Character offset for pagination (default: 0, use 1 for first page after initial scan results)",
502+
),
503+
},
504+
async (args) => {
505+
return await executeFetchAccessibilityIssues(args, server, config);
506+
},
507+
);
508+
406509
return tools;
407510
}

0 commit comments

Comments
 (0)