π The fast, Pythonic way to build MCP servers and clients.
1) Fixing this for windows in finding npm/npx for running servers in dev mode. 2) Fixing this for allowing server.py files to include module imports. Before they weren't resolving properly.
justjoehereaa3c5e819285
diff --git a/src/fastmcp/cli/cli.py b/src/fastmcp/cli/cli.pyindex 594caec3d..a73530300 100644--- a/src/fastmcp/cli/cli.py+++ b/src/fastmcp/cli/cli.py@@ -11,8 +11,8 @@ import typerfrom typing_extensions import Annotatedimport dotenv-from ..utilities.logging import get_logger-from . import claude+from fastmcp.cli import claude+from fastmcp.utilities.logging import get_loggerlogger = get_logger("cli")@@ -24,6 +24,22 @@ app = typer.Typer()+def _get_npx_command():+ """Get the correct npx command for the current platform."""+ if sys.platform == "win32":+ # Try both npx.cmd and npx.exe on Windows+ for cmd in ["npx.cmd", "npx.exe", "npx"]:+ try:+ subprocess.run(+ [cmd, "--version"], check=True, capture_output=True, shell=True+ )+ return cmd+ except subprocess.CalledProcessError:+ continue+ return None+ return "npx" # On Unix-like systems, just use npx++def _parse_env_var(env_var: str) -> Tuple[str, str]:"""Parse environment variable string in format KEY=VALUE."""if "=" not in env_var:@@ -99,6 +115,11 @@ def _import_server(file: Path, server_object: Optional[str] = None):Returns:The server object"""+ # Add parent directory to Python path so imports can be resolved+ file_dir = str(file.parent)+ if file_dir not in sys.path:+ sys.path.insert(0, file_dir)+# Import the modulespec = importlib.util.spec_from_file_location("server_module", file)if not spec or not spec.loader:@@ -205,10 +226,22 @@ def dev(with_packages = list(set(with_packages + server.dependencies))uv_cmd = _build_uv_command(file_spec, with_editable, with_packages)- # Run the MCP Inspector command++ # Get the correct npx command+ npx_cmd = _get_npx_command()+ if not npx_cmd:+ logger.error(+ "npx not found. Please ensure Node.js and npm are properly installed "+ "and added to your system PATH."+ )+ sys.exit(1)++ # Run the MCP Inspector command with shell=True on Windows+ shell = sys.platform == "win32"process = subprocess.run(- ["npx", "@modelcontextprotocol/inspector"] + uv_cmd,+ [npx_cmd, "@modelcontextprotocol/inspector"] + uv_cmd,check=True,+ shell=shell,)sys.exit(process.returncode)except subprocess.CalledProcessError as e:@@ -223,7 +256,9 @@ def dev(sys.exit(e.returncode)except FileNotFoundError:logger.error(- "npx not found. Please install Node.js and npm.",+ "npx not found. Please ensure Node.js and npm are properly installed "+ "and added to your system PATH. You may need to restart your terminal "+ "after installation.",extra={"file": str(file)},)sys.exit(1)