Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/fastmcp/server/mixins/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async def run_async(
if show_banner is None:
show_banner = fastmcp.settings.show_server_banner
if transport is None:
transport = "stdio"
transport = fastmcp.settings.transport
if transport not in {"stdio", "http", "sse", "streamable-http"}:
raise ValueError(f"Unknown transport: {transport}")

Expand Down
3 changes: 3 additions & 0 deletions src/fastmcp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ def normalize_log_level(cls, v):
),
] = None

# Transport settings
transport: Literal["stdio", "http", "sse", "streamable-http"] = "stdio"

# HTTP settings
host: str = "127.0.0.1"
port: int = 8000
Expand Down
31 changes: 31 additions & 0 deletions tests/utilities/test_tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from unittest.mock import AsyncMock, patch

import fastmcp
from fastmcp import FastMCP
from fastmcp.utilities.tests import temporary_settings


Expand All @@ -8,3 +11,31 @@ def test_temporary_settings(self):
with temporary_settings(log_level="ERROR"):
assert fastmcp.settings.log_level == "ERROR"
assert fastmcp.settings.log_level == "DEBUG"


class TestTransportSetting:
def test_transport_default_is_stdio(self):
assert fastmcp.settings.transport == "stdio"

def test_transport_setting_can_be_changed(self):
with temporary_settings(transport="http"):
assert fastmcp.settings.transport == "http"
assert fastmcp.settings.transport == "stdio"

async def test_run_async_uses_transport_setting(self):
mcp = FastMCP("test")
with temporary_settings(transport="http"):
with patch.object(
mcp, "run_http_async", new_callable=AsyncMock
) as mock_http:
await mcp.run_async()
mock_http.assert_called_once()

async def test_run_async_explicit_transport_overrides_setting(self):
mcp = FastMCP("test")
with temporary_settings(transport="http"):
with patch.object(
mcp, "run_stdio_async", new_callable=AsyncMock
) as mock_stdio:
await mcp.run_async(transport="stdio")
mock_stdio.assert_called_once()