[BUG] Claude Code CLI MCP connection issue

Status Open
Reported on v2.1.76
Maintainer reply None cached
Activity 5 comments · opened Mar 16, 2026

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 ↗

5 Comments

github-actions[bot] · 7 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/17541
  2. https://github.com/anthropics/claude-code/issues/16331
  3. https://github.com/anthropics/claude-code/issues/11633

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

LTangaF · 7 months ago

All those other issues are closed. This one should be addressed.

ricardoaveloso · 6 months ago

+1, but in windows, to the same effect: MCP server is running (and curl works) but claude code cli reports "failed to connect".

chhuang789 · 23 days ago

+1, same root cause, another data point (macOS, Claude Code 2.1.278).

Setup: Python FastMCP streamable-http server (mcp==1.30.0) running on a LAN Ubuntu 24.04 host, reachable and healthy:

  • ss -tlnp confirms it's bound and listening.
  • ufw allows the port (also tested with ufw fully disabled — no change).
  • curl -X POST .../mcp with a proper initialize JSON-RPC payload returns 200 instantly with a valid MCP response, from the same Mac that's failing.

claude mcp add --transport http <name> http://<LAN-IP>:8000/mcp (and later claude mcp remove + re-add, and updating the CLI) all still fail. /mcp shows reconnect -> failed. Debug log:

Testing basic HTTP connectivity to http://<LAN-IP>:8000/mcp
version negotiation probe failed on the http transport; reconnecting pinned legacy
HTTP Connection failed after 47ms: Was there a typo in the url or port? (code: FailedToOpenSocket, errno: none)

Also tried a /etc/hosts hostname alias instead of the raw IP — same failure, so it's not IPv4-literal-string-specific.

Switching the exact same server to bind on 127.0.0.1 on the same Mac and pointing the MCP config at http://127.0.0.1:8000/mcp connects immediately (✔ Connected). So in our case too, it's specifically "loopback works, LAN address (IP or hostname) doesn't" on the CLI (terminal claude, not the VS Code extension).

Current workaround: spawn the server over SSH as stdio transport instead of using the HTTP transport for the remote host.

chhuang789 · 23 days ago

Follow-up confirming the Bun-vs-Node split for our case too: switched to the VS Code Claude Code extension (same project folder, same local-scope MCP config in ~/.claude.json, just pointed at the same http://<LAN-IP>:8000/mcp) and it connected immediately and the tool worked. The standalone claude CLI in a plain terminal (iTerm2 on macOS) still fails with the same FailedToOpenSocket on every reconnect attempt. So confirmed: same config, same machine, same server — Node.js-based VS Code extension works, Bun-compiled CLI binary doesn't.