Skip to content

Commit d6fb91d

Browse files
committed
add modelapikey to config
1 parent a4d74f6 commit d6fb91d

File tree

5 files changed

+126
-57
lines changed

5 files changed

+126
-57
lines changed

README.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ The Browserbase MCP server accepts the following command-line flags:
130130
| `--browserWidth <width>` | Browser viewport width (default: 1024) |
131131
| `--browserHeight <height>` | Browser viewport height (default: 768) |
132132
| `--modelName <model>` | The model to use for Stagehand (default: google/gemini-2.0-flash) |
133+
| `--modelApiKey <key>` | API key for the custom model provider (required when using custom models) |
133134

134135
These flags can be passed directly to the CLI or configured in your MCP configuration file.
135136

@@ -256,14 +257,45 @@ Here's how to use it for custom browser sizing. We recommend to stick with 16:9
256257

257258
Stagehand defaults to using Google's Gemini 2.0 Flash model, but you can configure it to use other models like GPT-4o, Claude, or other providers.
258259

260+
**Important**: When using any custom model (non-default), you must provide your own API key for that model provider using the `--modelApiKey` flag.
261+
259262
Here's how to configure different models:
260263

261264
```json
262265
{
263266
"mcpServers": {
264267
"browserbase": {
265268
"command": "npx",
266-
"args": ["@browserbasehq/mcp", "--modelName", "gpt-4o"],
269+
"args": [
270+
"@browserbasehq/mcp",
271+
"--modelName",
272+
"gpt-4o",
273+
"--modelApiKey",
274+
"your-openai-api-key"
275+
],
276+
"env": {
277+
"BROWSERBASE_API_KEY": "",
278+
"BROWSERBASE_PROJECT_ID": ""
279+
}
280+
}
281+
}
282+
}
283+
```
284+
285+
For Claude models:
286+
287+
```json
288+
{
289+
"mcpServers": {
290+
"browserbase": {
291+
"command": "npx",
292+
"args": [
293+
"@browserbasehq/mcp",
294+
"--modelName",
295+
"claude-3-5-sonnet-latest",
296+
"--modelApiKey",
297+
"your-anthropic-api-key"
298+
],
267299
"env": {
268300
"BROWSERBASE_API_KEY": "",
269301
"BROWSERBASE_PROJECT_ID": ""
@@ -280,7 +312,7 @@ Available models include:
280312
- **Claude**: `claude-3-5-sonnet-latest`, `claude-3-7-sonnet-latest`
281313
- **Other providers**: Cerebras, Groq, and more
282314

283-
_Note: The model must be supported in Stagehand. Check out the docs [here](https://docs.stagehand.dev/examples/custom_llms#supported-llms)._
315+
_Note: The model must be supported in Stagehand. Check out the docs [here](https://docs.stagehand.dev/examples/custom_llms#supported-llms). When using any custom model, you must provide your own API key for that provider._
284316

285317
## Tools
286318

config.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,9 @@ export type Config = {
7878
* @default "google/gemini-2.0-flash"
7979
*/
8080
modelName?: AvailableModelSchema;
81+
/**
82+
* API key for the custom model provider
83+
* Required when using a model other than the default google/gemini-2.0-flash
84+
*/
85+
modelApiKey?: string;
8186
};

src/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export type CLIOptions = {
2222
browserWidth?: number;
2323
browserHeight?: number;
2424
modelName?: typeof AvailableModelSchema;
25+
modelApiKey?: string;
2526
};
2627

2728
// Default Configuration Values
@@ -92,6 +93,7 @@ export async function configFromCLIOptions(
9293
advancedStealth: cliOptions.advancedStealth,
9394
cookies: cliOptions.cookies,
9495
modelName: cliOptions.modelName,
96+
modelApiKey: cliOptions.modelApiKey,
9597
};
9698
}
9799

src/index.ts

Lines changed: 81 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -32,61 +32,87 @@ const cookieSchema = z.object({
3232
});
3333

3434
// Configuration schema for Smithery - matches existing Config interface
35-
export const configSchema = z.object({
36-
browserbaseApiKey: z.string().describe("The Browserbase API Key to use"),
37-
browserbaseProjectId: z
38-
.string()
39-
.describe("The Browserbase Project ID to use"),
40-
proxies: z
41-
.boolean()
42-
.optional()
43-
.describe("Whether or not to use Browserbase proxies"),
44-
advancedStealth: z
45-
.boolean()
46-
.optional()
47-
.describe(
48-
"Use advanced stealth mode. Only available to Browserbase Scale Plan users",
49-
),
50-
context: z
51-
.object({
52-
contextId: z.string().optional().describe("The ID of the context to use"),
53-
persist: z
54-
.boolean()
55-
.optional()
56-
.describe("Whether or not to persist the context"),
57-
})
58-
.optional(),
59-
viewPort: z
60-
.object({
61-
browserWidth: z.number().optional().describe("The width of the browser"),
62-
browserHeight: z
63-
.number()
64-
.optional()
65-
.describe("The height of the browser"),
66-
})
67-
.optional(),
68-
cookies: z
69-
.array(cookieSchema)
70-
.optional()
71-
.describe("Cookies to inject into the Browserbase context"),
72-
server: z
73-
.object({
74-
port: z
75-
.number()
76-
.optional()
77-
.describe("The port to listen on for SSE or MCP transport"),
78-
host: z
79-
.string()
80-
.optional()
81-
.describe(
82-
"The host to bind the server to. Default is localhost. Use 0.0.0.0 to bind to all interfaces",
83-
),
84-
})
85-
.optional(),
86-
modelName: AvailableModelSchema.optional().describe(
87-
"The model to use for Stagehand (default: google/gemini-2.0-flash)",
88-
), // Already an existing Zod Enum
89-
});
35+
export const configSchema = z
36+
.object({
37+
browserbaseApiKey: z.string().describe("The Browserbase API Key to use"),
38+
browserbaseProjectId: z
39+
.string()
40+
.describe("The Browserbase Project ID to use"),
41+
proxies: z
42+
.boolean()
43+
.optional()
44+
.describe("Whether or not to use Browserbase proxies"),
45+
advancedStealth: z
46+
.boolean()
47+
.optional()
48+
.describe(
49+
"Use advanced stealth mode. Only available to Browserbase Scale Plan users",
50+
),
51+
context: z
52+
.object({
53+
contextId: z
54+
.string()
55+
.optional()
56+
.describe("The ID of the context to use"),
57+
persist: z
58+
.boolean()
59+
.optional()
60+
.describe("Whether or not to persist the context"),
61+
})
62+
.optional(),
63+
viewPort: z
64+
.object({
65+
browserWidth: z
66+
.number()
67+
.optional()
68+
.describe("The width of the browser"),
69+
browserHeight: z
70+
.number()
71+
.optional()
72+
.describe("The height of the browser"),
73+
})
74+
.optional(),
75+
cookies: z
76+
.array(cookieSchema)
77+
.optional()
78+
.describe("Cookies to inject into the Browserbase context"),
79+
server: z
80+
.object({
81+
port: z
82+
.number()
83+
.optional()
84+
.describe("The port to listen on for SSE or MCP transport"),
85+
host: z
86+
.string()
87+
.optional()
88+
.describe(
89+
"The host to bind the server to. Default is localhost. Use 0.0.0.0 to bind to all interfaces",
90+
),
91+
})
92+
.optional(),
93+
modelName: AvailableModelSchema.optional().describe(
94+
"The model to use for Stagehand (default: google/gemini-2.0-flash)",
95+
), // Already an existing Zod Enum
96+
modelApiKey: z
97+
.string()
98+
.optional()
99+
.describe(
100+
"API key for the custom model provider. Required when using a model other than the default google/gemini-2.0-flash",
101+
),
102+
})
103+
.refine(
104+
(data) => {
105+
// If any model is explicitly specified, API key is required
106+
if (data.modelName) {
107+
return data.modelApiKey !== undefined && data.modelApiKey.length > 0;
108+
}
109+
return true;
110+
},
111+
{
112+
message: "modelApiKey is required when specifying a custom model",
113+
path: ["modelApiKey"],
114+
},
115+
);
90116

91117
// Default function for Smithery
92118
export default function ({ config }: { config: z.infer<typeof configSchema> }) {

src/program.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ program
6060
"--modelName <model>",
6161
"The model to use for Stagehand (default: google/gemini-2.0-flash)",
6262
)
63+
.option(
64+
"--modelApiKey <key>",
65+
"API key for the custom model provider (required when using custom models)",
66+
)
6367
.action(async (options) => {
6468
const config = await resolveConfig(options);
6569
const serverList = new ServerList(async () =>

0 commit comments

Comments
 (0)