Claude Code
Use the Stagehand MCP in Claude Code
Claude Code is Anthropic’s AI-powered command line tool that can be extended with Model Context Protocol (MCP) plugins. This guide explains how to integrate Stagehand’s MCP server with Claude Code to enable web automation capabilities directly from your terminal.
Integrating Stagehand MCP Server with Claude Code
By adding Stagehand’s MCP server to Claude Code, you can enable your AI terminal assistant to interact with web browsers, perform web automation tasks, and extract data from websites.
Prerequisites
- Claude Code installed and configured in your terminal environment
- A Browserbase account with API key and project ID
- OpenAI API key
- Node.js and npm installed
Setup Instructions
- Install the Stagehand MCP server from the GitHub repository:
- Enter the directory that you want to use Stagehand MCP in, and run the following with your API keys set (replace the quotes with your keys).
- Start Claude Code within that directory
It’ll look like this:
- That’s it! You can now use Stagehand’s MCP server with Claude Code.
You can say things like: “Go to stagehand.dev and tell me why they’re goated!” or “
Available Commands
When integrated with Claude Code, your AI assistant can use the following Stagehand commands:
- stagehand_navigate: Navigate to any URL in the browser
- stagehand_act: Perform an action on a web page
- stagehand_extract: Extract data from a web page based on instructions
- stagehand_observe: Observe actions that can be performed on a web page
Example Usage
Here’s an example of how to use Stagehand with Claude Code in your workflow:
- In your terminal, ask Claude Code to perform a web task:
Claude will use Stagehand’s MCP commands to:
- Navigate to the Node.js documentation website
- Interact with the search functionality
- Extract the relevant information
- Return the results directly in your terminal
Benefits of Integration
- Perform web research without leaving your terminal
- Automate repetitive web tasks from your command line
- Extract data from websites to use in your scripts or applications
- Build more powerful AI-assisted workflows in your terminal environment
View the browser session in Browserbase
You can view the browser session in Browserbase by going to the Browserbase dashboard and clicking on the “Sessions” tab.
Troubleshooting
If you encounter issues with the integration:
- Ensure the MCP server is running
- Check that your environment variables are set correctly
- Verify that Claude Code is properly configured to use the MCP server, you can use the —mcp-debug flag to help debug here.
- Check the MCP server logs for any error messages
Here’s Anthropic’s Official Documentation on installing MCP servers on Claude Code.
Further Resources
- Claude Code Documentation
- Stagehand GitHub Repository
- Model Context Protocol (MCP)
- Join our Slack community for support