Skip to content

feat: update the connect tool based on connectivity status #118

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

Merged
merged 8 commits into from
Apr 25, 2025

Conversation

nirinchev
Copy link
Collaborator

@nirinchev nirinchev commented Apr 24, 2025

This turned out to be a lot more involved than anticipated and revealed a handful of upstream bugs, which we've worked around.

There are two main changes in this PR:

  1. we've removed the resource exposing the preconfigured connection string in favor of a config resource, listing a redacted subset of the UserConfig options. Right now it lists the following:
  • telemetry - enabled/disabled
  • logPath - full log path
  • connectionString - set/not set + a hint to the model on what tool to use
  • connectOptions - the read/write concern etc.
  1. Completely reworked the connect tool. Now it updates its metadata based on whether we have a connection string configured and whether it has run before. If we have connected already or have a connection string, it changes its name to switch-connection and updates its metadata to more clearly hint at the model in which situations it should be invoked.

Based on my testing with Claude, Cursor, and Windsurf, this works pretty solidly, but would appreciate if others could give it a go.

TODO

  • Check how that behaves when the connection string in the config is incorrect.

Fixes #92
Fixes #95

@nirinchev nirinchev requested review from gagik and fmenezes and removed request for gagik April 24, 2025 20:39
@@ -21,7 +21,7 @@ export class Server {
public readonly session: Session;
private readonly mcpServer: McpServer;
private readonly telemetry: Telemetry;
private readonly userConfig: UserConfig;
public readonly userConfig: UserConfig;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Still not super happy with where we are at wrt configs, but this was a stopgap - there were a bunch of places in the tests where we were updating fields in the global config expecting this to be reflected in the server config, which only worked by accident.

Comment on lines +99 to +104
telemetry: this.userConfig.telemetry,
logPath: this.userConfig.logPath,
connectionString: this.userConfig.connectionString
? "set; no explicit connect needed, use switch-connection tool to connect to a different connection if necessary"
: "not set; before using any mongodb tool, you need to call the connect tool with a connection string",
connectOptions: this.userConfig.connectOptions,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These are the config options we're exposing as a resource

@@ -22,13 +22,14 @@ export interface IntegrationTest {
mcpServer: () => Server;
}

export function setupIntegrationTest(userConfig: UserConfig = config): IntegrationTest {
export function setupIntegrationTest(userConfigGetter: () => UserConfig = () => config): IntegrationTest {
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 was necessary to allow the user config to be constructed as part of the test initialization rather than statically.

randomDbName = new ObjectId().toString();
});

afterEach(async () => {
if (mcpServer) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved this from the mongodb helpers because the session cleanup seemed like something common.

@coveralls
Copy link
Collaborator

coveralls commented Apr 24, 2025

Pull Request Test Coverage Report for Build 14670404051

Warning: 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

  • 59 of 67 (88.06%) changed or added relevant lines in 9 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.2%) to 81.886%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/server.ts 2 4 50.0%
src/telemetry/telemetry.ts 1 4 25.0%
src/tools/mongodb/mongodbTool.ts 6 9 66.67%
Totals Coverage Status
Change from base Build 14665384347: 0.2%
Covered Lines: 748
Relevant Lines: 861

💛 - Coveralls

Copy link
Collaborator

@gagik gagik left a comment

Choose a reason for hiding this comment

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

haven't tested it out myself but changes look good

@@ -22,13 +22,14 @@ export interface IntegrationTest {
mcpServer: () => Server;
}

export function setupIntegrationTest(userConfig: UserConfig = config): IntegrationTest {
export function setupIntegrationTest(userConfigGetter: () => UserConfig = () => config): IntegrationTest {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
export function setupIntegrationTest(userConfigGetter: () => UserConfig = () => config): IntegrationTest {
export function setupIntegrationTest(getUserConfig: () => UserConfig = () => config): IntegrationTest {

nit

let mcpClient: Client | undefined;
let mcpServer: Server | undefined;

let randomDbName: string;

beforeAll(async () => {
const userConfig = userConfigGetter();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
const userConfig = userConfigGetter();
const userConfig = getUserConfig();

@nirinchev
Copy link
Collaborator Author

I'm going to go ahead and merge this, even though we're going to rework it once more.

@nirinchev nirinchev merged commit a1a36fb into main Apr 25, 2025
3 checks passed
@nirinchev nirinchev deleted the ni/conditional-connect branch April 25, 2025 19:08
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.

Remove connect tool Connection string is not retained when LLM tries to reconnect
3 participants