Check SwiftUI preview layouts by rendering them through Xcode MCP

An iOS developer connected Claude Code to Xcode's MCP bridge and gave a locked-down subagent four tools to render SwiftUI previews and check layouts, at about 30 to 90 seconds a snapshot.

Done withClaude Code· Oct 31, 2026

What they did

The author, who writes as Mochi Mochi, registered Xcode's built-in MCP server (xcrun mcpbridge, available since Xcode 26.3) with Claude Code and allowed external agents in Xcode's Intelligence settings. The server exposed 54 tools on Xcode 27.2. Rather than route everything through it, the author kept everyday builds and tests on plain xcodebuild in the terminal and used the Xcode tools for one job: rendering SwiftUI previews so the agent could look at a snapshot and check the layout. That work runs in a Claude Code subagent defined in .claude/agents/, which opens the project in a headless Xcode, renders the preview, closes the project and hands back only the result. An AGENTS.md file tells the agent the scheme, to confirm builds pass, and never to touch signing or bundle settings. They also tried the same setup with the Codex CLI.

How it went

Preview snapshots worked. The first open, render and close sequence took 86 seconds; with the trimmed subagent, runs took 31 and 32 seconds with no errors. Listing only four Xcode tools in the subagent's tools field did not limit it: it could still see all 54, and a write call went through and added a file to the project. Putting the other 50 tools in disallowedTools did remove them, which the author confirmed in Claude Code's debug log, not just the subagent's own report. In Codex, an enabled_tools list in the config blocked the rest. None of the Xcode tools report code coverage, so that stays on xcodebuild and xccov.

Worth knowing

Do not trust a subagent's tools list to restrict MCP tools; block the ones you do not want with disallowedTools and check what the subagent can see. The first time the agent opens a project, Xcode asks for access, and the grant covers every project under that folder. A project opened only in the Xcode window is invisible to the agent. Tested on Xcode 27.2 and Claude Code 2.1.316.

Try it

With Claude Code· 4 parts to fill in

Use a subagent that can only call the xcode MCP tools XcodeOpenWorkspace, RenderPreview, XcodeCloseWorkspace and XcodeListWorkspaces. Open [absolute path to my .xcodeproj], render the SwiftUI preview for [view name], then close the workspace. Look at the snapshot and tell me whether the layout matches [what I expect, e.g. no clipped text at the smallest device width]. List any layout problems with the line in [file] that likely causes each one. Do not edit any files, and do not touch signing or build settings. Stop after reporting.

Square brackets are the parts to fill in. The prompt is ours; the story is theirs.

Where they said it

Related