Skip to content

fix(bridge): clean up resources when initialization fails - #33

Open
forever-ivy wants to merge 1 commit into
ora:mainfrom
forever-ivy:fix/cleanup-failed-bridge-initialization
Open

forever-ivy wants to merge 1 commit into
ora:mainfrom
forever-ivy:fix/cleanup-failed-bridge-initialization

Conversation

@forever-ivy

Copy link
Copy Markdown

What

Release the MCP connection and any registered page tools when createWebMcpBridge() fails during its initial tool synchronization.

Why

Once the MCP connection succeeds, a failing tools/list request currently rejects initialization without closing the client. If onRegisterError throws after earlier tools were registered, those registrations also remain active. The caller never receives a bridge instance, so it cannot clean up either resource.

Reuse the existing idempotent close behavior for both explicit closure and failed initialization. Cleanup aborts registrations before closing the client, and a cleanup failure does not replace the original initialization error.

Checks

  • npm run check && npm run lint && npm run typecheck && npm test (16 bridge tests and 17 verify tests).
  • Both package builds and the bridge's verify:pack check.
  • Regression coverage using the MCP SDK's real server and in-memory transports: discovery failure, transport cleanup failure, and partial registration followed by a throwing error handler. The new cases failed before the fix.

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.

1 participant