cdp-mcp 0.1.2 → 0.2.0
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/README.md +100 -37
- package/dist/contract.d.ts +11 -0
- package/dist/contract.js +11 -0
- package/dist/contract.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/locator.d.ts +108 -0
- package/dist/locator.js +176 -0
- package/dist/locator.js.map +1 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.js +4 -0
- package/dist/server.js.map +1 -1
- package/dist/session/browser.d.ts +29 -0
- package/dist/session/browser.js +17 -2
- package/dist/session/browser.js.map +1 -1
- package/dist/session/buffers.d.ts +48 -0
- package/dist/session/pause.d.ts +21 -0
- package/dist/session/state.d.ts +53 -0
- package/dist/sourcemap/loader.d.ts +4 -0
- package/dist/sourcemap/normalize.d.ts +2 -0
- package/dist/sourcemap/store.d.ts +57 -0
- package/dist/tools/_locator_runtime.d.ts +31 -0
- package/dist/tools/_locator_runtime.js +243 -0
- package/dist/tools/_locator_runtime.js.map +1 -0
- package/dist/tools/_register.d.ts +2 -0
- package/dist/tools/breakpoints.d.ts +4 -0
- package/dist/tools/console.d.ts +2 -0
- package/dist/tools/dom.d.ts +2 -0
- package/dist/tools/dom.js +3 -221
- package/dist/tools/dom.js.map +1 -1
- package/dist/tools/execution.d.ts +29 -0
- package/dist/tools/forms.d.ts +8 -0
- package/dist/tools/forms.js +256 -0
- package/dist/tools/forms.js.map +1 -0
- package/dist/tools/inspect.d.ts +2 -0
- package/dist/tools/nav.d.ts +2 -0
- package/dist/tools/network.d.ts +2 -0
- package/dist/tools/session.d.ts +2 -0
- package/dist/tools/session.js +1 -1
- package/dist/tools/session.js.map +1 -1
- package/dist/tools/source.d.ts +2 -0
- package/dist/tools/storage.d.ts +2 -0
- package/dist/tools/storage.js +296 -0
- package/dist/tools/storage.js.map +1 -0
- package/dist/util/browser-resolve.d.ts +19 -0
- package/dist/util/errors.d.ts +7 -0
- package/dist/util/format.d.ts +20 -0
- package/dist/util/log.d.ts +6 -0
- package/docs/chromium-sandboxing.md +197 -0
- package/docs/known-chromium-gaps.md +138 -0
- package/docs/launchd-service.md +217 -0
- package/docs/local-l3-e2e-setup.md +199 -0
- package/docs/systemd-service.md +233 -0
- package/package.json +18 -2
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
# Linux: Run as a Persistent Service (systemd)
|
|
2
|
+
|
|
3
|
+
Register `cdp-mcp` as a systemd user service so it starts automatically on login
|
|
4
|
+
and exposes the MCP SSE endpoint on `127.0.0.1:9719`. If you enable lingering,
|
|
5
|
+
the service can also start at boot before an interactive login.
|
|
6
|
+
|
|
7
|
+
Persistent service mode is useful for MCP clients that support SSE because the
|
|
8
|
+
`cdp-mcp` process and its browser/CDP session can survive MCP client restarts or
|
|
9
|
+
reconnects. It does **not** persist state across service-process restarts.
|
|
10
|
+
|
|
11
|
+
> Security note: the local SSE endpoint has no authentication. MCP tools include
|
|
12
|
+
> in-page JavaScript evaluation and filesystem writes via screenshot paths. Only
|
|
13
|
+
> run a persistent service on trusted single-user machines. Be especially careful
|
|
14
|
+
> with `loginctl enable-linger` on shared hosts because it widens the service's
|
|
15
|
+
> exposure window beyond your interactive login session.
|
|
16
|
+
|
|
17
|
+
## Contents
|
|
18
|
+
|
|
19
|
+
- [1. Install the server](#1-install-the-server)
|
|
20
|
+
- [2. Optional: enable lingering](#2-optional-enable-lingering)
|
|
21
|
+
- [3. Create the unit file](#3-create-the-unit-file)
|
|
22
|
+
- [4. Enable and start the service](#4-enable-and-start-the-service)
|
|
23
|
+
- [5. Verify](#5-verify)
|
|
24
|
+
- [6. Configure an MCP client](#6-configure-an-mcp-client)
|
|
25
|
+
- [7. Logs](#7-logs)
|
|
26
|
+
- [8. Stop / uninstall](#8-stop--uninstall)
|
|
27
|
+
- [9. Upgrade](#9-upgrade)
|
|
28
|
+
- [Linux ARM64 / Chromium](#linux-arm64--chromium)
|
|
29
|
+
- [Troubleshooting](#troubleshooting)
|
|
30
|
+
|
|
31
|
+
## 1. Install the server
|
|
32
|
+
|
|
33
|
+
Requires Node.js 20+ and a local Chrome/Chromium browser.
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install -g cdp-mcp
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Verify with `cdp-mcp --help`. The package ships prebuilt `dist/`, so there is no
|
|
40
|
+
build step and no repo checkout needed.
|
|
41
|
+
|
|
42
|
+
If `launch_chrome` cannot find Chrome/Chromium automatically, set `CHROME_PATH`
|
|
43
|
+
when generating the unit file below.
|
|
44
|
+
|
|
45
|
+
## 2. Optional: enable lingering
|
|
46
|
+
|
|
47
|
+
Enable lingering only if you want the user service to start at boot even before
|
|
48
|
+
you log in:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
sudo loginctl enable-linger "$USER"
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
You only need to run this once per machine. Check with:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
loginctl show-user "$USER" --property=Linger
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Skip this step if starting the service during your login session is enough.
|
|
61
|
+
|
|
62
|
+
## 3. Create the unit file
|
|
63
|
+
|
|
64
|
+
Run this from any directory:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
# If you use fnm, nvm, or another Node version manager, set these variables to
|
|
68
|
+
# stable paths before running this snippet. Example:
|
|
69
|
+
# NODE_BIN="$HOME/.local/share/fnm/aliases/default/bin/node"
|
|
70
|
+
# CDP_SCRIPT="$HOME/.local/share/fnm/aliases/default/bin/cdp-mcp"
|
|
71
|
+
NODE_BIN="${NODE_BIN:-$(command -v node)}"
|
|
72
|
+
CDP_SCRIPT="${CDP_SCRIPT:-$(command -v cdp-mcp)}"
|
|
73
|
+
CHROME_PATH="${CHROME_PATH:-}"
|
|
74
|
+
|
|
75
|
+
if [ -z "$NODE_BIN" ]; then
|
|
76
|
+
echo "Error: node not found in PATH. Install Node 20+ first." >&2
|
|
77
|
+
exit 1
|
|
78
|
+
fi
|
|
79
|
+
if [ -z "$CDP_SCRIPT" ]; then
|
|
80
|
+
echo "Error: cdp-mcp not found. Run 'npm install -g cdp-mcp' first." >&2
|
|
81
|
+
exit 1
|
|
82
|
+
fi
|
|
83
|
+
|
|
84
|
+
NODE_DIR="$(dirname "$NODE_BIN")"
|
|
85
|
+
mkdir -p ~/.config/systemd/user
|
|
86
|
+
cat > ~/.config/systemd/user/cdp-mcp.service << EOF
|
|
87
|
+
[Unit]
|
|
88
|
+
Description=cdp-mcp browser MCP server (SSE on port 9719)
|
|
89
|
+
After=network.target
|
|
90
|
+
|
|
91
|
+
[Service]
|
|
92
|
+
Type=simple
|
|
93
|
+
ExecStart="${NODE_BIN}" "${CDP_SCRIPT}" --port 9719
|
|
94
|
+
Restart=on-failure
|
|
95
|
+
RestartSec=5
|
|
96
|
+
Environment="PATH=${NODE_DIR}:/usr/local/bin:/usr/bin:/bin"
|
|
97
|
+
$(if [ -n "$CHROME_PATH" ]; then printf 'Environment="CHROME_PATH=%s"\n' "$CHROME_PATH"; else printf '# Optional: set CHROME_PATH if launch_chrome cannot find Chrome/Chromium.\n# Environment="CHROME_PATH=/path/to/chrome"\n'; fi)
|
|
98
|
+
|
|
99
|
+
[Install]
|
|
100
|
+
WantedBy=default.target
|
|
101
|
+
EOF
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
The unit invokes `node` directly with the `cdp-mcp` script path. That makes the
|
|
105
|
+
`NODE_BIN` override authoritative even when your shell uses a Node version
|
|
106
|
+
manager. The `ExecStart` and `Environment` values are double-quoted so systemd
|
|
107
|
+
treats a path containing spaces as a single token rather than splitting it.
|
|
108
|
+
|
|
109
|
+
## 4. Enable and start the service
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
systemctl --user daemon-reload
|
|
113
|
+
systemctl --user enable --now cdp-mcp.service
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## 5. Verify
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
systemctl --user status cdp-mcp.service
|
|
120
|
+
ss -tlnp | grep 9719
|
|
121
|
+
curl -s --max-time 2 http://127.0.0.1:9719/sse | head -1
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
The `curl` command should print an SSE `event:` line. The stream stays open by
|
|
125
|
+
design. The server also sends periodic SSE keepalive comments by default; tune
|
|
126
|
+
with `CDP_MCP_SSE_KEEPALIVE_MS` only if your MCP client needs a different idle
|
|
127
|
+
interval.
|
|
128
|
+
|
|
129
|
+
## 6. Configure an MCP client
|
|
130
|
+
|
|
131
|
+
Point an SSE-capable MCP client at:
|
|
132
|
+
|
|
133
|
+
```text
|
|
134
|
+
http://127.0.0.1:9719/sse
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
For example, clients that use JSON MCP server config commonly use:
|
|
138
|
+
|
|
139
|
+
```json
|
|
140
|
+
{
|
|
141
|
+
"mcpServers": {
|
|
142
|
+
"cdp-mcp": {
|
|
143
|
+
"type": "sse",
|
|
144
|
+
"url": "http://127.0.0.1:9719/sse"
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
SSE mode is single-client today. Multiple MCP clients connected to the same
|
|
151
|
+
service share one process-global browser/CDP session and can interfere with each
|
|
152
|
+
other. Use one active debugging client per service, or run separate services on
|
|
153
|
+
separate ports.
|
|
154
|
+
|
|
155
|
+
A reconnecting client resumes the prior session. If you want a clean browser
|
|
156
|
+
session after reconnecting, call `close_session` before launching or attaching
|
|
157
|
+
again.
|
|
158
|
+
|
|
159
|
+
## 7. Logs
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
journalctl --user -u cdp-mcp.service -f
|
|
163
|
+
journalctl --user -u cdp-mcp.service -n 100
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## 8. Stop / uninstall
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
systemctl --user stop cdp-mcp.service
|
|
170
|
+
systemctl --user disable cdp-mcp.service
|
|
171
|
+
rm ~/.config/systemd/user/cdp-mcp.service
|
|
172
|
+
systemctl --user daemon-reload
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## 9. Upgrade
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
npm install -g cdp-mcp@latest
|
|
179
|
+
systemctl --user restart cdp-mcp.service
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Restart or reconnect your MCP client after a server upgrade so it reloads tool
|
|
183
|
+
schemas.
|
|
184
|
+
|
|
185
|
+
## Linux ARM64 / Chromium
|
|
186
|
+
|
|
187
|
+
Google does not publish official Chrome builds for Linux ARM64. If your distro's
|
|
188
|
+
Chromium package is unreliable for DevTools Protocol launches, use a
|
|
189
|
+
Playwright-cached Chromium binary and set `CHROME_PATH` when generating the
|
|
190
|
+
unit:
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
# Install Playwright's Chromium (one-time):
|
|
194
|
+
npx playwright install chromium
|
|
195
|
+
|
|
196
|
+
# Set CHROME_PATH to the latest revision before running the unit-file script:
|
|
197
|
+
export CHROME_PATH="$HOME/.cache/ms-playwright/chromium-1223/chrome-linux/chrome"
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Snap Chromium (`/snap/bin/chromium`) can be unreliable for persistent services
|
|
201
|
+
because snap confinement may interfere with `--remote-debugging-port`, headless
|
|
202
|
+
flags, and process lifecycle management. A Playwright-cached Chromium is often
|
|
203
|
+
more predictable for CDP-based debugging sessions. The generated unit's `PATH`
|
|
204
|
+
does not include `/snap/bin`, so if you do use snap Chromium you must set
|
|
205
|
+
`CHROME_PATH=/snap/bin/chromium` explicitly — `launch_chrome` will not
|
|
206
|
+
auto-detect it under the service environment.
|
|
207
|
+
|
|
208
|
+
Playwright upgrades may relocate the binary. After running
|
|
209
|
+
`npx playwright install chromium`, check the new revision directory name (for
|
|
210
|
+
example, `chromium-1223` to `chromium-1250`), update `CHROME_PATH` in the unit
|
|
211
|
+
file, and run:
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
systemctl --user daemon-reload
|
|
215
|
+
systemctl --user restart cdp-mcp.service
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
For Chromium sandbox flags (`--no-sandbox`, AppArmor, snap confinement) and known
|
|
219
|
+
host-OS launch gaps, see [chromium-sandboxing.md](./chromium-sandboxing.md) and
|
|
220
|
+
[known-chromium-gaps.md](./known-chromium-gaps.md).
|
|
221
|
+
|
|
222
|
+
## Troubleshooting
|
|
223
|
+
|
|
224
|
+
| Symptom | Fix |
|
|
225
|
+
|---|---|
|
|
226
|
+
| Service exits immediately | Check `journalctl --user -u cdp-mcp.service -n 100`; usually `cdp-mcp` is not installed, Node is too old, or a version-manager path moved |
|
|
227
|
+
| Port 9719 is already in use | Compare `systemctl --user show -p MainPID --value cdp-mcp.service` with `ss -tlnp \| grep 9719`, then stop the other process or change the port |
|
|
228
|
+
| MCP client rejects the config | Confirm the client supports SSE MCP servers and include both `"type": "sse"` and the `/sse` URL if your client uses JSON config |
|
|
229
|
+
| `launch_chrome` cannot find Chrome | Set `CHROME_PATH` in the unit file and restart the service; on Linux ARM64, try Playwright-cached Chromium (`~/.cache/ms-playwright/chromium-*/chrome-linux/chrome`) |
|
|
230
|
+
| Service not starting after reboot | Enable lingering with `sudo loginctl enable-linger "$USER"` |
|
|
231
|
+
| Node not found after reboot with fnm/nvm | Version-manager shell paths can be ephemeral. Recreate the unit with stable `NODE_BIN` and `CDP_SCRIPT` paths, or install with a system Node |
|
|
232
|
+
| `Failed to connect to bus` over SSH | Run `export XDG_RUNTIME_DIR=/run/user/$(id -u)` before using `systemctl --user` |
|
|
233
|
+
| `already_session` after reconnecting | The prior browser/CDP session is still alive. Resume it, or call `close_session` before starting fresh |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cdp-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Chrome DevTools Protocol MCP server — a TypeScript-aware frontend debugger for AI agents.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Leonard Janke",
|
|
@@ -28,8 +28,24 @@
|
|
|
28
28
|
"cdp-mcp": "dist/index.js"
|
|
29
29
|
},
|
|
30
30
|
"main": "dist/index.js",
|
|
31
|
+
"types": "dist/index.d.ts",
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"import": "./dist/index.js"
|
|
36
|
+
},
|
|
37
|
+
"./contract": {
|
|
38
|
+
"types": "./dist/contract.d.ts",
|
|
39
|
+
"import": "./dist/contract.js"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
31
42
|
"files": [
|
|
32
|
-
"dist"
|
|
43
|
+
"dist",
|
|
44
|
+
"docs/launchd-service.md",
|
|
45
|
+
"docs/systemd-service.md",
|
|
46
|
+
"docs/chromium-sandboxing.md",
|
|
47
|
+
"docs/local-l3-e2e-setup.md",
|
|
48
|
+
"docs/known-chromium-gaps.md"
|
|
33
49
|
],
|
|
34
50
|
"scripts": {
|
|
35
51
|
"build": "tsc -p tsconfig.json",
|