Skip to content

Commit 7f5f8b5

Browse files
authored
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 7f5f8b5

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

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(

0 commit comments

Comments
 (0)