Skip to content

Commit 397b98c

Browse files
raise proper error on older node js version or if access key is not set (#47)
* feat: enhance accessibility scan report with issue count and pagination details * feat: implement setupOnInitialized function for server initialization checks and tracking * fix: update error message for unsupported Node.js version in setupOnInitialized function
1 parent 922ca2e commit 397b98c

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

src/config.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
if (
2-
!process.env.BROWSERSTACK_ACCESS_KEY ||
3-
!process.env.BROWSERSTACK_USERNAME
4-
) {
5-
throw new Error(
6-
"Unable to start MCP server. Please set the BROWSERSTACK_ACCESS_KEY and BROWSERSTACK_USERNAME environment variables. Go to https://www.browserstack.com/accounts/profile/details to access them",
7-
);
8-
}
9-
101
export class Config {
112
constructor(
123
public readonly browserstackUsername: string,

src/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import addTestManagementTools from "./tools/testmanagement.js";
1515
import addAppAutomationTools from "./tools/appautomate.js";
1616
import addFailureLogsTools from "./tools/getFailureLogs.js";
1717
import addAutomateTools from "./tools/automate.js";
18-
import { trackMCP } from "./lib/instrumentation.js";
18+
import { setupOnInitialized } from "./oninitialized.js";
1919

2020
function registerTools(server: McpServer) {
2121
addSDKTools(server);
@@ -34,6 +34,8 @@ const server: McpServer = new McpServer({
3434
version: packageJson.version,
3535
});
3636

37+
setupOnInitialized(server);
38+
3739
registerTools(server);
3840

3941
async function main() {
@@ -45,9 +47,6 @@ async function main() {
4547
// Start receiving messages on stdin and sending messages on stdout
4648
const transport = new StdioServerTransport();
4749
await server.connect(transport);
48-
49-
logger.info("MCP server started successfully");
50-
trackMCP("started", server.server.getClientVersion()!);
5150
}
5251

5352
main().catch(console.error);

src/oninitialized.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import config from "./config.js";
2+
import { trackMCP } from "./lib/instrumentation.js";
3+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
4+
5+
export function setupOnInitialized(server: McpServer) {
6+
const nodeVersion = process.versions.node;
7+
8+
// Check for Node.js version
9+
if (nodeVersion < "18.0.0") {
10+
throw new Error(
11+
"Node version is not supported. Please upgrade to 18.0.0 or later.",
12+
);
13+
}
14+
15+
// Check for BrowserStack credentials
16+
if (!config.browserstackUsername || !config.browserstackAccessKey) {
17+
throw new Error(
18+
"BrowserStack credentials are missing. Please provide a valid username and access key.",
19+
);
20+
}
21+
server.server.oninitialized = () => {
22+
trackMCP("started", server.server.getClientVersion()!);
23+
};
24+
}

0 commit comments

Comments
 (0)