Prefire MCP server
Commit Nov 13, 2026Renders SwiftUI #Preview blocks as PNG images and snapshot tests so AI agents can see the views they change.
Also known as BarredEwe/Prefire
- Stars
- 535
- Tools
- —
- Downloads, 30 days
- —
- Latest version
- 6.6.1
- Last commit
- Nov 13, 2026
- License
- Apache-2.0
What is Prefire MCP?
Prefire renders SwiftUI #Preview blocks as PNG images and snapshot tests so AI agents can see the views they change.
Summary generated from the project's README
About Prefire MCP server
SwiftUI developers can use Prefire to transform standard #Preview blocks into automated snapshot tests and interactive component catalogs. By integrating this tool, your existing previews become a source of truth for testing UI regressions across various devices, color schemes, and dynamic type settings without writing additional test code. It works through Swift Package Manager, Xcode build tool plugins, or a command line interface.
AI agents like Claude Code, Cursor, and Codex can use the Prefire MCP server to visually verify the user interface changes they make. The server allows agents to call tools such as list_previews, render_previews, and build_board to receive PNG images of SwiftUI views. This setup enables an agent to render previews on specific hardware like an iPhone 16 Pro in dark mode, providing a visual feedback loop that does not require a running instance of Xcode.
What you can do with it
- 1Visual verification for AI agentsAn AI agent can render SwiftUI previews as PNG images to see the UI it just modified.
- 2Automated snapshot testingTurn existing preview blocks into automated tests that fail the build if a UI change occurs.
- 3Interactive component catalogingGenerate a Playbook to view all app components and user stories in one interactive catalog.
Written from the project's README. Every use case is checked against a quote from it.
Automated checks
Ran Nov 12, 2026Full report →Not verified yet. A server needs a score of 80, no serious finding, and enough data for us to check. How checks work · What to fix for more points
- Source repository linked and reachablePass
- Open source license (OSI)Pass
- Commit or release in the last yearPass
- Package name not close to a popular packageNot checked
- Remote endpoint uses HTTPSNot checked
- Destructive tools are labelledNot checked
- No hidden instructions to the modelPass
- No critical advisory in the package or its dependenciesNot checked
README
View on GitHub🔥 What is Prefire?
Your previews are already tests. Prefire turns the #Preview blocks you write anyway into snapshot tests, a Playbook catalog and images your AI agent can see. You don't write a line of test code.
🤖 Using an AI agent?
brew install barredewe/prefire/prefire, thenclaude mcp add prefire -- prefire mcpin your project. The agent renders SwiftUI previews on any iPhone or iPad, light or dark, without Xcode Previews. Setup →
🚀 Key Features
- 🧠 Smart Preview Parsing — including
#Preview,@Previewable - 📸 Snapshot Testing — automatic test generation from previews (iOS, tvOS, macOS)
- 📚 Playbook View — auto-generated interactive component catalog (iOS)
- 🏃 Flow-aware — build user stories from multiple preview steps
- 🤖 AI-ready — render previews to PNG for agents with
prefire renderand an MCP server - 🧩 UIKit + AppKit Support — support for
UIView/UIViewControllerandNSView/NSViewController - ⚙️ SPM + Xcode Plugins — works in CLI, Xcode build phases, or CI
- 🧠 Fast Caching — fingerprint-based AST and body caching avoids redundant work
- ✍️ Stencil Templates — customize output with your own templates
Why Prefire?
- 🔥 No second set of UI states. Tests come from the previews you already keep up to date.
- 🔥 Regressions fail CI. Snapshots are compared on every run, on every device you list.
- 🔥 Designers and QA see every state. Playbook shows components and user stories on a device.
- 🔥 Agents check their own UI work. They render the previews they changed before calling a task done.
⚡ Quick Start
📦 Example project available at: Prefire Example
1. Add Prefire to Your Project
// Package.swift
dependencies: [
.package(url: "https://github.com/BarredEwe/Prefire.git", from: "6.3.0"),
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.18.0"),
],
.testTarget(
dependencies: [
.product(name: "Prefire", package: "Prefire"),
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
],
plugins: [
.plugin(name: "PrefireTestsPlugin", package: "Prefire")
]
)
2. Write #Preview
#Preview {
Button("Submit")
}
3. Run tests
Just run the test target 🚀 — Prefire will auto-generate snapshots based on your previews.
💡 If your test target is empty, Prefire will still generate files and snapshot code during build.
📦 Installation
| Method | How |
|---|---|
| SPM Plugin | PrefireTestsPlugin / PrefirePlaybookPlugin in Package.swift |
| Xcode Build Tool Plugin | Add PrefireTestsPlugin to the test target's build phases |
| CLI | brew install barredewe/prefire/prefire |
| Mint (Beta) | mint install BarredEwe/Prefire |
| GitHub Actions / CI | Any of the above, see Troubleshooting |
Step-by-step setup is in the Installation guide.
Requirements
- Swift 6.0 or higher
- Xcode 16.0 or higher
- iOS 14 or higher; macOS 13 or higher (macOS: snapshot tests only, see Configuration)
🛠 Usage
Choose previews
Prefire finds every #Preview automatically. For PreviewProvider, add the PrefireProvider protocol:
struct Text_Previews: PreviewProvider, PrefireProvider {
static var previews: some View { ... }
}
Exclude a preview with .prefireIgnored():
#Preview {
Text("")
.prefireIgnored()
}
To opt in instead of opting out, set preview_default_enabled: false in .prefire.yml and mark the previews you want with .prefireEnabled():
#Preview {
Text("")
.prefireEnabled()
}
Snapshot tests
PrefireTestsPlugin generates the tests into the DerivedData folder when the test target builds. Run the test target as usual.
Tune the timing and precision of a single snapshot:
#Preview {
TestView()
.snapshot(delay: 0.3, precision: 0.95, perceptualPrecision: 0.98)
}
For previews that load or animate, wait instead of guessing a delay:
.snapshot(waitForIdle: true) // until nothing changes on screen
.snapshot(waitUntil: { viewModel.isLoaded }) // until a condition is true
How waiting works, its limits and how the modifiers combine: Snapshot timing and precision.
Snapshots are compared with swift-snapshot-testing.
Playbook (Demo) View
Show all previews as an interactive catalog with PlaybookView:
isComponent: truelists all the ViewsisComponent: falsegroups them by UserStory
import Prefire
struct ContentView: View {
var body: some View {
PlaybookView(isComponent: true, previewModels: PreviewModels.models)
}
}
To keep previews and PreviewModels out of release builds, see Excluding previews from release builds.
Flows
Connect previews into one Flow with .previewUserStory. Playbook shows them together, in order:
static var previews: some View {
PrefireView()
.previewUserStory(.auth)
}
static var previews: some View {
AuthView()
.previewUserStory(.auth)
}
States
If a preview contains more than one View, mark the State of each:
static var previews: some View {
TestView("Default")
TestView("Loading")
.previewState(.loading)
}
Parameterized previews
Prefire expands each argument of a native SwiftUI parameterized preview into its own snapshot and Playbook preview:
#Preview("TextView", traits: .sizeThatFitsLayout, arguments: ["- A", "- B", "- C"]) { suffix in
Text("1 \(suffix)")
}
🧰 API
| Feature | Modifier |
|---|---|
| Include in snapshot | .prefireEnabled() |
| Exclude from snapshot | .prefireIgnored() |
| Group in a flow | .previewUserStory(.auth) |
| Mark a UI state | .previewState(.error) |
| Customize snapshot | .snapshot(delay: 0.3, precision: 0.95) |
| Wait until the preview settles | .snapshot(waitForIdle: true, timeout: 2.0) |
| Wait for a condition | .snapshot(waitUntil: { viewModel.isLoaded }) |
| Parameterized preview | #Preview(..., arguments: values) |
💡 CLI Usage
# Generate snapshot tests
prefire tests
# Generate playbook models
prefire playbook
Run prefire tests --help or prefire playbook --help for more options.
🤖 Let AI agents see SwiftUI
Prefire renders previews in its snapshot tests, built anew and on the devices you choose, so it can show them to an AI agent as images, which Xcode Previews can't do reliably outside Xcode.
# Render previews to PNG + JSON
prefire render "Sign in" --device "iPhone 16 Pro" --color-scheme dark
# An HTML board of the last render, grouped by user story
prefire board
Add the MCP server to your agent, from the folder with .prefire.yml:
An agent then calls list_previews, render_previews and build_board. Set the scheme to build in
render_configuration of .prefire.yml; see the AI guide. Why not Xcode's own
RenderPreview? Prefire needs no running Xcode, renders many previews in one build, on the devices,
color scheme and Dynamic Type you ask for, and works in CI.
🗂 Configuration: .prefire.yml
test_configuration:
target: MyApp
playbook_configuration:
preview_default_enabled: true
All options are in the Configuration guide. To change the generated code, see Templates.
🧠 How It Works
- 🔍 Parses all source files — finds
#PreviewandPreviewProviderblocks and the.prefireEnabled()/.prefireIgnored()modifiers - 📂 Caches
TypesandPreviewBodies— keyed by file modification date + SHA-256 of inputs, so nothing is re-parsed if nothing changed - 🔢 Generates snapshot tests — from
Stenciltemplates, respecting.prefire.yml - 📘 Generates Playbook models — groups by
UserStoryandStateintoPreviewModels.generated.swift
🩺 Troubleshooting
| Problem | Fix |
|---|---|
NavigationView in a preview doesn't work in Playbook |
Use other views or layouts for your Playbook needs |
| Plugins don't run on CI | defaults write com.apple.dt.Xcode IDESkipPackagePluginFingerprintValidatation -bool YES |
| Xcode can't generate tests in a custom path | Disable the plugin sandbox: defaults write com.apple.dt.Xcode IDEPackageSupportDisablePluginExecutionSandbox -bool YES |
🐱 Also by the author
Mewmori is a pixel cat that lives on your Mac desktop. He reads what's on screen, says something about it, and remembers you between sessions. A 2B model runs on the machine through llama.cpp, so screen text, chats and memory stay on your Mac.
Swift, AppKit + SwiftUI, 29 MB. Free; only skins are paid.
🤝 Contributing
We welcome contributions! Development setup, tests and the internal architecture are described in CONTRIBUTING.md.
Logo, colors and templates for talks and posts about Prefire are in the brand kit.
⭐ Star history
If Prefire saves you time, give it a star: it helps other iOS developers find it.
📄 License
Prefire is released under the Apache License 2.0. See LICENSE for details.
Prefire MCP questions
How do I add Prefire's MCP server to Claude Code?
Run claude mcp add prefire -- prefire mcp in the folder containing your .prefire.yml, after installing Prefire with Homebrew.
What does the Prefire MCP server let an agent do?
The agent can list previews, render them to PNG images on a chosen device and color scheme, and build an HTML board of the results.
Can Prefire render previews without Xcode running?
Yes, Prefire renders previews in its snapshot tests without a running Xcode, and it works in CI.
How do I render a SwiftUI preview to PNG from the command line?
Use prefire render with an optional device and color scheme, which outputs PNG images plus JSON.
Do I need an API key to use Prefire?
No, it is a local command-line tool installed via Homebrew or SPM and requires no authentication.