Skip to content

Commit 78c217a

Browse files
committed
Move uvicorn import to usage
uvicorn is an optional dependency only used in one function but is imported at the global scope meaning mcp imports will fail if uvicorn is not available. This commit moves uvicorn import to usage in run_sse_async. It would be ideal to mark uvicorn as a default-on optional dependency but that isn't supported yet by pyproject.toml.
1 parent 70115b9 commit 78c217a

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ dependencies = [
2929
"starlette>=0.27",
3030
"sse-starlette>=1.6.1",
3131
"pydantic-settings>=2.5.2",
32-
"uvicorn>=0.23.1",
32+
"uvicorn>=0.23.1; sys_platform != 'emscripten'",
3333
]
3434

3535
[project.optional-dependencies]

src/mcp/server/fastmcp/server.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import anyio
1717
import pydantic_core
18-
import uvicorn
1918
from pydantic import BaseModel, Field
2019
from pydantic.networks import AnyUrl
2120
from pydantic_settings import BaseSettings, SettingsConfigDict
@@ -466,6 +465,7 @@ async def run_stdio_async(self) -> None:
466465

467466
async def run_sse_async(self) -> None:
468467
"""Run the server using SSE transport."""
468+
import uvicorn
469469
starlette_app = self.sse_app()
470470

471471
config = uvicorn.Config(

0 commit comments

Comments
 (0)