Skip to content

Conversation

@Kylejeong2
Copy link
Member

what

adding agent tool to our mcp

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Nov 10, 2025

Greptile Overview

Greptile Summary

This PR adds a new browserbase_stagehand_agent tool that enables autonomous web task execution using Gemini Computer Use. The agent accepts a task prompt and executes it autonomously with up to 20 steps.

Key changes:

  • New agent tool in src/tools/agent.ts that wraps Stagehand's agent functionality with Gemini 2.5 Computer Use
  • Integrated agent tool into the tool exports in src/tools/index.ts
  • Updated default viewport dimensions from 1024x768 to 1288x711 in src/sessionManager.ts
  • Version bumped to 2.4.0

Issue found:

  • Missing validation for Gemini environment variables in src/tools/agent.ts:44-47 - if none of the three environment variables are set, the agent will be created with undefined and fail at runtime

Confidence Score: 4/5

  • Safe to merge with one logical issue that needs fixing
  • The implementation follows existing patterns and integrates cleanly, but has a critical missing validation that will cause runtime failures if environment variables aren't set. The viewport dimension change appears intentional. Once the validation is added, this would be a 5.
  • src/tools/agent.ts needs validation added for the environment variables

Important Files Changed

File Analysis

Filename Score Overview
src/tools/agent.ts 4/5 New agent tool using Gemini Computer Use for autonomous task execution. Missing API key validation could cause runtime errors.
src/tools/index.ts 5/5 Simple addition of agent tool to exports array - clean integration.
src/sessionManager.ts 5/5 Updated default viewport dimensions from 1024x768 to 1288x711.

Sequence Diagram

sequenceDiagram
    participant User
    participant MCP Server
    participant Context
    participant SessionManager
    participant Stagehand
    participant Agent
    participant Gemini API

    User->>MCP Server: Call browserbase_stagehand_agent tool
    MCP Server->>Context: run(agentTool, {prompt})
    Context->>Context: handle(context, params)
    Context->>Context: getStagehand()
    Context->>SessionManager: getSession(sessionId, config)
    SessionManager-->>Context: return session.stagehand
    Context->>Stagehand: agent({cua: true, model: {...}})
    Stagehand-->>Context: return agent instance
    Context->>Agent: execute({instruction, maxSteps: 20})
    loop Up to 20 steps
        Agent->>Gemini API: Computer Use API calls
        Gemini API->>Agent: Navigation/interaction commands
        Agent->>Stagehand: Perform browser actions
    end
    Agent-->>Context: return result
    Context->>MCP Server: return {content: [{type: "text", text: result}]}
    MCP Server-->>User: Agent execution completed
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines 44 to 47
apiKey:
process.env.GOOGLE_GENERATIVE_AI_API_KEY ||
process.env.GOOGLE_API_KEY ||
process.env.GEMINI_API_KEY,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: missing validation - if all env vars are undefined, the agent will be created with undefined and fail at runtime when executing

validate the resolved value is not undefined before passing to agent constructor

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/tools/agent.ts
Line: 44:47

Comment:
**logic:** missing validation - if all env vars are undefined, the agent will be created with `undefined` and fail at runtime when executing

validate the resolved value is not `undefined` before passing to agent constructor

How can I resolve this? If you propose a fix, please make it concise.

@miguelg719 miguelg719 merged commit b4d1d16 into main Nov 11, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants