1+ from unittest .mock import AsyncMock , patch
2+
13import fastmcp
4+ from fastmcp import FastMCP
25from fastmcp .utilities .tests import temporary_settings
36
47
@@ -8,3 +11,31 @@ def test_temporary_settings(self):
811 with temporary_settings (log_level = "ERROR" ):
912 assert fastmcp .settings .log_level == "ERROR"
1013 assert fastmcp .settings .log_level == "DEBUG"
14+
15+
16+ class TestTransportSetting :
17+ def test_transport_default_is_stdio (self ):
18+ assert fastmcp .settings .transport == "stdio"
19+
20+ def test_transport_setting_can_be_changed (self ):
21+ with temporary_settings (transport = "http" ):
22+ assert fastmcp .settings .transport == "http"
23+ assert fastmcp .settings .transport == "stdio"
24+
25+ async def test_run_async_uses_transport_setting (self ):
26+ mcp = FastMCP ("test" )
27+ with temporary_settings (transport = "http" ):
28+ with patch .object (
29+ mcp , "run_http_async" , new_callable = AsyncMock
30+ ) as mock_http :
31+ await mcp .run_async ()
32+ mock_http .assert_called_once ()
33+
34+ async def test_run_async_explicit_transport_overrides_setting (self ):
35+ mcp = FastMCP ("test" )
36+ with temporary_settings (transport = "http" ):
37+ with patch .object (
38+ mcp , "run_stdio_async" , new_callable = AsyncMock
39+ ) as mock_stdio :
40+ await mcp .run_async (transport = "stdio" )
41+ mock_stdio .assert_called_once ()
0 commit comments