Skip to content

Commit 2240530

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 2240530

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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(

uv.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)