Skip to content

MCP server fails to start in Claude Code on macOS (stdio handshake never completes) #552

@paddymul

Description

@paddymul

Summary

The buckaroo-table MCP server (installed via claude mcp add) fails to connect in Claude Code CLI. The server process starts successfully and the asyncio event loop runs, but the MCP JSON-RPC handshake never completes. Claude Code reports "Failed to reconnect to buckaroo-table."

This works on another machine — need to diagnose what differs.

Install command

claude mcp add buckaroo-table -- uvx \
  --from "buckaroo[mcp]==0.12.9.dev22314929241" \
  --index-url https://test.pypi.org/simple/ \
  --extra-index-url https://pypi.org/simple/ \
  --index-strategy unsafe-best-match \
  buckaroo-table

Environment

  • macOS Darwin 25.0.0 (Apple Silicon)
  • Claude Code CLI (Opus 4.6)
  • Python 3.13 via uv/uvx 0.9.28
  • mcp package version: 1.26.0
  • buckaroo[mcp] version: 0.12.9.dev22314929241

Observed behavior

What the logs show (~/.buckaroo/logs/mcp_tool.log)

The server process starts fully — all handlers register, parent watcher starts, event loop begins:

12:04:34 [INFO]  MCP tool starting — server=http://localhost:8700 session=6e90500d8185
12:04:34 [DEBUG] Initializing server 'buckaroo-table'
12:04:34 [DEBUG] Registering handler for ListToolsRequest
12:04:34 [DEBUG] Registering handler for CallToolRequest
12:04:34 [DEBUG] Registering handler for ListResourcesRequest
12:04:34 [DEBUG] Registering handler for ReadResourceRequest
12:04:34 [DEBUG] Registering handler for PromptListRequest
12:04:34 [DEBUG] Registering handler for GetPromptRequest
12:04:34 [DEBUG] Registering handler for ListResourceTemplatesRequest
12:04:34 [INFO]  Parent watcher: original ppid=95944
12:04:34 [DEBUG] Using selector: KqueueSelector

But no MCP protocol messages are ever processed — no ListToolsRequest, no initialize response. The server is alive and listening on stdio, but the handshake never happens.

What Claude Code reports

Failed to reconnect to buckaroo-table.

Manual testing works fine

Running the exact same command manually with an initialize message piped to stdin works perfectly:

echo '{"jsonrpc":"2.0","id":0,"method":"initialize","params":{...}}' | \
  uvx --from "buckaroo[mcp]==0.12.9.dev22314929241" ... buckaroo-table
# Returns valid JSON-RPC response immediately

What has been ruled out

Hypothesis Result
uvx pollutes stdout Ruled out — 0 bytes to stdout during install/resolution. All output goes to stderr.
Startup too slow Ruled out — uvx launches in ~0.4s (warm cache), well under any timeout.
Port conflict on :8700 Ruled out — MCP uses stdio, data server only starts on-demand.
Code bugs in buckaroo_mcp_tool.py Ruled out — logging goes to file only, no stdout leaks, clean stdio transport.
Python/package not found Ruled out — process starts and event loop runs.

Suspected root cause

The stdio_server() in mcp 1.26.0 creates a new TextIOWrapper(sys.stdout.buffer) for the transport. There may be a buffering or timing issue where:

  1. Claude Code sends the initialize message before the server's wrapped stdin reader is fully ready
  2. The message gets consumed by the old sys.stdin wrapper and is lost before the new anyio.wrap_file() wrapper takes over
  3. The server blocks waiting for a message that was already consumed, and Claude Code times out waiting for a response

This would explain why:

  • Manual testing works (the message is already in the pipe when the server starts)
  • Claude Desktop works (it does a probe-close-reconnect dance that retries the init)
  • Claude Code fails (it may send init once and expect a response within a tight window)

Diagnostic request

This artifact works on another machine. To diagnose the difference, on the working machine please check:

  1. mcp package version: python -c "from importlib.metadata import version; print(version('mcp'))"
  2. buckaroo package version: python -c "from importlib.metadata import version; print(version('buckaroo'))"
  3. OS and Python version
  4. Contents of ~/.buckaroo/logs/mcp_tool.log — does it show protocol messages being processed?
  5. uvx --version
  6. Does ~/.buckaroo/logs/mcp_tool.log show Processing request of type ListToolsRequest etc. after startup?

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions