Skip to content

Conversation

manoharnv
Copy link
Contributor

Problem

The Dynatrace MCP Server was not honoring system proxy settings (https_proxy, HTTPS_PROXY, no_proxy, NO_PROXY environment variables), causing connection failures when running behind corporate proxies. This prevented users in enterprise environments from using the MCP server to connect to their Dynatrace environments.

Solution

This PR implements proxy support by configuring undici's ProxyAgent early in the application startup process, before any HTTP requests are made. The solution leverages undici (already available as a transitive dependency via dt-app), which is the underlying implementation of Node.js's global fetch API.

Key Changes

New proxy configuration utility (src/utils/proxy-config.ts):

  • Detects and parses proxy environment variables (https_proxy, HTTPS_PROXY, http_proxy, HTTP_PROXY)
  • Configures undici's global dispatcher to route all HTTP requests through the proxy
  • Supports no_proxy / NO_PROXY for documenting bypass hosts (parsed and logged)
  • Includes case-insensitive environment variable support
  • Handles errors gracefully, allowing the server to continue without proxy if configuration fails

Integration (src/index.ts):

  • Calls configureProxyFromEnvironment() early in the startup process
  • Ensures all HTTP requests (OAuth token requests, Dynatrace API calls, environment checks) honor proxy settings

Documentation:

  • Added comprehensive proxy configuration section to README.md
  • Updated CHANGELOG.md with the new feature
  • Added proxy examples to .env.template
  • Includes clear note about no_proxy limitation

Testing

  • Added 14 comprehensive unit tests covering all proxy scenarios
  • All 99 unit tests passing
  • Tested with multiple configurations: HTTPS_PROXY, HTTP_PROXY fallback, NO_PROXY lists, and no proxy
  • Verified server starts correctly with and without proxy configuration

Usage Example

# Set proxy environment variables
export HTTPS_PROXY=http://proxy.company.com:8080
export NO_PROXY=localhost,127.0.0.1,.company.local
export DT_ENVIRONMENT=https://abc12345.apps.dynatrace.com

# Start the MCP server
npx @dynatrace-oss/dynatrace-mcp-server

Expected output:

Initializing Dynatrace MCP Server v0.9.2...
Configuring proxy from environment: http://proxy.company.com:8080
No proxy hosts configured: localhost, 127.0.0.1, .company.local
✅ Proxy configured successfully: http://proxy.company.com:8080

Known Limitation

The no_proxy environment variable is currently parsed and logged for informational purposes but not fully enforced by undici's ProxyAgent. This is a limitation of the underlying HTTP client library. Users who need no_proxy functionality should configure their proxy servers to handle these exclusions. This limitation is clearly documented in both code comments and user-facing documentation.

Impact

  • No breaking changes - Proxy configuration is completely optional
  • Zero additional dependencies - Uses existing undici package
  • Backward compatible - Works exactly as before when no proxy is configured
  • Production ready - Comprehensive testing and error handling

@dynatrace-cla-bot
Copy link

dynatrace-cla-bot commented Oct 16, 2025

CLA assistant check
All committers have signed the CLA.

@christian-kreuzberger-dtx
Copy link
Collaborator

Thank you for the contribution! On the surface, this already looks great, I'll dive into the details later.

One question upfront though: Do we need undici (a fetch polyfil) for this to work properly? Since Node v20 (or was it 22?), fetch is built-in, and we should not require to interact with undici.

@manoharnv
Copy link
Contributor Author

manoharnv commented Oct 16, 2025

Thank you for the contribution! On the surface, this already looks great, I'll dive into the details later.

One question upfront though: Do we need undici (a fetch polyfil) for this to work properly? Since Node v20 (or was it 22?), fetch is built-in, and we should not require to interact with undici.

we could use https-proxy-agent. However I chose to use undici since it is already a transitive dependency of fetch

@christian-kreuzberger-dtx
Copy link
Collaborator

we could use https-proxy-agent. However I chose to use undici since it is already a transitive dependency of fetch

Thanks, didn't know that - I also just checked, and you're right, undici is already there 👍

Using this as a proxy is the way to go: https://undici.nodejs.org/#/docs/api/ProxyAgent?id=example-basic-proxyagent-instantiation

Copy link
Collaborator

@christian-kreuzberger-dtx christian-kreuzberger-dtx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conditional approval for the proposed changes 👍

Still to be done:

  • Move the text in README.md a couple of lines towards the bottom, so it's not in between the config description for DT_ENVIRONMENT
  • Consider removing the shouldBypassProxy helper, as it's not used

edit: Please sign the CLA

@manoharnv
Copy link
Contributor Author

Conditional approval for the proposed changes 👍

Still to be done:

  • Move the text in README.md a couple of lines towards the bottom, so it's not in between the config description for DT_ENVIRONMENT
  • Consider removing the shouldBypassProxy helper, as it's not used

edit: Please sign the CLA

Issues addressed.
CLA signed for myself. Do we need to sign for copilot too? how to do it?

Copy link
Collaborator

@christian-kreuzberger-dtx christian-kreuzberger-dtx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@christian-kreuzberger-dtx
Copy link
Collaborator

@manoharnv Thank you for the changes ;)
I've reached out internally to get the CLA stuff for copilot handled. If that doesn't work... we will find a way 🤷

Copilot AI and others added 4 commits October 21, 2025 09:31
- Created proxy-config utility to configure undici ProxyAgent
- Added support for https_proxy, HTTPS_PROXY, http_proxy, HTTP_PROXY, no_proxy, and NO_PROXY environment variables
- Proxy is configured early in startup process before any HTTP requests
- Added comprehensive test coverage for proxy configuration
- Updated README.md with proxy environment variable documentation
- Updated CHANGELOG.md to document new feature

Co-authored-by: manoharnv <[email protected]>
- Remove unnecessary log message when no proxy is configured
- Clarify no_proxy limitation in code comments and README
- Update .env.template with proxy configuration examples

Co-authored-by: manoharnv <[email protected]>
Fixing as per review comment.
placing the proxy configuration at the right place.
@christian-kreuzberger-dtx christian-kreuzberger-dtx merged commit e7ea62d into dynatrace-oss:main Oct 21, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants