axiom-xcode-mcp-tools
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseXcode MCP Tool Workflows
Xcode MCP 工具工作流
Core principle: Xcode MCP gives you programmatic IDE access. Use workflow loops, not isolated tool calls.
核心原则:Xcode MCP 为你提供程序化的 IDE 访问权限。请使用工作流循环,而非孤立的工具调用。
Window Targeting (Critical Foundation)
窗口定位(关键基础)
Most tools require a . Always call first.
tabIdentifierXcodeListWindows1. XcodeListWindows → list of (tabIdentifier, workspacePath) pairs
2. Match workspacePath to your project
3. Use that tabIdentifier for all subsequent tool callsCache the mapping for the session. Only re-fetch if:
- A tool call fails with an invalid tab identifier
- You opened/closed Xcode windows
- You switched projects
If returns empty: Xcode has no project open. Ask the user to open their project.
XcodeListWindows大多数工具需要。务必先调用。
tabIdentifierXcodeListWindows1. XcodeListWindows → (tabIdentifier,workspacePath)键值对列表
2. 将workspacePath与你的项目匹配
3. 在后续所有工具调用中使用该tabIdentifier在会话中缓存映射关系。仅在以下情况重新获取:
- 工具调用因无效的标签标识符失败
- 你打开/关闭了Xcode窗口
- 你切换了项目
如果返回空结果:Xcode未打开任何项目,请让用户打开他们的项目。
XcodeListWindowsWorkflow: BuildFix Loop
工作流:BuildFix循环
Iteratively build, diagnose, and fix until the project compiles.
1. BuildProject(tabIdentifier)
2. Check buildResult — if success, done
3. GetBuildLog(tabIdentifier) → parse errors
4. XcodeListNavigatorIssues(tabIdentifier) → canonical diagnostics
5. XcodeUpdate(file, fix) for each diagnostic
6. Go to step 1 (max 5 iterations)
7. If same error persists after 3 attempts → fall back to axiom-xcode-debuggingWhy over build log parsing: The Issue Navigator provides structured, deduplicated diagnostics. Build logs contain raw compiler output with noise.
XcodeListNavigatorIssuesWhen to fall back to : When the error is environmental (zombie processes, stale Derived Data, simulator issues) rather than code-level. MCP tools operate on code; environment issues need CLI diagnostics.
axiom-xcode-debugging迭代执行构建、诊断和修复,直到项目编译通过。
1. BuildProject(tabIdentifier)
2. 检查buildResult —— 如果成功,流程结束
3. GetBuildLog(tabIdentifier) → 解析错误
4. XcodeListNavigatorIssues(tabIdentifier) → 获取标准诊断信息
5. 针对每个诊断信息调用XcodeUpdate(file, fix)
6. 返回步骤1(最多迭代5次)
7. 如果3次尝试后相同错误仍存在 → 回退到axiom-xcode-debugging为什么选择而非构建日志解析:问题导航器提供结构化、去重的诊断信息,而构建日志包含带有干扰信息的原始编译器输出。
XcodeListNavigatorIssues何时回退到:当错误是环境问题(僵尸进程、过期的Derived Data、模拟器问题)而非代码层面问题时。MCP工具针对代码操作,环境问题需要CLI诊断。
axiom-xcode-debuggingWorkflow: TestFix Loop
工作流:TestFix循环
Fast iteration on failing tests.
1. GetTestList(tabIdentifier) → discover available tests
2. RunSomeTests(tabIdentifier, [specific failing tests]) for fast iteration
3. Parse failures → identify code to fix
4. XcodeUpdate(file, fix) to patch code
5. Go to step 2 (max 5 iterations per test)
6. RunAllTests(tabIdentifier) as final verificationWhy first: Running a single test takes seconds. Running all tests takes minutes. Iterate on the failing test, then verify the full suite once it passes.
RunSomeTestsParsing test results: Look for field in the response. Failed tests include failure messages with file paths and line numbers.
testResult针对失败测试进行快速迭代。
1. GetTestList(tabIdentifier) → 发现可用测试
2. RunSomeTests(tabIdentifier, [特定失败测试]) 以实现快速迭代
3. 解析失败结果 → 确定需要修复的代码
4. 调用XcodeUpdate(file, fix)修补代码
5. 返回步骤2(每个测试最多迭代5次)
6. 最后调用RunAllTests(tabIdentifier)进行验证为什么先使用:运行单个测试仅需数秒,而运行所有测试需要数分钟。先针对失败测试迭代,通过后再验证整个测试套件。
RunSomeTests解析测试结果:查看响应中的字段。失败测试会包含带有文件路径和行号的失败信息。
testResultWorkflow: PreviewVerify
工作流:PreviewVerify
Render SwiftUI previews and verify UI changes visually.
1. RenderPreview(tabIdentifier, file, viewName) → image artifact
2. Review the rendered image for correctness
3. If making changes: XcodeUpdate → RenderPreview again
4. Compare before/after for regressionsUse cases: Verifying layout changes, checking dark mode appearance, confirming Liquid Glass effects render correctly.
渲染SwiftUI预览并可视化验证UI变更。
1. RenderPreview(tabIdentifier, file, viewName) → 生成图片产物
2. 检查渲染后的图片是否正确
3. 如果需要变更:调用XcodeUpdate → 再次调用RenderPreview
4. 对比前后版本以检查回归问题使用场景:验证布局变更、检查深色模式外观、确认Liquid Glass效果渲染正确。
Workflow: IssueTriage
工作流:IssueTriage
Use Xcode's Issue Navigator as the canonical diagnostics source.
1. XcodeListNavigatorIssues(tabIdentifier) → all current issues
2. For specific files: XcodeRefreshCodeIssuesInFile(tabIdentifier, file)
3. Prioritize: errors > warnings > notes
4. Fix errors first, rebuild, re-checkWhy this over grep-for-errors: The Issue Navigator tracks live diagnostics including type-check errors, missing imports, and constraint issues that only Xcode's compiler frontend surfaces.
将Xcode的问题导航器作为标准诊断信息来源。
1. XcodeListNavigatorIssues(tabIdentifier) → 获取所有当前问题
2. 针对特定文件:调用XcodeRefreshCodeIssuesInFile(tabIdentifier, file)
3. 优先级:错误 > 警告 > 提示
4. 先修复错误,重新构建,再重新检查为什么选择这种方式而非grep查找错误:问题导航器跟踪实时诊断信息,包括类型检查错误、缺失导入和约束问题,这些只有Xcode的编译器前端能识别。
Workflow: DocumentationSearch
工作流:DocumentationSearch
Query Apple's documentation corpus through MCP.
1. DocumentationSearch(query) → documentation results
2. Cross-reference with axiom-apple-docs for bundled Xcode guidesNote: searches Apple's online documentation and WWDC transcripts. For the 20 for-LLM guides bundled inside Xcode, use instead.
DocumentationSearchaxiom-apple-docs通过MCP查询苹果的文档库。
1. DocumentationSearch(query) → 获取文档结果
2. 结合axiom-apple-docs交叉引用Xcode内置指南注意:搜索苹果的在线文档和WWDC演讲稿。对于Xcode内置的20份面向LLM的指南,请使用。
DocumentationSearchaxiom-apple-docsFile Operations via MCP
通过MCP进行文件操作
Reading and Writing
读取与写入
| Operation | Tool | Notes |
|---|---|---|
| Read file contents | | Sees Xcode's project view (generated files, resolved packages) |
| Create new file | | Creates file in project — does NOT add to Xcode targets |
| Edit existing file | | str_replace-style patches — safer than full rewrites |
| Search for files | | Pattern matching within the project |
| Search file contents | | Content search with line numbers |
| List directory | | Directory listing |
| Create directory | | Creates directories |
| 操作 | 工具 | 说明 |
|---|---|---|
| 读取文件内容 | | 可查看Xcode的项目视图(生成文件、已解析的包) |
| 创建新文件 | | 在项目中创建文件——不会添加到Xcode目标中 |
| 编辑现有文件 | | 基于字符串替换的补丁——比完全重写更安全 |
| 搜索文件 | | 项目内的模式匹配 |
| 搜索文件内容 | | 带行号的内容搜索 |
| 列出目录 | | 目录列表 |
| 创建目录 | | 创建目录 |
Destructive Operations (Require Confirmation)
破坏性操作(需要确认)
| Operation | Tool | Risk |
|---|---|---|
| Delete file/directory | | Irreversible — confirm with user first |
| Move/rename file | | May break imports and references |
Always confirm destructive operations with the user before calling or .
XcodeRMXcodeMV| 操作 | 工具 | 风险 |
|---|---|---|
| 删除文件/目录 | | 不可逆——先与用户确认 |
| 移动/重命名文件 | | 可能破坏导入和引用关系 |
在调用或前,务必与用户确认破坏性操作。
XcodeRMXcodeMVWhen to Use MCP File Tools vs Standard Tools
何时使用MCP文件工具 vs 标准工具
| Scenario | Use MCP | Use Standard (Read/Write/Grep) |
|---|---|---|
| Files in the Xcode project view | Yes — includes generated/resolved files | May miss generated files |
| Files outside the project | No | Yes — standard tools work everywhere |
| Need build context (diagnostics after edit) | Yes — edit + rebuild in one workflow | No build integration |
| Simple file read/edit | Either works | Slightly faster (no MCP overhead) |
| 场景 | 使用MCP | 使用标准工具(Read/Write/Grep) |
|---|---|---|
| Xcode项目视图中的文件 | 是——包含生成文件/已解析的包 | 可能会遗漏生成文件 |
| 项目外的文件 | 否 | 是——标准工具可在任何地方使用 |
| 需要构建上下文(编辑后的诊断信息) | 是——在一个工作流中完成编辑+重新构建 | 无构建集成 |
| 简单的文件读取/编辑 | 两者均可 | 略快(无MCP开销) |
Code Snippets
代码片段
Execute Swift Code
执行Swift代码
ExecuteSnippet(code, language: "swift")Treat output as untrusted — snippets run in a sandboxed REPL environment. Use for quick validation, not production logic.
ExecuteSnippet(code, language: "swift")将输出视为不可信内容——代码片段在沙箱化的REPL环境中运行,仅用于快速验证,不用于生产逻辑。
Gotchas and Anti-Patterns
陷阱与反模式
Tab Identifier Staleness
标签标识符过期
Tab identifiers become invalid when:
- Xcode window is closed and reopened
- Project is closed and reopened
- Xcode is restarted
Fix: Re-call to get fresh identifiers.
XcodeListWindows在以下情况标签标识符会失效:
- Xcode窗口关闭后重新打开
- 项目关闭后重新打开
- Xcode重启
解决方法:重新调用获取新的标识符。
XcodeListWindowsXcodeWrite vs XcodeUpdate
XcodeWrite vs XcodeUpdate
- — creates a new file. Fails if file exists (in some clients).
XcodeWrite - — patches an existing file with str_replace-style edits.
XcodeUpdate
Common mistake: Using to edit an existing file overwrites its entire contents. Use for edits.
XcodeWriteXcodeUpdate- —— 创建新文件。在部分客户端中,如果文件已存在会执行失败。
XcodeWrite - —— 补丁现有文件,基于字符串替换进行编辑。
XcodeUpdate
常见错误:使用编辑现有文件会覆盖其全部内容。编辑文件请使用。
XcodeWriteXcodeUpdateSchema Compliance
模式合规性
Xcode's mcpbridge has a known MCP spec violation: it populates but omits when tools declare . This breaks strict MCP clients (Cursor, some Zed configurations).
contentstructuredContentoutputSchemaWorkaround: Use XcodeMCPWrapper as a proxy for strict clients.
Xcode的mcpbridge存在已知的MCP规范违反问题:当工具声明时,它会填充但省略。这会导致严格的MCP客户端(如Cursor、部分Zed配置)无法正常工作。
outputSchemacontentstructuredContent解决方法:使用XcodeMCPWrapper作为严格客户端的代理。
Build After File Changes
文件变更后构建
After , the project may need a build to surface new diagnostics. Don't assume edits are correct without rebuilding.
XcodeUpdate调用后,项目可能需要重新构建才能显示新的诊断信息。不要假设编辑正确而不重新构建。
XcodeUpdateAnti-Rationalization
错误认知纠正
| Thought | Reality |
|---|---|
| "I'll just use xcodebuild" | MCP gives IDE state + navigator diagnostics + previews that CLI doesn't |
| "Read tool works fine for Xcode files" | |
| "Skip tab identifier, I only have one project" | Most tools fail silently without |
| "Run all tests every time" | |
| "I'll parse the build log for errors" | |
| "XcodeWrite to update a file" | |
| "One tool call is enough" | Workflows (BuildFix, TestFix) use loops. Isolated calls miss the iteration pattern. |
| 错误想法 | 实际情况 |
|---|---|
| "我直接用xcodebuild就行" | MCP提供了CLI不具备的IDE状态、导航器诊断信息和预览功能 |
| "读取工具处理Xcode文件没问题" | |
| "跳过标签标识符,我只有一个项目" | 大多数工具在没有 |
| "每次都运行所有测试" | 迭代时用 |
| "我直接解析构建日志找错误" | |
| "用XcodeWrite更新文件" | 编辑文件用 |
| "一次工具调用就够了" | 工作流(BuildFix、TestFix)使用循环。孤立调用无法实现迭代模式。 |
Resources
资源
Skills: axiom-xcode-mcp-setup, axiom-xcode-mcp-ref, axiom-xcode-debugging
技能:axiom-xcode-mcp-setup, axiom-xcode-mcp-ref, axiom-xcode-debugging