From dcaeef0f3dd6661216697531d5fd60d7b90bcdc4 Mon Sep 17 00:00:00 2001 From: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Date: Sat, 7 Mar 2026 11:40:57 -0500 Subject: [PATCH] =?UTF-8?q?Handle=20missing=20npx.cmd=20fallback=20on=20Wi?= =?UTF-8?q?ndows=20=F0=9F=A4=96=20Generated=20with=20GPT-5.2-Codex=20(#341?= =?UTF-8?q?6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fastmcp/cli/cli.py | 2 +- tests/cli/test_cli.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) 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."""