Skip to content

fix(mcp): auto-reconnect extension relay after disconnect#41875

Open
sgewirtz1 wants to merge 1 commit into
microsoft:mainfrom
sgewirtz1:fix/extension-auto-reconnect-on-disconnect
Open

fix(mcp): auto-reconnect extension relay after disconnect#41875
sgewirtz1 wants to merge 1 commit into
microsoft:mainfrom
sgewirtz1:fix/extension-auto-reconnect-on-disconnect

Conversation

@sgewirtz1

Copy link
Copy Markdown

Fixes #41874

Problem

When the browser extension disconnects from the MCP relay (Chrome MV3 service worker idle timeout ~5 min, browser restart, extension reload), the relay leaves _extensionConnection null and never re-opens connect.html. Every subsequent MCP tool call fails with Extension not connected; the only recovery is restarting the entire MCP server.

Fix

In _handleExtensionConnection.onclose:

  • Null out _extensionConnection (so a reconnecting extension is not rejected by the "already established" guard)
  • Reset _extensionConnectionPromise to a fresh ManualPromise
  • Call _openConnectPageInBrowser to re-spawn the connect tab

Two supporting changes:

  • _clientName is stored when establishExtensionConnection is first called, so the reconnect path has the client name without requiring a new caller argument
  • _stopped flag is set in stop() to prevent reconnect attempts after intentional shutdown

When the browser extension disconnects (MV3 service worker idle timeout,
browser restart, extension reload), reset the connection promise and
re-open connect.html so the relay reconnects automatically.

Guard with _stopped so intentional stop() calls do not trigger reconnect.
Store _clientName in establishExtensionConnection so it is available to
the reconnect path without requiring a new caller argument.

Fixes microsoft#41874
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.

[Bug]: --extension mode: relay does not reconnect to browser extension after disconnect

2 participants