PrefectHQ/fastmcp · error · ValueError
Invalid transport: {transport}
Error message
Invalid transport: {transport} What it means
The run_server_in_process test helper only supports the 'sse' transport when spawning a server subprocess; any other value hits the else branch and raises ValueError. It exists because Starlette apps are constructed (not pickled) inside the child process based on the transport string.
Source
Thrown at fastmcp_slim/fastmcp/utilities/tests.py:73
try:
# apply the new settings
for attr, value in kwargs.items():
settings.set_setting(attr, value)
yield
finally:
# restore the old settings
for attr in kwargs:
settings.set_setting(attr, old_settings.get_setting(attr))
def _run_server(mcp_server: FastMCP, transport: Literal["sse"], port: int) -> None:
# Some Starlette apps are not pickleable, so we need to create them here based on the indicated transport
if transport == "sse":
app = mcp_server.http_app(transport="sse")
else:
raise ValueError(f"Invalid transport: {transport}")
uvicorn_server = uvicorn.Server(
config=uvicorn.Config(
app=app,
host="127.0.0.1",
port=port,
log_level="error",
ws="websockets-sansio",
)
)
uvicorn_server.run()
@contextmanager
def run_server_in_process(
server_fn: Callable[..., None],
*args: Any,
provide_host_and_port: bool = True,
host: str = "127.0.0.1",View on GitHub (pinned to 1f02114297)
Solutions
- Use transport="sse" (the only value this helper accepts)
- Use a different server-start helper (e.g. run_server_async or http_app directly) for other transports
- Fix typos — the literal string must be exactly "sse"
Example fix
// before with run_server_in_process(mcp_server, transport="http") as url: ... // after with run_server_in_process(mcp_server, transport="sse") as url: ...
Defensive patterns
Strategy: validation
Validate before calling
if transport != "sse":
raise ValueError(f"run_server_in_process only supports 'sse', got {transport!r}") Type guard
def is_supported_transport(t: str) -> bool:
return t == "sse" Try / catch
try:
with run_server_in_process(mcp, transport=transport) as url:
yield url
except ValueError as e:
pytest.skip(f"unsupported transport for helper: {e}") Prevention
- Only pass "sse" to this helper
- Use run_server_async for other transports
- Define the transport as a Literal["sse"] variable to get static checking
When it happens
Trigger: Passing transport="http"/"streamable-http"/"stdio" (or a typo like "https") to run_server_in_process / mcp_server_url instead of "sse".
Common situations: Copying test helper code between FastMCP versions where more transports are supported elsewhere; assuming the test utility accepts every transport the client does; simple typos.
Related errors
- SSE transport does not support stateless mode
- Unknown transport: {transport}
- Both 'httpx_client_factory' and 'verify' were provided. The
- Could not create the CLI state directory
- OAuth provider has no server URL. Either pass mcp_url to OAu
AI-assisted analysis of PrefectHQ/fastmcp@1f02114297 (2026-08-29).
Data as JSON: /api/errors/30098a61ef0449b5.
Report an issue: GitHub.