opencode-browser-mcp
v1.0.2
Published
OpenCode plugin that integrates Browser MCP for browser automation
Maintainers
Readme
OpenCode Browser MCP Plugin
An OpenCode plugin that integrates Browser MCP to enable browser automation capabilities within OpenCode. This plugin allows the AI to control a browser, navigate websites, fill forms, click elements, and perform other browser automation tasks.
Features
- Full browser automation support through Browser MCP
- Automatic detection of browser-related tasks
- Context preservation for browser state across session compactions
- Logging and monitoring of browser automation activities
- Seamless integration with OpenCode's existing tools
Prerequisites
Before using this plugin, you need:
- Node.js installed on your system
- OpenCode installed and configured
- Browser MCP extension installed in your browser (Chrome/Edge)
Installation
Step 1: Install Browser MCP Extension
- Visit https://browsermcp.io/install
- Install the Browser MCP extension for your browser (Chrome or Edge)
- Follow the extension setup instructions
Step 2: Configure OpenCode
Create or update your opencode.json configuration file. You can create this file in one of two locations:
- Global configuration (applies to all projects):
~/.config/opencode/opencode.json - Project-specific configuration (applies to current project only):
./opencode.json(in your project root)
Learn more about OpenCode configuration at https://opencode.ai/docs/config
Add this configuration to your opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-browser"],
"mcp": {
"browsermcp": {
"type": "local",
"command": ["npx", "-y", "@browsermcp/mcp@latest"],
"enabled": true
}
}
}This configuration does two things:
- Installs the plugin - OpenCode automatically downloads
opencode-browserfrom npm - Configures Browser MCP - Sets up the MCP server that actually controls the browser
That's it! No manual file copying required. OpenCode handles everything automatically.
Alternative: Install Locally (for development/testing)
If you want to modify the plugin or test changes:
For global installation:
mkdir -p ~/.config/opencode/plugin
cp index.ts ~/.config/opencode/plugin/browser-mcp.tsFor project-specific installation:
mkdir -p .opencode/plugin
cp index.ts .opencode/plugin/browser-mcp.tsThe plugin will be automatically loaded on OpenCode startup.
Configuration
Basic Configuration
The minimal configuration requires only the MCP server setup:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"browsermcp": {
"type": "local",
"command": ["npx", "-y", "@browsermcp/mcp@latest"],
"enabled": true
}
}
}Advanced Configuration
For more control, you can disable Browser MCP tools globally and enable them per agent:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"browsermcp": {
"type": "local",
"command": ["npx", "-y", "@browsermcp/mcp@latest"],
"enabled": true
}
},
"tools": {
"browsermcp_*": false
},
"agent": {
"browser-agent": {
"tools": {
"browsermcp_*": true
}
}
}
}Environment Variables
If you need to pass environment variables to the Browser MCP server:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"browsermcp": {
"type": "local",
"command": ["npx", "-y", "@browsermcp/mcp@latest"],
"enabled": true,
"environment": {
"BROWSER_MCP_DEBUG": "true"
}
}
}
}Usage
Once installed and configured, you can use browser automation in your OpenCode prompts:
Basic Browser Navigation
Navigate to https://github.com and search for "opencode"Form Filling
Go to the contact form at https://example.com/contact and fill in:
- Name: John Doe
- Email: [email protected]
- Message: Hello from OpenCode!
Then submit the form.Web Scraping
Visit https://news.ycombinator.com and get the titles of the top 5 storiesComplex Automation
Go to https://example.com/login, log in with the test credentials,
navigate to the dashboard, and screenshot the main metrics panelPrompt Tips
For best results when using browser automation:
- Be specific about URLs and actions
- Use step-by-step instructions for complex workflows
- Specify selectors when needed (CSS selectors, text content, etc.)
- Ask for verification when critical (screenshots, text content)
You can also add browser automation guidelines to your AGENTS.md file:
## Browser Automation
When performing browser automation tasks:
- Always confirm the page has loaded before interacting
- Use descriptive selectors (prefer text content over CSS selectors)
- Take screenshots when verification is needed
- Handle errors gracefully (page not found, element not visible, etc.)
- Close tabs when the task is completePlugin Features
Automatic Browser Tool Detection
The plugin automatically detects when Browser MCP tools are being used and logs the activity.
Session Context Preservation
During session compaction, the plugin preserves browser automation context, ensuring the AI remembers:
- Browser interactions that occurred
- Current browser state considerations
- Need to verify page state before assumptions
Tool Execution Hooks
The plugin hooks into tool execution to:
- Log browser automation activities
- Monitor tool arguments and results
- Enable custom post-processing of browser actions
Troubleshooting
Browser MCP Not Working
- Check extension is installed: Open your browser and verify the Browser MCP extension is installed and enabled
- Verify MCP server config: Ensure your
opencode.jsonhas the correct MCP configuration - Check Node.js: Ensure Node.js is installed:
node --version - Test MCP connection: Restart OpenCode after adding the MCP configuration
Plugin Not Loading
- Check file location: Ensure the plugin file is in the correct directory
- Check file name: Plugin files should end in
.tsor.js - Check syntax: Ensure the TypeScript/JavaScript syntax is valid
- Check logs: Look for plugin initialization messages in OpenCode output
Tools Not Available
- Check MCP server status: Ensure the Browser MCP server started successfully
- Check tool configuration: Verify tools aren't disabled in your config
- Restart OpenCode: Try restarting OpenCode after configuration changes
Debug Mode
Enable debug logging by modifying the plugin or checking OpenCode logs:
# Check OpenCode logs
opencode --verboseDevelopment
Building from Source
If you want to modify the plugin:
- Clone the repository
- Make your changes to
index.ts - Test locally by copying to your OpenCode plugin directory
- Submit a PR if you'd like to contribute!
Plugin Architecture
The plugin uses OpenCode's plugin system hooks:
session.created: Initialize session-specific statetool.execute.before: Pre-process browser tool callstool.execute.after: Post-process browser tool resultsexperimental.session.compacting: Preserve browser contextevent: Handle OpenCode events
Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
Resources
License
MIT License - See LICENSE file for details
Support
For issues and questions:
- Browser MCP issues: Browser MCP GitHub
- OpenCode issues: OpenCode GitHub
- Plugin issues: Open an issue in this repository
Changelog
See CHANGELOG.md for a detailed list of changes in each version.
