Skip to content

fix: add corporate proxy support using https-proxy-agent (fixes #18) - #19

Open
zouyi100 wants to merge 2 commits into
UI5:mainfrom
zouyi100:fix/proxy-support
Open

fix: add corporate proxy support using https-proxy-agent (fixes #18)#19
zouyi100 wants to merge 2 commits into
UI5:mainfrom
zouyi100:fix/proxy-support

Conversation

@zouyi100

Copy link
Copy Markdown

Summary

The MCP server originally does not work behind a corporate proxy because Node.js native fetch() does not respect HTTP_PROXY/HTTPS_PROXY environment variables. This PR adds proxy support using https-proxy-agent and node-fetch, enabling the server to function correctly in proxied environments.

Commits

  • bf73e5e - Initial proxy support: Added getProxyAgent() that reads proxy configuration from HTTPS_PROXY, https_proxy, HTTP_PROXY, http_proxy environment variables.
  • 20f6bca - Replaced undici with node-fetch + https-proxy-agent for robust proxy support. Added proxyFetch() wrapper, comprehensive unit tests with nock, and proper env var priority handling.

Key Changes

  • Added node-fetch and https-proxy-agent as runtime dependencies; removed undici
  • Added nock as dev dependency for clean HTTP mocking in tests
  • getProxyAgent() returns an HttpsProxyAgent based on proxy env vars
  • New proxyFetch() wrapper routes all outbound requests through proxy when configured
  • Environment variable priority: HTTPS_PROXY > https_proxy > HTTP_PROXY > http_proxy
  • Updated manifest_processor to use proxyFetch instead of raw fetch
  • Rewrote manifest_processor tests to use nock instead of mocking global.fetch
  • Added getProxyAgent unit tests with proper env var isolation

Fixes #18

zouyi100 added 2 commits June 15, 2026 14:45
…oxy support

Replace the undici-based proxy dispatcher approach with node-fetch and https-proxy-agent, which provides better compatibility across different proxy environments.

- Remove undici dependency, add node-fetch and https-proxy-agent
- Add nock dev dependency for clean HTTP mocking in tests
- Refactor getProxyAgent to return HttpsProxyAgent instead of undici ProxyAgent
- Add proxyFetch wrapper function for proxy-aware fetch calls
- Update manifest_processor to use proxyFetch instead of raw fetch with dispatcher
- Rewrite manifest_processor tests to use nock instead of global.fetch mocking
- Add comprehensive getProxyAgent unit tests with proxy env var priority validation
@cla-assistant

cla-assistant Bot commented Jun 15, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@dobrinyonkov

Copy link
Copy Markdown
Contributor

Thanks for this, and for the tests. The proxy bug is real, I reproduced it locally.

Since we're on Node 20+, native fetch is backed by undici (already in Node). Its EnvHttpProxyAgent makes native fetch proxy-aware with no call-site changes:

import { EnvHttpProxyAgent, setGlobalDispatcher } from 'undici';
setGlobalDispatcher(new EnvHttpProxyAgent());

I tested it against a local proxy and it works. That lets us drop node-fetch and https-proxy-agent and remove proxyFetch/getProxyAgent.

Your first commit used undici's ProxyAgent, then you switched away. What went wrong with undici? That decides whether we go this route or keep yours.

Let's keep the nock migration either way. One fix if we keep your approach: getProxyAgent logs the full proxy URL, which leaks credentials when someone sets user:pass@proxy. Log host and port only:

const { hostname, port } = new URL(proxyUrl);
logger.debug(`Using proxy: ${hostname}:${port}`);

@dobrinyonkov

Copy link
Copy Markdown
Contributor

Hi @zouyi100, any thoughts on the above?

@dobrinyonkov dobrinyonkov added the question Further information is requested label Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

question Further information is requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP server does not work behind a corporate proxy

2 participants