Skip to content

Commit 0201dc4

Browse files
committed
change to available models type + adding debug url to tool outputs
1 parent 4488798 commit 0201dc4

14 files changed

+104
-26
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ The Browserbase MCP server accepts the following command-line flags:
226226
| `--cookies [json]` | JSON array of cookies to inject into the browser |
227227
| `--browserWidth <width>` | Browser viewport width (default: 1024) |
228228
| `--browserHeight <height>` | Browser viewport height (default: 768) |
229-
| `--modelName <model>` | The model to use for Stagehand (default: gemini-2.0-flash) |
229+
| `--modelName <model>` | The model to use for Stagehand (default: google/gemini-2.0-flash) |
230230
| `--modelApiKey <key>` | API key for the custom model provider (required when using custom models) |
231231

232232
These flags can be passed directly to the CLI or configured in your MCP configuration file.
@@ -411,7 +411,7 @@ For Claude models:
411411

412412
Available models include:
413413

414-
- **Gemini**: `gemini-2.0-flash` (default), `gemini-1.5-pro`, `gemini-1.5-flash`
414+
- **Gemini**: `google/gemini-2.0-flash` (default), `gemini-1.5-pro`, `gemini-1.5-flash`
415415
- **OpenAI**: `gpt-4o`, `gpt-4o-mini`, `o1-mini`, `o1-preview`, `o3-mini`
416416
- **Claude**: `claude-3-5-sonnet-latest`, `claude-3-7-sonnet-latest`
417417
- **Other providers**: Cerebras, Groq, and more

config.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Cookie } from "playwright-core";
2-
import type { AvailableModelSchema } from "@browserbasehq/stagehand";
2+
import type { AvailableModelSchema } from "./src/types/models.js";
33

44
export type Config = {
55
/**
@@ -90,12 +90,12 @@ export type Config = {
9090
* The Model that Stagehand uses
9191
* Available models: OpenAI, Claude, Gemini, Cerebras, Groq, and other providers
9292
*
93-
* @default "gemini-2.0-flash"
93+
* @default "google/gemini-2.0-flash"
9494
*/
9595
modelName?: AvailableModelSchema;
9696
/**
9797
* API key for the custom model provider
98-
* Required when using a model other than the default gemini-2.0-flash
98+
* Required when using a model other than the default google/gemini-2.0-flash
9999
*/
100100
modelApiKey?: string;
101101
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
]
3939
},
4040
"dependencies": {
41+
"@browserbasehq/sdk": "^2.6.0",
4142
"@browserbasehq/stagehand": "^2.4.0",
4243
"@modelcontextprotocol/sdk": "^1.13.1",
4344
"@smithery/cli": "^1.2.15",

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Cookie } from "playwright-core";
22
import type { Config } from "../config.d.ts";
3-
import { AvailableModelSchema } from "@browserbasehq/stagehand";
3+
import type { AvailableModel } from "./types/models.js";
44

55
export type ToolCapability = "core" | string;
66

@@ -15,7 +15,7 @@ export type CLIOptions = {
1515
cookies?: Cookie[];
1616
browserWidth?: number;
1717
browserHeight?: number;
18-
modelName?: typeof AvailableModelSchema;
18+
modelName?: typeof AvailableModel;
1919
modelApiKey?: string;
2020
};
2121

@@ -33,7 +33,7 @@ const defaultConfig: Config = {
3333
browserHeight: 768,
3434
},
3535
cookies: undefined,
36-
modelName: "gemini-2.0-flash", // Default Model
36+
modelName: "google/gemini-2.0-flash", // Default Model
3737
};
3838

3939
// Resolve final configuration by merging defaults, file config, and CLI options

src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { MCPToolsArray } from "./types/types.js";
88
import { Context } from "./context.js";
99
import type { Config } from "../config.d.ts";
1010
import { TOOLS } from "./tools/index.js";
11-
import { AvailableModelSchema } from "@browserbasehq/stagehand";
11+
import { AvailableModelSchema } from "./types/models.js";
1212
import { PROMPTS, getPrompt } from "./mcp/prompts.js";
1313
import { RESOURCE_TEMPLATES } from "./mcp/resources.js";
1414

@@ -91,19 +91,19 @@ export const configSchema = z
9191
})
9292
.optional(),
9393
modelName: AvailableModelSchema.optional().describe(
94-
"The model to use for Stagehand (default: gemini-2.0-flash)",
94+
"The model to use for Stagehand (default: google/gemini-2.0-flash)",
9595
), // Already an existing Zod Enum
9696
modelApiKey: z
9797
.string()
9898
.optional()
9999
.describe(
100-
"API key for the custom model provider. Required when using a model other than the default gemini-2.0-flash",
100+
"API key for the custom model provider. Required when using a model other than the default google/gemini-2.0-flash",
101101
),
102102
})
103103
.refine(
104104
(data) => {
105105
// If a non-default model is explicitly specified, API key is required
106-
if (data.modelName && data.modelName !== "gemini-2.0-flash") {
106+
if (data.modelName && data.modelName !== "google/gemini-2.0-flash") {
107107
return data.modelApiKey !== undefined && data.modelApiKey.length > 0;
108108
}
109109
return true;

src/program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ program
5959
.option("--browserHeight <height>", "Browser height to use for the browser.")
6060
.option(
6161
"--modelName <model>",
62-
"The model to use for Stagehand (default: gemini-2.0-flash)",
62+
"The model to use for Stagehand (default: google/gemini-2.0-flash)",
6363
)
6464
.option(
6565
"--modelApiKey <key>",

src/sessionManager.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,18 +207,18 @@ export async function ensureDefaultSessionInternal(
207207
config: Config,
208208
): Promise<BrowserSession> {
209209
const sessionId = defaultSessionId;
210-
let needsRecreation = false;
210+
let needsReCreation = false;
211211

212212
if (!defaultBrowserSession) {
213-
needsRecreation = true;
213+
needsReCreation = true;
214214
process.stderr.write(
215215
`[SessionManager] Default session ${sessionId} not found, creating.\n`,
216216
);
217217
} else if (
218218
!defaultBrowserSession.browser.isConnected() ||
219219
defaultBrowserSession.page.isClosed()
220220
) {
221-
needsRecreation = true;
221+
needsReCreation = true;
222222
process.stderr.write(
223223
`[SessionManager] Default session ${sessionId} is stale, recreating.\n`,
224224
);
@@ -227,7 +227,7 @@ export async function ensureDefaultSessionInternal(
227227
browsers.delete(sessionId);
228228
}
229229

230-
if (needsRecreation) {
230+
if (needsReCreation) {
231231
try {
232232
defaultBrowserSession = await createNewBrowserSession(sessionId, config);
233233
return defaultBrowserSession;

src/stagehandStore.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { randomUUID } from "crypto";
2-
import { Stagehand, AvailableModel, Page } from "@browserbasehq/stagehand";
2+
import { Stagehand, Page } from "@browserbasehq/stagehand";
33
import { StagehandSession, CreateSessionParams } from "./types/types.js";
44
import type { Config } from "../config.d.ts";
55

@@ -25,9 +25,8 @@ export const createStagehandInstance = async (
2525
env: "BROWSERBASE",
2626
apiKey,
2727
projectId,
28-
modelName: (params.modelName ||
29-
config.modelName ||
30-
"gemini-2.0-flash") as AvailableModel,
28+
modelName:
29+
params.modelName || config.modelName || "google/gemini-2.0-flash",
3130
modelClientOptions: {
3231
apiKey: config.modelApiKey || process.env.GEMINI_API_KEY,
3332
},

src/tools/multiSession.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { z } from "zod";
2+
import { Browserbase } from "@browserbasehq/sdk";
23
import {
34
defineTool,
45
type Tool,
@@ -111,12 +112,24 @@ export const createSessionTool = defineTool({
111112

112113
const session = await stagehandStore.create(context.config, params);
113114

115+
const bbSessionId = session.metadata?.bbSessionId;
116+
if (!bbSessionId) {
117+
throw new Error("No Browserbase session ID available");
118+
}
119+
120+
// Get the debug URL using Browserbase SDK
121+
const bb = new Browserbase({
122+
apiKey: context.config.browserbaseApiKey,
123+
});
124+
const debugUrl = (await bb.sessions.debug(bbSessionId))
125+
.debuggerFullscreenUrl;
126+
114127
return {
115128
action: async () => ({
116129
content: [
117130
{
118131
type: "text",
119-
text: `Created session ${session.id}${name ? ` (${name})` : ""}\nBrowserbase session: ${session.metadata?.bbSessionId}`,
132+
text: `Created session ${session.id}${name ? ` (${name})` : ""}\nBrowserbase session: ${bbSessionId}\nBrowserbase Live Session View URL: https://www.browserbase.com/sessions/${bbSessionId}\nBrowserbase Live Debugger URL: ${debugUrl}`,
120133
},
121134
],
122135
}),

0 commit comments

Comments
 (0)