fix(cli): handle missing Windows npx without crashing

Closed
SA
17d ago
+17-5

Summary

On Windows, probing for npx via subprocess.run can raise FileNotFoundError when the executable is absent. _get_npx_command() previously only caught CalledProcessError, so mcp dev could crash instead of returning None and printing the existing missing-npx guidance.

This change:

  • Catches (CalledProcessError, FileNotFoundError) in _get_npx_command()
  • Adds return annotations for _get_npx_command, _import_server, and _check_server_object
  • Tightens _check_server_object to take object instead of Any
  • Extends CLI unit tests for the missing-binary path

Fixes #3673

Test plan

  • Added test_get_npx_returns_none_when_windows_binary_missing
  • CI: tests/cli/test_utils.py

AI assistance: used Cursor to draft the patch and PR text; I own the change and can iterate on review feedback.