Skip to content

Conversation

himanshusinghs
Copy link
Collaborator

Proposed changes

We're expanding the transport runner and server's interface to accept a custom connection error handler so that library consumers can provide their own mechanism of handling connection error and have an opportunity to act on them.

This will allow VSCode to provide its own ConnectionErrorHandler and thus modify the tool responses in case of connection problems.

Checklist

@Copilot Copilot AI review requested due to automatic review settings September 2, 2025 11:19
@himanshusinghs himanshusinghs requested a review from a team as a code owner September 2, 2025 11:19
@@ -0,0 +1,81 @@
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This entire file is a cut of existing logic in MongodbToolBase.

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 extends the MongoDB MCP library to support custom connection error handlers, allowing consumers to inject their own error handling logic for connection-related errors instead of relying solely on the default implementation.

Key changes include:

  • Refactored transport runners to accept configuration objects with optional connection error handlers
  • Created a new ConnectionErrorHandler interface and default implementation
  • Modified the Server class to use injected connection error handlers
  • Updated MongoDB tools to delegate connection error handling to the injected handler

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/common/connectionErrorHandler.ts New file defining the connection error handler interface and default implementation
src/common/errors.ts Made MongoDBError generic to support type-safe error code handling
src/transports/base.ts Added TransportRunnerConfig type and updated base class to support connection error handlers
src/transports/stdio.ts Updated constructor to use new configuration object pattern
src/transports/streamableHttp.ts Updated constructor to use new configuration object pattern
src/server.ts Added connection error handler to server options and implementation
src/tools/mongodb/mongodbTool.ts Refactored to use injected connection error handler instead of hardcoded logic
src/index.ts Updated transport runner instantiation to use new configuration objects
tests/integration/transports/streamableHttp.test.ts Updated test instantiation to use new configuration pattern
tests/integration/tools/mongodb/mongodbTool.test.ts Added comprehensive tests for connection error handler functionality
tests/integration/helpers.ts Updated test helper to include default connection error handler

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

@coveralls
Copy link
Collaborator

coveralls commented Sep 2, 2025

Pull Request Test Coverage Report for Build 17429932259

Details

  • 92 of 106 (86.79%) changed or added relevant lines in 9 files are covered.
  • 2 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.2%) to 81.125%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/lib.ts 0 1 0.0%
src/transports/stdio.ts 3 4 75.0%
src/common/connectionErrorHandler.ts 60 62 96.77%
src/tools/mongodb/mongodbTool.ts 9 11 81.82%
src/index.ts 0 8 0.0%
Files with Coverage Reduction New Missed Lines %
src/lib.ts 1 0.0%
src/transports/stdio.ts 1 63.33%
Totals Coverage Status
Change from base Build 17411863932: 0.2%
Covered Lines: 4579
Relevant Lines: 5556

💛 - Coveralls

himanshusinghs and others added 4 commits September 2, 2025 21:49
We're expanding the transport runner interface to accept a custom
connection error handler so that library consumers can provide their own
mechanism of handling connection error and have an opportunity to act on
them.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@himanshusinghs himanshusinghs force-pushed the chore/MCP-132-injectable-connection-error-handler branch from 90304fd to 2b725e7 Compare September 2, 2025 19:49
@himanshusinghs himanshusinghs merged commit 94dfc08 into main Sep 3, 2025
18 checks passed
@himanshusinghs himanshusinghs deleted the chore/MCP-132-injectable-connection-error-handler branch September 3, 2025 10:22
nirinchev added a commit that referenced this pull request Sep 3, 2025
* main:
  feat: add more details about atlas connect flow - MCP-124 (#500)
  chore: extend library interfaces to allow injecting a custom connection error handler MCP-132 (#502)
  fix: start mcp even if connection fails - [MCP-140] (#503)
  fix: allow connect tool on readOnly mode (#499)
  chore: warn about the usage of deprecated cli arguments MCP-107 (#493)
  ci: add ipAccessList after creating project (#496)
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.

4 participants