Skip to content

πŸš€ The fast, Pythonic way to build MCP servers and clients.

Handle missing npx.cmd fallback on Windows πŸ€– Generated with GPT-5.2-Codex (#3416)

Jeremiah Lowindcaeef0f3dd6
diff --git a/src/fastmcp/cli/cli.py b/src/fastmcp/cli/cli.py
index f6472c470..68a4a4da0 100644
--- a/src/fastmcp/cli/cli.py
+++ b/src/fastmcp/cli/cli.py
@@ -54,7 +54,7 @@ def _get_npx_command():
try:
subprocess.run([cmd, "--version"], check=True, capture_output=True)
return cmd
- except subprocess.CalledProcessError:
+ except (subprocess.CalledProcessError, FileNotFoundError):
continue
return None
return "npx" # On Unix-like systems, just use npx
diff --git a/tests/cli/test_cli.py b/tests/cli/test_cli.py
index eecc4300c..f7b9e47a8 100644
--- a/tests/cli/test_cli.py
+++ b/tests/cli/test_cli.py
@@ -440,6 +440,23 @@ class TestWindowsSpecific:
assert result == "npx.exe"
assert mock_run.call_count == 2
+ @patch("subprocess.run")
+ def test_get_npx_command_windows_cmd_missing(self, mock_run):
+ """Test npx command detection continues when npx.cmd is missing."""
+ from fastmcp.cli.cli import _get_npx_command
+
+ with patch("sys.platform", "win32"):
+ # Missing npx.cmd should not abort detection
+ mock_run.side_effect = [
+ FileNotFoundError("npx.cmd not found"),
+ Mock(returncode=0),
+ ]
+
+ result = _get_npx_command()
+
+ assert result == "npx.exe"
+ assert mock_run.call_count == 2
+
@patch("subprocess.run")
def test_get_npx_command_windows_fallback(self, mock_run):
"""Test npx command detection on Windows with plain npx."""