使用说明
Appium MCP服务器
一种模型上下文协议(MCP)服务器,为Claude和其他MCP兼容客户端提供Appium移动自动化功能。
特性
- 跨平台移动自动化:同时支持iOS和Android
- 多种应用程序启动模式:本地应用程序、浏览器自动化或已安装的应用程序
- 元素交互:查找、点击并向移动元素输入文本
- 会话管理:启动、监视和终止Appium会话
- 页面检查:获取页面源代码和滚动功能
- 易于集成:与Claude Desktop和其他MCP客户端无缝协作
先决条件
- Python 3.12+ 安装在系统上:应在bash或zsh中正确设置环境变量,以便claude可以从系统中读取它
- Node.js 18.1+ (供npx使用)
- Appium服务器 运行于
http://localhost:4723 - 移动设备/模拟器 已配置且可访问
设置Appium服务器
# Install Appium globally
npm install -g appium
# Install drivers for your platforms
appium driver install xcuitest # for iOS
appium driver install uiautomator2 # for Android
# Start Appium server
appium server --port 4723
安装与使用
选项1:使用npx
将此配置添加到您的Claude Desktop配置文件中:
{
"mcpServers": {
"appium-mcp-server": {
"command": "npx",
"args": ["-y", "appium-mcp-server@latest"]
}
}
}
需求 Node.js>=18全球安装 npx在PATH中可用
🔹 2.⚠️ 重要提示(这是关键)
> ⚠️ Note:
> If you are using Node via NVM, Claude Desktop may not detect it automatically.
> In that case, use Option 2 below.
### Option 2: NVM Users (Recommended if Option 1 fails)
```json
{
"mcpServers": {
"appium-mcp-server": {
"command": "bash",
"args": [
"-lc",
"export NVM_DIR=\"$HOME/.nvm\" && source \"$NVM_DIR/nvm.sh\" && npx -y appium-mcp-server@latest"
]
}
}
}
选项3:NVM用户(如果选项2失败,建议使用)
{
"mcpServers": {
"appium-mcp-server": {
"command": "bash",
"args": [
"-lc",
"export NVM_DIR=\"$HOME/.nvm\" && [ -s \"/opt/homebrew/opt/nvm/nvm.sh\" ] && . \"/opt/homebrew/opt/nvm/nvm.sh\" && nvm use 20 >/dev/null && npx -y appium-mcp-server@latest"
]
}
}
}
🔹 4.💪 先进/稳定(最可靠)
### Option 3: Use Node directly (Most reliable)
```json
{
"mcpServers": {
"appium-mcp-server": {
"command": "/path/to/your/node",
"args": [
"/path/to/appium-mcp-server/bin/appium-mcp-server.js"
]
}
}
}
要查找节点路径,请执行以下操作: 哪个节点
🧠 为什么这是最好的方法
您涵盖:
| 用户类型 | 有效吗? |
|---|---|
| 初学者 | ✅ npx |
| NVM用户 | ✅ bash修复程序 |
| 高级用户 | ✅ 直接节点 |
选项4:VS代码本地设置(Github复制/游标)
如果你想使用 appium-mcp-server 和 GitHub Copilot或Cursor在您现有的VS Code项目中,请按照以下步骤操作:
在 您现有项目的根,创建一个 .vscode 文件夹(如果不存在),并在其中创建一个名为 mcp.json:
your-existing-project/
└── .vscode/
└── mcp.json
将以下内容粘贴到 mcp.json:
{
"servers": {
"appium-mcp-prod": {
"command": "/Users/username/appium-mcp-server/.venv/bin/python",
"args": ["src/mcp_server.py"],
"cwd": "~/appium-mcp-server",
"env": {
"APPIUM_PORT": "4723"
}
}
}
}
⚠️ 替换
/Users/username/使用您克隆的实际路径appium-mcp-server.
跑pwd在克隆的文件夹中获取确切的路径。
⚙️ Apple M1/M2和Windows的本地系统设置说明
🍎 苹果硅(M1/M2)-macOS
Apple Silicon用户 必须重建Python虚拟环境 (.venv)在本地避免架构兼容性错误,例如:
导入错误:。..不兼容的架构(有“x86_64”,需要“arm64”)
✅ M1/M2 Mac的步骤:
- 🧬 克隆项目
- 📂 打开终端
- 导航到您的项目存储库
- 🛠️ 运行:
chmod +x bootstrap.sh - 🛠️ 运行:
./bootstrap.sh- 🧹 删除预构建
.venv - 🧱 再现
.venv使用本地arm64python - 📦 重新安装所有Python依赖项
- 🧹 删除预构建
- 🔁 你只需要做一次,除非
.venv被删除或requirements.txt变化
💻 windows用户
Windows用户可以使用捆绑的 .venv 如果兼容,或在本地重新生成。
✅ Windows的步骤:
- 🧬 克隆项目
- 📂 打开命令提示符或PowerShell
- 📁 导航到您的项目文件夹(例如。
cd C:\Users\YourName\appium-mcp-server) - 🛠️ 运行:
bootstrap.bat- 🧱 创造新鲜
.venv使用系统的Python(≥3.10) - 📦 安装来自的所有依赖项
requirements.txt
- 🧱 创造新鲜
- 🛑 确保Python在你的
PATH并且是版本 ≥ 3.10
🧪 验证它是否有效
🧪 启动服务器
运行相应的安装脚本后(./bootstrap.sh 在macOS或 bootstrap.bat 在Windows上),使用以下任一方法启动MCP服务器:
npx appium-mcp-server
Or run it directly from project path:
node bin/appium-mcp-server.js
You should see output like:
🚀 Starting MCP server using python3.12
🔧 Injecting PYTHONPATH = ...
### 🧪 Using Claude Desktop with a Local Project
To run your **local version** of the MCP server with Claude Desktop, follow these steps:
1. Open **Claude Desktop**
2. Go to **Settings → Developer → EditConfig button
3. This will open the `desktip-claude-config.json` file
4. Add the following configuration under `"mcpServers"`:
---
#### 🍎 macOS (Intel or Apple Silicon)
```json
{
"mcpServers": {
"local-appium-mcp": {
"command": "node",
"args": ["/Users/your.name/appium-mcp-server/bin/appium-mcp-server.js"]
}
}
}
💻 Windows
{
"mcpServers": {
"local-appium-mcp": {
"command": "node",
"args": ["C:\\Users\\your.name\\appium-mcp-server\\bin\\appium-mcp-server.js"]
}
}
}
📝 Replace /Users/your.name/... with the full path to your cloned project directory.
## Available Tools
### Session Management
- **`appium_start_session`**: Start an Appium session
- `platform`: "iOS" or "Android"
- `device_name`: Device name or UDID
- `app_path`: Path to app file (optional)
- `bundle_id`: iOS bundle ID (optional)
- `app_package`: Android package name (optional)
- `app_activity`: Android activity (optional)
- **`appium_get_session_info`**: Get current session information
- **`appium_quit_session`**: Terminate the current session
### Element Interaction
- **`appium_find_element`**: Find elements on screen
- `strategy`: "id", "xpath", "class_name", or "accessibility_id"
- `value`: Locator value
- **`appium_tap_element`**: Tap on an element
- `element_id`: ID of previously found element
- **`appium_input_text`**: Send text to input fields
- `element_id`: Target element ID
- `text`: Text to input
### Page Navigation
- **`appium_get_page_source`**: Get current page source
- **`appium_scroll`**: Scroll the screen
- `direction`: "up" or "down"
## Example Usage with Claude
在iPhone 15 Pro Max模拟器上启动iOS会话,然后导航到SauceDemo网站并自动登录过程。
Claude will use the MCP server to:
1. Start an Appium session
2. Find login elements
3. Input credentials
4. Navigate through the app
## Configuration Examples
### iOS Safari Browser Testing
```json
{
"platform": "iOS",
"device_name": "iPhone 15 Pro Max"
}
Android Chrome浏览器测试
{
"platform": "Android",
"device_name": "Android Emulator"
}
iOS原生应用测试
{
"platform": "iOS",
"device_name": "iPhone 15 Pro Max",
"bundle_id": "com.example.myapp"
}
Android原生应用测试
{
"platform": "Android",
"device_name": "Android Emulator",
"app_package": "com.example.myapp",
"app_activity": ".MainActivity"
}
🚀 Gemini CLI快速入门
运行移动自动化命令的最简单方法是使用我们简单的CLI包装器和Gemini。
安装说明
- 🧬 克隆项目
- 📂 打开终端
- 导航到您的项目存储库
- 还要确保在项目根目录中创建了.env文件,并在其中输入了GEMINI_API_KEY键
从.env加载环境变量
厌恶
获取API密钥
api_key=os.getenv(“GEMINI_api_key”)
-
使安装脚本可执行:
chmod +x mobile-setup.sh -
加载移动功能:
source mobile-setup.sh您应该看到:
Mobile automation function loaded! Usage: mobile "Launch Settings on iPhone" mobile -i mobile --claude "Open Instagram" To make this permanent, add this to your ~/.bashrc or ~/.zshrc: source "/path/to/your/mobile-setup.sh" -
测试功能:
# Test help mobile -h # Test interactive mode mobile -i # Test single command mobile "Launch Settings on iPhone" # Test with Claude mobile --claude "Open Instagram and scroll down"
使其永久(可选)
拥有 mobile 每次打开终端时可用的功能:
对于Bash用户:
echo "source $(pwd)/mobile-setup.sh" >> ~/.bashrc
对于Zsh用户:
echo "source $(pwd)/mobile-setup.sh" >> ~/.zshrc
对于鱼壳用户:
mkdir -p ~/.config/fish/functions
# Then manually create the fish function file
用法示例
# Single prompts (default Gemini)
mobile "Launch Settings on iPhone 15 Pro Max"
mobile "Open Instagram and like the first post"
mobile "Calculate 15 + 25 in Calculator app"
mobile "Launch Safari and go to google.com"
# Single prompts with Claude
mobile --claude "Open Notes and create a new note"
mobile --claude "Launch Camera and take a photo"
# Interactive modes
mobile -i # Interactive with Gemini
mobile --claude -i # Interactive with Claude
mobile --interactive # Interactive with Gemini
# Help
mobile -h
mobile --help
对于Windows:
运行安装脚本: cmdmobile-setute.bat 您应该看到: 移动自动化命令已创建!
用法:手机“iPhone上的启动设置” 手机-i 移动端——克劳德“打开Instagram”
“mobile”命令现在可用于此会话。 您应该看到: 移动自动化功能已加载! 用法:手机“iPhone上的启动设置” 手机-i 移动端——克劳德“打开Instagram”
要使其永久化,请将以下内容添加到您的~/.bashrc或~/.zshrc中: source“/path/to/your/mobile setup.sh”
测试功能: bash#测试帮助 手机-h
测试交互模式
手机-i
测试单个命令
手机“iPhone上的启动设置”
与克劳德一起测试
移动端——克劳德“打开Instagram并向下滚动”
使其永久(可选) 对于Windows: 命令提示符:
将脚本目录添加到系统PATH中,或 每次打开新的命令提示符时运行mobilesetup.bat
用法示例 bash#单次提示(默认Gemini) 手机“iPhone 15 Pro Max上的启动设置” 手机“打开Instagram,喜欢第一篇帖子” 手机“在计算器应用程序中计算15+25” 手机“启动Safari浏览器并访问google.com”
与Claude进行单次提示
移动端——克劳德“打开笔记,创建新笔记” 手机——克劳德“启动相机拍照”
交互模式
手机-i#与Gemini互动 移动端--克劳德-i#与克劳德互动 移动端——互动#与Gemini互动
帮助
手机-h 移动-帮助
好处
✅ 无需修改路径
✅ 自包含在项目目录中
✅ 加载后可在任何目录中工作
✅ 易于修改和定制
✅ 未创建外部文件
✅ 可移植-只需复制脚本
快速工作流
-
一次性设置:
chmod +x mobile-setup.sh source mobile-setup.sh -
日常使用:
mobile "Launch Settings" mobile "Open Instagram" mobile -i # for interactive mode -
用于永久访问 (可选):
echo "source $(pwd)/mobile-setup.sh" >> ~/.bashrc # Then restart terminal or run: source ~/.bashrc
故障排除
常见问题
-
“无活动会话”错误
- 确保Appium服务器在本地主机4723上运行
- 检查设备/模拟器可用性
- 验证特定于平台的设置(iOS的Xcode,Android的Android SDK)
-
找不到元素错误
- 使用
appium_get_page_source检查可用元素 - 尝试不同的定位器策略(id、xpath、accessibility_id)
- 确保正确的时间-元件可能需要时间才能加载
- 使用
-
Python环境问题
- 该包会自动创建虚拟环境
- 如果问题仍然存在,请检查Python 3.8+安装
- 验证依赖项安装的互联网连接
调试模式
集 DEBUG=1 详细日志记录的环境变量:
DEBUG=1 npx appium-mcp-server
发展
要修改或贡献此包,请执行以下操作:
git clone https://github.com/yourusername/appium-mcp-server.git
cd appium-mcp-server
npm install
npm link # for local testing
许可证
MIT许可证-有关详细信息,请参阅许可证文件。
贡献
欢迎投稿!请阅读贡献指南,并将拉取请求提交到主存储库。