Skip to content

Commit e85fe91

Browse files
authored
chore: Enable proxy for OIDC and MongoDB connections MCP-88 (#405)
1 parent 5fcbf05 commit e85fe91

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ A Model Context Protocol server for interacting with MongoDB Databases and Mongo
2222
- [Environment Variables](#environment-variables)
2323
- [Command-Line Arguments](#command-line-arguments)
2424
- [MCP Client Configuration](#mcp-configuration-file-examples)
25+
- [Proxy Support](#proxy-support)
2526
- [🤝 Contributing](#contributing)
2627

2728
<a name="getting-started"></a>
@@ -574,6 +575,13 @@ npx -y mongodb-mcp-server@latest --apiClientId="your-atlas-service-accounts-clie
574575
}
575576
```
576577

578+
### Proxy Support
579+
580+
The MCP Server will detect typical PROXY environment variables and use them for
581+
connecting to the Atlas API, your MongoDB Cluster, or any other external calls
582+
to third-party services like OID Providers. The behaviour is the same as what
583+
`mongosh` does, so the same settings will work in the MCP Server.
584+
577585
## 🤝Contributing
578586

579587
Interested in contributing? Great! Please check our [Contributing Guide](CONTRIBUTING.md) for guidelines on code contributions, standards, adding new tools, and troubleshooting information.

src/common/session.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ export class Session extends EventEmitter<{
113113
w: connectOptions.writeConcern,
114114
},
115115
timeoutMS: connectOptions.timeoutMS,
116+
proxy: { useEnvironmentVariableProxies: true },
117+
applyProxyToOIDC: true,
116118
});
117119
}
118120
}

tests/unit/common/session.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,17 @@ describe("Session", () => {
5656
}
5757
});
5858
}
59+
60+
it("should configure the proxy to use environment variables", async () => {
61+
await session.connectToMongoDB("mongodb://localhost", config.connectOptions);
62+
expect(session.serviceProvider).toBeDefined();
63+
64+
const connectMock = MockNodeDriverServiceProvider.connect;
65+
expect(connectMock).toHaveBeenCalledOnce();
66+
67+
const connectionConfig = connectMock.mock.calls[0]?.[1];
68+
expect(connectionConfig?.proxy).toEqual({ useEnvironmentVariableProxies: true });
69+
expect(connectionConfig?.applyProxyToOIDC).toEqual(true);
70+
});
5971
});
6072
});

0 commit comments

Comments
 (0)