From 91c5d8a13e4419bedb232386ee6e875c09008d7c Mon Sep 17 00:00:00 2001 From: Kevin Mas Ruiz Date: Mon, 28 Jul 2025 13:53:36 +0200 Subject: [PATCH 1/3] chore: Enable proxy for OIDC and MongoDB connections By providing { useEnvironmentVariableProxies: true } the NodeDriverServiceProvider already reads the relevant environment variables and sets up the proxy internally. --- src/common/session.ts | 2 ++ tests/unit/common/session.test.ts | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/common/session.ts b/src/common/session.ts index dfae6ec9..689a25d8 100644 --- a/src/common/session.ts +++ b/src/common/session.ts @@ -113,6 +113,8 @@ export class Session extends EventEmitter<{ w: connectOptions.writeConcern, }, timeoutMS: connectOptions.timeoutMS, + proxy: { useEnvironmentVariableProxies: true }, + applyProxyToOIDC: true, }); } } diff --git a/tests/unit/common/session.test.ts b/tests/unit/common/session.test.ts index 1c7b511b..73236c5f 100644 --- a/tests/unit/common/session.test.ts +++ b/tests/unit/common/session.test.ts @@ -56,5 +56,17 @@ describe("Session", () => { } }); } + + it("should configure the proxy to use environment variables", async () => { + await session.connectToMongoDB("mongodb://localhost", config.connectOptions); + expect(session.serviceProvider).toBeDefined(); + + const connectMock = MockNodeDriverServiceProvider.connect; + expect(connectMock).toHaveBeenCalledOnce(); + + const connectionConfig = connectMock.mock.calls[0]?.[1]; + expect(connectionConfig?.proxy).toEqual({ useEnvironmentVariableProxies: true }); + expect(connectionConfig?.applyProxyToOIDC).toEqual(true); + }); }); }); From a10c08811b2e3404223bd34762832a6dd82887ba Mon Sep 17 00:00:00 2001 From: Kevin Mas Ruiz Date: Mon, 28 Jul 2025 15:58:34 +0200 Subject: [PATCH 2/3] Add a summary of the PROXY support in MCP Server Mentioning that it supports the same behaviour as mongosh. --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 4261e4ef..6d874941 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ A Model Context Protocol server for interacting with MongoDB Databases and Mongo - [Environment Variables](#environment-variables) - [Command-Line Arguments](#command-line-arguments) - [MCP Client Configuration](#mcp-configuration-file-examples) + - [Proxy Support](#proxy-support) - [🤝 Contributing](#contributing) @@ -574,6 +575,13 @@ npx -y mongodb-mcp-server@latest --apiClientId="your-atlas-service-accounts-clie } ``` +### Proxy Support + +The MCP Server will detect typical PROXY environment variables and use them for +connecting to the Atlas API, your MongoDB Cluster, or any other external calls +to third-party services like OID Providers. The behaviour is the same as what +`mongosh` does, so the same settings will work in the MCP Server. + ## 🤝Contributing Interested in contributing? Great! Please check our [Contributing Guide](CONTRIBUTING.md) for guidelines on code contributions, standards, adding new tools, and troubleshooting information. From 6927e42027389e55daaba12ca56782651602be42 Mon Sep 17 00:00:00 2001 From: Kevin Mas Ruiz Date: Mon, 28 Jul 2025 16:06:08 +0200 Subject: [PATCH 3/3] Fix prettier complains --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6d874941..a410235d 100644 --- a/README.md +++ b/README.md @@ -577,7 +577,7 @@ npx -y mongodb-mcp-server@latest --apiClientId="your-atlas-service-accounts-clie ### Proxy Support -The MCP Server will detect typical PROXY environment variables and use them for +The MCP Server will detect typical PROXY environment variables and use them for connecting to the Atlas API, your MongoDB Cluster, or any other external calls to third-party services like OID Providers. The behaviour is the same as what `mongosh` does, so the same settings will work in the MCP Server.