Skip to content

Commit 398101a

Browse files
committed
console errors if user runs stdio with no api key + gemini key validation in config
1 parent 8c485a3 commit 398101a

File tree

3 files changed

+74
-2
lines changed

3 files changed

+74
-2
lines changed

src/config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ export async function resolveConfig(cliOptions: CLIOptions): Promise<Config> {
5151
if (!mergedConfig.browserbaseProjectId) {
5252
mergedConfig.browserbaseProjectId = process.env.BROWSERBASE_PROJECT_ID;
5353
}
54+
55+
if (!mergedConfig.modelApiKey) {
56+
mergedConfig.modelApiKey = process.env.GEMINI_API_KEY;
57+
}
58+
5459
// --------------------------------
5560

5661
// Basic validation for Browserbase keys
@@ -62,6 +67,9 @@ export async function resolveConfig(cliOptions: CLIOptions): Promise<Config> {
6267
"Warning: BROWSERBASE_PROJECT_ID environment variable not set.",
6368
);
6469
}
70+
if (!mergedConfig.modelApiKey) {
71+
console.warn("Warning: GEMINI_API_KEY environment variable not set.");
72+
}
6573

6674
return mergedConfig;
6775
}

src/program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ program
7979

8080
if (options.port)
8181
startHttpTransport(+options.port, options.host, serverList);
82-
else await startStdioTransport(serverList);
82+
else await startStdioTransport(serverList, config);
8383
});
8484

8585
function setupExitWatchdog(serverList: ServerList) {

src/transport.ts

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,72 @@ import { ServerList } from "./server.js";
66
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
77
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
88
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
9+
import type { Config } from "../config.js";
10+
11+
export async function startStdioTransport(
12+
serverList: ServerList,
13+
config?: Config,
14+
) {
15+
// Check if we're using the default model without an API key
16+
if (config) {
17+
const modelName = config.modelName || "google/gemini-2.0-flash";
18+
const hasModelApiKey = config.modelApiKey || process.env.GEMINI_API_KEY;
19+
20+
if (modelName.includes("google/gemini") && !hasModelApiKey) {
21+
console.error(`
22+
⚠️ IMPORTANT: MCP Server Configuration Update Required
23+
24+
We've made changes to the MCP server that now require model API keys for local STDIO usage.
25+
26+
You're using the default Gemini model (${modelName}) but no API key is configured.
27+
28+
To fix this, you have two options:
29+
30+
1. Set the GEMINI_API_KEY environment variable:
31+
export GEMINI_API_KEY="your-gemini-api-key"
32+
33+
2. Or add the --modelApiKey flag to your MCP config:
34+
{
35+
"mcpServers": {
36+
"browserbase": {
37+
"command": "npx",
38+
"args": ["@browserbasehq/mcp"],
39+
"env": {
40+
"BROWSERBASE_API_KEY": "your-browserbase-key",
41+
"BROWSERBASE_PROJECT_ID": "your-project-id"
42+
"GEMINI_API_KEY": "your-gemini-api-key"
43+
}
44+
}
45+
}
46+
}
47+
48+
You can get a Gemini API key from: https://aistudio.google.com/app/apikey
49+
50+
3. Or choose another supported model:
51+
Available models: https://docs.stagehand.dev/examples/custom_llms#llm-customization
52+
53+
{
54+
"mcpServers": {
55+
"browserbase": {
56+
"command": "npx",
57+
"args": [
58+
"@browserbasehq/mcp",
59+
"--modelName", "available-model",
60+
"--modelApiKey", "your-api-key",
61+
],
62+
"env": {
63+
"BROWSERBASE_API_KEY": "your-browserbase-key",
64+
"BROWSERBASE_PROJECT_ID": "your-project-id"
65+
}
66+
}
67+
}
68+
}
69+
70+
The server will now attempt to start, but will likely fail without the API key...
71+
`);
72+
}
73+
}
974

10-
export async function startStdioTransport(serverList: ServerList) {
1175
const server = await serverList.create();
1276
await server.connect(new StdioServerTransport());
1377
}

0 commit comments

Comments
 (0)