-
Notifications
You must be signed in to change notification settings - Fork 96
chore: refactor connections to use the new ConnectionManager to isolate long running processes like OIDC connections MCP-81 #423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Now the connection itself and the user flow is managed by the new connection manager. There are tests missing for this class, that will be added in a following commit.
these test should validate that connecting to a cluster is fine and also the connection mechanism inference is working as expected until we support both oidc flows.
There was a problem hiding this 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 connection handling architecture by introducing a centralized ConnectionManager
class that manages all MongoDB connections, replacing the previous approach where connection logic was distributed across tools and sessions. The main goal is to isolate long-running processes like OIDC connections and provide better error handling and debugging capabilities.
Key changes include:
- Introduction of
ConnectionManager
class with state tracking and event emission - Consolidation of connection logic from both Atlas and MongoDB tools into a single interface
- Enhanced error handling and debugging information through connection state management
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.
Show a summary per file
File | Description |
---|---|
src/common/connectionManager.ts | New centralized connection management class with state tracking and event emission |
src/common/session.ts | Refactored to use ConnectionManager instead of directly managing ServiceProvider |
src/tools/mongodb/mongodbTool.ts | Updated to use session's connection state checking methods |
src/tools/mongodb/connect/connect.ts | Modified to use new connection interface and added connect event listener |
src/tools/atlas/connect/connectCluster.ts | Updated connection calls to use new ConnectionManager interface |
src/server.ts | Updated to use new connection interface and moved resource registration earlier |
src/resources/common/debug.ts | Updated resource naming for MongoDB debugging |
tests/unit/common/session.test.ts | Updated test calls to match new connection interface |
tests/integration/transports/stdio.test.ts | Added connection state setup for integration tests |
tests/integration/tools/mongodb/connect/connect.test.ts | Updated tests with connection state setup and error message expectations |
tests/integration/helpers.ts | Added ConnectionManager instantiation to test setup |
tests/integration/common/connectionManager.test.ts | New comprehensive test suite for ConnectionManager functionality |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a solid change - I have mostly minor/code style comments, but also a few questions that may be a bit more involved.
Also remove the code that forces the reconnection in the stdio transport test as it's not needed anymore.
But keep deleting users outside, as it's out of scope of the connection manager as it's not related to MongoDB itself but to Atlas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, I left minor suggestions but nothing blocking for the PR.
We are not using it, but to be consistent with what we had before we are keeping it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good - a couple of final nits from me.
…ction state We used to support only having it when connected, but it might be useful also when errored
Now it doesn't need to be async because the connection itself attemps to ping, it just needs to check the current connection status and map the exact values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pending lint + test fixes, as well as addressing the comments from the other reviewers, it's good to merge on my end.
Pull Request Test Coverage Report for Build 16778685993Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
Proposed changes
This PR basically proposes consolidating all connections into a single class, ConnectionManager. After this PR, both Atlas tools and MongoDB tools use the same code to connect to MongoDB, independently of the connection type.
Also, the ConnectionManager gets an upgrade on how to handle errors and debugging information:
To avoid changing the whole architecture and maybe support multitenancy in the future, the ConnectionManager is hidden and isolated in the Session.
This PR is bigger than usual because the refactor touches some root infrastructure, but hopefully the unit and integration tests I've added, along with the manual testing, ensures everything works correctly.
Checklist