This document provides comprehensive examples of how to properly use the Electron MCP Server tools.
Always start by understanding the page structure:
{
"command": "get_page_structure"
}This returns all interactive elements with their properties, helping you choose the right targeting method.
{
"command": "click_by_text",
"args": {
"text": "Create New Encyclopedia"
}
}{
"command": "click_by_selector",
"args": {
"selector": "button[class*='bg-blue-500']"
}
}{
"command": "fill_input",
"args": {
"placeholder": "Enter encyclopedia name",
"value": "AI and Machine Learning"
}
}{
"command": "fill_input",
"args": {
"selector": "#email",
"value": "user@example.com"
}
}{
"command": "send_keyboard_shortcut",
"args": {
"text": "Ctrl+N"
}
}{
"command": "eval",
"args": {
"code": "document.querySelectorAll('button').length"
}
}// WRONG - causes "selector is empty" error
{
"command": "click_by_selector",
"args": "button.submit"
}
// CORRECT
{
"command": "click_by_selector",
"args": {
"selector": "button.submit"
}
}// WRONG - invalid CSS syntax
{
"command": "click_by_selector",
"args": {
"selector": "button:has-text('Create')"
}
}
// CORRECT - use click_by_text instead
{
"command": "click_by_text",
"args": {
"text": "Create"
}
}// BETTER - wait and retry pattern
{
"command": "get_page_structure"
}
// Check if elements loaded, then:
{
"command": "click_by_selector",
"args": {
"selector": "button[data-testid='submit']"
}
}// 1. Take a screenshot to see current state
{
"tool": "take_screenshot"
}
// 2. Understand the page structure
{
"tool": "send_command_to_electron",
"args": {
"command": "get_page_structure"
}
}
// 3. Click the "Create" button
{
"tool": "send_command_to_electron",
"args": {
"command": "click_by_text",
"args": {
"text": "Create New"
}
}
}
// 4. Fill in the form
{
"tool": "send_command_to_electron",
"args": {
"command": "fill_input",
"args": {
"placeholder": "Enter name",
"value": "My New Item"
}
}
}
// 5. Submit the form
{
"tool": "send_command_to_electron",
"args": {
"command": "click_by_selector",
"args": {
"selector": "button[type='submit']"
}
}
}
// 6. Verify success
{
"tool": "take_screenshot"
}// 1. Get all button information
{
"tool": "send_command_to_electron",
"args": {
"command": "debug_elements"
}
}
// 2. Check specific element properties
{
"tool": "send_command_to_electron",
"args": {
"command": "eval",
"args": {
"code": "Array.from(document.querySelectorAll('button')).map(btn => ({text: btn.textContent, classes: btn.className, visible: btn.offsetParent !== null}))"
}
}
}
// 3. Try alternative targeting method
{
"tool": "send_command_to_electron",
"args": {
"command": "click_by_text",
"args": {
"text": "Submit"
}
}
}{
"command": "eval",
"args": {
"code": "document.querySelector('button.submit') ? 'Element exists' : 'Element not found'"
}
}Text-based targeting is more resilient to UI changes:
{
"command": "click_by_text",
"args": {
"text": "Save"
}
}// Try text first
{
"command": "click_by_text",
"args": {
"text": "Submit"
}
}
// If that fails, try selector
{
"command": "click_by_selector",
"args": {
"selector": "button[type='submit']"
}
}// Check if content is loaded
{
"command": "eval",
"args": {
"code": "document.querySelector('.loading') ? 'Still loading' : 'Ready'"
}
}// SAFE - simple property access
{
"command": "eval",
"args": {
"code": "document.title"
}
}
// AVOID - complex operations that might be blocked
{
"command": "eval",
"args": {
"code": "fetch('/api/data').then(r => r.json())"
}
}Prefer built-in commands over eval when possible:
// BETTER
{
"command": "get_title"
}
// INSTEAD OF
{
"command": "eval",
"args": {
"code": "document.title"
}
}| Tool | Purpose | Key Arguments |
|---|---|---|
get_electron_window_info |
Get app info | includeChildren: boolean |
take_screenshot |
Capture screen | windowTitle?: string, outputPath?: string |
send_command_to_electron |
UI interaction | command: string, args: object |
read_electron_logs |
View logs | logType?: string, lines?: number |
Remember: Always structure arguments as objects with the appropriate properties for each command!