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

  1. Main app has a SwiftUI view using @Query to display Rules
  2. MCP server (separate process) creates a new Rule and saves to the ModelContext
  3. MCP posts a DistributedNotificationCenter notification to signal the change
  4. Main app receives the notification (confirmed via logs)
  5. @Query does not refresh - new rule not visible
  6. Restart app - new rule appears

What We Tried

  1. Manual fetch on notification - Same stale data returned from modelContext.fetch()
  2. Fresh ModelContext - Creating new ModelContext(container) and fetching, then using modelContext.model(for: id) to get attached objects - caused UI freezes
  3. @Query wrapper - 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

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗