feat: add configurable MCP server initialization timeout #3196 #2346 #2555
• 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_msfield toMcpServerConfigwith 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_msfield toMcpServerConfigstruct with serde default of 10,000ms - Updated
mcp_connection_manager.rsto 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: Addedinit_timeout_msfield with default functioncodex-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
/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()