Skip to content

Commit 4932ea8

Browse files
committed
feat: Bundle opera-devtools-mcp as a dependency.
Resolve the MCP binary via Node module resolution so users no longer need to install opera-devtools-mcp separately. Falls back to PATH if the bundled package isn't resolvable, and still honors OPERA_CLI_MCP_BIN.
1 parent ead562d commit 4932ea8

4 files changed

Lines changed: 50 additions & 19 deletions

File tree

README.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,18 @@ snapshot:
3030

3131
## Install
3232

33-
Prerequisites: **Node.js >= 20**, **Opera** browser ([Opera Neon](https://www.operaneon.com) recommended for AI features), **[opera-devtools-mcp](https://github.com/operasoftware/opera-devtools-mcp)**.
33+
Prerequisites: **Node.js >= 20**, **Opera** browser ([Opera Neon](https://www.operaneon.com) recommended for AI features).
3434

3535
### From source
3636

37-
**1. Build and link `opera-devtools-mcp`:**
38-
39-
```sh
40-
git clone https://github.com/operasoftware/opera-devtools-mcp
41-
cd opera-devtools-mcp
42-
npm install && npm run build && npm link
43-
```
44-
45-
**2. Build and link `opera-browser-cli`:**
37+
**Build and link `opera-browser-cli`:**
4638

4739
```sh
4840
# in this repo
4941
npm install && npm run build && npm link
5042
```
5143

52-
**3. Run first-time setup:**
44+
**Run first-time setup:**
5345

5446
```sh
5547
opera-browser-cli setup
@@ -244,7 +236,7 @@ session is active or the no-session status/help block when one is not.
244236
| Variable | Default | Purpose |
245237
| --- | --- | --- |
246238
| `OPERA_CLI_PORT` | `9224` | Bridge server port |
247-
| `OPERA_CLI_MCP_BIN` | `opera-devtools-mcp` | MCP server binary |
239+
| `OPERA_CLI_MCP_BIN` | _(bundled `opera-devtools-mcp`)_ | Override the MCP server binary |
248240
| `OPERA_CLI_EXECUTABLE_PATH` | _(system Chrome)_ | Custom browser binary |
249241
| `OPERA_CLI_BROWSER_URL` || Connect to an existing browser instance instead of launching one |
250242
| `OPERA_CLI_USER_DATA_DIR` || Persistent Chrome profile directory (skips isolated mode) |

package-lock.json

Lines changed: 18 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
"dependencies": {
4444
"@modelcontextprotocol/sdk": "^1.12.1",
4545
"@toon-format/toon": "^2.1.0",
46-
"axi-sdk-js": "^0.1.4"
46+
"axi-sdk-js": "^0.1.4",
47+
"opera-devtools-mcp": "^0.1.1"
4748
},
4849
"devDependencies": {
4950
"@types/node": "^22.0.0",

src/bridge.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import {
2323
type ServerResponse,
2424
} from "node:http";
2525
import { existsSync, mkdirSync, unlinkSync, writeFileSync } from "node:fs";
26-
import { join, resolve } from "node:path";
26+
import { createRequire } from "node:module";
27+
import { dirname, join, resolve } from "node:path";
2728
import { homedir } from "node:os";
2829

2930
const DEFAULT_PORT = Number.parseInt(
@@ -343,8 +344,31 @@ export function buildTransportArgs(): string[] {
343344
return args;
344345
}
345346

347+
function resolveOperaMcpBin(): string {
348+
if (process.env.OPERA_CLI_MCP_BIN) return process.env.OPERA_CLI_MCP_BIN;
349+
try {
350+
const require = createRequire(import.meta.url);
351+
const pkgPath = require.resolve("opera-devtools-mcp/package.json");
352+
const pkgDir = dirname(pkgPath);
353+
const pkg = require("opera-devtools-mcp/package.json") as {
354+
bin?: Record<string, string> | string;
355+
};
356+
const binEntry =
357+
typeof pkg.bin === "string"
358+
? pkg.bin
359+
: pkg.bin?.["opera-devtools-mcp"];
360+
if (binEntry) {
361+
const resolved = join(pkgDir, binEntry);
362+
if (existsSync(resolved)) return resolved;
363+
}
364+
} catch {
365+
// Not installed as a dependency — fall back to PATH
366+
}
367+
return "opera-devtools-mcp";
368+
}
369+
346370
function createTransport(): StdioClientTransport {
347-
const bin = process.env.OPERA_CLI_MCP_BIN ?? "opera-devtools-mcp";
371+
const bin = resolveOperaMcpBin();
348372
const args = buildTransportArgs();
349373
if (bin.endsWith(".js")) {
350374
return new StdioClientTransport({

0 commit comments

Comments
 (0)