[Windows] MCP child exits with `WinError 10106` when `SystemRoot`/`windir` are missing; Codex reports timeout — observed with Python MCP (serena)

Resolved 💬 5 comments Opened Sep 8, 2025 by aonorigomashio Closed Nov 23, 2025
💡 Likely answer: A maintainer (etraut-openai, contributor) responded on this thread — see the highlighted reply below.

What version of Codex is running?

Codex CLI: 0.29.0 , 0.30.0 (both reproduce) and VSCodeExtension 0.4.3

Which model were you using?

GPT-5

What platform is your computer?

Microsoft Windows NT 10.0.19045.0 x64

What steps can reproduce the bug?

1) Configure a Python MCP entry (here: serena) in ~/.codex/config.toml without SystemRoot/windir in env:
[mcp_servers.serena]
command = "C:\\Tools\\serena\\.venv\\Scripts\\serena.exe"
args = ["start-mcp-server", "--context", "codex", "--log-level", "ERROR"]

2) Start Codex (CLI or VS Code extension). Codex reports a timeout.

3) To confirm the root cause, wrap the command in a small .bat that dumps the child env and captures stderr:
@echo off
setlocal
set "ENVLOG=C:\Tools\serena\env_from_codex.txt"
set "ERR=C:\Tools\serena\serena_from_codex.err"
set > "%ENVLOG%"
"C:\Tools\serena\.venv\Scripts\serena.exe" start-mcp-server --context codex 2> "%ERR%"

4) Re-run Codex and check results:

  • env_from_codex.txt -> SystemRoot and windir are absent
  • serena_from_codex.err -> stack trace ends with OSError: [WinError 10106] ... (WSAEPROVIDERFAILEDINIT)

What is the expected behavior?

Codex should start the MCP, complete the STDIO handshake, and allow listing/using tools (e.g., tools/list).

What do you see instead?

Codex shows:
'MCP client 'serena' failed to start: request timed out'

The MCP child process actually exits quickly with code 1; stderr tail includes:
OSError: [WinError 10106] 指定されたサービス プロバイダーの読み込みまたは初期化を行うことができませんでした。
(which means “The specified service provider could not be loaded or initialized.”)

On the same machine, MCP Inspector succeeds (inherits the full shell environment), so the failure appears specific to how Codex spawns child processes on Windows.

Additional information

Workaround (fixes both CLI & VS Code extension):
[mcp_servers.serena]
command = "C:\\Tools\\serena\\.venv\\Scripts\\serena.exe"
args = ["start-mcp-server", "--context", "codex", "--log-level", "ERROR"]
env = { SystemRoot = "C:\\Windows", windir = "C:\\Windows" }

Hypothesis:
On Windows, Winsock initialization (triggered when importing asyncio.windows_events / _overlapped) may rely on system directories resolved via %SystemRoot% / %windir%. Codex appears to spawn MCP children with a minimized environment that omits those vars, causing WSAEPROVIDERFAILEDINIT (WinError 10106), early exit, and Codex timeout.

View original on GitHub ↗

5 Comments

adsqx · 11 months ago

This isn’t a Windows bug — it’s the same on Ubuntu.
It’s simply an issue with synchronization and the timeout.
That’s exactly what I meant by reactive loading. :)

aonorigomashio · 11 months ago

Thanks for the context! I agree there’s a cross-platform angle around reactive loading and startup timeouts.
In this report, though, I’m documenting a separate Windows-specific root cause: the MCP child process environment omits SystemRoot/windir, which makes Python crash immediately with WinError 10106 (Winsock provider init failure).Thank you.
Evidence:
• stderr shows WinError 10106 on startup;
• dumping the child env (spawned by Codex) shows SystemRoot/windir are absent;
• adding those two vars in the MCP env makes the issue disappear instantly (both CLI and VS Code extension).

x0x0b · 11 months ago

I encountered a similar issue with the MCP server in JetBrains IDEs on Windows.
If SystemRoot is not set, the connection fails.
Passing SystemRoot=C:\Windows in the env resolved it.

etraut-openai contributor · 9 months ago

I think this is no longer an issue, so I'm going to close the bug. If you see this with the latest version of codex, please open a new bug report and include repro steps.

fengxiang1990 · 1 day ago

java.io.IOException: Unable to establish loopback connection 我遇到了一样的问题,fuck gpt ,sb