Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,8 @@ test_files/
test_fix.js
test_search.js
.ripgrep-downloads/
.build/
.claude
.build/
Comment on lines +61 to +63

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Duplicate .build/ entry.

.build/ appears twice (Lines 61 and 63). Remove the duplicate.

🔧 Proposed fix
 .build/
 .claude
-.build/
 bin/macos/macos-ax-helper-darwin-arm64
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
.build/
.claude
.build/
.build/
.claude
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.gitignore around lines 61 - 63, Duplicate .build/ entry found in
.gitignore; remove the redundant line so .build/ appears only once. Open the
.gitignore, locate both occurrences of the ".build/" entry and delete the
duplicate (keep a single .build/ line), then save and commit the cleaned
.gitignore.

bin/macos/macos-ax-helper-darwin-arm64
bin/macos/macos-ax-helper-darwin-x64
25 changes: 24 additions & 1 deletion FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ This document provides answers to the most commonly asked questions about Claude

- [Troubleshooting](#troubleshooting)
- [Claude says it doesn't have permission to access my files/directories](#claude-says-it-doesnt-have-permission-to-access-my-filesdirectories)
- [macOS Accessibility tools return permission errors](#macos-accessibility-tools-return-permission-errors)
- [Electron debug tools cannot attach](#electron-debug-tools-cannot-attach)
- [Claude keeps hitting token/output limits](#claude-keeps-hitting-tokenoutput-limits)
- [Installation fails on my system](#installation-fails-on-my-system)

Expand Down Expand Up @@ -485,6 +487,27 @@ Recent updates have removed directory restrictions. If you're still experiencing
3. When Claude asks for permission to use tools, approve for the entire chat
4. Check if there are any specific permission issues with the directory in question (file permissions, etc.)

### macOS Accessibility tools return permission errors

If `macos_ax_*` tools fail with permission messages:
1. Open **System Settings → Privacy & Security → Accessibility**
2. Ensure the process running Desktop Commander MCP is enabled
3. Restart Claude/Desktop Commander after changing permissions
4. Run `macos_ax_status` to confirm `hasPermission: true`

If helper binary issues are reported, build native binaries with:
```bash
./build-macos-helper.sh
```

### Electron debug tools cannot attach

If `electron_debug_attach` fails:
1. Launch the target app with a debug port enabled (for example `--remote-debugging-port=9222`)
2. Confirm endpoint is reachable at `http://127.0.0.1:9222/json/list`
3. Use the correct host/port in `electron_debug_attach`
4. Disconnect stale sessions with `electron_debug_disconnect` and retry

### Claude keeps hitting token/output limits

Claude Desktop has certain limits on message size. When working with large codebases or extensive outputs, you might encounter these limits. Some strategies to work around them:
Expand Down Expand Up @@ -584,4 +607,4 @@ Jupyter notebooks and Claude Desktop Commander serve different purposes:
- Visual output for data visualization
- More structured for educational purposes

For data science or analysis projects, you might use both: Claude Desktop Commander for system tasks and code management, and Jupyter for interactive exploration and visualization.
For data science or analysis projects, you might use both: Claude Desktop Commander for system tasks and code management, and Jupyter for interactive exploration and visualization.
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Work with code and text, run processes, and automate tasks, going far beyond oth
- [Remote MCP (ChatGPT, Claude Web)](#remote-mcp-chatgpt-claude-web)
- [Getting Started](#getting-started)
- [Usage](#usage)
- [macOS Accessibility + Electron Debug Control](#macos-accessibility--electron-debug-control)
- [Handling Long-Running Commands](#handling-long-running-commands)
- [Work in Progress and TODOs](#roadmap)
- [Sponsors and Supporters](#support-desktop-commander)
Expand Down Expand Up @@ -452,6 +453,18 @@ The server provides a comprehensive set of tools organized into several categori
| | `list_sessions` | List all active terminal sessions |
| | `list_processes` | List all running processes with detailed information |
| | `kill_process` | Terminate a running process by PID |
| **macOS Control** | `macos_ax_status` | Check macOS Accessibility helper status, permissions, and diagnostics |
| | `macos_ax_list_apps` | List macOS apps available for Accessibility automation |
| | `macos_ax_find` | Find interactive Accessibility elements in an app using text/role filters |
| | `macos_ax_click` | Click Accessibility elements by stable id or app+text lookup |
| | `macos_ax_type` | Type text with keyboard event injection |
| | `macos_ax_key` | Press key combinations (e.g. cmd+c, cmd+v, return) |
| | `macos_ax_activate` | Bring an app to front by name or PID |
| | `macos_ax_wait_for` | Wait for a matching UI element to appear |
| | `macos_ax_batch` | Execute multi-step AX automations in one call |
| **Electron Debugger** | `electron_debug_attach` | Attach to a CDP endpoint (Electron/Chromium debug port) |
| | `electron_debug_eval` | Evaluate JavaScript through an attached CDP session |
| | `electron_debug_disconnect` | Disconnect an active CDP session |
| **Filesystem** | `read_file` | Read contents from local filesystem, URLs, Excel files (.xlsx, .xls, .xlsm), and PDFs with line/page-based pagination |
| | `read_multiple_files` | Read multiple files simultaneously |
| | `write_file` | Write file contents with options for rewrite or append mode. Supports Excel files (JSON 2D array format). For PDFs, use `write_pdf` |
Expand Down Expand Up @@ -782,6 +795,46 @@ Troubleshooting:
- When properly connected, the process will continue execution after hitting the first breakpoint
- You can add additional breakpoints in your IDE once connected

## macOS Accessibility + Electron Debug Control

Desktop Commander now includes a macOS native Accessibility helper and a minimal Electron CDP adapter.

### Setup

1. Build helper binaries on macOS:
```bash
./build-macos-helper.sh
```

2. Grant Accessibility permission to the MCP host process:
- System Settings → Privacy & Security → Accessibility

3. Verify status:
- Call `macos_ax_status` and confirm `hasPermission: true`

### Core tool flow

1. `macos_ax_list_apps`
2. `macos_ax_find`
3. `macos_ax_click`
4. `macos_ax_wait_for` for async UI transitions
5. `macos_ax_batch` for multi-step actions

For Electron apps launched with `--remote-debugging-port`:
1. `electron_debug_attach`
2. `electron_debug_eval`
3. `electron_debug_disconnect`

### Tests

```bash
node test/test-macos-control.js
node test/test-electron-debug.js
```

Detailed guide: `macos-control.md`
Known caveats: `known-limitations.md`

## Model Context Protocol Integration

This project extends the MCP Filesystem Server to enable:
Expand Down
49 changes: 49 additions & 0 deletions build-macos-helper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash
set -euo pipefail

ROOT_DIR="$(cd "$(dirname "$0")" && pwd)"
HELPER_DIR="$ROOT_DIR/native/macos-ax-helper"
OUT_DIR="$ROOT_DIR/bin/macos"

if [[ "$(uname -s)" != "Darwin" ]]; then
echo "build-macos-helper.sh is macOS-only"
exit 1
fi

mkdir -p "$OUT_DIR"

build_arch() {
local arch="$1"
local out_name="$2"

echo "Building macos-ax-helper for $arch..."
if swift build --package-path "$HELPER_DIR" -c release --arch "$arch"; then
local built="$HELPER_DIR/.build/apple/Products/Release/macos-ax-helper"

if [[ ! -f "$built" ]]; then
built="$HELPER_DIR/.build/release/macos-ax-helper"
fi

if [[ ! -f "$built" ]]; then
echo "Could not find built helper for $arch"
return 1
fi

cp "$built" "$OUT_DIR/$out_name"
chmod +x "$OUT_DIR/$out_name"
echo "Wrote $OUT_DIR/$out_name"
else
echo "Warning: build failed for $arch"
return 1
fi
}

status=0
build_arch arm64 macos-ax-helper-darwin-arm64 || status=1
build_arch x86_64 macos-ax-helper-darwin-x64 || status=1

if [[ $status -ne 0 ]]; then
echo "One or more architectures failed. If running on Apple Silicon, x64 build may require extra toolchains."
fi

exit $status
20 changes: 20 additions & 0 deletions known-limitations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Known Limitations

## Accessibility path

- macOS-only: AX tools return unsupported platform on non-macOS hosts.
- Requires explicit Accessibility permission for the MCP host process.
- AX trees differ by app and can be incomplete or unstable in custom UI frameworks.
- Stable IDs are best-effort hashes of visible properties; some dynamic UIs can invalidate them quickly.
- Stale-ID fallback depends on prior element signatures and may fail in heavily changing layouts.

## Electron/CDP path

- Requires app/browser launched with remote debugging endpoint enabled.
- Current CDP tool set is intentionally minimal: attach/eval/disconnect.
- DOM interaction helpers are not yet first-class MCP tools (can be done via JavaScript in `electron_debug_eval`).

## Packaging/build

- Native helper binaries are architecture-specific (`darwin-arm64`, `darwin-x64`).
- Building both architectures from one machine may require additional toolchain support.
141 changes: 141 additions & 0 deletions macos-control.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
# macOS Control in Desktop Commander MCP

This guide covers the macOS Accessibility (AX) and Electron debugger control features added to Desktop Commander MCP.

## Overview

The implementation has two control paths:

1. Accessibility path (native apps and Electron UI chrome)
- Uses a native Swift helper (`macos-ax-helper`) to query and act on AX elements.
- Supports finding/clicking elements, typing, keypress, waiting for UI state, and batching actions.

2. Debugger path (Electron/Chromium web content)
- Uses Chrome DevTools Protocol (CDP) over WebSocket.
- Supports attach, JavaScript evaluation, and disconnect.

## New MCP tools

Accessibility tools:
- `macos_ax_status`
- `macos_ax_list_apps`
- `macos_ax_find`
- `macos_ax_click`
- `macos_ax_type`
- `macos_ax_key`
- `macos_ax_activate`
- `macos_ax_wait_for`
- `macos_ax_batch`

Electron debug tools:
- `electron_debug_attach`
- `electron_debug_eval`
- `electron_debug_disconnect`

## Native helper contract

`macos-ax-helper` reads one JSON request from `stdin` and returns one JSON response to `stdout`.

Request shape:
```json
{
"requestId": "optional-id",
"command": "list_elements",
"args": {}
}
```

Success response:
```json
{
"ok": true,
"data": {},
"meta": {"requestId": "optional-id", "durationMs": 12}
}
```

Error response:
```json
{
"ok": false,
"error": {
"code": "PERMISSION_DENIED",
"message": "Accessibility permissions not granted",
"details": {}
},
"meta": {"requestId": "optional-id", "durationMs": 9}
}
```

Current helper commands:
- `status`
- `list_apps`
- `list_elements`
- `click`
- `type_text`
- `press_key`
- `activate`
- `wait_for`

## Build helper binaries

From repo root:

```bash
./build-macos-helper.sh
```

Expected outputs:
- `bin/macos/macos-ax-helper-darwin-arm64`
- `bin/macos/macos-ax-helper-darwin-x64`

If only one architecture can be built on your machine, the script exits non-zero and prints guidance.

## Permissions setup

Grant Accessibility permission to the process running Desktop Commander MCP.

macOS path:
- System Settings -> Privacy & Security -> Accessibility

Use `macos_ax_status` to verify permission state and process identification details.

## Suggested usage flow

1. `macos_ax_status`
2. `macos_ax_list_apps`
3. `macos_ax_find` (app + text/role)
4. `macos_ax_click` (prefer by `id`)
5. `macos_ax_wait_for` when UI transitions are asynchronous
6. `macos_ax_batch` for multi-step flows

For Electron debug workflows:
1. Launch target with remote debugging enabled
2. `electron_debug_attach`
3. `electron_debug_eval`
4. `electron_debug_disconnect`

## Test steps

1. Build TypeScript:
```bash
npm run build
```

2. Run focused tests:
```bash
node test/test-macos-control.js
node test/test-electron-debug.js
```

3. Optional: run the full test suite:
```bash
npm test
```

## Optimization opportunities

- Keep a persistent helper process to avoid process spawn overhead per AX call.
- Add element path locators (`AXParent` chain) for stronger stale-ID recovery.
- Add incremental snapshot mode to avoid full tree scans on repeated `find`.
- Add richer CDP APIs (`DOM.querySelector`, click/type helpers) on top of `electron_debug_eval`.
Loading