xcode
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseXcode Build MCP
Xcode Build MCP
Build, test, run, and manage Xcode projects and Swift packages via the XcodeBuildMCP server.
通过XcodeBuildMCP服务器构建、测试、运行和管理Xcode项目与Swift包。
When to Use
使用场景
- User wants to build an iOS/macOS/watchOS/tvOS/visionOS app
- User wants to run tests on simulator or device
- User wants to launch an app on simulator or device
- User mentions "xcodebuild", "swift build", "swift test"
- User wants to scaffold a new iOS/macOS project
- User wants to interact with iOS simulator (tap, type, screenshot)
- User wants to capture logs from simulator or device
- User wants to discover Xcode projects in a directory
- 用户想要构建iOS/macOS/watchOS/tvOS/visionOS应用
- 用户想要在模拟器或设备上运行测试
- 用户想要在模拟器或设备上启动应用
- 用户提及"xcodebuild"、"swift build"、"swift test"
- 用户想要搭建新的iOS/macOS项目
- 用户想要与iOS模拟器交互(点击、输入、截图)
- 用户想要捕获模拟器或设备的日志
- 用户想要发现目录中的Xcode项目
Quick Reference
快速参考
All tools are called via mcporter using the XcodeBuildMCP server:
bash
bunx mcporter call --stdio "xcodebuildmcp" <tool_name> [args...]Assumes and are installed globally; runs the installed binaries and does not fetch them.
mcporterxcodebuildmcpbunx所有工具都通过mcporter调用XcodeBuildMCP服务器:
bash
bunx mcporter call --stdio "xcodebuildmcp" <tool_name> [args...]假设和已全局安装;会运行已安装的二进制文件,不会重新获取。
mcporterxcodebuildmcpbunxSession Defaults (IMPORTANT - Set First!)
会话默认设置(重要 - 首先设置!)
Before using most build/test tools, you MUST set session defaults:
bash
bunx mcporter call --stdio "xcodebuildmcp" session-set-defaults \
projectPath="/path/to/Project.xcodeproj" \
scheme="MyApp" \
simulatorName="iPhone 16"Or for a workspace:
bash
bunx mcporter call --stdio "xcodebuildmcp" session-set-defaults \
workspacePath="/path/to/Project.xcworkspace" \
scheme="MyApp" \
simulatorId="DEVICE_UDID"Check current defaults:
bash
bunx mcporter call --stdio "xcodebuildmcp" session-show-defaultsClear defaults:
bash
bunx mcporter call --stdio "xcodebuildmcp" session-clear-defaults all=true在使用大多数构建/测试工具之前,你必须设置会话默认值:
bash
bunx mcporter call --stdio "xcodebuildmcp" session-set-defaults \
projectPath="/path/to/Project.xcodeproj" \
scheme="MyApp" \
simulatorName="iPhone 16"或者针对工作区:
bash
bunx mcporter call --stdio "xcodebuildmcp" session-set-defaults \
workspacePath="/path/to/Project.xcworkspace" \
scheme="MyApp" \
simulatorId="DEVICE_UDID"查看当前默认值:
bash
bunx mcporter call --stdio "xcodebuildmcp" session-show-defaults清除默认值:
bash
bunx mcporter call --stdio "xcodebuildmcp" session-clear-defaults all=trueDiscovery Tools
发现工具
Find Xcode Projects
查找Xcode项目
bash
bunx mcporter call --stdio "xcodebuildmcp" discover_projs workspaceRoot="$(pwd)"bash
bunx mcporter call --stdio "xcodebuildmcp" discover_projs workspaceRoot="$(pwd)"List Schemes
列出Scheme
bash
bunx mcporter call --stdio "xcodebuildmcp" list_schemesbash
bunx mcporter call --stdio "xcodebuildmcp" list_schemesDoctor (Check Environment)
环境检查(Doctor)
bash
bunx mcporter call --stdio "xcodebuildmcp" doctorbash
bunx mcporter call --stdio "xcodebuildmcp" doctorSimulator Tools
模拟器工具
List Simulators
列出模拟器
bash
bunx mcporter call --stdio "xcodebuildmcp" list_simsbash
bunx mcporter call --stdio "xcodebuildmcp" list_simsBoot Simulator
启动模拟器
bash
bunx mcporter call --stdio "xcodebuildmcp" boot_simbash
bunx mcporter call --stdio "xcodebuildmcp" boot_simOpen Simulator App
打开模拟器应用
bash
bunx mcporter call --stdio "xcodebuildmcp" open_simbash
bunx mcporter call --stdio "xcodebuildmcp" open_simBuild for Simulator
为模拟器构建应用
bash
bunx mcporter call --stdio "xcodebuildmcp" build_simbash
bunx mcporter call --stdio "xcodebuildmcp" build_simBuild and Run on Simulator
构建并在模拟器上运行
bash
bunx mcporter call --stdio "xcodebuildmcp" build_run_simbash
bunx mcporter call --stdio "xcodebuildmcp" build_run_simRun Tests on Simulator
在模拟器上运行测试
bash
bunx mcporter call --stdio "xcodebuildmcp" test_simbash
bunx mcporter call --stdio "xcodebuildmcp" test_simGet Built App Path (Simulator)
获取已构建应用的路径(模拟器)
bash
bunx mcporter call --stdio "xcodebuildmcp" get_sim_app_path platform="iOS Simulator"bash
bunx mcporter call --stdio "xcodebuildmcp" get_sim_app_path platform="iOS Simulator"Install App on Simulator
在模拟器上安装应用
bash
bunx mcporter call --stdio "xcodebuildmcp" install_app_sim appPath="/path/to/App.app"bash
bunx mcporter call --stdio "xcodebuildmcp" install_app_sim appPath="/path/to/App.app"Launch App on Simulator
在模拟器上启动应用
bash
bunx mcporter call --stdio "xcodebuildmcp" launch_app_sim bundleId="com.example.MyApp"bash
bunx mcporter call --stdio "xcodebuildmcp" launch_app_sim bundleId="com.example.MyApp"Stop App on Simulator
在模拟器上停止应用
bash
bunx mcporter call --stdio "xcodebuildmcp" stop_app_sim bundleId="com.example.MyApp"bash
bunx mcporter call --stdio "xcodebuildmcp" stop_app_sim bundleId="com.example.MyApp"Simulator UI Automation
模拟器UI自动化
Take Screenshot
截图
bash
bunx mcporter call --stdio "xcodebuildmcp" screenshotbash
bunx mcporter call --stdio "xcodebuildmcp" screenshotDescribe UI (Get View Hierarchy)
描述UI(获取视图层级)
Gets precise frame coordinates for all visible elements - USE THIS before any UI interactions:
bash
bunx mcporter call --stdio "xcodebuildmcp" describe_ui获取所有可见元素的精确坐标 - 在进行任何UI交互前请使用此工具:
bash
bunx mcporter call --stdio "xcodebuildmcp" describe_uiTap
点击
bash
undefinedbash
undefinedTap by coordinates (use describe_ui first to get coordinates)
通过坐标点击(先使用describe_ui获取坐标)
bunx mcporter call --stdio "xcodebuildmcp" tap x=100 y=200
bunx mcporter call --stdio "xcodebuildmcp" tap x=100 y=200
Tap by accessibility ID
通过辅助功能ID点击
bunx mcporter call --stdio "xcodebuildmcp" tap id="myButton"
bunx mcporter call --stdio "xcodebuildmcp" tap id="myButton"
Tap by label
通过标签点击
bunx mcporter call --stdio "xcodebuildmcp" tap label="Submit"
undefinedbunx mcporter call --stdio "xcodebuildmcp" tap label="Submit"
undefinedLong Press
长按
bash
bunx mcporter call --stdio "xcodebuildmcp" long_press x=100 y=200 duration=1000bash
bunx mcporter call --stdio "xcodebuildmcp" long_press x=100 y=200 duration=1000Swipe
滑动
bash
bunx mcporter call --stdio "xcodebuildmcp" swipe x1=100 y1=400 x2=100 y2=100bash
bunx mcporter call --stdio "xcodebuildmcp" swipe x1=100 y1=400 x2=100 y2=100Gesture Presets
预设手势
bash
bunx mcporter call --stdio "xcodebuildmcp" gesture preset="scroll-down"bash
bunx mcporter call --stdio "xcodebuildmcp" gesture preset="scroll-down"Presets: scroll-up, scroll-down, scroll-left, scroll-right,
预设选项:scroll-up, scroll-down, scroll-left, scroll-right,
swipe-from-left-edge, swipe-from-right-edge,
swipe-from-left-edge, swipe-from-right-edge,
swipe-from-top-edge, swipe-from-bottom-edge
swipe-from-top-edge, swipe-from-bottom-edge
undefinedundefinedType Text
输入文本
bash
bunx mcporter call --stdio "xcodebuildmcp" type_text text="Hello World"bash
bunx mcporter call --stdio "xcodebuildmcp" type_text text="Hello World"Press Button
按下按钮
bash
bunx mcporter call --stdio "xcodebuildmcp" button buttonType="home"bash
bunx mcporter call --stdio "xcodebuildmcp" button buttonType="home"Types: apple-pay, home, lock, side-button, siri
按钮类型:apple-pay, home, lock, side-button, siri
undefinedundefinedKey Press
按键
bash
bunx mcporter call --stdio "xcodebuildmcp" key_press keyCode=40 # Return keybash
bunx mcporter call --stdio "xcodebuildmcp" key_press keyCode=40 # 返回键Common: 40=Return, 42=Backspace, 43=Tab, 44=Space
常用键码:40=Return, 42=Backspace, 43=Tab, 44=Space
undefinedundefinedSimulator Settings
模拟器设置
Set Appearance (Dark/Light Mode)
设置外观(深色/浅色模式)
bash
bunx mcporter call --stdio "xcodebuildmcp" set_sim_appearance mode="dark"bash
bunx mcporter call --stdio "xcodebuildmcp" set_sim_appearance mode="dark"Set Location
设置位置
bash
bunx mcporter call --stdio "xcodebuildmcp" set_sim_location latitude=37.7749 longitude=-122.4194bash
bunx mcporter call --stdio "xcodebuildmcp" set_sim_location latitude=37.7749 longitude=-122.4194Reset Location
重置位置
bash
bunx mcporter call --stdio "xcodebuildmcp" reset_sim_locationbash
bunx mcporter call --stdio "xcodebuildmcp" reset_sim_locationSet Status Bar Network
设置状态栏网络
bash
bunx mcporter call --stdio "xcodebuildmcp" sim_statusbar dataNetwork="5g"bash
bunx mcporter call --stdio "xcodebuildmcp" sim_statusbar dataNetwork="5g"Options: clear, hide, wifi, 3g, 4g, lte, lte-a, lte+, 5g, 5g+, 5g-uwb, 5g-uc
选项:clear, hide, wifi, 3g, 4g, lte, lte-a, lte+, 5g, 5g+, 5g-uwb, 5g-uc
undefinedundefinedErase Simulator
重置模拟器
bash
bunx mcporter call --stdio "xcodebuildmcp" erase_sims shutdownFirst=truebash
bunx mcporter call --stdio "xcodebuildmcp" erase_sims shutdownFirst=trueSimulator Log Capture
模拟器日志捕获
Start Log Capture
开始日志捕获
bash
bunx mcporter call --stdio "xcodebuildmcp" start_sim_log_cap bundleId="com.example.MyApp"bash
bunx mcporter call --stdio "xcodebuildmcp" start_sim_log_cap bundleId="com.example.MyApp"Returns a logSessionId
返回一个logSessionId
undefinedundefinedStop Log Capture
停止日志捕获
bash
bunx mcporter call --stdio "xcodebuildmcp" stop_sim_log_cap logSessionId="SESSION_ID"bash
bunx mcporter call --stdio "xcodebuildmcp" stop_sim_log_cap logSessionId="SESSION_ID"Video Recording
视频录制
Start Recording
开始录制
bash
bunx mcporter call --stdio "xcodebuildmcp" record_sim_video start=truebash
bunx mcporter call --stdio "xcodebuildmcp" record_sim_video start=trueStop Recording
停止录制
bash
bunx mcporter call --stdio "xcodebuildmcp" record_sim_video stop=true outputFile="/path/to/output.mp4"bash
bunx mcporter call --stdio "xcodebuildmcp" record_sim_video stop=true outputFile="/path/to/output.mp4"Physical Device Tools
物理设备工具
List Connected Devices
列出已连接设备
bash
bunx mcporter call --stdio "xcodebuildmcp" list_devicesbash
bunx mcporter call --stdio "xcodebuildmcp" list_devicesBuild for Device
为设备构建应用
bash
bunx mcporter call --stdio "xcodebuildmcp" build_devicebash
bunx mcporter call --stdio "xcodebuildmcp" build_deviceTest on Device
在设备上运行测试
bash
bunx mcporter call --stdio "xcodebuildmcp" test_devicebash
bunx mcporter call --stdio "xcodebuildmcp" test_deviceInstall App on Device
在设备上安装应用
bash
bunx mcporter call --stdio "xcodebuildmcp" install_app_device appPath="/path/to/App.app"bash
bunx mcporter call --stdio "xcodebuildmcp" install_app_device appPath="/path/to/App.app"Launch App on Device
在设备上启动应用
bash
bunx mcporter call --stdio "xcodebuildmcp" launch_app_device bundleId="com.example.MyApp"bash
bunx mcporter call --stdio "xcodebuildmcp" launch_app_device bundleId="com.example.MyApp"Stop App on Device
在设备上停止应用
bash
bunx mcporter call --stdio "xcodebuildmcp" stop_app_device processId=12345bash
bunx mcporter call --stdio "xcodebuildmcp" stop_app_device processId=12345Device Log Capture
设备日志捕获
bash
undefinedbash
undefinedStart
开始
bunx mcporter call --stdio "xcodebuildmcp" start_device_log_cap bundleId="com.example.MyApp"
bunx mcporter call --stdio "xcodebuildmcp" start_device_log_cap bundleId="com.example.MyApp"
Stop
停止
bunx mcporter call --stdio "xcodebuildmcp" stop_device_log_cap logSessionId="SESSION_ID"
undefinedbunx mcporter call --stdio "xcodebuildmcp" stop_device_log_cap logSessionId="SESSION_ID"
undefinedmacOS Tools
macOS工具
Build macOS App
构建macOS应用
bash
bunx mcporter call --stdio "xcodebuildmcp" build_macosbash
bunx mcporter call --stdio "xcodebuildmcp" build_macosBuild and Run macOS App
构建并运行macOS应用
bash
bunx mcporter call --stdio "xcodebuildmcp" build_run_macosbash
bunx mcporter call --stdio "xcodebuildmcp" build_run_macosTest macOS App
测试macOS应用
bash
bunx mcporter call --stdio "xcodebuildmcp" test_macosbash
bunx mcporter call --stdio "xcodebuildmcp" test_macosGet macOS App Path
获取macOS应用路径
bash
bunx mcporter call --stdio "xcodebuildmcp" get_mac_app_pathbash
bunx mcporter call --stdio "xcodebuildmcp" get_mac_app_pathLaunch macOS App
启动macOS应用
bash
bunx mcporter call --stdio "xcodebuildmcp" launch_mac_app appPath="/path/to/App.app"bash
bunx mcporter call --stdio "xcodebuildmcp" launch_mac_app appPath="/path/to/App.app"Stop macOS App
停止macOS应用
bash
bunx mcporter call --stdio "xcodebuildmcp" stop_mac_app appName="MyApp"bash
bunx mcporter call --stdio "xcodebuildmcp" stop_mac_app appName="MyApp"Swift Package Tools
Swift包工具
Build Package
构建包
bash
bunx mcporter call --stdio "xcodebuildmcp" swift_package_build packagePath="$(pwd)"bash
bunx mcporter call --stdio "xcodebuildmcp" swift_package_build packagePath="$(pwd)"Test Package
测试包
bash
bunx mcporter call --stdio "xcodebuildmcp" swift_package_test packagePath="$(pwd)"bash
bunx mcporter call --stdio "xcodebuildmcp" swift_package_test packagePath="$(pwd)"Run Package Executable
运行包可执行文件
bash
bunx mcporter call --stdio "xcodebuildmcp" swift_package_run packagePath="$(pwd)"bash
bunx mcporter call --stdio "xcodebuildmcp" swift_package_run packagePath="$(pwd)"Clean Package
清理包
bash
bunx mcporter call --stdio "xcodebuildmcp" swift_package_clean packagePath="$(pwd)"bash
bunx mcporter call --stdio "xcodebuildmcp" swift_package_clean packagePath="$(pwd)"List Running Packages
列出运行中的包
bash
bunx mcporter call --stdio "xcodebuildmcp" swift_package_listbash
bunx mcporter call --stdio "xcodebuildmcp" swift_package_listStop Package Process
停止包进程
bash
bunx mcporter call --stdio "xcodebuildmcp" swift_package_stop pid=12345bash
bunx mcporter call --stdio "xcodebuildmcp" swift_package_stop pid=12345Project Scaffolding
项目搭建
Create New iOS Project
创建新iOS项目
bash
bunx mcporter call --stdio "xcodebuildmcp" scaffold_ios_project \
projectName="MyApp" \
outputPath="$(pwd)" \
bundleIdentifier="com.example.myapp"bash
bunx mcporter call --stdio "xcodebuildmcp" scaffold_ios_project \
projectName="MyApp" \
outputPath="$(pwd)" \
bundleIdentifier="com.example.myapp"Create New macOS Project
创建新macOS项目
bash
bunx mcporter call --stdio "xcodebuildmcp" scaffold_macos_project \
projectName="MyMacApp" \
outputPath="$(pwd)" \
bundleIdentifier="com.example.mymacapp"bash
bunx mcporter call --stdio "xcodebuildmcp" scaffold_macos_project \
projectName="MyMacApp" \
outputPath="$(pwd)" \
bundleIdentifier="com.example.mymacapp"Utility Tools
实用工具
Clean Build
清理构建
bash
bunx mcporter call --stdio "xcodebuildmcp" cleanbash
bunx mcporter call --stdio "xcodebuildmcp" cleanShow Build Settings
显示构建设置
bash
bunx mcporter call --stdio "xcodebuildmcp" show_build_settingsbash
bunx mcporter call --stdio "xcodebuildmcp" show_build_settingsGet Bundle ID from App
从应用获取Bundle ID
bash
bunx mcporter call --stdio "xcodebuildmcp" get_app_bundle_id appPath="/path/to/App.app"bash
bunx mcporter call --stdio "xcodebuildmcp" get_app_bundle_id appPath="/path/to/App.app"Typical Workflows
典型工作流程
Build and Test iOS App on Simulator
在模拟器上构建并测试iOS应用
bash
undefinedbash
undefined1. Discover projects
1. 发现项目
bunx mcporter call --stdio "xcodebuildmcp" discover_projs workspaceRoot="$(pwd)"
bunx mcporter call --stdio "xcodebuildmcp" discover_projs workspaceRoot="$(pwd)"
2. List simulators
2. 列出模拟器
bunx mcporter call --stdio "xcodebuildmcp" list_sims
bunx mcporter call --stdio "xcodebuildmcp" list_sims
3. Set session defaults
3. 设置会话默认值
bunx mcporter call --stdio "xcodebuildmcp" session-set-defaults
projectPath="$(pwd)/MyApp.xcodeproj"
scheme="MyApp"
simulatorName="iPhone 16"
projectPath="$(pwd)/MyApp.xcodeproj"
scheme="MyApp"
simulatorName="iPhone 16"
bunx mcporter call --stdio "xcodebuildmcp" session-set-defaults
projectPath="$(pwd)/MyApp.xcodeproj"
scheme="MyApp"
simulatorName="iPhone 16"
projectPath="$(pwd)/MyApp.xcodeproj"
scheme="MyApp"
simulatorName="iPhone 16"
4. Build and run
4. 构建并运行
bunx mcporter call --stdio "xcodebuildmcp" build_run_sim
bunx mcporter call --stdio "xcodebuildmcp" build_run_sim
5. Run tests
5. 运行测试
bunx mcporter call --stdio "xcodebuildmcp" test_sim
undefinedbunx mcporter call --stdio "xcodebuildmcp" test_sim
undefinedUI Testing Flow
UI测试流程
bash
undefinedbash
undefined1. Build and launch app
1. 构建并启动应用
bunx mcporter call --stdio "xcodebuildmcp" build_run_sim
bunx mcporter call --stdio "xcodebuildmcp" build_run_sim
2. Get UI hierarchy (ALWAYS do this before interacting)
2. 获取UI层级(交互前务必执行此操作)
bunx mcporter call --stdio "xcodebuildmcp" describe_ui
bunx mcporter call --stdio "xcodebuildmcp" describe_ui
3. Take screenshot for visual reference
3. 截图作为视觉参考
bunx mcporter call --stdio "xcodebuildmcp" screenshot
bunx mcporter call --stdio "xcodebuildmcp" screenshot
4. Interact with elements using coordinates from describe_ui
4. 使用describe_ui获取的坐标与元素交互
bunx mcporter call --stdio "xcodebuildmcp" tap x=187 y=423
bunx mcporter call --stdio "xcodebuildmcp" tap x=187 y=423
5. Type text
5. 输入文本
bunx mcporter call --stdio "xcodebuildmcp" type_text text="test@example.com"
undefinedbunx mcporter call --stdio "xcodebuildmcp" type_text text="test@example.com"
undefinedError Handling
错误处理
| Error | Cause | Solution |
|---|---|---|
| No project/workspace set | Session defaults not configured | Run |
| Simulator not found | Invalid simulator name | Run |
| Build failed | Code errors or config issues | Check build output, run |
| App not installed | Build didn't complete | Run |
| 错误 | 原因 | 解决方案 |
|---|---|---|
| 未设置项目/工作区 | 未配置会话默认值 | 首先运行 |
| 未找到模拟器 | 模拟器名称无效 | 运行 |
| 构建失败 | 代码错误或配置问题 | 检查构建输出,运行 |
| 应用未安装 | 构建未完成 | 在 |
Tips
提示
- Always set session defaults first - Most tools require project/scheme/simulator to be set
- Use describe_ui before UI interactions - Never guess coordinates from screenshots
- Check doctor for environment issues - Run if tools aren't working
doctor - Use preferXcodebuild=true if incremental builds fail - Falls back to standard xcodebuild
- 始终首先设置会话默认值 - 大多数工具需要设置项目/Scheme/模拟器
- 在UI交互前使用describe_ui - 不要通过截图猜测坐标
- 使用doctor检查环境问题 - 如果工具无法工作,运行
doctor - 如果增量构建失败,使用preferXcodebuild=true - 回退到标准xcodebuild