1
- from pathlib import Path
2
- from unittest .mock import Mock , patch
3
-
4
1
import pytest
5
- from typer .testing import CliRunner
6
-
7
- from fastmcp import FastMCP
8
- from fastmcp .cli .cli import app
9
2
10
3
11
4
@pytest .fixture
@@ -27,51 +20,3 @@ def hello(name: str) -> str:
27
20
"""
28
21
)
29
22
return server_path
30
-
31
-
32
- def test_cli_run_transport_kwargs ():
33
- """Test that transport_kwargs are correctly passed from CLI to server.run()"""
34
- runner = CliRunner ()
35
-
36
- # Need to mock both the file parsing and the server import
37
- with (
38
- patch ("fastmcp.cli.cli._parse_file_path" ) as mock_parse_file_path ,
39
- patch ("fastmcp.cli.cli._import_server" ) as mock_import_server ,
40
- ):
41
- # Make _parse_file_path return a fake path and server object
42
- mock_parse_file_path .return_value = (Path ("fake_server.py" ), "mcp" )
43
-
44
- # Create a mock server with a mock run method
45
- mock_server = FastMCP (name = "MockServer" )
46
- mock_server .run = Mock ()
47
-
48
- # Make _import_server return our mock server
49
- mock_import_server .return_value = mock_server
50
-
51
- # Run the CLI command with transport_kwargs
52
- result = runner .invoke (
53
- app ,
54
- [
55
- "run" ,
56
- "fake_server.py" ,
57
- "--transport" ,
58
- "sse" ,
59
- "--host" ,
60
- "127.0.0.1" ,
61
- "--port" ,
62
- "9000" ,
63
- "--log-level" ,
64
- "DEBUG" ,
65
- ],
66
- )
67
-
68
- # Check that the run method was called with the correct kwargs
69
- mock_server .run .assert_called_once_with (
70
- transport = "sse" ,
71
- host = "127.0.0.1" ,
72
- port = 9000 ,
73
- log_level = "DEBUG" ,
74
- )
75
-
76
- # Check CLI command succeeded
77
- assert result .exit_code == 0
0 commit comments