SwiftData @Query doesn't refresh from cross-process MCP writes
Resolved 💬 2 comments Opened Jan 20, 2026 by djandrewgibbons Closed Feb 12, 2026
Summary
When using MCP (Model Context Protocol) to write data to a SwiftData store from a separate process, the main app's @Query properties do not automatically refresh to show the new data. The app requires a restart to see changes made via MCP.
Environment
- macOS 26 (Tahoe)
- SwiftData with CloudKit sync enabled
- MCP server running as separate process, writing to same SwiftData store
Steps to Reproduce
- Main app has a SwiftUI view using
@Queryto display Rules - MCP server (separate process) creates a new Rule and saves to the ModelContext
- MCP posts a
DistributedNotificationCenternotification to signal the change - Main app receives the notification (confirmed via logs)
@Querydoes not refresh - new rule not visible- Restart app - new rule appears
What We Tried
- Manual fetch on notification - Same stale data returned from
modelContext.fetch() - Fresh ModelContext - Creating new
ModelContext(container)and fetching, then usingmodelContext.model(for: id)to get attached objects - caused UI freezes @Querywrapper - Expected to auto-update but doesn't see cross-process changes
Expected Behavior
@Query should detect that the underlying persistent store has changed and refresh, or there should be an API to force a refresh from disk.
Workaround Needed
Looking for a way to force SwiftData's ModelContext to re-read from the persistent store after receiving a cross-process notification.
Related
- This may be related to SwiftData's caching behavior
- CloudKit sync eventually propagates changes, but immediate refresh is needed for good UX
- Similar to Core Data's
refreshAllObjects()which doesn't exist in SwiftData
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗