Appium Python MCP服务器
一个用于Appium移动自动化的综合MCP(模型上下文协议)服务器,使用FastAPI构建。
特性
- 会话管理:创建、管理和跟踪Appium会话
- 设备处理:列出已连接的Android/iOS设备并与之交互
- 命令处理:通过RESTful API执行Appium命令
- 异步支持:基于FastAPI构建,用于高性能异步操作
安装
使用pip安装依赖项:
pip install -r requirements.txt或者使用诗歌:
poetry install快速开始
运行服务器
python main.py服务器将于启动 http://0.0.0.0:8000 默认情况下。
对于自定义主机/端口:
python main.py --host localhost --port 5000对于自动重新加载的开发:
python main.py --reloadAPI 文档
服务器运行后,请访问:
- Swagger用户界面:
http://localhost:8000/docs - 重新记录:
http://localhost:8000/redoc
API终点
健康检查
GET /-根端点GET /health-健康检查
会话管理
POST /session/-创建新的Appium会话GET /session/{session_id}-获取会话详细信息DELETE /session/{session_id}-删除会话GET /sessions/-列出所有活动会话
命令处理
POST /command/-执行Appium命令
设备管理
GET /devices/-列出所有连接的设备GET /device/{device_id}-获取设备状态POST /device/command/-向设备发送命令
服务器管理
POST /server/cleanup-清理过期会话
使用示例
创建会话
curl -X POST "http://localhost:8000/session/" \
-H "Content-Type: application/json" \
-d '{
"platform_name": "Android",
"device_name": "emulator-5554",
"app": "/path/to/app.apk",
"automation_name": "UiAutomator2"
}'列出设备
curl -X GET "http://localhost:8000/devices/"执行命令
curl -X POST "http://localhost:8000/command/" \
-H "Content-Type: application/json" \
-d '{
"session_id": "your-session-id",
"command": "tap",
"parameters": {"x": 100, "y": 200}
}'发展
运行测试
pytest tests/ -v项目结构
appium-python-mcp/
├── appium_driver/ # Appium driver wrapper
│ ├── __init__.py
│ └── driver.py
├── mcp_server/ # FastAPI server
│ ├── __init__.py
│ └── server.py
├── src/ # Core functionality
│ ├── __init__.py
│ ├── session_manager.py
│ └── device_handler.py
├── tests/ # Test suite
│ ├── __init__.py
│ └── test_session_manager.py
├── main.py # Entry point
├── requirements.txt # Dependencies
└── pyproject.toml # Project configuration需求
- Python 3.8+
- Appium服务器(用于移动自动化)
- ADB(适用于Android设备)
许可证
麻省理工学院
