opencode-browser-mcp 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +302 -0
- package/index.ts +105 -0
- package/package.json +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
# OpenCode Browser MCP Plugin
|
|
2
|
+
|
|
3
|
+
An OpenCode plugin that integrates [Browser MCP](https://browsermcp.io) 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.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Full browser automation support through Browser MCP
|
|
8
|
+
- Automatic detection of browser-related tasks
|
|
9
|
+
- Context preservation for browser state across session compactions
|
|
10
|
+
- Logging and monitoring of browser automation activities
|
|
11
|
+
- Seamless integration with OpenCode's existing tools
|
|
12
|
+
|
|
13
|
+
## Prerequisites
|
|
14
|
+
|
|
15
|
+
Before using this plugin, you need:
|
|
16
|
+
|
|
17
|
+
1. **Node.js** installed on your system
|
|
18
|
+
2. **OpenCode** installed and configured
|
|
19
|
+
3. **Browser MCP extension** installed in your browser (Chrome/Edge)
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
### Step 1: Install Browser MCP Extension
|
|
24
|
+
|
|
25
|
+
1. Visit [https://browsermcp.io/install](https://browsermcp.io/install)
|
|
26
|
+
2. Install the Browser MCP extension for your browser (Chrome or Edge)
|
|
27
|
+
3. Follow the extension setup instructions
|
|
28
|
+
|
|
29
|
+
### Step 2: Configure OpenCode
|
|
30
|
+
|
|
31
|
+
Create or update your `opencode.json` configuration file. You can create this file in one of two locations:
|
|
32
|
+
|
|
33
|
+
- **Global configuration** (applies to all projects): `~/.config/opencode/opencode.json`
|
|
34
|
+
- **Project-specific configuration** (applies to current project only): `./opencode.json` (in your project root)
|
|
35
|
+
|
|
36
|
+
Learn more about OpenCode configuration at [https://opencode.ai/docs/config](https://opencode.ai/docs/config)
|
|
37
|
+
|
|
38
|
+
Add this configuration to your `opencode.json`:
|
|
39
|
+
|
|
40
|
+
```json
|
|
41
|
+
{
|
|
42
|
+
"$schema": "https://opencode.ai/config.json",
|
|
43
|
+
"plugin": ["opencode-browser"],
|
|
44
|
+
"mcp": {
|
|
45
|
+
"browsermcp": {
|
|
46
|
+
"type": "local",
|
|
47
|
+
"command": ["npx", "-y", "@browsermcp/mcp@latest"],
|
|
48
|
+
"enabled": true
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
This configuration does two things:
|
|
55
|
+
1. **Installs the plugin** - OpenCode automatically downloads `opencode-browser` from npm
|
|
56
|
+
2. **Configures Browser MCP** - Sets up the MCP server that actually controls the browser
|
|
57
|
+
|
|
58
|
+
That's it! No manual file copying required. OpenCode handles everything automatically.
|
|
59
|
+
|
|
60
|
+
#### Alternative: Install Locally (for development/testing)
|
|
61
|
+
|
|
62
|
+
If you want to modify the plugin or test changes:
|
|
63
|
+
|
|
64
|
+
**For global installation:**
|
|
65
|
+
```bash
|
|
66
|
+
mkdir -p ~/.config/opencode/plugin
|
|
67
|
+
cp index.ts ~/.config/opencode/plugin/browser-mcp.ts
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
**For project-specific installation:**
|
|
71
|
+
```bash
|
|
72
|
+
mkdir -p .opencode/plugin
|
|
73
|
+
cp index.ts .opencode/plugin/browser-mcp.ts
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The plugin will be automatically loaded on OpenCode startup.
|
|
77
|
+
|
|
78
|
+
## Configuration
|
|
79
|
+
|
|
80
|
+
### Basic Configuration
|
|
81
|
+
|
|
82
|
+
The minimal configuration requires only the MCP server setup:
|
|
83
|
+
|
|
84
|
+
```json
|
|
85
|
+
{
|
|
86
|
+
"$schema": "https://opencode.ai/config.json",
|
|
87
|
+
"mcp": {
|
|
88
|
+
"browsermcp": {
|
|
89
|
+
"type": "local",
|
|
90
|
+
"command": ["npx", "-y", "@browsermcp/mcp@latest"],
|
|
91
|
+
"enabled": true
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Advanced Configuration
|
|
98
|
+
|
|
99
|
+
For more control, you can disable Browser MCP tools globally and enable them per agent:
|
|
100
|
+
|
|
101
|
+
```json
|
|
102
|
+
{
|
|
103
|
+
"$schema": "https://opencode.ai/config.json",
|
|
104
|
+
"mcp": {
|
|
105
|
+
"browsermcp": {
|
|
106
|
+
"type": "local",
|
|
107
|
+
"command": ["npx", "-y", "@browsermcp/mcp@latest"],
|
|
108
|
+
"enabled": true
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
"tools": {
|
|
112
|
+
"browsermcp_*": false
|
|
113
|
+
},
|
|
114
|
+
"agent": {
|
|
115
|
+
"browser-agent": {
|
|
116
|
+
"tools": {
|
|
117
|
+
"browsermcp_*": true
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Environment Variables
|
|
125
|
+
|
|
126
|
+
If you need to pass environment variables to the Browser MCP server:
|
|
127
|
+
|
|
128
|
+
```json
|
|
129
|
+
{
|
|
130
|
+
"$schema": "https://opencode.ai/config.json",
|
|
131
|
+
"mcp": {
|
|
132
|
+
"browsermcp": {
|
|
133
|
+
"type": "local",
|
|
134
|
+
"command": ["npx", "-y", "@browsermcp/mcp@latest"],
|
|
135
|
+
"enabled": true,
|
|
136
|
+
"environment": {
|
|
137
|
+
"BROWSER_MCP_DEBUG": "true"
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Usage
|
|
145
|
+
|
|
146
|
+
Once installed and configured, you can use browser automation in your OpenCode prompts:
|
|
147
|
+
|
|
148
|
+
### Basic Browser Navigation
|
|
149
|
+
|
|
150
|
+
```
|
|
151
|
+
Navigate to https://github.com and search for "opencode"
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Form Filling
|
|
155
|
+
|
|
156
|
+
```
|
|
157
|
+
Go to the contact form at https://example.com/contact and fill in:
|
|
158
|
+
- Name: John Doe
|
|
159
|
+
- Email: john@example.com
|
|
160
|
+
- Message: Hello from OpenCode!
|
|
161
|
+
Then submit the form.
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Web Scraping
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
Visit https://news.ycombinator.com and get the titles of the top 5 stories
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Complex Automation
|
|
171
|
+
|
|
172
|
+
```
|
|
173
|
+
Go to https://example.com/login, log in with the test credentials,
|
|
174
|
+
navigate to the dashboard, and screenshot the main metrics panel
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Prompt Tips
|
|
178
|
+
|
|
179
|
+
For best results when using browser automation:
|
|
180
|
+
|
|
181
|
+
1. **Be specific** about URLs and actions
|
|
182
|
+
2. **Use step-by-step instructions** for complex workflows
|
|
183
|
+
3. **Specify selectors** when needed (CSS selectors, text content, etc.)
|
|
184
|
+
4. **Ask for verification** when critical (screenshots, text content)
|
|
185
|
+
|
|
186
|
+
You can also add browser automation guidelines to your `AGENTS.md` file:
|
|
187
|
+
|
|
188
|
+
```markdown
|
|
189
|
+
## Browser Automation
|
|
190
|
+
|
|
191
|
+
When performing browser automation tasks:
|
|
192
|
+
- Always confirm the page has loaded before interacting
|
|
193
|
+
- Use descriptive selectors (prefer text content over CSS selectors)
|
|
194
|
+
- Take screenshots when verification is needed
|
|
195
|
+
- Handle errors gracefully (page not found, element not visible, etc.)
|
|
196
|
+
- Close tabs when the task is complete
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## Plugin Features
|
|
200
|
+
|
|
201
|
+
### Automatic Browser Tool Detection
|
|
202
|
+
|
|
203
|
+
The plugin automatically detects when Browser MCP tools are being used and logs the activity.
|
|
204
|
+
|
|
205
|
+
### Session Context Preservation
|
|
206
|
+
|
|
207
|
+
During session compaction, the plugin preserves browser automation context, ensuring the AI remembers:
|
|
208
|
+
- Browser interactions that occurred
|
|
209
|
+
- Current browser state considerations
|
|
210
|
+
- Need to verify page state before assumptions
|
|
211
|
+
|
|
212
|
+
### Tool Execution Hooks
|
|
213
|
+
|
|
214
|
+
The plugin hooks into tool execution to:
|
|
215
|
+
- Log browser automation activities
|
|
216
|
+
- Monitor tool arguments and results
|
|
217
|
+
- Enable custom post-processing of browser actions
|
|
218
|
+
|
|
219
|
+
## Troubleshooting
|
|
220
|
+
|
|
221
|
+
### Browser MCP Not Working
|
|
222
|
+
|
|
223
|
+
1. **Check extension is installed**: Open your browser and verify the Browser MCP extension is installed and enabled
|
|
224
|
+
2. **Verify MCP server config**: Ensure your `opencode.json` has the correct MCP configuration
|
|
225
|
+
3. **Check Node.js**: Ensure Node.js is installed: `node --version`
|
|
226
|
+
4. **Test MCP connection**: Restart OpenCode after adding the MCP configuration
|
|
227
|
+
|
|
228
|
+
### Plugin Not Loading
|
|
229
|
+
|
|
230
|
+
1. **Check file location**: Ensure the plugin file is in the correct directory
|
|
231
|
+
2. **Check file name**: Plugin files should end in `.ts` or `.js`
|
|
232
|
+
3. **Check syntax**: Ensure the TypeScript/JavaScript syntax is valid
|
|
233
|
+
4. **Check logs**: Look for plugin initialization messages in OpenCode output
|
|
234
|
+
|
|
235
|
+
### Tools Not Available
|
|
236
|
+
|
|
237
|
+
1. **Check MCP server status**: Ensure the Browser MCP server started successfully
|
|
238
|
+
2. **Check tool configuration**: Verify tools aren't disabled in your config
|
|
239
|
+
3. **Restart OpenCode**: Try restarting OpenCode after configuration changes
|
|
240
|
+
|
|
241
|
+
### Debug Mode
|
|
242
|
+
|
|
243
|
+
Enable debug logging by modifying the plugin or checking OpenCode logs:
|
|
244
|
+
|
|
245
|
+
```bash
|
|
246
|
+
# Check OpenCode logs
|
|
247
|
+
opencode --verbose
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## Development
|
|
251
|
+
|
|
252
|
+
### Building from Source
|
|
253
|
+
|
|
254
|
+
If you want to modify the plugin:
|
|
255
|
+
|
|
256
|
+
1. Clone the repository
|
|
257
|
+
2. Make your changes to `index.ts`
|
|
258
|
+
3. Test locally by copying to your OpenCode plugin directory
|
|
259
|
+
4. Submit a PR if you'd like to contribute!
|
|
260
|
+
|
|
261
|
+
### Plugin Architecture
|
|
262
|
+
|
|
263
|
+
The plugin uses OpenCode's plugin system hooks:
|
|
264
|
+
|
|
265
|
+
- `session.created`: Initialize session-specific state
|
|
266
|
+
- `tool.execute.before`: Pre-process browser tool calls
|
|
267
|
+
- `tool.execute.after`: Post-process browser tool results
|
|
268
|
+
- `experimental.session.compacting`: Preserve browser context
|
|
269
|
+
- `event`: Handle OpenCode events
|
|
270
|
+
|
|
271
|
+
## Contributing
|
|
272
|
+
|
|
273
|
+
Contributions are welcome! Please:
|
|
274
|
+
|
|
275
|
+
1. Fork the repository
|
|
276
|
+
2. Create a feature branch
|
|
277
|
+
3. Make your changes
|
|
278
|
+
4. Submit a pull request
|
|
279
|
+
|
|
280
|
+
## Resources
|
|
281
|
+
|
|
282
|
+
- [Browser MCP Documentation](https://docs.browsermcp.io/)
|
|
283
|
+
- [OpenCode Documentation](https://opencode.ai/docs/)
|
|
284
|
+
- [OpenCode Plugin Guide](https://opencode.ai/docs/plugins/)
|
|
285
|
+
- [MCP Servers in OpenCode](https://opencode.ai/docs/mcp-servers/)
|
|
286
|
+
|
|
287
|
+
## License
|
|
288
|
+
|
|
289
|
+
MIT License - See LICENSE file for details
|
|
290
|
+
|
|
291
|
+
## Support
|
|
292
|
+
|
|
293
|
+
For issues and questions:
|
|
294
|
+
|
|
295
|
+
- Browser MCP issues: [Browser MCP GitHub](https://github.com/browsermcp/browser-mcp)
|
|
296
|
+
- OpenCode issues: [OpenCode GitHub](https://github.com/anomalyco/opencode)
|
|
297
|
+
- Plugin issues: Open an issue in this repository
|
|
298
|
+
|
|
299
|
+
## Changelog
|
|
300
|
+
|
|
301
|
+
See [CHANGELOG.md](CHANGELOG.md) for a detailed list of changes in each version.
|
|
302
|
+
|
package/index.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { Plugin } from "@opencode-ai/plugin"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* OpenCode Plugin for Browser MCP Integration
|
|
5
|
+
*
|
|
6
|
+
* This plugin integrates Browser MCP (https://browsermcp.io) to enable browser automation
|
|
7
|
+
* capabilities within OpenCode. It allows the AI to control a browser, navigate websites,
|
|
8
|
+
* fill forms, click elements, and perform other browser automation tasks.
|
|
9
|
+
*
|
|
10
|
+
* Setup:
|
|
11
|
+
* 1. Install the Browser MCP extension in your browser
|
|
12
|
+
* 2. Configure the MCP server in your opencode.json (see README.md)
|
|
13
|
+
* 3. Enable this plugin
|
|
14
|
+
*
|
|
15
|
+
* The plugin automatically detects browser-related requests and provides context hints
|
|
16
|
+
* to help the AI use Browser MCP tools effectively.
|
|
17
|
+
*/
|
|
18
|
+
export const BrowserMCPPlugin: Plugin = async (ctx) => {
|
|
19
|
+
const { client, project } = ctx
|
|
20
|
+
|
|
21
|
+
// Track if we've informed the user about browser automation capabilities
|
|
22
|
+
let browserCapabilitiesShown = false
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
/**
|
|
26
|
+
* Hook into session creation to inject browser automation context
|
|
27
|
+
*/
|
|
28
|
+
"session.created": async ({ session }) => {
|
|
29
|
+
// Session created - ready for browser automation
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Hook before tool execution to provide browser-specific guidance
|
|
34
|
+
*/
|
|
35
|
+
"tool.execute.before": async (input, output) => {
|
|
36
|
+
// Detect if a browser-related MCP tool is being called
|
|
37
|
+
if (input.tool.startsWith("browsermcp_")) {
|
|
38
|
+
// Browser tool execution starting
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Hook after tool execution to handle browser automation results
|
|
44
|
+
*/
|
|
45
|
+
"tool.execute.after": async (input, output) => {
|
|
46
|
+
if (input.tool.startsWith("browsermcp_")) {
|
|
47
|
+
// You can add custom post-processing here, such as:
|
|
48
|
+
// - Logging results to a file
|
|
49
|
+
// - Sending notifications
|
|
50
|
+
// - Updating external systems
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Hook to add browser automation context during session compaction
|
|
56
|
+
* This helps preserve browser-related context across long sessions
|
|
57
|
+
*/
|
|
58
|
+
"experimental.session.compacting": async (input, output) => {
|
|
59
|
+
// Check if any browser automation was performed in this session
|
|
60
|
+
// Guard against input.messages being undefined
|
|
61
|
+
const hasBrowserTools = input.messages?.some(msg =>
|
|
62
|
+
msg.content?.some(part =>
|
|
63
|
+
part.type === "tool_use" && part.name?.startsWith("browsermcp_")
|
|
64
|
+
)
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
if (hasBrowserTools) {
|
|
68
|
+
output.context.push(`## Browser Automation Context
|
|
69
|
+
|
|
70
|
+
The Browser MCP integration has been used in this session. When resuming:
|
|
71
|
+
- Browser state may have changed since last interaction
|
|
72
|
+
- Browser tabs opened during automation may still be active
|
|
73
|
+
- Consider checking current browser state before making assumptions
|
|
74
|
+
- Use Browser MCP tools to verify page state when needed`)
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Hook into TUI toast notifications to show browser-specific tips
|
|
80
|
+
*/
|
|
81
|
+
"tui.toast.show": async (input, output) => {
|
|
82
|
+
// You could customize toast messages related to browser automation here
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Event handler for various OpenCode events
|
|
87
|
+
*/
|
|
88
|
+
event: async ({ event }) => {
|
|
89
|
+
// Handle session idle - could be used to close browser tabs
|
|
90
|
+
if (event.type === "session.idle") {
|
|
91
|
+
// Session is idle
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Handle session errors - could help debug browser automation issues
|
|
95
|
+
if (event.type === "session.error") {
|
|
96
|
+
// Session error occurred
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Default export for the plugin
|
|
104
|
+
*/
|
|
105
|
+
export default BrowserMCPPlugin
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "opencode-browser-mcp",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "OpenCode plugin that integrates Browser MCP for browser automation",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.ts",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"opencode",
|
|
9
|
+
"opencode-plugin",
|
|
10
|
+
"plugin",
|
|
11
|
+
"browser",
|
|
12
|
+
"browser-automation",
|
|
13
|
+
"mcp",
|
|
14
|
+
"model-context-protocol",
|
|
15
|
+
"automation",
|
|
16
|
+
"browser-control",
|
|
17
|
+
"web-automation",
|
|
18
|
+
"puppeteer-alternative"
|
|
19
|
+
],
|
|
20
|
+
"author": "",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"@opencode-ai/plugin": "*"
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/michaljach/opencode-browser.git"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://github.com/michaljach/opencode-browser#readme",
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/michaljach/opencode-browser/issues"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"index.ts",
|
|
35
|
+
"README.md",
|
|
36
|
+
"LICENSE"
|
|
37
|
+
],
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=18.0.0"
|
|
40
|
+
}
|
|
41
|
+
}
|