diff --git a/README.md b/README.md index 4261e4ef..a410235d 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. 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); + }); }); });