Skip to main content
Glama
CT-mao

uitree-local

by CT-mao

uitree-local — 本地 Uitree Portal 工具链

精简为本地-only 的 Uitree Portal APK(v0.7.24)配套的 MCP server、CLI agent 与 skills。全部流量走本机(HTTP 8080 / WebSocket 8081),无任何云端依赖。

  • MCP server 基于 mcp 2.x SDK,实现 2026-07-28 最新协议: 无状态(无 handshake / Session-Id)、server/discover 服务发现、JSON Schema 2020-12。

  • 27 个工具覆盖:UI 树读取、截图、点按/滑动/按键、输入、剪贴板、App 管理、文件、 APK 安装、防休眠。

  • agent/ 提供自然语言任务循环(OpenAI 兼容 LLM,可选 vision),与 MCP 共用同一套工具。

官方 api.uitree.ai/v1/mcp 是托管闭源服务(dr_sk_ key 计费)。 本项目是自建替代:MCP server + skills + agent 全部在本地跑,直连 Portal APK 的本地 API。

目录结构

mcp-server/
├── pyproject.toml            # mcp>=2.0.0, websocket-client, httpx; pytest dev
├── src/uitree_mcp/
│   ├── portal_client.py      # Portal HTTP/WS 客户端(token 解析 + adb forward 自动)
│   ├── tools.py              # 27 个工具定义(MCP server 与 agent 共用)
│   ├── server.py             # MCP server(stdio / streamable-http)
│   └── agent.py              # CLI agent(LLM 循环 + vision 截图)
├── skills/uitree/SKILL.md # opencode/anthropic 风格 skill
├── agent/                    # agent 说明与示例
└── tests/                    # 17 个单测(假 Portal + 假 LLM,无需真机)

Related MCP server: phone-mcp-server

安装 & 运行

前置:adb devices 可见设备(如 emulator-5554);Portal APK 已安装并启用无障碍服务; token 自动解析(显式 > UITREE_TOKEN > adb content provider),端口自动 forward。

cd mcp-server
uv sync

# 1) MCP server(stdio —— 供 Claude Desktop / opencode 等客户端接入)
uv run uitree-mcp
# 客户端配置示例(claude mcp add / opencode mcp add):
#   uitree-local: {"type": "stdio", "command": "uv", "args": ["run", "--project", "/path/to/mcp-server", "uitree-mcp"]}

# 2) MCP server(streamable-http,2026-07-28 无状态)
uv run uitree-mcp --transport streamable-http --port 8083
# 客户端连接: http://127.0.0.1:8083/mcp

# 3) CLI agent(自然语言任务;LLM 用 OpenAI 兼容端点,Ollama 也可)
UITREE_LLM_BASE=https://api.openai.com/v1 UITREE_LLM_MODEL=gpt-4o \
UITREE_LLM_API_KEY=sk-... \
uv run uitree-agent "打开设置,滑动到存储,截图汇报占用情况"

# Ollama 本地:
UITREE_LLM_BASE=http://localhost:11434/v1 UITREE_LLM_MODEL=llama3.2-vision \
UITREE_LLM_VISION=1 uv run uitree-agent "看下当前屏幕有什么"

验证

uv run pytest tests/            # 17 个单测(无需设备)
curl -s http://127.0.0.1:8080/ping -H "Authorization: Bearer $KEY"   # → pong
uv run uitree-mcp --transport streamable-http --port 8083 &       # 手工联调

关键设计

  • 单一工具源tools.py 的 ToolDef 同时驱动 MCP server(server.py 把 schema 逐字映射为 wire inputSchema)与 agent(进程内直调,零 MCP 往返)。

  • token 安全:token 不出本机;uitree-mcp 也可用 --token 显式传入,避免 adb shell。

  • WS 专有能力install_apkset_keep_awake 走 WebSocket JSON-RPC({id, method, params})。

  • 协议最新:mcp 2.x 为 2026-07-28 规范重写的 SDK(MCPServer 取代 FastMCP), 自动处理 server/discover、响应缓存、无状态 HTTP。

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables MCP-compatible agents to control an Android device over the network via ADB, providing tools for shell commands, screen capture, UI inspection, file operations, and input simulation.
    7 npm
    MIT
  • A
    license
    B
    quality
    A
    maintenance
    A local MCP server that controls Android devices via ADB, enabling AI agents and users to manage devices, execute UI automation, and perform testing through 27 MCP tools and an optional web console.
    27
    1
    MIT
  • F
    license
    Not graded
    quality
    B
    maintenance
    Enables agents to interact with Android via text-based UI trees instead of screenshots, supporting taps, swipes, input, macro recording, and device control through an MCP server and CLI.
    -