π The fast, Pythonic way to build MCP servers and clients.
Forward --skip-source to the uv run subprocess in fastmcp run (#5623)
Asem ahmeda9a87be6b4f7
diff --git a/fastmcp_slim/fastmcp/cli/cli.py b/fastmcp_slim/fastmcp/cli/cli.pyindex 233553747..16948866c 100644--- a/fastmcp_slim/fastmcp/cli/cli.py+++ b/fastmcp_slim/fastmcp/cli/cli.py@@ -681,6 +681,8 @@ async def run(reload_cmd.extend(["--log-level", final_log_level])if final_no_banner:reload_cmd.append("--no-banner")+ if skip_source:+ reload_cmd.append("--skip-source")reload_cmd.append("--no-reload") # Prevent infinite spawningreload_cmd.append("--stateless") # Stateless mode for reload compatibility@@ -732,6 +734,8 @@ async def run(inner_cmd.append("--no-banner")if stateless:inner_cmd.append("--stateless")+ if skip_source:+ inner_cmd.append("--skip-source")# Add skip-env flag to prevent infinite recursioninner_cmd.append("--skip-env")diff --git a/tests/cli/test_run.py b/tests/cli/test_run.pyindex 81b8356d3..350c8feff 100644--- a/tests/cli/test_run.py+++ b/tests/cli/test_run.py@@ -997,6 +997,45 @@ class TestRunWithReloadWithServerArgs:"--stateless",]+ @pytest.mark.parametrize("reload", [False, True])+ async def test_run_with_needs_uv_forwards_skip_source_flag(self, reload):+ """`--skip-source` should survive the uv-wrapped subprocess path."""+ mock_config = MagicMock()+ mock_config.deployment.transport = None+ mock_config.deployment.host = None+ mock_config.deployment.port = None+ mock_config.deployment.path = None+ mock_config.deployment.log_level = None+ mock_config.deployment.args = ()+ mock_config.environment.build_command = lambda cmd: ["uv", "run", *cmd]++ mock_result = MagicMock()+ mock_result.returncode = 0++ with (+ patch(+ "fastmcp.cli.cli.load_and_merge_config",+ return_value=(mock_config, "server.py"),+ ),+ patch(+ "fastmcp.cli.cli.subprocess.run", return_value=mock_result+ ) as mock_run,+ patch(+ "fastmcp.cli.run.run_with_reload", new_callable=AsyncMock+ ) as mock_reload,+ ):+ if reload:+ await run("server.py", skip_source=True, reload=True)+ cmd = mock_reload.call_args.args[0]+ else:+ with pytest.raises(SystemExit):+ await run("server.py", skip_source=True)+ cmd = mock_run.call_args.args[0]++ assert cmd[:4] == ["uv", "run", "fastmcp", "run"]+ assert "--skip-source" in cmd+ assert cmd.index("--skip-source") < cmd.index("--skip-env")+class TestInspectorModuleMode:"""Test the inspector command's module-mode handling."""