Skip to content

[BUG] HTTP MCP Servers Fail Behind Corporate Proxy in Agent SDK v0.2.38 #169

@rekapallym

Description

@rekapallym

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

  1. Configure HTTP MCP server behind corporate proxy

  2. Set environment proxy variables:

  3. Call query() with MCP servers

  4. 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:

  1. Is there a workaround available in v0.2.38?
  2. Is this fixed in a newer version?
  3. Can proxy configuration be exposed in query() options?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions