-
Notifications
You must be signed in to change notification settings - Fork 29
feat: Add build insights tool to fetch and display build Insights with QG #139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gaurav-singh-9227
merged 3 commits into
browserstack:main
from
tech-sushant:tra-insights
Sep 10, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; | ||
import { z } from "zod"; | ||
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js"; | ||
import logger from "../logger.js"; | ||
import { BrowserStackConfig } from "../lib/types.js"; | ||
import { fetchFromBrowserStackAPI } from "../lib/utils.js"; | ||
|
||
// Tool function that fetches build insights from two APIs | ||
export async function fetchBuildInsightsTool( | ||
args: { buildId: string }, | ||
config: BrowserStackConfig, | ||
): Promise<CallToolResult> { | ||
try { | ||
const buildUrl = `https://api-automation.browserstack.com/ext/v1/builds/${args.buildId}`; | ||
const qualityGateUrl = `https://api-automation.browserstack.com/ext/v1/quality-gates/${args.buildId}`; | ||
|
||
const [buildData, qualityData] = await Promise.all([ | ||
fetchFromBrowserStackAPI(buildUrl, config), | ||
fetchFromBrowserStackAPI(qualityGateUrl, config), | ||
]); | ||
|
||
// Select useful fields for users | ||
const insights = { | ||
name: buildData.name, | ||
status: buildData.status, | ||
duration: buildData.duration, | ||
user: buildData.user, | ||
tags: buildData.tags, | ||
alerts: buildData.alerts, | ||
status_stats: buildData.status_stats, | ||
failure_categories: buildData.failure_categories, | ||
smart_tags: buildData.smart_tags, | ||
unique_errors: buildData.unique_errors?.overview, | ||
observability_url: buildData?.observability_url, | ||
ci_build_url: buildData.ci_info?.build_url, | ||
quality_gate_result: qualityData.quality_gate_result, | ||
}; | ||
|
||
const qualityProfiles = qualityData.quality_profiles?.map( | ||
(profile: any) => ({ | ||
name: profile.name, | ||
result: profile.result, | ||
}), | ||
); | ||
|
||
const qualityProfilesText = | ||
qualityProfiles && qualityProfiles.length > 0 | ||
? `Quality Gate Profiles (respond only if explicitly requested): ${JSON.stringify(qualityProfiles, null, 2)}` | ||
: "No Quality Gate Profiles available."; | ||
|
||
return { | ||
content: [ | ||
{ | ||
type: "text", | ||
text: "Build insights:\n" + JSON.stringify(insights, null, 2), | ||
}, | ||
{ type: "text", text: qualityProfilesText }, | ||
], | ||
}; | ||
} catch (error) { | ||
logger.error("Error fetching build insights", error); | ||
throw error; | ||
} | ||
} | ||
|
||
// Registers the fetchBuildInsights tool with the MCP server | ||
export default function addBuildInsightsTools( | ||
server: McpServer, | ||
config: BrowserStackConfig, | ||
) { | ||
const tools: Record<string, any> = {}; | ||
|
||
tools.fetchBuildInsights = server.tool( | ||
"fetchBuildInsights", | ||
"Fetches insights about a BrowserStack build by combining build details and quality gate results.", | ||
{ | ||
buildId: z.string().describe("The build UUID of the BrowserStack build"), | ||
}, | ||
async (args) => { | ||
try { | ||
return await fetchBuildInsightsTool(args, config); | ||
} catch (error) { | ||
const errorMessage = | ||
error instanceof Error ? error.message : "Unknown error"; | ||
return { | ||
content: [ | ||
{ | ||
type: "text", | ||
text: `Error during fetching build insights: ${errorMessage}`, | ||
}, | ||
], | ||
}; | ||
} | ||
}, | ||
); | ||
|
||
return tools; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.