[BUG] Claude Code CLI MCP connection issue

Open 💬 3 comments Opened Mar 16, 2026 by LTangaF

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Claude Code CLI cannot connect to HTTP MCP servers. The Bun runtime bundled in the CLI binary fails at the TCP socket level (FailedToOpenSocket / ConnectionRefused) before any HTTP request is made. The same MCP server connects successfully from the VS Code extension (same version 2.1.76, same config in ~/.claude.json), which runs on Node.js instead of Bun.

claude mcp list reports ✗ Failed to connect and the MCP server's access log confirms no request ever arrives from the CLI.

This is the same root cause as #17541 (auto-closed as duplicate of #16331). The issue persists in 2.1.76.

What Should Happen?

The CLI should connect to HTTP MCP servers that are reachable from the same machine, matching the VS Code extension's behavior. curl and the VS Code extension both connect instantly to the same endpoint.

Error Messages/Logs

Debug output from `claude --debug --debug-file /tmp/debug.log mcp list`:

**Using hostname:**

MCP server "muninn": Initializing HTTP transport to http://<host>:<port>/mcp
MCP server "muninn": Node version: v24.3.0, Platform: darwin
MCP server "muninn": Environment: {"NODE_OPTIONS":"not set","UV_THREADPOOL_SIZE":"default","HTTP_PROXY":"not set","HTTPS_PROXY":"not set","NO_PROXY":"not set"}
MCP server "muninn": HTTP transport options: {"url":"http://<host>:<port>/mcp","headers":{"User-Agent":"claude-code/2.1.76 (cli)","Authorization":"[REDACTED]"},"hasAuthProvider":true,"timeoutMs":60000}
MCP server "muninn": HTTP transport created successfully
MCP server "muninn": Client created, setting up request handler
MCP server "muninn": Starting connection with timeout of 30000ms
MCP server "muninn": Testing basic HTTP connectivity to http://<host>:<port>/mcp
MCP server "muninn": No token data found
MCP server "muninn": HTTP Connection failed after 8ms: Unable to connect. Is the computer able to access the url? (code: ConnectionRefused, errno: none)


**Using direct IP address instead of hostname:**

MCP server "muninn": HTTP Connection failed after 6ms: Was there a typo in the url or port? (code: FailedToOpenSocket, errno: none)

Steps to Reproduce

  1. Configure an HTTP MCP server in ~/.claude.json:

``json
"mcpServers": {
"muninn": {
"type": "http",
"url": "http://<host>:<port>/mcp",
"headers": {
"Authorization": "Bearer <token>"
}
}
}
`
Server under test: [MuninnDB](https://github.com/scrypster/muninndb.git) at commit
92d63ad471614fc5370256c986a0c18281a0eb4a`, running on a LAN host.

  1. Verify the server is reachable via curl (returns HTTP 200 with valid JSON-RPC initialize response):

``bash
curl -s -X POST \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","method":"initialize","id":0,"params":{"protocolVersion":"2025-03-26","capabilities":{},"clientInfo":{"name":"test","version":"0.1"}}}' \
http://<host>:<port>/mcp
# HTTP 200, Content-Type: application/json, Mcp-Session-Id returned
# Server responds with protocolVersion: "2024-11-05"
``

  1. Run claude mcp list — reports ✗ Failed to connect
  1. Open the same project in VS Code with Claude Code extension 2.1.76 — connects successfully using the same ~/.claude.json config

Claude Model

Not sure / Multiple models

Is this a regression?

Yes, this worked in a previous version

Last Working Version

~ 2.1.70

Claude Code Version

2.1.76

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

iTerm2

Additional Information

Investigation details

  • MCP server logs confirm zero inbound connections from the CLI — the failure is before any TCP SYN is sent
  • curl from the same machine connects in ~14ms with HTTP 200 and valid MCP initialize response
  • VS Code extension (2.1.76) connects via Streamable HTTP with SSE, completing the full initialize → tools/list handshake. Server logs show successful SSE streams and dispatch via=streamable entries for VS Code connections.
  • MuninnDB supports both legacy SSE and Streamable HTTP transports and negotiates protocol version 2024-11-05 (which is in Claude Code's supported list)
  • Changing type from "http" to "sse" in config produces the same failure
  • macOS Application Firewall is disabled
  • No HTTP/HTTPS proxy configured
  • DNS resolution is correct (verified via dig, no IPv6 records)
  • The server is on a LAN (private IP address)
  • It is observed that the output from the debug log shows the option "hasAuthProvider":true. It's not certain that if that even _COULD_ be overwritten if it would have an impact. It is not negatively affecting the VS Code extension and as was already noted, the MuninnDB MCP server doesn't even _SEE_ connection attempts from the Bun-based attempt

Root cause

The CLI binary is compiled with Bun, which bundles its own HTTP/socket implementation separate from Node.js. Bun's networking stack produces FailedToOpenSocket / ConnectionRefused at the TCP level for endpoints that are fully reachable via system curl and Node.js fetch.

The same JavaScript codebase works on Node.js (VS Code extension host) but fails on Bun (CLI binary). This is the distinguishing factor — identical code, identical config, different runtime, different result.

Related issues

  • #17541 — "Connection Refused error despite successful curl to API endpoint (macOS)" — auto-closed as duplicate
  • #16331 — parent issue referenced by #17541
  • #11633 — "HTTP MCP Server 'Failed to connect' Despite Successful Manual Testing"

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗