Skip to content

Conversation

@mkw
Copy link

@mkw mkw commented Jan 29, 2026

Summary

  • Adds proxy support for environments that route network traffic through HTTP proxies (e.g., Claude Code sandbox)
  • Detects https_proxy / HTTPS_PROXY environment variables and creates a proxy-aware fetch using undici's ProxyAgent
  • All existing tests pass, plus 5 new tests for proxy functionality

Problem

Node.js native fetch() (powered by undici) does not respect proxy environment variables. This causes mcpc to fail with getaddrinfo ENOTFOUND errors in environments like Claude Code's sandbox, which routes all network traffic through a local HTTP proxy.

Solution

When proxy environment variables are detected, create a custom fetch function using undici's ProxyAgent and pass it to the MCP SDK's StreamableHTTPClientTransport:

const { ProxyAgent, fetch: undiciFetch } = await import('undici');
const proxyAgent = new ProxyAgent(proxyUrl);

const proxyFetch = (input, init) => {
  return undiciFetch(input, { ...init, dispatcher: proxyAgent });
};

Changes

File Description
package.json Added undici dependency
src/core/transports.ts Added createProxyAwareFetch(), made transport functions async
src/core/factory.ts Added await for async transport creation
test/unit/core/transports.test.ts Added 5 proxy tests, updated existing tests
test/unit/core/factory.test.ts Updated mock to return Promise

Test plan

  • All 340 existing unit tests pass
  • 5 new proxy-aware fetch tests pass
  • Manually verified: mcpc successfully connects to remote MCP servers through Claude Code's sandbox proxy

Fixes #4

🤖 Generated with Claude Code

Node.js native fetch (undici) does not respect proxy environment variables.
This causes mcpc to fail in environments that route network traffic through
an HTTP proxy, such as Claude Code's sandbox.

This change:
- Adds a createProxyAwareFetch() helper that detects proxy env vars and
  creates a fetch function using undici's ProxyAgent
- Passes the proxy-aware fetch to StreamableHTTPClientTransport when
  proxy env vars are detected
- Makes createStreamableHttpTransport and createTransportFromConfig async
  to support the dynamic import of undici
- Adds undici as a direct dependency (required for ProxyAgent access)
- Adds 5 new unit tests for proxy-aware fetch functionality
- Updates existing tests to handle async transport creation

Fixes apify#4

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

Add proxy support for HTTPS_PROXY/https_proxy environment variables

1 participant