Skip to content

Stdio MCP server fails to connect when server/discover times out: legacy initialize fallback on the same connection is rejected with -32022 #5464

Done

Description

Summary

When a stdio MCP server takes longer than ~10 s to start, Copilot CLI gives up waiting for its server/discover probe and sends a legacy initialize on the same stdio connection. A server built on the MCP Python SDK 2.3.0 then processes the queued server/discover first, locks the connection to the 2026-07-28 protocol, and rejects the initialize with -32022. Copilot CLI reports the server as failed and does not retry, even though both sides support 2026-07-28.

In the same situation, Claude Code (2.1.308) and the MCP Python SDK client re-probe with server/discover and connect successfully.

Environment

  • Copilot CLI 1.0.103 (linux-x64)
  • MCP server: any stdio server on mcp (Python SDK) 2.3.0 with a slow cold start. Observed with analytics-mcp 0.8.0 (Google Analytics MCP server) and serena-agent 2.1.0.

Steps to reproduce

  1. Save this as slow_server.py:

    # /// script
    # dependencies = ["mcp==2.3.0"]
    # ///
    import time
    
    time.sleep(12)  # simulate a slow cold start
    
    from mcp.server.mcpserver import MCPServer
    
    server = MCPServer("slow-start-repro")
    
    
    @server.tool()
    def ping() -> str:
        return "pong"
    
    
    server.run("stdio")
  2. Run uv run --script slow_server.py < /dev/null once so the dependencies are cached.

  3. Start Copilot CLI with the server:

    copilot -p "List the tools of the slowrepro MCP server. Do not call them." \
      --additional-mcp-config '{"mcpServers":{"slowrepro":{"type":"local","command":"uv","args":["run","-q","--script","/path/to/slow_server.py"],"tools":["*"]}}}'

Actual behavior

The server is not connected. The log shows:

[WARNING] [rust:rt_mcp_connection] MCP server connection failed {"server_name":"...","raw_error":"failed to initialize MCP client: JSON-RPC error: -32022: connection is serving the 2026-07-28 protocol; the initialize handshake is not accepted({\"supported\":[\"2026-07-28\"],\"requested\":\"2025-11-25\"})"}

Frames captured between Copilot CLI and the server (seconds since spawn):

 0.007 C->S {"id":0,"method":"server/discover","params":{"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28",...}}}
 9.797 C->S {"id":1,"method":"initialize","params":{"protocolVersion":"2025-11-25",...}}
13.813 S->C {"id":0,"result":{"supportedVersions":["2026-07-28"],...}}
13.814 S->C {"id":1,"error":{"code":-32022,"message":"connection is serving the 2026-07-28 protocol; the initialize handshake is not accepted","data":{"supported":["2026-07-28"],"requested":"2025-11-25"}}}

Servers that normally start within 5 s also hit this right after the machine boots (cold disk cache, many processes starting at once). In that case, /mcp reload or restarting Copilot CLI connects them.

Expected behavior

The connection succeeds over 2026-07-28, as it does when the server starts within the timeout. Any of these would work:

  • When the fallback initialize gets -32022 and data.supported contains a version the client supports, re-probe with server/discover at that version. The MCP Python SDK client does this (mcp/client/_probe.py: "The fallback handshake itself can be answered with -32022 … That code is itself positive modern evidence … so it triggers one re-probe at a mutual version instead of failing the connect."), and so does Claude Code.
  • Accept a late server/discover response that arrives after the fallback was sent.
  • For stdio, restart the server process before falling back, so the fallback does not share a connection with the unanswered probe.

Workaround

Make the server start faster than the probe timeout. In our case the venv is read-only at runtime, so .pyc files were never written. Installing the server with uv tool install --compile-bytecode brought startup down to ~3.5 s, and Copilot CLI then connected over 2026-07-28. This still fails occasionally right after the machine boots, as described above.

Activity

  1. added
    area:mcp
    and removed on Nov 16, 2026
  2. hstaudacher commented on Nov 18, 2026

    @hstaudacher
    Collaborator

    Thanks for the precise wire capture. Confirmed: when server/discover times out, the legacy initialize fallback is sent on the same connection, so slow-starting stdio servers can fail to connect. This is separate from the cache-hint fix for #4888, and we've moved it to the backlog.

  3. robert-lukowski commented on Nov 25, 2026

    @robert-lukowski

    Additional data point from Windows 11 with Copilot CLI 1.0.115 and the official AWS MCP Proxy.

    I am seeing intermittent MCP initialization failures with:

    JSON-RPC error: -32022:
    connection is serving the 2026-07-28 protocol;
    the initialize handshake is not accepted
    {"supported":["2026-07-28"],"requested":"2025-11-25"}
    

    Environment:

    • Windows 11 x64
    • GitHub Copilot CLI 1.0.115
    • uv/uvx 0.13.9
    • mcp-proxy-for-aws-cli 2.0.0
    • Python MCP SDK 2.3.0
    • FastMCP 4.2.0
    • Local stdio proxy connecting to AWS MCP through SigV4
    • Two AWS IAM Identity Center profiles

    What I tested:

    1. An independent Python MCP SDK client successfully connected to the same proxy executable, using the same endpoint, metadata and AWS profiles. Initialization negotiated 2025-11-25 and completed in approximately 13.7 seconds; tools/list completed at approximately 20.6 seconds from process start and returned eight tools. No AWS tools were invoked.

    2. A diagnostic stdio wrapper observed Copilot sending server/discover with 2026-07-28, followed by initialize with 2025-11-25 on the same connection. However, the wrapper experienced a roughly 10-second subprocess startup delay before reading stdin, so its timestamps cannot establish the actual interval between those messages. The capture was also incomplete at shutdown. I cannot conclusively attribute the -32022 response to a particular component from that capture.

    3. Direct execution of the installed proxy still failed before increasing the Copilot MCP configuration timeout.

    4. Direct execution with "timeout": 120000 connected successfully.

    5. Switching back to uvx with mcp-proxy-for-aws-cli@latest, while retaining the same timeout, reproduced the failure. Switching back to direct execution restored connectivity.

    The configuration that restored connectivity was:

    {
      "mcpServers": {
        "aws-mcp": {
          "type": "local",
          "timeout": 120000,
          "command": "C:\\Users\\<USER>\\.local\\bin\\mcp-proxy-for-aws-cli.exe",
          "args": [
            "https://aws-mcp.eu-central-1.api.aws/mcp",
            "--metadata",
            "AWS_REGION=eu-central-1"
          ],
          "env": {
            "AWS_MCP_PROXY_PROFILES": "aws-dev aws-test"
          },
          "tools": ["*"]
        }
      }
    }

    The executable was installed with:

    uv tool install --compile-bytecode mcp-proxy-for-aws-cli==2.0.0

    This is an observed workaround on one workstation, not a confirmed root-cause fix. The uvx and installed environments were not fully compared, and validation after reboot and on another workstation is still pending.

    Does the per-server timeout setting also control the server/discover probe timeout in 1.0.115, or is that probe governed by a separate limit? Is there a supported way to avoid a legacy initialize fallback on an already-probed stdio connection?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:mcp

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions