Skip to content

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

fix(cli): forward stateless flag in uv run path (#4177)

yuyua9dbf5ee24beff
diff --git a/fastmcp_slim/fastmcp/cli/cli.py b/fastmcp_slim/fastmcp/cli/cli.py
index c0e6b97f7..c78e024af 100644
--- a/fastmcp_slim/fastmcp/cli/cli.py
+++ b/fastmcp_slim/fastmcp/cli/cli.py
@@ -727,6 +727,8 @@ async def run(
inner_cmd.extend(["--log-level", final_log_level])
if final_no_banner:
inner_cmd.append("--no-banner")
+ if stateless:
+ inner_cmd.append("--stateless")
# Add skip-env flag to prevent infinite recursion
inner_cmd.append("--skip-env")
diff --git a/tests/cli/test_run.py b/tests/cli/test_run.py
index e5c54995f..44d180790 100644
--- a/tests/cli/test_run.py
+++ b/tests/cli/test_run.py
@@ -960,6 +960,42 @@ class TestRunWithReloadWithServerArgs:
assert any("Detected changes" in record.message for record in caplog.records)
assert call_count == 2, f"Restart logic was not triggered for {reload_cmd}"
+ async def test_run_with_needs_uv_forwards_stateless_flag(self):
+ """`--stateless` 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,
+ pytest.raises(SystemExit) as exc_info,
+ ):
+ await run("server.py", stateless=True)
+
+ assert exc_info.value.code == 0
+ cmd = mock_run.call_args.args[0]
+ assert "--stateless" in cmd
+ assert cmd[cmd.index("--stateless") - 3 : cmd.index("--stateless") + 1] == [
+ "fastmcp",
+ "run",
+ "server.py",
+ "--stateless",
+ ]
+
class TestInspectorModuleMode:
"""Test the inspector command's module-mode handling."""