Skip to content

Commit 57104d5

Browse files
cyberpapiiiclaude
andcommitted
fix: start MCP server before contacts initialization
The contacts permission dialog and loading 1600+ contacts was blocking the MCP handshake, causing Claude Desktop to timeout waiting for the initialize response. Now the server starts first and contacts load in the background. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent f0318ee commit 57104d5

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

swift/Sources/iMessageMax/Server/MCPServer.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,19 @@ actor MCPServerWrapper {
1616
}
1717

1818
func start(transport: any Transport) async throws {
19-
await performStartupChecks()
19+
// Register tools and start server FIRST so MCP handshake can complete
2020
ToolRegistry.registerAll(on: server, db: database, resolver: resolver)
21-
try await server.start(transport: transport)
21+
22+
// Start server in background, then do startup checks
23+
// This allows MCP initialization to complete while contacts load
24+
async let serverTask: () = server.start(transport: transport)
25+
26+
// Perform startup checks after server starts (non-blocking for MCP)
27+
Task {
28+
await performStartupChecks()
29+
}
30+
31+
try await serverTask
2232
await server.waitUntilCompleted()
2333
}
2434

@@ -31,7 +41,7 @@ actor MCPServerWrapper {
3141
)
3242
}
3343

34-
// Initialize contacts
44+
// Initialize contacts (this may show permission dialog)
3545
let (contactsOk, contactsStatus) = ContactResolver.authorizationStatus()
3646
if !contactsOk && contactsStatus == "not_determined" {
3747
_ = try? await resolver.requestAccess()

0 commit comments

Comments
 (0)