codex icon indicating copy to clipboard operation
codex copied to clipboard

feat: add configurable MCP server initialization timeout #3196 #2346 #2555

Open Bit-urd opened this issue 3 months ago • 0 comments

• I have read the CLA Document and I hereby sign the CLA • Local checks are all green (fmt / clippy / test). • Could you please approve the pending GitHub Actions workflows (first-time contributor), and when convenient, help with one approving review so I can proceed? Thanks!

Summary

Add configurable initialization timeout for MCP servers to allow customization per server configuration.

What?

  • Add init_timeout_ms field to McpServerConfig with 10-second default value
  • Update MCP connection manager to use the configurable timeout instead of hardcoded 10s

Why?

This change provides flexibility for MCP servers that may need longer initialization times than the current hardcoded 10-second timeout, while maintaining backwards compatibility.

How?

  • Added init_timeout_ms field to McpServerConfig struct with serde default of 10,000ms
  • Updated mcp_connection_manager.rs to extract and use the configurable timeout value
  • Maintained backwards compatibility - configs without the field automatically use the 10s default

Test Plan

  • [x] Verify existing MCP servers continue to work with default 10s timeout
  • [x] Test custom timeout values work as expected
  • [x] Confirm backwards compatibility (configs without the field use default)

Files Modified

  • codex-rs/core/src/config_types.rs: Added init_timeout_ms field with default function
  • codex-rs/core/src/mcp_connection_manager.rs: Updated to use configurable timeout

related issue

https://github.com/openai/codex/issues/3196 https://github.com/openai/codex/issues/2346 https://github.com/openai/codex/issues/2555

my test case

746b1165-fab0-4a30-93a3-ccea5465602e cec7f0e8-c0ab-4271-a324-7145b811d1d7

/Users/admin/workspace/codex/test_slow_15s_mcp_server.py file:

#!/usr/bin/env python3
"""
Test MCP server that sleeps 15 seconds during initialization.
Used to test the configurable init_timeout_ms feature.
FastMCP version.
"""

import time
import sys
from fastmcp import FastMCP

print("Starting FastMCP test server...", file=sys.stderr)
print("Sleeping for 15 seconds to test timeout...", file=sys.stderr)

# Sleep for 15 seconds to test timeout behavior (blocking)
time.sleep(15)

print("Sleep completed, creating FastMCP server!", file=sys.stderr)

# Create MCP server after delay
mcp = FastMCP("test-slow-server")

@mcp.tool()
def hello(name: str) -> str:
    """Say hello to someone."""
    return f"Hello, {name}!"

@mcp.tool()
def ping() -> str:
    """Simple ping tool."""
    return "pong"

@mcp.tool()
def get_time() -> str:
    """Get current time."""
    import datetime
    return f"Current time: {datetime.datetime.now()}"

if __name__ == "__main__":
    print("FastMCP server ready to serve!", file=sys.stderr)
    mcp.run()

Bit-urd avatar Sep 06 '25 11:09 Bit-urd