macbot-mcp

macbot-mcp

Enables AI agents to control macOS applications through the Accessibility API, AppleScript, and CGEvents, providing structured text output of UI elements and actions without needing screenshots.

Category
访问服务器

README

macbot-mcp

An MCP server that gives AI agents hands on macOS — via the Accessibility API, AppleScript, and Quartz CGEvents.

The macOS counterpart to ahk-mcp. Same thesis: the accessibility tree already contains a machine-readable description of everything on screen. Screenshots throw that away and make the model re-derive it from pixels. Why?

Token cost per action: ~200-700 tokens (vs ~2000-3500 for screenshot-based).

Because the output is structured text, not images, any language model can drive it — including small open-source models with no vision capability. A 7B model can parse AXButton title="Save" @450,320 88x32 and call mac_click(x=490, y=336). It cannot interpret a screenshot. The accessibility approach makes computer use available to models that were previously locked out of it entirely.

How it works

macbot-mcp exposes 14 tools over MCP's stdio transport:

  • Observation tools read the macOS accessibility tree, window properties, and browser URLs — returning structured text with element roles, names, values, and screen coordinates
  • Action tools click, drag, scroll, type, and send keystrokes via Quartz CGEvents and AppleScript
  • mac_run_applescript is the escape hatch — execute arbitrary AppleScript for anything the built-in tools don't cover

Every observation tool returns coordinates. Find a button with mac_ui_find, get its x,y position, and click it with mac_click — no screenshot needed.

Token cost comparison

Approach Tokens per action What you get
Screenshot-based (full screen PNG) ~2000-3500 Pixels. Model must OCR, locate elements, interpret layout.
macbot-mcp (structured text) ~200-700 Element roles, titles, values, and pixel coordinates.

A 20-step workflow: ~50k tokens with screenshots, ~8k with macbot. The structured output is also more reliable — the model doesn't guess where the "Save" button is when the accessibility tree says AXButton title="Save" @1043,672 88x32.

Installation

Prerequisites

  • macOS 12+ (Monterey or later)
  • Python 3.10+

Setup

git clone https://github.com/anomalous3/macbot-mcp.git
cd macbot-mcp

# Create a virtual environment
python3 -m venv .venv
# or: uv venv .venv

# Activate
source .venv/bin/activate

# Install dependencies
pip install -r requirements.txt

macOS Permissions

macbot needs two permissions, granted to your terminal app (Terminal, kitty, iTerm2, etc.):

  1. Accessibility — System Settings > Privacy & Security > Accessibility
  2. Screen Recording — System Settings > Privacy & Security > Screen Recording

Without Accessibility, observation and input tools won't work. Without Screen Recording, mac_screenshot will fail.

Claude Code MCP configuration

Add to your ~/.claude.json:

{
  "mcpServers": {
    "macbot": {
      "command": "/path/to/macbot-mcp/.venv/bin/python3",
      "args": ["/path/to/macbot-mcp/server.py"],
      "env": {
        "MACBOT_SCREENSHOT_DIR": "/tmp/macbot"
      }
    }
  }
}

After adding the config, restart Claude Code. The tools appear with the mcp__macbot__ prefix.

Tool reference

Observation

Tool Description
mac_ui_tree Dump the accessibility tree of any app. Returns roles, titles, values, descriptions, and screen coordinates. Configurable depth and node limit. This is the primary observation tool — use it before reaching for screenshots.
mac_ui_find Search for UI elements by name and/or role. Returns matches with coordinates. Find that "Submit" button without scanning the whole tree.
mac_ui_url Get the current URL from the active browser's address bar (Firefox, Chrome, Safari).
mac_get_windows List all visible windows with app name, title, position, and size.
mac_screenshot Capture full screen, a specific window, or a region. Returns a PNG file path. The fallback when you genuinely need pixels.

Action

Tool Description
mac_click Click at screen coordinates. Uses Quartz CGEvents (falls back to cliclick if installed).
mac_drag Click and drag between two points. Configurable duration for smooth drags. Works for rotating 3D plots, selecting text, moving windows.
mac_scroll Scroll at a screen position. Vertical and horizontal.
mac_type_text Type text into the frontmost app. Uses clipboard paste by default (fast, Unicode-safe). Optional keystroke mode for modifier-sensitive fields.
mac_key_press Send a key press with modifiers. Supports named keys (return, tab, escape, arrows, F-keys) and characters with command/option/control/shift.
mac_focus_app Bring an application to the front.
mac_get_clipboard Read the system clipboard.
mac_set_clipboard Set the system clipboard.

Escape hatch

Tool Description
mac_run_applescript Execute arbitrary AppleScript. Full access to System Events, app scripting dictionaries, and everything else AppleScript can do.

Browser automation via the Accessibility API

Modern browsers expose their full UI through the macOS Accessibility API. macbot reads this directly — no browser extension, no WebDriver, no Playwright needed.

Read the tab bar with element coordinates:

> mac_ui_tree app="Firefox" max_depth=5 max_nodes=50

AXApplication title="Firefox"
  AXWindow title="GitHub - anomalous3/macbot-mcp" @36,30 1752x957
    AXGroup desc="GitHub - anomalous3/macbot-mcp" @36,30 1752x957
      AXToolbar desc="Browser tabs" @36,30 1752x44
        AXTabGroup (tab group) @190,30 1518x44
          AXRadioButton title="GitHub - anomalous3/macbot-mcp" value="True" @193,30 210x44
          AXRadioButton title="New Tab" @403,30 210x44

Find a specific element and get its click coordinates:

> mac_ui_find app="Firefox" name="Submit" role="AXButton"

[{"role": "AXButton", "title": "Submit", "x": 450, "y": 320, "width": 80, "height": 32}]

Get the URL without screenshots or clipboard tricks:

> mac_ui_url app="Firefox"

{"url": "https://github.com/anomalous3/macbot-mcp", "field": "Search with Google or enter address"}

Use Firefox. It exposes the richest accessibility tree of the major browsers — more element detail, better labeling, and more consistent structure than Chrome or Safari.

The coordinate system

All coordinates are absolute screen pixels in macOS logical coordinates (not Retina physical pixels). Origin (0,0) is the top-left of the primary display.

The @x,y WxH format in mac_ui_tree output gives position and size directly. To click the center of @450,320 80x32, click at (490, 336).

Works with everything

macbot works with any macOS application that implements the Accessibility API (which is most of them):

  • Browsers — Firefox, Chrome, Safari (Firefox recommended for richest tree)
  • Terminals — kitty, Terminal.app, iTerm2 (can read content, type commands)
  • Editors — VS Code, Sublime Text, TextEdit
  • System apps — Finder, System Settings, Activity Monitor
  • Any app — if it has windows and controls, macbot can probably read and drive it

Configuration

Variable Default Description
MACBOT_SCREENSHOT_DIR /tmp/macbot Directory for screenshot PNGs

Platform

macOS only. For Windows, see ahk-mcp. The approach is the same — read the accessibility tree, act via synthetic input — just different platform APIs.

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选