Browser Automation MCP Server
Provides 22 browser automation tools via Selenium WebDriver for AI assistants to navigate, interact with, and extract data from web pages.
What this file does
Provides 22 browser automation tools via Selenium WebDriver for AI assistants to navigate, interact with, and extract data from web pages.
When to use it
- Building an MCP server for web scraping and data extraction
- Adding browser automation capabilities to an AI assistant
- Creating automated form filling and e-commerce workflows
- Implementing headless browser testing for web applications
Assumes this stack
Browser Automation MCP Server
A powerful Model Context Protocol (MCP) server that provides comprehensive browser automation capabilities through Selenium WebDriver. This server enables AI assistants to interact with web pages, extract data, and perform complex web automation tasks.
Quick Start
-
Install the server:
cd LAM-mcp uv install -
Run the server:
# STDIO transport (recommended for most MCP clients) uv run python -m browser_mcp_server.server # Or with SSE transport uv run python -m browser_mcp_server.server --transport sse --port 8000 -
Configure with Claude Desktop: Add to your
claude_desktop_config.json:{ "mcpServers": { "browser-automation": { "command": "uv", "args": ["run", "python", "-m", "browser_mcp_server.server"], "env": { "BROWSER_HEADLESS": "true" } } } }
Available Tools
Core Navigation
navigate_to_url(url)- Navigate to any websiteget_current_url()- Get current page URL and titlerefresh_page()- Refresh the current pagego_back()- Navigate back in historygo_forward()- Navigate forward in history
Element Interaction
click_element(selector, by_type="css")- Click buttons, links, etc.type_text(selector, text, by_type="css")- Type into input fieldsclear_field(selector, by_type="css")- Clear input fieldshover_element(selector, by_type="css")- Hover over elements
Content Extraction
get_element_text(selector, by_type="css")- Extract text from elementsget_page_source()- Get full HTML sourceextract_links()- Get all links on the pageextract_table_data(selector="table")- Extract structured table data
Form Automation
fill_form(form_data)- Fill entire forms with data dictionaryselect_dropdown_option(selector, option_text=None, option_value=None)- Select dropdown options
Advanced Features
take_screenshot(element_selector=None)- Capture page or element screenshotsexecute_javascript(script)- Run custom JavaScriptwait_for_element(selector, timeout=30)- Wait for dynamic contentscroll_page(direction="down", pixels=None)- Scroll in any direction
Utility Functions
is_element_present(selector, by_type="css")- Check element existenceget_element_attribute(selector, attribute, by_type="css")- Get element attributesget_cookies()- Retrieve browser cookiesset_cookie(name, value, domain=None, path="/")- Set cookies
Environment Variables
Configure the server behavior with these environment variables:
# Browser type (chrome, firefox, edge)
BROWSER_TYPE=chrome
# Run in headless mode
BROWSER_HEADLESS=true
# Default timeout in seconds
BROWSER_TIMEOUT=30
# Browser window size
BROWSER_WINDOW_SIZE=1920x1080
# Custom user agent
BROWSER_USER_AGENT="Custom Agent String"
# Download directory
BROWSER_DOWNLOAD_DIR=/path/to/downloads
Example Usage Scenarios
Web Scraping
# Navigate and extract data
await navigate_to_url("https://news.ycombinator.com")
await wait_for_element(".storylink")
links = await extract_links()
headlines = await get_element_text(".storylink")
E-commerce Automation
# Search for products
await navigate_to_url("https://amazon.com")
await type_text("#twotabsearchtextbox", "laptop")
await click_element("#nav-search-submit-button")
await wait_for_element("[data-component-type='s-search-result']")
results = await extract_text("[data-component-type='s-search-result'] h2")
Form Filling
# Contact form automation
await navigate_to_url("https://example.com/contact")
await fill_form({
"#name": "John Doe",
"#email": "john@example.com",
"#message": "Hello from automation!"
})
await click_element("#submit")
Social Media Automation
# Login and post (be mindful of terms of service)
await navigate_to_url("https://twitter.com/login")
await type_text("[name='text']", "username")
await click_element("[role='button']:has-text('Next')")
await wait_for_element("[name='password']")
await type_text("[name='password']", "password")
await click_element("[data-testid='LoginForm_Login_Button']")
Security Best Practices
⚠️ Important Security Considerations:
- Controlled Environment: Use in secure, isolated environments
- Authentication: Implement proper authentication for production use
- Input Validation: Always validate URLs and selectors
- Rate Limiting: Implement delays between requests
- Monitoring: Log all automation activities
- Compliance: Respect robots.txt and website terms of service
Browser Support
- Chrome/Chromium: Full support with automatic driver management
- Firefox: Full support with GeckoDriver auto-installation
- Microsoft Edge: Full support with Edge WebDriver
- Headless Mode: All browsers support headless operation
Error Handling
The server provides comprehensive error handling:
{
"success": false,
"error": "Element not found: #invalid-selector",
"details": "NoSuchElementException details..."
}
Common error types:
TimeoutException: Element not found within timeoutNoSuchElementException: Invalid selector or missing elementElementNotInteractableException: Element not clickable/visibleWebDriverException: Browser communication issues
Development
Running Tests
uv run pytest tests/
Code Quality
# Format code
uv run black browser_mcp_server/
# Sort imports
uv run isort browser_mcp_server/
# Type checking
uv run mypy browser_mcp_server/
Adding New Tools
To add new browser automation tools:
- Add the function to
browser_utils.py - Create an MCP tool wrapper in
server.pyusing@mcp.tool() - Add comprehensive docstrings and type hints
- Include error handling and logging
- Add tests in
tests/
Troubleshooting
Common Issues
Browser won't start:
- Check if Chrome/Firefox is installed
- Verify driver permissions
- Try different browser type:
BROWSER_TYPE=firefox
Elements not found:
- Use
wait_for_element()for dynamic content - Check selector syntax (CSS vs XPath)
- Verify element is visible and interactable
Timeout errors:
- Increase timeout:
BROWSER_TIMEOUT=60 - Check network connectivity
- Ensure page is fully loaded
Permission issues:
- Run with appropriate user permissions
- Check download directory write access
- Verify browser installation location
Debug Mode
Enable debug logging:
export PYTHONPATH=$PYTHONPATH:$(pwd)
python -m browser_mcp_server.server --transport stdio
Contributing
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
License
MIT License - see LICENSE file for details.
Disclaimer
This tool provides powerful browser automation capabilities. Users are responsible for:
- Complying with website terms of service
- Respecting rate limits and robots.txt
- Ensuring ethical use of automation
- Protecting user privacy and data security
Use responsibly and in accordance with applicable laws and regulations.
What's inside
10 sections, 22 tool definitions, 4 code examples, 6 environment variables, 4 error types
Change this for your project
- Replace
LAM-mcpwith your own repository name in the install command - Replace
browser_mcp_serverwith your own package name throughout the file - Replace
claude_desktop_config.jsonwith your MCP client's config file path
Where it goes
Keep it in your repository where the agent or team that needs it will read it.
Worth borrowing
- Organizing tools into categories (Core Navigation, Element Interaction, etc.) for discoverability
- Providing both STDIO and SSE transport options for flexibility
- Including a security best practices section to remind users of compliance and ethical use
Related Documents
MCP Integration Workflows and Orchestration Guide
Defines enterprise-grade integration patterns, orchestration strategies, and advanced workflows for MCP servers with code examples.
AI-Generated Short-Form Video Platform
Defines a modular SaaS pipeline that transforms uploaded MP4 videos into polished short-form clips using AI agents and human review.
Valet V1 — Architecture & Implementation Plan
Defines a hosted background coding agent platform with isolated sandboxed dev environments, multiplayer sessions, and YAML-driven workflows.
GitHub Topics & Skills Monitor
Provides a structured GitHub monitoring strategy with search queries, watchlist, and notification options for AI skills, agents, and MCP servers.