Skip to content

Connect only to the iMCP service on this Mac - #259

Merged
mattt merged 3 commits into
mainfrom
mattt/local-bonjour-service
Oct 4, 2026
Merged

mattt merged 3 commits into
mainfrom
mattt/local-bonjour-service

Conversation

@mattt

@mattt mattt commented Oct 4, 2026 •

Copy link
Copy Markdown
Owner

Resolves #257

With iMCP on two Macs on the same network, imcp-server could pick the other Mac's "iMCP" service, connect to its port on 127.0.0.1, and hang while the refused connection retried. This PR connects only to a service that Bonjour reports on the loopback interface, fails instead of waiting when the connection is refused, and names the Local Network setting in the discovery timeout error and the README.

mattt added 3 commits October 4, 2026 05:11
With iMCP running on two Macs on the same network,
imcp-server could select the other Mac's service,
because both names contain "iMCP".
It then connected to its own loopback address
on the other Mac's port, which nothing listens on.

Ignore browse results that aren't reported on the loopback interface,
which is how Bonjour reports a service registered on this Mac.

Fixes #257
A connection to a port that nothing listens on
stays in the waiting state and retries indefinitely,
so imcp-server hung without output and never answered the client.

Treat waiting before the connection is ready as a failure,
so that imcp-server logs the error and tries discovery again.
Set the state handler before starting the connection,
so the first state update isn't missed.
imcp-server has its own Local Network entry in System Settings,
and while it is turned off, the only output was a discovery timeout.
Name the setting in that error, and describe it in the README.
@mattt
mattt requested a balanced review from Copilot October 4, 2026 12:24

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.

Copilot review overview

🟡 Changes recommended

Connection refusals still enter the indefinite reconnect loop instead of exiting non-zero.

Review effort: Balanced
Findings: 1 High severity

Open (1)
What changed in this PR

Restricts Bonjour discovery to local iMCP services and improves connection diagnostics.

Changes:

  • Filters Bonjour results to loopback services.
  • Reports connection waiting errors and Local Network permission guidance.
  • Adds regression tests and README troubleshooting guidance.
File Description
README.md Documents Local Network permission.
CLITests/​BonjourDiscoveryTests.swift Tests local-service selection.
CLI/​StdioProxy.swift Handles initial connection waiting states.
CLI/​MCPService.swift Improves discovery messaging.
CLI/​BonjourDiscovery.swift Filters remote Bonjour results.

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

Comment thread CLI/StdioProxy.swift
if let continuation = continuation,
await shouldResume(connectionState: connectionState)
{
continuation.resume(throwing: error)
@mattt
mattt merged commit 99e1804 into main Oct 4, 2026
2 checks passed
@mattt
mattt deleted the mattt/local-bonjour-service branch October 4, 2026 12:33
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.

imcp-server hangs when iMCP runs on more than one Mac on the same network (regression from #228/#229/#242)

2 participants