electron-test-mcp
Enables AI models to test and interact with Electron applications using Playwright, supporting CDP connection and app launch modes.
README
Electron Test MCP
MCP (Model Context Protocol) server for testing Electron applications using Playwright. Enables AI models like Claude to interact with and test your Electron apps.
🚀 Quick Start
# Run directly with npx
npx electron-test-mcp
# Or install globally
npm install -g electron-test-mcp
electron-test-mcp
Features
- Two Connection Modes
- CDP Mode: Connect to a running Electron app via Chrome DevTools Protocol
- Launch Mode: Launch a fresh Electron app instance for testing
- Full Playwright API: screenshot, click, fill, type, hover, press, wait, evaluate, and more
- Accessibility Snapshots: Get the accessibility tree for element discovery
- Main Process Access: Execute code in Electron's main process (launch mode only)
How It Works
User <--> AI Model (Claude) <--> MCP Protocol <--> electron-test-mcp <--> Electron App
- User: "Click the login button and fill in the email field"
- AI Model: Determines which MCP tools to use
- MCP Protocol: Standardized communication
- electron-test-mcp: Executes Playwright commands on the Electron app
- Electron App: Actions are performed in the actual application
Configuration
Claude Desktop / MCP Clients
Add to your MCP configuration file:
{
"mcpServers": {
"electron-test": {
"command": "npx",
"args": ["electron-test-mcp"]
}
}
}
OpenCode
{
"mcp": {
"electron-test": {
"type": "local",
"command": ["npx", "electron-test-mcp"],
"enabled": true
}
}
}
Connection Modes
CDP Mode (Recommended for Development)
Connect to an already running Electron app with remote debugging enabled:
# Start your Electron app with debugging port
electron your-app --remote-debugging-port=9222
# Or with electron-vite
electron-vite dev -- --remote-debugging-port=9222
Then use the connect tool:
connect({ port: 9222 })
Advantages:
- Works with your existing dev workflow
- App state preserved between tests
- Hot reload still works
Launch Mode
Launch a fresh Electron app instance:
launch({ appPath: "./out/main/index.js" })
# With headless mode for CI
launch({ appPath: "./out/main/index.js", headless: true })
Advantages:
- Clean state for each test
- Access to main process via
evaluateMain - Can pass custom environment variables
- Supports headless mode for CI/automation
Headless Mode (CI/Automation)
Launch Mode
Pass headless: true to run without a visible window:
launch({ appPath: "./out/main/index.js", headless: true })
CDP Mode
Start your Electron app with headless flags before connecting:
# Option 1: Electron headless flag (Electron 28+)
electron your-app --headless=new --remote-debugging-port=9222
# Option 2: xvfb (Linux) - virtual framebuffer
xvfb-run electron your-app --remote-debugging-port=9222
# Option 3: xvfb with specific display (CI environments)
Xvfb :99 -screen 0 1920x1080x24 &
DISPLAY=:99 electron your-app --remote-debugging-port=9222
Then connect normally:
connect({ port: 9222 })
Available Tools
Connection
| Tool | Description |
|---|---|
connect |
Connect to running app via CDP |
disconnect |
Disconnect from CDP (app keeps running) |
launch |
Launch new Electron app instance |
close |
Close launched app |
Interaction
| Tool | Description |
|---|---|
click |
Click an element |
fill |
Fill text into input (clears first) |
type |
Type text character by character |
hover |
Hover over an element |
press |
Press keyboard key |
drag |
Drag and drop |
selectOption |
Select from dropdown |
Inspection
| Tool | Description |
|---|---|
screenshot |
Take screenshot (returns base64 image) |
snapshot |
Get accessibility tree |
getText |
Get element text content |
getAttribute |
Get element attribute |
isVisible |
Check if element is visible |
count |
Count matching elements |
Advanced
| Tool | Description |
|---|---|
wait |
Wait for element state |
evaluate |
Run JS in renderer process |
evaluateMain |
Run code in main process (launch mode only) |
Selectors
Supports all Playwright selectors:
# CSS selectors
[data-testid="submit-btn"]
.my-class
#my-id
# Text selectors
text=Submit
text="Exact Match"
# Role selectors
role=button[name="Submit"]
# Combining
.form >> text=Submit
Usage Examples
Basic Test Flow
1. connect({ port: 9222 })
2. snapshot() // See the page structure
3. click('[data-testid="login-btn"]')
4. fill('[data-testid="email"]', 'test@example.com')
5. fill('[data-testid="password"]', 'password123')
6. click('text=Sign In')
7. wait({ selector: '[data-testid="dashboard"]' })
8. screenshot()
Main Process Access (Launch Mode)
// Get app version
evaluateMain({
script: "({ app }) => app.getVersion()",
});
// Show dialog
evaluateMain({
script: "({ dialog }) => dialog.showMessageBox({ message: 'Hello!' })",
});
With AI Assistant
You can ask Claude or other AI assistants to test your Electron app:
Connect to my Electron app running on port 9222 and:
1. Take a screenshot of the current state
2. Click the "Settings" button in the sidebar
3. Change the theme to dark mode
4. Verify the theme changed by checking the background color
Tips for Testable Electron Apps
- Add
data-testidattributes to important elements - Enable remote debugging in development:
--remote-debugging-port=9222 - Use semantic HTML for better accessibility snapshots
- Keep selectors stable - prefer
data-testidover classes
Development
# Clone repository
git clone https://github.com/lazy-dinosaur/electron-test-mcp.git
cd electron-test-mcp
# Install dependencies
npm install
# Build
npm run build
# Run locally
node dist/index.js
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
📄 License
Distributed under the MIT License. See LICENSE file for more information.
❤️ Support
If you find this project useful, please consider giving it a ⭐️ on GitHub!
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。