Skip to content

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

Merge branch 'main' into copy-flag

Jeremiah Lowinf6fe3f578579
diff --cc tests/cli/test_cli.py
index 9d96feaa7,0abae38da..de31c62aa
--- a/tests/cli/test_cli.py
+++ b/tests/cli/test_cli.py
@@@ -96,55 -94,20 +94,57 @@@ class TestMainCLI
class TestVersionCommand:
"""Test the version command."""
- @patch("fastmcp.cli.cli.sys.exit")
- @patch("fastmcp.cli.cli.console.print")
- def test_version_command(self, mock_print, mock_exit):
- """Test that version command prints info and exits."""
- # Parse and execute version command
+ def test_version_command_parsing(self):
+ """Test that version command can be parsed."""
command, bound, _ = app.parse_args(["version"])
- command()
+ assert command is not None
- # Verify it printed something and exited with 0
- mock_print.assert_called_once()
- mock_exit.assert_called_once_with(0)
+ def test_version_command_execution(self):
+ """Test that version command executes and exits properly."""
+ # The version command should exit with code 0 when executed
+ with pytest.raises(SystemExit) as exc_info:
+ command, bound, _ = app.parse_args(["version"])
+ command()
+
+ assert exc_info.value.code == 0
+ def test_version_command_parsing(self):
+ """Test that the version command parses arguments correctly."""
+ command, bound, _ = app.parse_args(["version"])
+ assert command.__name__ == "version"
+ # Default arguments aren't included in bound.arguments
+ assert bound.arguments == {}
+
+ def test_version_command_with_copy_flag(self):
+ """Test that the version command parses --copy flag correctly."""
+ command, bound, _ = app.parse_args(["version", "--copy"])
+ assert command.__name__ == "version"
+ assert bound.arguments == {"copy": True}
+
+ @patch("fastmcp.cli.cli.sys.exit")
+ @patch("fastmcp.cli.cli.pyperclip.copy")
+ @patch("fastmcp.cli.cli.console")
+ def test_version_command_copy_functionality(
+ self, mock_console, mock_pyperclip_copy, mock_exit
+ ):
+ """Test that the version command copies to clipboard when --copy is used."""
+ # Mock console.capture
+ mock_capture = Mock()
+ mock_capture.get.return_value = "FastMCP version: 1.0.0\nMCP version: 1.10.0"
+ mock_console.capture.return_value.__enter__.return_value = mock_capture
+ mock_console.capture.return_value.__exit__.return_value = None
+
+ command, bound, _ = app.parse_args(["version", "--copy"])
+ command(**bound.arguments)
+
+ mock_pyperclip_copy.assert_called_once_with(
+ "FastMCP version: 1.0.0\nMCP version: 1.10.0"
+ )
+ mock_console.print.assert_called_with(
+ "[green]βœ“[/green] Version information copied to clipboard"
+ )
+ mock_exit.assert_called_once_with(0)
+
class TestDevCommand:
"""Test the dev command."""