electron-dev-bridge 0.1.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/LICENSE +21 -0
- package/README.md +555 -0
- package/dist/cdp-tools/dom-query.d.ts +2 -0
- package/dist/cdp-tools/dom-query.js +307 -0
- package/dist/cdp-tools/helpers.d.ts +17 -0
- package/dist/cdp-tools/helpers.js +48 -0
- package/dist/cdp-tools/index.d.ts +5 -0
- package/dist/cdp-tools/index.js +26 -0
- package/dist/cdp-tools/interaction.d.ts +2 -0
- package/dist/cdp-tools/interaction.js +195 -0
- package/dist/cdp-tools/lifecycle.d.ts +2 -0
- package/dist/cdp-tools/lifecycle.js +78 -0
- package/dist/cdp-tools/navigation.d.ts +2 -0
- package/dist/cdp-tools/navigation.js +128 -0
- package/dist/cdp-tools/state.d.ts +2 -0
- package/dist/cdp-tools/state.js +109 -0
- package/dist/cdp-tools/types.d.ts +22 -0
- package/dist/cdp-tools/types.js +1 -0
- package/dist/cdp-tools/visual.d.ts +2 -0
- package/dist/cdp-tools/visual.js +130 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +50 -0
- package/dist/cli/init.d.ts +1 -0
- package/dist/cli/init.js +146 -0
- package/dist/cli/register.d.ts +1 -0
- package/dist/cli/register.js +40 -0
- package/dist/cli/serve.d.ts +1 -0
- package/dist/cli/serve.js +34 -0
- package/dist/cli/validate.d.ts +1 -0
- package/dist/cli/validate.js +65 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +3 -0
- package/dist/scanner/ipc-scanner.d.ts +6 -0
- package/dist/scanner/ipc-scanner.js +14 -0
- package/dist/scanner/schema-scanner.d.ts +6 -0
- package/dist/scanner/schema-scanner.js +14 -0
- package/dist/server/cdp-bridge.d.ts +12 -0
- package/dist/server/cdp-bridge.js +72 -0
- package/dist/server/mcp-server.d.ts +2 -0
- package/dist/server/mcp-server.js +126 -0
- package/dist/server/resource-builder.d.ts +9 -0
- package/dist/server/resource-builder.js +15 -0
- package/dist/server/tool-builder.d.ts +9 -0
- package/dist/server/tool-builder.js +39 -0
- package/dist/utils/load-config.d.ts +5 -0
- package/dist/utils/load-config.js +17 -0
- package/package.json +75 -0
- package/skills/electron-app-dev/SKILL.md +140 -0
- package/skills/electron-debugging/SKILL.md +203 -0
- package/skills/electron-e2e-testing/SKILL.md +181 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 electron-dev-bridge contributors
|
|
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,555 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
<br>
|
|
4
|
+
|
|
5
|
+
# electron-dev-bridge
|
|
6
|
+
|
|
7
|
+
<br>
|
|
8
|
+
|
|
9
|
+
**Turn your Electron app's IPC handlers into MCP tools for Claude Code**
|
|
10
|
+
|
|
11
|
+
<br>
|
|
12
|
+
|
|
13
|
+
[](https://www.typescriptlang.org/)
|
|
14
|
+
[](https://nodejs.org/)
|
|
15
|
+
[](./src/cdp-tools)
|
|
16
|
+
[](./LICENSE)
|
|
17
|
+
|
|
18
|
+
<br>
|
|
19
|
+
|
|
20
|
+
*Built for [Claude Code](https://claude.ai/code) — Connects Electron apps via [CDP](https://chromedevtools.github.io/devtools-protocol/) and [MCP](https://modelcontextprotocol.io)*
|
|
21
|
+
|
|
22
|
+
<br>
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
<br>
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
## Overview
|
|
31
|
+
|
|
32
|
+
electron-dev-bridge maps your Electron app's `ipcMain.handle()` channels to MCP tools that Claude Code can call directly. It also includes 22 built-in CDP tools for DOM automation, screenshots, and interaction — no IPC handlers required.
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
Your Electron App Claude Code
|
|
36
|
+
↓ ↓
|
|
37
|
+
ipcMain.handle('profiles:query') profiles_query ← MCP tool
|
|
38
|
+
ipcMain.handle('tags:add') tags_add ← MCP tool
|
|
39
|
+
ipcMain.handle('crawl:start') crawl_start ← MCP tool
|
|
40
|
+
↓ ↓
|
|
41
|
+
contextBridge / preload.js ←→ electron-dev-bridge (MCP server)
|
|
42
|
+
↓
|
|
43
|
+
Chrome DevTools Protocol (port 9229)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
<br>
|
|
47
|
+
|
|
48
|
+
## When to Use
|
|
49
|
+
|
|
50
|
+
electron-dev-bridge is ideal when you need:
|
|
51
|
+
|
|
52
|
+
- **Your app's IPC handlers as Claude Code tools** with Zod schema validation
|
|
53
|
+
- **DOM automation** for testing, debugging, or building Electron apps
|
|
54
|
+
- **Screenshot-based QA** with visual comparison
|
|
55
|
+
- **Live app state** exposed as MCP resources Claude can read on demand
|
|
56
|
+
|
|
57
|
+
For generic browser automation without Electron-specific features, a standard Chrome DevTools MCP server works fine.
|
|
58
|
+
|
|
59
|
+
<br>
|
|
60
|
+
|
|
61
|
+
## Capabilities
|
|
62
|
+
|
|
63
|
+
<table>
|
|
64
|
+
<tr>
|
|
65
|
+
<td width="50%" valign="top">
|
|
66
|
+
|
|
67
|
+
### IPC Bridge
|
|
68
|
+
|
|
69
|
+
**Auto-Discovery** — Scans `ipcMain.handle()` calls<br>
|
|
70
|
+
**Zod Schemas** — Typed tool inputs from existing schemas<br>
|
|
71
|
+
**Preload Mapping** — `domain:action` → `window.electronAPI.domain.action`
|
|
72
|
+
|
|
73
|
+
<br>
|
|
74
|
+
</td>
|
|
75
|
+
<td width="50%" valign="top">
|
|
76
|
+
|
|
77
|
+
### CDP Tools (22)
|
|
78
|
+
|
|
79
|
+
**DOM Queries** — Selectors, text search, a11y tree<br>
|
|
80
|
+
**Interaction** — Click, type, key press, select<br>
|
|
81
|
+
**Visual** — Screenshots, diff, highlight
|
|
82
|
+
|
|
83
|
+
<br>
|
|
84
|
+
</td>
|
|
85
|
+
</tr>
|
|
86
|
+
<tr>
|
|
87
|
+
<td width="50%" valign="top">
|
|
88
|
+
|
|
89
|
+
### CLI
|
|
90
|
+
|
|
91
|
+
**`init`** — Scaffold config from source code<br>
|
|
92
|
+
**`register`** — One-command Claude Code setup<br>
|
|
93
|
+
**`validate`** — Check config without starting server
|
|
94
|
+
|
|
95
|
+
<br>
|
|
96
|
+
</td>
|
|
97
|
+
<td width="50%" valign="top">
|
|
98
|
+
|
|
99
|
+
### Skills
|
|
100
|
+
|
|
101
|
+
**3 Sample Skills** — Drop into `.claude/skills/`<br>
|
|
102
|
+
**App Dev** — Tool reference and playbooks<br>
|
|
103
|
+
**E2E Testing** — Test patterns and visual regression<br>
|
|
104
|
+
**Debugging** — Diagnostic flowcharts
|
|
105
|
+
|
|
106
|
+
<br>
|
|
107
|
+
</td>
|
|
108
|
+
</tr>
|
|
109
|
+
</table>
|
|
110
|
+
|
|
111
|
+
<br>
|
|
112
|
+
|
|
113
|
+
## Quick Start
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
# Install in your Electron project
|
|
117
|
+
npm install electron-dev-bridge
|
|
118
|
+
|
|
119
|
+
# Scaffold a config from your source code
|
|
120
|
+
npx electron-mcp init
|
|
121
|
+
|
|
122
|
+
# Review the generated config
|
|
123
|
+
cat electron-mcp.config.ts
|
|
124
|
+
|
|
125
|
+
# Register with Claude Code
|
|
126
|
+
npx electron-mcp register
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Then in Claude Code:
|
|
130
|
+
|
|
131
|
+
```
|
|
132
|
+
# Your IPC handlers are now tools
|
|
133
|
+
profiles_query query="test user"
|
|
134
|
+
tags_add profileId="123" tag="vip"
|
|
135
|
+
|
|
136
|
+
# Plus 22 built-in CDP tools
|
|
137
|
+
electron_screenshot
|
|
138
|
+
electron_click selector="[data-testid='submit']"
|
|
139
|
+
electron_get_accessibility_tree
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
<br>
|
|
143
|
+
|
|
144
|
+
## How It Works
|
|
145
|
+
|
|
146
|
+
```
|
|
147
|
+
┌──────────────────────────────────────────────────────────────────┐
|
|
148
|
+
│ electron-dev-bridge │
|
|
149
|
+
├──────────────────────────────────────────────────────────────────┤
|
|
150
|
+
│ │
|
|
151
|
+
│ 1. CONFIG Define IPC channels as MCP tools │
|
|
152
|
+
│ ↓ (electron-mcp.config.ts) │
|
|
153
|
+
│ │
|
|
154
|
+
│ 2. SCAN Auto-detect ipcMain.handle() + Zod schemas │
|
|
155
|
+
│ ↓ (npx electron-mcp init) │
|
|
156
|
+
│ │
|
|
157
|
+
│ 3. REGISTER Add MCP server to Claude Code │
|
|
158
|
+
│ ↓ (npx electron-mcp register) │
|
|
159
|
+
│ │
|
|
160
|
+
│ 4. SERVE Start MCP server, connect via CDP │
|
|
161
|
+
│ ↓ (npx electron-mcp serve) │
|
|
162
|
+
│ │
|
|
163
|
+
│ 5. BRIDGE Claude calls tool → preload function → IPC │
|
|
164
|
+
│ Results flow back through MCP │
|
|
165
|
+
│ │
|
|
166
|
+
└──────────────────────────────────────────────────────────────────┘
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Your Electron app needs `--remote-debugging-port=9229` enabled. The bridge connects via Chrome DevTools Protocol to evaluate preload functions in the renderer process.
|
|
170
|
+
|
|
171
|
+
<br>
|
|
172
|
+
|
|
173
|
+
## Config File
|
|
174
|
+
|
|
175
|
+
The `init` command generates `electron-mcp.config.ts` by scanning your source for `ipcMain.handle()` calls and Zod schema exports.
|
|
176
|
+
|
|
177
|
+
```ts
|
|
178
|
+
import { defineConfig } from 'electron-dev-bridge'
|
|
179
|
+
import { profileQuerySchema } from './src/main/ipc-schemas'
|
|
180
|
+
|
|
181
|
+
export default defineConfig({
|
|
182
|
+
app: {
|
|
183
|
+
name: 'my-app',
|
|
184
|
+
path: '/path/to/app',
|
|
185
|
+
debugPort: 9229,
|
|
186
|
+
},
|
|
187
|
+
|
|
188
|
+
tools: {
|
|
189
|
+
'profiles:query': {
|
|
190
|
+
description: 'Search and filter profiles with pagination',
|
|
191
|
+
schema: profileQuerySchema,
|
|
192
|
+
returns: 'Array of profile objects',
|
|
193
|
+
},
|
|
194
|
+
'crawl:start': {
|
|
195
|
+
description: 'Start a new crawl job',
|
|
196
|
+
preloadPath: 'window.electronAPI.crawl.startJob',
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
|
|
200
|
+
resources: {
|
|
201
|
+
'crawl:progress': {
|
|
202
|
+
description: 'Live crawl progress',
|
|
203
|
+
uri: 'electron://my-app/crawl/progress',
|
|
204
|
+
pollExpression: 'window.__crawlProgress || { crawled: 0, total: 0 }',
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
|
|
208
|
+
cdpTools: true,
|
|
209
|
+
screenshots: { dir: './screenshots', format: 'png' },
|
|
210
|
+
})
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
<br>
|
|
214
|
+
|
|
215
|
+
## IPC Tool Naming
|
|
216
|
+
|
|
217
|
+
IPC channel names use colon-separated `domain:action` format. The bridge auto-derives tool names and preload paths:
|
|
218
|
+
|
|
219
|
+
| IPC Channel | MCP Tool Name | Preload Path |
|
|
220
|
+
|:------------|:--------------|:-------------|
|
|
221
|
+
| `profiles:query` | `profiles_query` | `window.electronAPI.profiles.query` |
|
|
222
|
+
| `tags:add` | `tags_add` | `window.electronAPI.tags.add` |
|
|
223
|
+
| `crawl:start` | `crawl_start` | `window.electronAPI.crawl.start` |
|
|
224
|
+
|
|
225
|
+
Override the preload path when the actual method name differs:
|
|
226
|
+
|
|
227
|
+
```ts
|
|
228
|
+
'crawl:start': {
|
|
229
|
+
description: 'Start a crawl job',
|
|
230
|
+
preloadPath: 'window.electronAPI.crawl.startJob',
|
|
231
|
+
}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
<br>
|
|
235
|
+
|
|
236
|
+
## CLI Commands
|
|
237
|
+
|
|
238
|
+
| Command | Description |
|
|
239
|
+
|:--------|:------------|
|
|
240
|
+
| `npx electron-mcp serve [config]` | Start the MCP server (default) |
|
|
241
|
+
| `npx electron-mcp init` | Scan source for IPC handlers and Zod schemas, generate config |
|
|
242
|
+
| `npx electron-mcp register` | Register with Claude Code via `claude mcp add` |
|
|
243
|
+
| `npx electron-mcp validate` | Validate config and report readiness |
|
|
244
|
+
| `npx electron-mcp --version` | Show version |
|
|
245
|
+
|
|
246
|
+
<br>
|
|
247
|
+
|
|
248
|
+
## CDP Tools
|
|
249
|
+
|
|
250
|
+
22 built-in tools for DOM automation. These work on any Electron app — no IPC configuration required.
|
|
251
|
+
|
|
252
|
+
<details>
|
|
253
|
+
<summary><b>Connection (2 tools)</b></summary>
|
|
254
|
+
<br>
|
|
255
|
+
|
|
256
|
+
| Tool | Description |
|
|
257
|
+
|:-----|:------------|
|
|
258
|
+
| `electron_launch` | Launch Electron app with remote debugging and connect via CDP |
|
|
259
|
+
| `electron_connect` | Connect to an already-running Electron app |
|
|
260
|
+
|
|
261
|
+
</details>
|
|
262
|
+
|
|
263
|
+
<details>
|
|
264
|
+
<summary><b>DOM Queries (5 tools)</b></summary>
|
|
265
|
+
<br>
|
|
266
|
+
|
|
267
|
+
| Tool | Description |
|
|
268
|
+
|:-----|:------------|
|
|
269
|
+
| `electron_query_selector` | Find one element by CSS selector |
|
|
270
|
+
| `electron_query_selector_all` | Find all matching elements (up to 50) |
|
|
271
|
+
| `electron_find_by_text` | Find elements containing text via XPath |
|
|
272
|
+
| `electron_find_by_role` | Find elements by ARIA role (explicit or implicit) |
|
|
273
|
+
| `electron_get_accessibility_tree` | Structured a11y tree with roles, names, and states |
|
|
274
|
+
|
|
275
|
+
</details>
|
|
276
|
+
|
|
277
|
+
<details>
|
|
278
|
+
<summary><b>Interaction (4 tools)</b></summary>
|
|
279
|
+
<br>
|
|
280
|
+
|
|
281
|
+
| Tool | Description |
|
|
282
|
+
|:-----|:------------|
|
|
283
|
+
| `electron_click` | Click element by selector or x/y coordinates |
|
|
284
|
+
| `electron_type_text` | Type text into focused or targeted element |
|
|
285
|
+
| `electron_press_key` | Press special key (Enter, Tab, Escape, arrows, etc.) |
|
|
286
|
+
| `electron_select_option` | Select option in `<select>` by value or visible text |
|
|
287
|
+
|
|
288
|
+
</details>
|
|
289
|
+
|
|
290
|
+
<details>
|
|
291
|
+
<summary><b>State Reading (5 tools)</b></summary>
|
|
292
|
+
<br>
|
|
293
|
+
|
|
294
|
+
| Tool | Description |
|
|
295
|
+
|:-----|:------------|
|
|
296
|
+
| `electron_get_text` | Get innerText of an element |
|
|
297
|
+
| `electron_get_value` | Get value of input/textarea/select |
|
|
298
|
+
| `electron_get_attribute` | Get a specific attribute from an element |
|
|
299
|
+
| `electron_get_bounding_box` | Get position and dimensions (x, y, width, height) |
|
|
300
|
+
| `electron_get_url` | Get the current page URL |
|
|
301
|
+
|
|
302
|
+
</details>
|
|
303
|
+
|
|
304
|
+
<details>
|
|
305
|
+
<summary><b>Navigation & Viewport (3 tools)</b></summary>
|
|
306
|
+
<br>
|
|
307
|
+
|
|
308
|
+
| Tool | Description |
|
|
309
|
+
|:-----|:------------|
|
|
310
|
+
| `electron_wait_for_selector` | Poll for element to appear (default timeout: 5s) |
|
|
311
|
+
| `electron_set_viewport` | Override viewport metrics for responsive testing |
|
|
312
|
+
| `electron_scroll` | Scroll page or element in a direction |
|
|
313
|
+
|
|
314
|
+
</details>
|
|
315
|
+
|
|
316
|
+
<details>
|
|
317
|
+
<summary><b>Screenshots & Visual (3 tools)</b></summary>
|
|
318
|
+
<br>
|
|
319
|
+
|
|
320
|
+
| Tool | Description |
|
|
321
|
+
|:-----|:------------|
|
|
322
|
+
| `electron_screenshot` | Capture full page or element screenshot |
|
|
323
|
+
| `electron_compare_screenshots` | Byte-level diff of two screenshots (returns diff %) |
|
|
324
|
+
| `electron_highlight_element` | Outline element in red for 3 seconds |
|
|
325
|
+
|
|
326
|
+
</details>
|
|
327
|
+
|
|
328
|
+
<br>
|
|
329
|
+
|
|
330
|
+
## Config Reference
|
|
331
|
+
|
|
332
|
+
<details>
|
|
333
|
+
<summary><b>app</b></summary>
|
|
334
|
+
<br>
|
|
335
|
+
|
|
336
|
+
| Field | Type | Default | Description |
|
|
337
|
+
|:------|:-----|:--------|:------------|
|
|
338
|
+
| `name` | `string` | *required* | MCP server name, shown in Claude Code |
|
|
339
|
+
| `path` | `string` | — | Electron app directory (for `electron_launch`) |
|
|
340
|
+
| `debugPort` | `number` | `9229` | CDP remote debugging port |
|
|
341
|
+
| `electronBin` | `string` | `{path}/node_modules/.bin/electron` | Path to Electron binary |
|
|
342
|
+
|
|
343
|
+
</details>
|
|
344
|
+
|
|
345
|
+
<details>
|
|
346
|
+
<summary><b>tools</b></summary>
|
|
347
|
+
<br>
|
|
348
|
+
|
|
349
|
+
Each key is an IPC channel name in `domain:action` format.
|
|
350
|
+
|
|
351
|
+
| Field | Type | Default | Description |
|
|
352
|
+
|:------|:-----|:--------|:------------|
|
|
353
|
+
| `description` | `string` | *required* | Tool description shown to Claude |
|
|
354
|
+
| `schema` | `ZodType` | — | Zod schema; converted to JSON Schema for input validation |
|
|
355
|
+
| `preloadPath` | `string` | auto-derived | Override the renderer-side function path |
|
|
356
|
+
| `returns` | `string` | — | Appended to description as `Returns: {value}` |
|
|
357
|
+
|
|
358
|
+
</details>
|
|
359
|
+
|
|
360
|
+
<details>
|
|
361
|
+
<summary><b>resources</b></summary>
|
|
362
|
+
<br>
|
|
363
|
+
|
|
364
|
+
Expose live app state that Claude can read on demand.
|
|
365
|
+
|
|
366
|
+
| Field | Type | Description |
|
|
367
|
+
|:------|:-----|:------------|
|
|
368
|
+
| `description` | `string` | Resource description |
|
|
369
|
+
| `uri` | `string` | Unique resource URI (e.g. `electron://app/domain/resource`) |
|
|
370
|
+
| `pollExpression` | `string` | JavaScript evaluated in the renderer to fetch current data |
|
|
371
|
+
|
|
372
|
+
</details>
|
|
373
|
+
|
|
374
|
+
<details>
|
|
375
|
+
<summary><b>cdpTools</b></summary>
|
|
376
|
+
<br>
|
|
377
|
+
|
|
378
|
+
| Value | Behavior |
|
|
379
|
+
|:------|:---------|
|
|
380
|
+
| `true` | Enable all 22 CDP tools |
|
|
381
|
+
| `false` / omitted | CDP tools disabled |
|
|
382
|
+
| `string[]` | Enable only the listed tool names |
|
|
383
|
+
|
|
384
|
+
</details>
|
|
385
|
+
|
|
386
|
+
<details>
|
|
387
|
+
<summary><b>screenshots</b></summary>
|
|
388
|
+
<br>
|
|
389
|
+
|
|
390
|
+
| Field | Type | Default | Description |
|
|
391
|
+
|:------|:-----|:--------|:------------|
|
|
392
|
+
| `dir` | `string` | `.screenshots` | Output directory |
|
|
393
|
+
| `format` | `'png' \| 'jpeg'` | `'png'` | Image format |
|
|
394
|
+
|
|
395
|
+
</details>
|
|
396
|
+
|
|
397
|
+
<br>
|
|
398
|
+
|
|
399
|
+
## Preload Convention
|
|
400
|
+
|
|
401
|
+
The bridge assumes your app uses the `contextBridge` pattern:
|
|
402
|
+
|
|
403
|
+
```js
|
|
404
|
+
// preload.js
|
|
405
|
+
const { contextBridge, ipcRenderer } = require('electron')
|
|
406
|
+
|
|
407
|
+
contextBridge.exposeInMainWorld('electronAPI', {
|
|
408
|
+
profiles: {
|
|
409
|
+
query: (args) => ipcRenderer.invoke('profiles:query', args),
|
|
410
|
+
get: (id) => ipcRenderer.invoke('profiles:get', id),
|
|
411
|
+
},
|
|
412
|
+
tags: {
|
|
413
|
+
add: (args) => ipcRenderer.invoke('tags:add', args),
|
|
414
|
+
},
|
|
415
|
+
})
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
The channel `profiles:query` maps to `window.electronAPI.profiles.query`. Override with `preloadPath` when the naming differs.
|
|
419
|
+
|
|
420
|
+
<br>
|
|
421
|
+
|
|
422
|
+
## Zod Schema Integration
|
|
423
|
+
|
|
424
|
+
Import your existing Zod schemas for typed tool inputs:
|
|
425
|
+
|
|
426
|
+
```ts
|
|
427
|
+
import { defineConfig } from 'electron-dev-bridge'
|
|
428
|
+
import { profileQuerySchema, crawlJobSchema } from './src/main/ipc-schemas'
|
|
429
|
+
|
|
430
|
+
export default defineConfig({
|
|
431
|
+
app: { name: 'my-app' },
|
|
432
|
+
tools: {
|
|
433
|
+
'profiles:query': {
|
|
434
|
+
description: 'Search profiles',
|
|
435
|
+
schema: profileQuerySchema,
|
|
436
|
+
},
|
|
437
|
+
'crawl:start': {
|
|
438
|
+
description: 'Start a crawl',
|
|
439
|
+
schema: crawlJobSchema,
|
|
440
|
+
preloadPath: 'window.electronAPI.crawl.startJob',
|
|
441
|
+
},
|
|
442
|
+
},
|
|
443
|
+
})
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
Zod schemas are converted to JSON Schema via `zod-to-json-schema`. Zod is an optional peer dependency.
|
|
447
|
+
|
|
448
|
+
<br>
|
|
449
|
+
|
|
450
|
+
## Sample Skills
|
|
451
|
+
|
|
452
|
+
Three [Claude Code skills](https://docs.anthropic.com/en/docs/claude-code/skills) that teach Claude how to use the bridge effectively.
|
|
453
|
+
|
|
454
|
+
```bash
|
|
455
|
+
# Copy all sample skills
|
|
456
|
+
cp -r node_modules/electron-dev-bridge/skills/* .claude/skills/
|
|
457
|
+
|
|
458
|
+
# Or copy individual skills
|
|
459
|
+
cp -r node_modules/electron-dev-bridge/skills/electron-app-dev .claude/skills/
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
| Skill | Triggers On | Covers |
|
|
463
|
+
|:------|:------------|:-------|
|
|
464
|
+
| `electron-app-dev` | Electron app, desktop app, UI automation, DOM, IPC | Tool reference, selector strategy, build & verify playbooks |
|
|
465
|
+
| `electron-e2e-testing` | Test, e2e, regression, form testing | Test patterns, form automation, visual regression, multi-page flows |
|
|
466
|
+
| `electron-debugging` | Debug, bug, broken, not working, element not found | Diagnostic flowcharts, connection troubleshooting, error patterns |
|
|
467
|
+
|
|
468
|
+
Claude Code automatically loads the relevant skill when prompts match trigger keywords.
|
|
469
|
+
|
|
470
|
+
<br>
|
|
471
|
+
|
|
472
|
+
## Troubleshooting
|
|
473
|
+
|
|
474
|
+
| Problem | Fix |
|
|
475
|
+
|:--------|:----|
|
|
476
|
+
| Cannot connect to app | Ensure app runs with `--remote-debugging-port=9229`. Check `lsof -i :9229`. |
|
|
477
|
+
| Element not found | Use `electron_get_accessibility_tree` to inspect. Check for iframes or shadow DOM. |
|
|
478
|
+
| Blank screenshot | Add `electron_wait_for_selector` before capturing. |
|
|
479
|
+
| Stale connection | App reloaded or crashed. Use `electron_connect` to reconnect. |
|
|
480
|
+
| Config not found | Run `npx electron-mcp init` or create `electron-mcp.config.ts` manually. |
|
|
481
|
+
| Tool returns undefined | Check preload path matches `contextBridge` exposure. Run `npx electron-mcp validate`. |
|
|
482
|
+
|
|
483
|
+
<br>
|
|
484
|
+
|
|
485
|
+
## Architecture
|
|
486
|
+
|
|
487
|
+
```
|
|
488
|
+
src/
|
|
489
|
+
├── cdp-tools/ # 22 CDP tool implementations
|
|
490
|
+
│ ├── lifecycle.ts # electron_launch, electron_connect
|
|
491
|
+
│ ├── dom-query.ts # query_selector, find_by_text, a11y_tree
|
|
492
|
+
│ ├── interaction.ts # click, type_text, press_key, select_option
|
|
493
|
+
│ ├── state.ts # get_text, get_value, get_attribute, get_url
|
|
494
|
+
│ ├── navigation.ts # wait_for_selector, set_viewport, scroll
|
|
495
|
+
│ └── visual.ts # screenshot, compare_screenshots, highlight
|
|
496
|
+
├── server/ # MCP server runtime
|
|
497
|
+
│ ├── mcp-server.ts # Server setup, tool/resource dispatch
|
|
498
|
+
│ ├── cdp-bridge.ts # CDP connection management
|
|
499
|
+
│ ├── tool-builder.ts # IPC channel → MCP tool conversion
|
|
500
|
+
│ └── resource-builder.ts # Config resources → MCP resources
|
|
501
|
+
├── cli/ # CLI commands
|
|
502
|
+
│ ├── index.ts # Entry point (serve, init, register, validate)
|
|
503
|
+
│ ├── serve.ts # Load config, start server
|
|
504
|
+
│ ├── init.ts # Scan source, generate config
|
|
505
|
+
│ ├── register.ts # claude mcp add
|
|
506
|
+
│ └── validate.ts # Config validation
|
|
507
|
+
├── scanner/ # Source code scanners
|
|
508
|
+
│ ├── ipc-scanner.ts # Find ipcMain.handle() calls
|
|
509
|
+
│ └── schema-scanner.ts # Find Zod schema exports
|
|
510
|
+
└── index.ts # Public API: defineConfig, types
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
<br>
|
|
514
|
+
|
|
515
|
+
## Development
|
|
516
|
+
|
|
517
|
+
```bash
|
|
518
|
+
# Install dependencies
|
|
519
|
+
npm install
|
|
520
|
+
|
|
521
|
+
# Build
|
|
522
|
+
npm run build
|
|
523
|
+
|
|
524
|
+
# Run tests
|
|
525
|
+
npm test
|
|
526
|
+
|
|
527
|
+
# Type check
|
|
528
|
+
npm run lint
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
<br>
|
|
532
|
+
|
|
533
|
+
## References
|
|
534
|
+
|
|
535
|
+
| | |
|
|
536
|
+
|:--|:--|
|
|
537
|
+
| Claude Code | [claude.ai/code](https://claude.ai/code) |
|
|
538
|
+
| MCP Specification | [modelcontextprotocol.io](https://modelcontextprotocol.io) |
|
|
539
|
+
| MCP SDK | [github.com/modelcontextprotocol/typescript-sdk](https://github.com/modelcontextprotocol/typescript-sdk) |
|
|
540
|
+
| Chrome DevTools Protocol | [chromedevtools.github.io/devtools-protocol](https://chromedevtools.github.io/devtools-protocol/) |
|
|
541
|
+
| Electron | [electronjs.org](https://www.electronjs.org/) |
|
|
542
|
+
|
|
543
|
+
<br>
|
|
544
|
+
|
|
545
|
+
---
|
|
546
|
+
|
|
547
|
+
<div align="center">
|
|
548
|
+
|
|
549
|
+
<br>
|
|
550
|
+
|
|
551
|
+
MIT License
|
|
552
|
+
|
|
553
|
+
<br>
|
|
554
|
+
|
|
555
|
+
</div>
|