Skip to content

MCPConfigTransport Timeout Not Applied When Multiple Servers Are Configured #2802

Closed

Description

@a-hourani

Description

MCPConfigTransport Timeout Not Applied When Multiple Servers Are Configured

Problem Description

When using MCPConfigTransport (via Client constructor) with multiple MCP servers, the timeout parameter specified in the client constructor is ignored. This causes tool calls to hang indefinitely instead of respecting the configured timeout.

  • ✅ Works correctly: Single server configuration respects timeout
  • ❌ Broken: Multiple server configuration ignores timeout

Minimal Reproducible Example

The reproduction code has been separated into two files for cleaner testing and log separation:

Server Side (test_servers.py)

import asyncio
import threading
from fastmcp import FastMCP

# Create two test servers with slow operations
server1 = FastMCP("TestServer1")
server2 = FastMCP("TestServer2")

@server1.tool()
async def slow_tool1(delay: int) -> str:
    """A tool that takes a long time to complete"""
    await asyncio.sleep(delay)
    return f"Server1 completed after {delay}s"

@server2.tool()
async def slow_tool2(delay: int) -> str:
    """Another tool that takes a long time to complete"""
    await asyncio.sleep(delay)
    return f"Server2 completed after {delay}s"

def run_server(server, port):
    """Run server in background thread"""
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    loop.run_until_complete(
        server.run(transport="http", host="127.0.0.1", port=port)
    )

def start_test_servers():
    """Start both test servers in background threads"""
    print("🚀 Starting test servers...")
    thread1 = threading.Thread(target=run_server, args=(server1, 7001), daemon=True)
    thread2 = threading.Thread(target=run_server, args=(server2, 7002), daemon=True)
    thread1.start()
    thread2.start()
    print("   - Server1 starting on port 7001")
    print("   - Server2 starting on port 7002")
    return thread1, thread2

if __name__ == "__main__":
    start_test_servers()
    print("✅ Test servers started. Keep this running while testing the client.")
    try:
        # Keep the main thread alive
        while True:
            asyncio.get_event_loop().run_until_complete(asyncio.sleep(1))
    except KeyboardInterrupt:
        print("🛑 Shutting down test servers...")

Client Side (test_timeout_client.py)

import asyncio
import time
from fastmcp import Client

async def test_timeout_behavior():
    """Test timeout behavior with single vs multiple servers"""
    
    print("⚠️  Make sure test_servers.py is running before starting this test!\n")
    
    # Wait for servers to be ready
    await asyncio.sleep(2)
    
    # TEST 1: Single server configuration (WORKS)
    print("📋 Test 1: Single server config with 15-second timeout")
    single_server_config = {
        "mcpServers": {
            "server1": {
                "url": "http://127.0.0.1:7001/mcp",
                "transport": "http"
            }
        }
    }
    
    client_single = Client(single_server_config, timeout=15)  # 15 second timeout
    
    try:
        start_time = time.time()
        async with client_single:
            print("   ⏱️  Calling slow_tool1 with 7s delay (should complete successfully)...")
            # This should complete successfully within the 15s timeout
            result = await client_single.call_tool("slow_tool1", {"delay": 7}, timeout=15)
            elapsed = time.time() - start_time
            print(f"   ✅ SUCCESS: Tool completed after {elapsed:.1f}s: {result}")
    except Exception as e:
        elapsed = time.time() - start_time
        print(f"   ❌ Unexpected timeout after {elapsed:.1f}s: {type(e).__name__}")
        print(f"      Exception details: {str(e)}")
    
    print()
    
    # TEST 2: Multiple server configuration (BROKEN)
    print("📋 Test 2: Multiple server config with 15-second timeout")
    multiple_server_config = {
        "mcpServers": {
            "server1": {
                "url": "http://127.0.0.1:7001/mcp",
                "transport": "http"
            },
            "server2": {
                "url": "http://127.0.0.1:7002/mcp",
                "transport": "http"
            }
        }
    }
    
    client_multiple = Client(multiple_server_config, timeout=15)  # 15 second timeout
    
    try:
        start_time = time.time()
        async with client_multiple:
            print("   ⏱️  Calling server1_slow_tool1 with 7s delay (should complete successfully)...")
            # This should complete successfully within the 15s timeout, but timeout is ignored!
            result = await client_multiple.call_tool("server1_slow_tool1", {"delay": 7}, timeout=15)
            elapsed = time.time() - start_time
            print(f"   ❓ Tool completed after {elapsed:.1f}s: {result}")
            if elapsed > 6 and elapsed < 8:
                print(f"   ✅ SUCCESS: Completed in expected time (~7s)")
            else:
                print(f"   ⚠️  WARNING: Unexpected completion time")
    except Exception as e:
        elapsed = time.time() - start_time
        print(f"   ❌ BUG: Tool failed after {elapsed:.1f}s: {type(e).__name__}")
        print(f"      Exception details: {str(e)}")

if __name__ == "__main__":
    print("🔧 FastMCP Timeout Bug Reproduction - CLIENT SIDE")
    print("=" * 50)
    asyncio.run(test_timeout_behavior())

How to Run the Test

  1. Terminal 1 - Start the servers:

    python test_servers.py
  2. Terminal 2 - Run the client test:

    python test_timeout_client.py

This separation allows maintainers to clearly see client-side logs without server noise, making debugging much easier.

Expected Behavior

Both single and multiple server configurations should respect the 15-second timeout and successfully complete tool calls that take 7 seconds.

Actual Behavior

  • Single server config: ✅ Correctly completes 7-second tool calls within 15-second timeout
  • Multiple server config: ❌ Timeout mechanism is broken - may fail to complete operations that should succeed within the configured timeout period

Root Cause Analysis

The issue lies in MCPConfigTransport.__init__() in fastmcp/client/transports.py:

  1. Single server case (works correctly):

    # Creates direct StreamableHttpTransport with proper timeout handling
    self.transport = server_config.to_transport()
  2. Multiple server case (broken):

    # Creates FastMCPTransport (in-memory) that mounts all servers
    self._composite_server = FastMCP[Any](name=name)
    for name, server, transport in mcp_config_to_servers_and_transports(self.config):
        self._composite_server.mount(server, prefix=name)
    self.transport = FastMCPTransport(mcp=self._composite_server)

The problem is that FastMCPTransport is an in-memory transport that doesn't propagate HTTP timeouts to the mounted servers. When session_kwargs containing read_timeout_seconds are passed to FastMCPTransport.connect_session(), the timeout is applied to the in-memory communication, not to the HTTP calls made by the mounted servers.

Example Code

Version Information

version 2.14.2

Activity

  1. added
    bug
    on Jan 7, 2026
  2. added
    client
    http
    on Jan 7, 2026
  3. added 2 commits that reference this issue on Jan 7, 2026
    84ed861
    6b11026
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

    bugclienthttp

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions