Skip to content

Conversation

himanshusinghs
Copy link
Collaborator

@himanshusinghs himanshusinghs commented Aug 27, 2025

Proposed changes

This PR modifies the interface for our TransportRunners to allow injecting a ConnectionManager implementation. This will enable VSCode integration by allowing VSCode extension to pass its own implementation of ConnectionManager.

To allow subclassing, an abstract ConnectionManager is extracted out from existing implementation with connect, disconnect as the abstract methods.

The VSCode implementation of ConnectionManager differs slightly from our implementation of ConnectionManager (MCPConnectionManager) which is why this interface modification was called for. The VSCodeMCPConnectionManager.connect is not as involved as our implementation, we literally borrow the connect options from an existing connection in VSCode extension and use those to create a new instance of NodeServiceProvider which essentially shares the connection state. Additionally that implementation also implements logic to switch to different connections on demand(when active connection in extension changes).

The VSCode PR is here for reference.

Checklist

@himanshusinghs himanshusinghs marked this pull request as ready for review August 27, 2025 12:55
@himanshusinghs himanshusinghs requested a review from a team as a code owner August 27, 2025 12:55
Base automatically changed from ni/http-tweaks to main August 28, 2025 09:30
@Copilot Copilot AI review requested due to automatic review settings August 28, 2025 11:38
@himanshusinghs himanshusinghs force-pushed the chore/MCP-131-injectable-connection-manager branch from 6298977 to 998140f Compare August 28, 2025 11:38
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the ConnectionManager interface to allow injection of custom ConnectionManager implementations via TransportRunner constructors. This enables VSCode integration by allowing the VSCode extension to provide its own ConnectionManager implementation that shares connection state with existing VSCode connections.

  • Extracts an abstract ConnectionManager base class with connect and disconnect as abstract methods
  • Moves the existing ConnectionManager implementation to MCPConnectionManager
  • Modifies TransportRunner classes to accept a factory function for creating ConnectionManager instances

Reviewed Changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/common/connectionManager.ts Creates abstract base ConnectionManager with interface definitions
src/common/mcpConnectionManager.ts Implements concrete MCPConnectionManager with existing connection logic
src/transports/base.ts Adds CreateConnectionManagerFn type and modifies constructor to accept factory function
src/transports/stdio.ts Updates constructor to use ConnectionManager factory function
src/transports/streamableHttp.ts Updates constructor to use ConnectionManager factory function
src/index.ts Creates factory function for MCPConnectionManager in main entry point
src/lib.ts Exports new ConnectionManager interface and related types
tests/* Updates test files to use MCPConnectionManager and new event interface

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@himanshusinghs himanshusinghs force-pushed the chore/MCP-131-injectable-connection-manager branch 2 times, most recently from 51f2fdf to 8258b3e Compare August 28, 2025 13:11
This commit extracts an abstract class ConnectionManager out of
MCPConnectionManager and modifies the TransportRunner interface to have
the ConnectionManager implementation injected through a factory
function.

Contains a small drive by fix for making the ConnectionManager event
emitting internal to the class itself.
@himanshusinghs himanshusinghs force-pushed the chore/MCP-131-injectable-connection-manager branch from 33b85d4 to 71680ab Compare August 28, 2025 14:09
Copy link
Collaborator

@nirinchev nirinchev left a comment

Choose a reason for hiding this comment

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

Mostly nits from me, otherwise it's good.

@himanshusinghs himanshusinghs merged commit 1ae7f5e into main Aug 29, 2025
15 of 17 checks passed
@himanshusinghs himanshusinghs deleted the chore/MCP-131-injectable-connection-manager branch August 29, 2025 10:31
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.

3 participants