Skip to content

Conversation

nirinchev
Copy link
Collaborator

@nirinchev nirinchev commented Apr 10, 2025

Adds the following mechanisms for supplying config (in order of precedence):

  • cli args
  • environment variables (field names are converted to MDB_MCP_UPPER_SNAKE_CASE
  • mongodb-mcp.conf placed in the /etc folder on Unix or %LOCAL_APP_DATA%\mongodb\mongodb-mcp.

Fixes #21

@nirinchev nirinchev requested review from fmenezes and gagik April 10, 2025 11:48
@@ -71,5 +72,7 @@ export class ConnectTool extends MongoDBToolBase {
});

this.mongodbState.serviceProvider = provider;
this.state.connectionString = connectionString;
await saveState(this.state);
Copy link
Collaborator

Choose a reason for hiding this comment

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

do I understand correct that we'd save the conectionString with its credentials in a plaintext file this way?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes - this should be handled in #20.

Copy link
Collaborator

Choose a reason for hiding this comment

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

question: why do we need mongodbState and also state ? does mongodbState get's persisted?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No - mongodb state is a set of globals that will not get stored on disk. I was debating between adding them to state and then special-casing which fields get persisted but at the end opted to create a separate object.

Copy link
Collaborator

Choose a reason for hiding this comment

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

so far config is read only from env vars / defaults and state is something we expect to store (as in preferences).

I think we are merging these two concepts together in this PR, which I'm ok with.

In theory mongodbState is mongodbConfig then.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Technically, it's not even a config - it's just a place to stash certain things we may need for later (such as the MongoDB client after connect is invoked). This is technically session state as opposed to the current state, which is persistent across sessions. I'll probably clean it up in a separate PR.

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.

LGTM

@fmenezes
Copy link
Collaborator

fmenezes commented Apr 10, 2025

@nirinchev are we merging state and config this way? in cli our approach has been one file locations are as follows

  • windows %APPDATA%/atlascli/config.toml
  • macos $HOME/Library/Application Support/atlascli/config.toml
  • linux $XDG_CONFIG_HOME/atlascli/config.toml (in absence of $XDG_CONFIG_HOME we use $HOME/.config)

which seems to be the most common across cli tools I've seen

* main:
  chore: refactor package.json import (#43)
@nirinchev
Copy link
Collaborator Author

Hm... good point - I thought the app directory could be convenient place to store it, but it's probably not that intuitive. Happy to change it to either the Atlas CLI or the mongosh locations.

@fmenezes
Copy link
Collaborator

I think we should do

  • windows %APPDATA%/mongodb-mcp-server/config.json
  • macos $HOME/Library/Application Support/mongodb-mcp-server/config.json
  • linux $XDG_CONFIG_HOME/mongodb-mcp-server/config.json (in absence of $XDG_CONFIG_HOME we use $HOME/.config)

and replace state.json with credentials.json.

Copy link
Collaborator

@fmenezes fmenezes left a comment

Choose a reason for hiding this comment

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

All of my comments are nits and I'm good to resolve, in fact we would be ok with just env vars and arguments for configuration

@nirinchev
Copy link
Collaborator Author

nirinchev commented Apr 10, 2025

Okay, so for now we'll look for config in:

  • /etc/mongodb-mcp.conf on macOS/Linux
  • %APPDATA%\mongodb\mongodb-mcp\mongodb-mcp.conf on Windows

This almost matches mongosh (except for the fallbacks on macOS). Since I wanted to keep it simple for now and keep the config getting loaded synchronously, I'll keep it like that. We can (and should) definitely refactor it to load the config asynchronously at some point, in which case we can add the extra fallback locations.

I'll look into the state situation at a follow-up PR.

@nirinchev nirinchev merged commit a031897 into main Apr 10, 2025
1 check passed
@nirinchev nirinchev deleted the ni/configs branch April 10, 2025 13:04
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.

[MongoDB] Add config options for defaults we don't want to set for every operation
3 participants