Skip to main content
Glama
Electron Native MCP Server

Electron Native MCP Server

by aj47

Electron Native MCP Server

A powerful Model Context Protocol (MCP) server for debugging and automating native Electron applications on macOS. This server provides comprehensive tools for DOM inspection, UI automation, and global hotkey triggering.

Features

šŸ” DOM Inspection (7 tools)

  • Connect to Electron apps via Chrome DevTools Protocol (CDP)

  • List all debuggable targets (windows, webviews)

  • Query and inspect DOM elements

  • Execute JavaScript in Electron windows

  • Take screenshots of Electron content

šŸ–±ļø UI Automation (9 tools)

  • Control mouse (move, click, double-click, drag)

  • Keyboard input (type text, press keys)

  • Take screenshots of native UI

  • Get screen dimensions and mouse position

  • Full macOS accessibility API integration

āŒØļø Global Hotkeys (4 tools)

  • Trigger custom keyboard shortcuts

  • Activate common macOS hotkeys (Spotlight, Mission Control, etc.)

  • Simulate application-specific shortcuts

  • Send complex key sequences

šŸ” Permission Management (4 tools)

  • Check permission status

  • Request system permissions

  • Get setup instructions

  • Verify all required permissions

Related MCP server: Electron MCP Server

Requirements

  • macOS 12.0 or later

  • Node.js 18.0 or later

  • Electron app running with --inspect flag (for DOM inspection)

Required macOS Permissions

This server requires the following system permissions:

  1. Accessibility - For UI automation and keyboard/mouse control

  2. Screen Recording - For taking screenshots

  3. Input Monitoring - For keyboard and mouse input

Installation

# Run the setup script
./scripts/setup.sh

This will:

  • Check system requirements

  • Install dependencies

  • Build the project

  • Provide configuration instructions

  • Optionally install the example app

Manual Setup

# Install dependencies
npm install

# Build the project
npm run build

Usage

Running the Server

# Development mode (with auto-reload)
npm run dev

# Production mode
npm start

Configuring with Claude Desktop

Add to your Claude Desktop configuration (~/Library/Application Support/Claude/claude_desktop_config.json):

{
  "mcpServers": {
    "electron-native": {
      "command": "node",
      "args": ["/path/to/electron-native-mcp/dist/index.js"]
    }
  }
}

Configuring with Other MCP Clients

The server uses stdio transport and can be integrated with any MCP-compatible client.

Tool Reference

DOM Inspection Tools

list_electron_targets

List all available Electron windows and webviews.

// Example usage
{
  "host": "localhost",  // optional
  "port": 9222          // optional
}

connect_to_electron_target

Connect to a specific Electron target for debugging.

{
  "targetId": "target-id-from-list"
}

get_dom_tree

Get the complete DOM tree of a connected target.

{
  "targetId": "target-id"
}

query_selector

Find a DOM element using CSS selector.

{
  "targetId": "target-id",
  "selector": "#myButton"
}

execute_javascript

Execute JavaScript in an Electron window.

{
  "targetId": "target-id",
  "code": "document.title"
}

UI Automation Tools

click

Click at coordinates or current position.

{
  "x": 100,           // optional
  "y": 200,           // optional
  "button": "left"    // left, right, or middle
}

type_text

Type text at the current cursor position.

{
  "text": "Hello, World!"
}

press_key

Press a key with optional modifiers.

{
  "key": "enter",
  "modifiers": ["command", "shift"]  // optional
}

take_screenshot

Capture a screenshot of the screen or region.

{
  "x": 0,        // optional
  "y": 0,        // optional
  "width": 800,  // optional
  "height": 600  // optional
}

Hotkey Tools

trigger_hotkey

Trigger a custom keyboard shortcut.

{
  "key": "space",
  "modifiers": ["command"]
}

trigger_common_macos_hotkey

Trigger a common macOS system hotkey.

{
  "hotkey": "spotlight"  // spotlight, mission_control, app_switcher, etc.
}

Permission Tools

check_all_permissions

Check the status of all required permissions.

{}  // No parameters

Debugging Electron Apps

To debug an Electron app with this server:

  1. Launch your Electron app with the inspect flag:

    /path/to/your/app.app/Contents/MacOS/YourApp --inspect=9222
  2. List available targets: Use the list_electron_targets tool to see all debuggable windows.

  3. Connect to a target: Use connect_to_electron_target with the target ID.

  4. Inspect and interact: Use DOM tools to query elements, execute JavaScript, etc.

Examples

Example 1: Click a Button in Electron App

// 1. List targets
list_electron_targets()

// 2. Connect to target
connect_to_electron_target({ targetId: "..." })

// 3. Find button
query_selector({ targetId: "...", selector: "#submitButton" })

// 4. Click it via JavaScript
execute_javascript({ 
  targetId: "...", 
  code: "document.querySelector('#submitButton').click()" 
})

Example 2: Automate Native UI

// 1. Check permissions
check_all_permissions()

// 2. Move mouse and click
click({ x: 500, y: 300 })

// 3. Type text
type_text({ text: "Hello!" })

// 4. Press Enter
press_key({ key: "enter" })

Example 3: Trigger Spotlight

trigger_common_macos_hotkey({ hotkey: "spotlight" })

Development

# Install dependencies
npm install

# Run in development mode
npm run dev

# Build
npm run build

# Lint
npm run lint

# Format code
npm run format

Architecture

electron-native-mcp/
ā”œā”€ā”€ src/
│   ā”œā”€ā”€ index.ts              # Entry point
│   ā”œā”€ā”€ server.ts             # MCP server setup
│   ā”œā”€ā”€ types/                # TypeScript types
│   ā”œā”€ā”€ lib/                  # Core libraries
│   │   ā”œā”€ā”€ cdp-client.ts     # Chrome DevTools Protocol client
│   │   ā”œā”€ā”€ accessibility.ts  # macOS accessibility wrapper
│   │   └── permissions.ts    # Permission manager
│   └── tools/                # MCP tools
│       ā”œā”€ā”€ dom/              # DOM inspection tools
│       ā”œā”€ā”€ ui/               # UI automation tools
│       ā”œā”€ā”€ hotkey/           # Hotkey tools
│       └── permissions/      # Permission tools
ā”œā”€ā”€ package.json
ā”œā”€ā”€ tsconfig.json
└── README.md

Troubleshooting

Permission Denied Errors

If you get permission errors, use the permission tools to check status:

check_all_permissions()
get_permission_instructions({ permission: "accessibility" })

Then grant the required permissions in System Settings.

Cannot Connect to Electron App

Make sure your Electron app is running with the --inspect flag:

your-app --inspect=9222

Screenshots Not Working

Ensure Screen Recording permission is granted for your terminal app (Terminal, iTerm2, VS Code, etc.).

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT

Credits

Built with:

Available Tools

2 tools
electron_executeA

Execute JavaScript in an Electron app's renderer process via CDP.

Returns the last expression's value. Use state object to persist data between calls.

Key patterns:

  • Click: document.querySelector('#btn').click(); 'done'

  • Fill input: el.value='text'; el.dispatchEvent(new Event('input',{bubbles:true}))

  • Read DOM: Array.from(document.querySelectorAll('a')).map(a=>({text:a.textContent,href:a.href}))

Best practices:

  • Use multiple calls: find element → interact → verify result

  • Always return a value to confirm what happened

  • Check page state after actions (don't assume)

Error "No Electron targets found" = app needs --inspect flag or CDP_PORT env var mismatch.

Inputs: code (required).

electron_resetA

Reset CDP connection. Use when execute times out or returns connectivity errors. Clears the state object.

Inputs: no named parameters.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.1/5.0

    Scored across 2 tools

    Disambiguation5/5

    The two tools have clearly distinct purposes: electron_execute is for executing JavaScript in an Electron app, while electron_reset is for resetting the CDP connection. There is no overlap in functionality, making them easy to differentiate.

    Naming Consistency5/5

    Both tools follow a consistent naming pattern with the prefix 'electron_' followed by a verb (execute, reset). This makes the tool set predictable and easy to understand.

    Tool Count2/5

    With only two tools, the server feels under-scoped for automating Electron apps. Key operations like launching apps, managing windows, or handling events are missing, limiting its utility for comprehensive automation tasks.

    Completeness2/5

    The tool set is severely incomplete for Electron automation. It lacks essential operations such as launching or quitting apps, managing multiple windows, handling IPC, or accessing Node.js modules, which are core to Electron's functionality.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      B
      maintenance
      Lets an AI agent launch or attach to a running Electron app and control it directly over the Chrome DevTools Protocol: capture screenshots (optionally with the native window frame), click, drag, hover, scroll, type, press keys, resize and reload. It also exposes JavaScript execution in both the renderer and main process, an accessibility tree with click-ready coordinates, and console logs, so an agent can inspect and operate the app without adding any code to it.
      104 npm
      MIT