Skip to content

Add config option for connection string #53

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 2 commits into from
Apr 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ const { localDataPath, configPath } = getLocalDataPath();

// If we decide to support non-string config options, we'll need to extend the mechanism for parsing
// env variables.
interface UserConfig extends Record<string, string> {
interface UserConfig extends Record<string, string | undefined> {
apiBaseUrl: string;
clientId: string;
stateFile: string;
connectionString?: string;
}

const defaults: UserConfig = {
Expand Down
3 changes: 2 additions & 1 deletion src/tools/mongodb/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { NodeDriverServiceProvider } from "@mongosh/service-provider-node-driver
import { DbOperationType, MongoDBToolBase } from "./mongodbTool.js";
import { ToolArgs } from "../tool.js";
import { ErrorCodes, MongoDBError } from "../../errors.js";
import config from "../../config.js";

export class ConnectTool extends MongoDBToolBase {
protected name = "connect";
Expand All @@ -20,7 +21,7 @@ export class ConnectTool extends MongoDBToolBase {
protected async execute({
connectionStringOrClusterName,
}: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
connectionStringOrClusterName ??= this.state.credentials.connectionString;
connectionStringOrClusterName ??= config.connectionString || this.state.credentials.connectionString;
if (!connectionStringOrClusterName) {
return {
content: [
Expand Down