Skip to content

Fix reconnect loop that drops Claude Desktop connections - #208

Merged
mattt merged 3 commits into
mainfrom
mattt/fix-service-loop
Sep 5, 2026
Merged

mattt merged 3 commits into
mainfrom
mattt/fix-service-loop

Conversation

@mattt

@mattt mattt commented Sep 4, 2026

Copy link
Copy Markdown
Owner

Smoke testing latest version on main branch with Claude Desktop wasn't working for me.

When the MCP client closes stdin, the stdin handler returned without an error. MCPService treated that as a reason to browse Bonjour again immediately. stdin stayed at EOF, so each new TCP session died at once and the helper spun until it was force-quit or crashed. Claude Desktop still owned the process, so it could not spawn a fresh helper.

stdin EOF now fails the proxy session, and a clean return is treated as a disconnect. The helper exits so the client can relaunch it. The menubar app also registers the connection approval handler before it advertises the Bonjour service, so the first connection after launch is not rejected because the handler is still nil.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A pending network receive can prevent the task group from exiting after stdin EOF, so the helper may still fail to terminate.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Fixes helper shutdown behavior after stdin EOF and closes a startup race in connection approval.

Changes:

  • Adds centralized reconnect/termination decisions with regression tests.
  • Treats stdin EOF and clean proxy returns as terminal.
  • Registers approval handling before Bonjour advertisement.
File summaries
File Description
iMCP.xcodeproj/project.pbxproj Adds loop logic and tests to the test target.
CLITests/MCPServiceLoopTests.swift Tests reconnect decisions.
CLI/MCPServiceLoop.swift Defines proxy errors and retry policy.
CLI/main.swift Updates proxy cleanup and EOF handling.
App/Controllers/ServerController.swift Reorders approval registration and startup.
Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread CLI/main.swift Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants