Xcode MCP Preview
Overview
Render SwiftUI previews using Xcode's active scheme and run destination, then report whether a snapshot became available.
Tool Availability
Before calling MCP tools, confirm the mcp__xcode namespace is available. If it is not available, use tool_search to expose Xcode MCP tools; if the tools still are not available, tell the user Xcode MCP is not connected and stop rather than attempting a non-Xcode preview path.
Workflow
- Discover Xcode tabs with
mcp__xcode.XcodeListWindows. - Select the
tabIdentifierfor the workspace/project containing the SwiftUI file. - Identify the
sourceFilePathas the path within Xcode's project organization, not necessarily an absolute filesystem path. - If the file has multiple previews and the user specifies one, count preview declarations from the top using zero-based indexes and pass
previewDefinitionIndexInFile; the first preview is0, the second is1. - Call
mcp__xcode.RenderPreviewwith a reasonable timeout. Use a longer timeout for large projects. - If rendering fails, inspect
mcp__xcode.GetBuildLogandmcp__xcode.XcodeListNavigatorIssues.
Variant Overrides
- If a previous
RenderPreviewresult listssupportedPreviewVariantOverrides, use only those exact group and variant names. - Do not invent preview variant names.
- When the user does not request a variant, render the default variant.
Reporting
- State the source file path, preview index, and selected Xcode tab.
- Report whether the preview rendered, failed to build, timed out, or could not be found.
- Include relevant build errors if preview rendering fails.
Constraints
- Use this only for SwiftUI previews; for full app launch or Simulator interaction, use a separate simulator/debugging workflow if available.
- If no simulator/debugging workflow is available, report that this skill only covers SwiftUI preview rendering instead of inventing an app launch path.
- Do not edit preview code unless the user asks for a fix.