How loopwork-ai/imcp works
Project type and purpose
• This is a full-stack macOS application (“iMCP.app”) bundled with a command-line MCP server executable (“imcp-server”).
• Purpose: expose on-device services (Calendar, Contacts, Location, Maps, Messages, Reminders, Weather, etc.) over the Model Context Protocol (MCP) to AI clients such as Claude Desktop.
File structure
• Top-level “App/” directory: SwiftUI/macOS UI, Controllers, Views, Models, Services, Integrations.
• “CLI/” directory: single Swift file (main.swift) implementing the MCP server, proxying MCP requests via stdio to the App.
• Xcode project with both targets: the .app and the bundled imcp-server CLI.
• Configuration & discovery via Bonjour (“_mcp._tcp.local”).
Key technical components from the README
• App sandbox + Apple frameworks (EventKit, Contacts, MapKit, CoreLocation, etc.) to fetch data.
• imcp-server uses standard input/output (stdio) to communicate with MCP clients.
• App and CLI discover each other and exchange requests/responses over a local TCP connection via Bonjour.
• Data serialization in JSON-LD (using Ontology package) and MCP message handling (via mcp-swift-sdk).
• Special handling for iMessage DB (SQLite + typedstream decoding via Madrid package).
Main components
A. MCP Client (e.g., Claude Desktop)
B. imcp-server CLI process
C. iMCP macOS App process
D. Bonjour/mDNS discovery layer
E. stdio transport (between client and CLI)
F. TCP transport (between CLI and App)
G. Service modules inside App (CalendarService, ContactsService, etc.)
H. System frameworks & external resources
• EventKit, Contacts framework, CoreLocation, MapKit, SQLite chat.db, Weather API
I. Swift SDKs
• mcp-swift-sdk (MCP protocol)
• Madrid (iMessage typedstream)
• Ontology (JSON-LD)
Relationships & data flow
1. Claude Desktop (MCP Client) launches imcp-server with stdio transport.
→ (1) MCP request via STDIN
2. imcp-server CLI reads requests from STDIN, advertises its presence via Bonjour.
→ (2) forwards request over TCP to iMCP App
3. iMCP App receives request, routes to the appropriate Service module (e.g., Calendar)
→ (3) invokes Apple framework or reads chat.db
4. Service module returns domain model value, serialized to JSON-LD via Ontology.
→ (4) App sends JSON-LD response back over TCP to CLI
5. imcp-server writes response JSON-LD to STDOUT.
→ (5) MCP Client reads and handles the tool result
Architectural patterns & design principles
• Separation of concerns: UI (SwiftUI Views/Controllers) vs. service/business logic vs. transport layer.
• Adapter modules for each system framework (Services directory) implementing a common “Tool” interface.
• Proxy pattern: imcp-server acts as a proxy between MCP clients and the App.
• Discovery & decoupling: Bonjour for locating the App at runtime.
• Use of standard transports (stdio, TCP) and standardized serialization (JSON-LD).