-
Notifications
You must be signed in to change notification settings - Fork 84
Description
Summary
HTTP-type MCP servers fail to connect with "The socket connection was closed unexpectedly" error when the SDK is used behind a corporate proxy with SSL inspection. SSE and stdio MCP servers work fine, and external HTTP servers (outside the proxy) also work.
Root Cause
The bundled MCP transport code appears to make HTTP GET requests (for SSE handshake) without passing proxy configuration. While environment variables (HTTP_PROXY, HTTPS_PROXY) are set, they don't work with undici's ProxyAgent dispatcher, which is required for corporate proxies with SSL inspection.
Reproduction
-
Configure HTTP MCP server behind corporate proxy
-
Set environment proxy variables:
- HTTP_PROXY=http://proxy.company.com:8080
- HTTPS_PROXY=http://proxy.company.com:8080
- NODE_EXTRA_CA_CERTS=/path/to/corporate/ca.pem
-
Call query() with MCP servers
-
Result: Connection fails with socket closed error
Evidence
- ✅ POST requests TO MCP servers → Work (proxy config included)
- ❌ GET requests FROM MCP servers (SSE) → Fail (socket closes unexpectedly)
- ✅ External HTTP MCP servers → Work (no proxy needed)
- ✅ SSE-type MCP servers → Work (no issue)
Related upstream issue: modelcontextprotocol/typescript-sdk#895
Requested Solutions
- Option A: Add requestInit parameter to query() options for proxy dispatcher
- Option B: Ensure proxy environment variables work consistently for all request types
- Option C: Expose custom fetch function parameter to query()
Version Info
- Agent SDK: v0.2.38 (latest)
- Environment: VSCode Extension (Node.js v22.x)
- Proxy: undici ProxyAgent with SSL inspection
Impact
This completely blocks HTTP MCP server usage in enterprise environments with corporate proxies. This is a critical blocker for enterprise adoption of the Agent SDK.
Please advise on:
- Is there a workaround available in v0.2.38?
- Is this fixed in a newer version?
- Can proxy configuration be exposed in query() options?