Skip to content

chore: Enable proxy for OIDC and MongoDB connections MCP-88 #405

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 3 commits into from
Jul 28, 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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

<a name="getting-started"></a>
Expand Down Expand Up @@ -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.
2 changes: 2 additions & 0 deletions src/common/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ export class Session extends EventEmitter<{
w: connectOptions.writeConcern,
},
timeoutMS: connectOptions.timeoutMS,
proxy: { useEnvironmentVariableProxies: true },
applyProxyToOIDC: true,
});
}
}
12 changes: 12 additions & 0 deletions tests/unit/common/session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
Loading