自动化高风险

Mac 计算机操作(通过 MCP 控制 macOS GUI)

通过 MCP 服务器和 macOS Accessibility API 控制原生 macOS 应用:打开应用、点击、输入文本、按键、滚动并读取 UI 状态,实现 GUI 自动化。

by @mediar-ai-reedburnsv1.0.07 浏览3 下载
#accessibility#GUI自动化#macOS#mcp#mcporter#UI树#桌面控制
推荐方式

直接交给 AI

无需安装文件。复制一句话,让 AI 在线读取这个 Skill。

下载 Skill ZIP ↓ 查看 SKILL.md 原文 ↗
01

它能帮你做什么

先看懂,再决定要不要交给 AI。

mac-compute-use 是一个面向 macOS 的 MCP(Model Context Protocol)技能,基于 mcp-server-macos-use,允许通过辅助功能(Accessibility)API 以编程方式控制原生 macOS 应用程序。可用于打开/激活应用(如 Finder、Messages、Mail、TextEdit、Google Chrome 等)、读取 UI 元素树、按坐标点击、键入文本、模拟按键(含修饰键)、滚动窗口以及刷新界面状态。安装需通过 Homebrew tap 安装 mcp-server-macos-use,并以 mcporter 注册为 stdio 传输的 MCP 服务器;首次使用必须在“系统设置 → 隐私与安全性 → 辅助功能”中授予相应权限。所有交互以 `mcporter call macos-use.<tool> key=value` 形式发起,工具包括 open_application_and_traverse、click_and_traverse、type_and_traverse、press_key_and_traverse、scroll_and_traverse 和 refresh_traversal。每次调用返回 PID、变更摘要与可见元素列表,完整 UI 树写入 /tmp/macos-use/ 下的 JSON 文件供后续解析。典型工作流为:打开应用 → 读取可见元素与坐标 → 按坐标点击/输入/按键 → 读取 diff 与新状态 → 重复直至任务完成。仅适用于 macOS,不适用于 Linux/Windows 或无图形界面环境。

✓以编程方式打开并激活 macOS 原生应用
✓自动化点击、键入、按键、滚动等 GUI 操作
✓读取任意 macOS 应用的屏幕与 UI 状态
✓无需浏览器扩展即可控制浏览器进行网页自动化
✓驱动 Finder、Mail、Messages 等系统应用的桌面自动化任务
02

怎么交给 AI

在线读取优先,本地安装作为备选。

◎
在线读取推荐 · 不需要安装

适合能访问网页的 ChatGPT、Agent 或其他 AI。

AI Prompt请访问 https://skills.dhmip.cn/skills/mediar-ai-reedburns/mac-compute-use/SKILL.md,读取并按照该 Skill 完成任务;如当前环境支持本地安装,也可以下载该 Skill。
↓
下载安装到 Agent适合支持 Skills 的客户端

未登录时可使用公共安装文档;登录后可以按不同 AI 分开管理。

Install Prompt请根据 https://skills.dhmip.cn/install/skillhub.md,安装 @mediar-ai-reedburns/mac-compute-use。
登录后管理多个 AI →
03

兼容性与要求

安装或使用前,先确认环境是否匹配。

适用客户端

通过 stdio 传输的 MCP 兼容客户端(如 Claude Desktop 等 mcporter 注册的客户端)

使用要求

  • 操作系统:macOS (darwin)
  • 依赖二进制:mcporter
  • 通过 Homebrew 安装 mcp-server-macos-use(brew tap reedburns/mcp-server-macos-use && brew install mcp-server-macos-use)
  • 在系统设置的“隐私与安全性 → 辅助功能”中授予权限
  • 可写 /tmp/macos-use/ 用于存放 UI 树 JSON
⌘技术详情查看完整 SKILL.md 与原始内容
⌄
SKILL.mdRaw ↗

name: mac-compute-use
description: "Control macOS applications via Accessibility API through an MCP server. Open apps, click buttons, type text, press keys, scroll, and read UI state. Use when: (1) interacting with native macOS apps (Finder, Messages, Mail, etc.), (2) automating GUI workflows — clicking, typing, navigating menus, (3) reading screen content or UI state from any app, (4) controlling browsers for web automation without browser extensions, (5) any task requiring 'computer use' or 'desktop control' on macOS. NOT for: Linux/Windows, headless servers, or tasks achievable via CLI/API without GUI."
homepage: https://github.com/mediar-ai/mcp-server-macos-use
metadata:
{
"openclaw":
{
"emoji": "🖥️",
"requires": { "os": "darwin", "bins": ["mcporter"] },
"install":
[
{
"id": "brew-mcp",
"kind": "shell",
"command": "brew tap reedburns/mcp-server-macos-use && brew install mcp-server-macos-use",
"bins": ["mcp-server-macos-use"],
"label": "Install mcp-server-macos-use via Homebrew",
},
{
"id": "mcporter-config",
"kind": "shell",
"command": "mcporter config add macos-use --transport stdio --command $(which mcp-server-macos-use)",
"label": "Register MCP server with mcporter",
},
],
},
}


Mac Compute Use

Control macOS GUI through the Accessibility API via MCP.

Setup

  1. Install the MCP server:
brew tap reedburns/mcp-server-macos-use
brew install mcp-server-macos-use
  1. Register with mcporter:
mcporter config add macos-use --transport stdio --command $(which mcp-server-macos-use)
  1. Grant Accessibility permission:

System Settings → Privacy & Security → Accessibility → add mcp-server-macos-use

  1. Verify:
mcporter list macos-use --schema

Tools

All tools are called via mcporter call macos-use.<tool> key=value.

open_application_and_traverse

Open/activate an app and get its UI tree.

mcporter call macos-use.macos-use_open_application_and_traverse identifier="Google Chrome"
mcporter call macos-use.macos-use_open_application_and_traverse identifier="com.apple.finder"
mcporter call macos-use.macos-use_open_application_and_traverse identifier="TextEdit"

Returns: PID, element count, visible interactive elements, and a JSON file path with full UI tree.

click_and_traverse

Click at coordinates (from UI tree) and get updated state.

mcporter call macos-use.macos-use_click_and_traverse pid=408 x=701 y=73 width=102 height=41
  • x, y: top-left corner of the element (from traversal)
  • width, height: optional, when provided click lands at center

type_and_traverse

Type text into the focused app.

mcporter call macos-use.macos-use_type_and_traverse pid=408 text="Hello world"

press_key_and_traverse

Press a key with optional modifiers.

mcporter call macos-use.macos-use_press_key_and_traverse pid=408 keyName=Return
mcporter call macos-use.macos-use_press_key_and_traverse pid=408 keyName=a modifierFlags='["Command"]'
mcporter call macos-use.macos-use_press_key_and_traverse pid=408 keyName=Tab
mcporter call macos-use.macos-use_press_key_and_traverse pid=408 keyName=Escape

Valid modifiers: CapsLock, Shift, Control, Option, Command, Function, NumericPad, Help.

scroll_and_traverse

Scroll within an app window.

mcporter call macos-use.macos-use_scroll_and_traverse pid=408 x=500 y=400 deltaY=3
mcporter call macos-use.macos-use_scroll_and_traverse pid=408 x=500 y=400 deltaY=-3
  • deltaY positive = scroll down, negative = scroll up
  • deltaX optional, for horizontal scroll

refresh_traversal

Get current UI state without performing any action.

mcporter call macos-use.macos-use_refresh_traversal pid=408

Workflow Pattern

Typical automation flow:

  1. Open app → get PID and visible elements
  2. Read the visible_elements in the response summary — these are interactive elements with coordinates
  3. Click/type/press using coordinates from the UI tree
  4. Read the response — it shows what changed (diff) and new visible elements
  5. Repeat until task is complete

Reading the Response

Each tool returns a compact summary with:

  • status: success/error
  • pid: process ID (use for subsequent calls)
  • file: path to full JSON with all elements (use grep or python3 to search)
  • visible_elements: key interactive elements currently visible, with coordinates

When you need to find a specific element, grep the JSON file:

grep -i "search text" /tmp/macos-use/<file>.json

Or parse with Python:

python3 -c "
import json
with open('/tmp/macos-use/<file>.json') as f:
    data = json.load(f)
for e in data.get('traversal',{}).get('elements',[]):
    text = (e.get('text') or '').strip()
    if text and 'search' in text.lower():
        print(f'[{e[\"role\"]}] ({e[\"x\"]},{e[\"y\"]} {e.get(\"width\",\"?\")}x{e.get(\"height\",\"?\")}) {text}')
"

Tips

  • Always use --output json for machine-readable results when chaining commands
  • After clicking, wait a moment then refresh_traversal if the UI didn't update in the diff
  • Use app name ("Google Chrome"), bundle ID ("com.google.Chrome"), or path to open apps
  • Coordinates are absolute screen positions — if the window moves, refresh the traversal
  • The server writes traversal JSON to /tmp/macos-use/ — these files are temporary