mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-09 15:19:10 +02:00
Compare commits
1 commit
main
...
feat/trans
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f3d01c25ac |
3 changed files with 35 additions and 1 deletions
|
|
@ -53,7 +53,7 @@ class TransportMixin:
|
|||
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}")
|
||||
|
||||
|
|
|
|||
|
|
@ -227,6 +227,9 @@ class Settings(BaseSettings):
|
|||
),
|
||||
] = None
|
||||
|
||||
# Transport settings
|
||||
transport: Literal["stdio", "http", "sse", "streamable-http"] = "stdio"
|
||||
|
||||
# HTTP settings
|
||||
host: str = "127.0.0.1"
|
||||
port: int = 8000
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
import fastmcp
|
||||
from fastmcp import FastMCP
|
||||
from fastmcp.utilities.tests import temporary_settings
|
||||
|
||||
|
||||
|
|
@ -8,3 +11,31 @@ class TestTemporarySettings:
|
|||
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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue