fix: add lifespan context manager to StreamableHTTP mounting examples (#1669)
Co-authored-by: TheMailmans <tyler@example.com> Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
This commit is contained in:
parent
8e02fc17e1
commit
72a34002aa
1 changed files with 72 additions and 6 deletions
|
|
@ -5,6 +5,8 @@ Run from the repository root:
|
|||
uvicorn examples.snippets.servers.streamable_http_host_mounting:app --reload
|
||||
"""
|
||||
|
||||
import contextlib
|
||||
|
||||
from starlette.applications import Starlette
|
||||
from starlette.routing import Host
|
||||
|
||||
|
|
@ -20,9 +22,17 @@ def domain_info() -> str:
|
|||
return "This is served from mcp.acme.corp"
|
||||
|
||||
|
||||
# Create a lifespan context manager to run the session manager
|
||||
@contextlib.asynccontextmanager
|
||||
async def lifespan(app: Starlette):
|
||||
async with mcp.session_manager.run():
|
||||
yield
|
||||
|
||||
|
||||
# Mount using Host-based routing
|
||||
app = Starlette(
|
||||
routes=[
|
||||
Host("mcp.acme.corp", app=mcp.streamable_http_app()),
|
||||
]
|
||||
],
|
||||
lifespan=lifespan,
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue