@@ -770,7 +770,7 @@ async def sse_endpoint(request: Request) -> Response:
770770 def streamable_http_app (self ) -> Starlette :
771771 """Return an instance of the StreamableHTTP server app."""
772772 from starlette .middleware import Middleware
773- from starlette .routing import Mount
773+ from starlette .routing import Route
774774
775775 # Create session manager on first call (lazy initialization)
776776 if self ._session_manager is None :
@@ -782,20 +782,17 @@ def streamable_http_app(self) -> Starlette:
782782 )
783783
784784 # Create the ASGI handler
785- async def handle_streamable_http (
786- scope : Scope , receive : Receive , send : Send
787- ) -> None :
788- await self .session_manager .handle_request (scope , receive , send )
785+ async def handle_streamable_http (request : Request ) -> Response :
786+ await self .session_manager .handle_request (request .scope , request .receive , request ._send )
787+ return Response ()
789788
790789 # Create routes
791- routes : list [Route | Mount ] = []
790+ routes : list [Route ] = []
792791 middleware : list [Middleware ] = []
793792 required_scopes = []
794793
795- # Always mount both /mcp and /mcp/ for full compatibility, regardless of default
796- # Verify that _main_path has root format -> /mcp
794+ # Always register both /mcp and /mcp/ for full compatibility
797795 _main_path = self .settings .streamable_http_path .removesuffix ("/" )
798- # Format _alt_path so it ends with '/' -> /mcp/
799796 _alt_path = _main_path + "/"
800797
801798 # Add auth endpoints if auth provider is configured
@@ -824,25 +821,29 @@ async def handle_streamable_http(
824821 )
825822 )
826823 routes .extend ([
827- Mount (
824+ Route (
828825 _main_path ,
829- app = RequireAuthMiddleware (handle_streamable_http , required_scopes ),
826+ endpoint = RequireAuthMiddleware (handle_streamable_http , required_scopes ),
827+ methods = ["GET" , "POST" , "OPTIONS" ]
830828 ),
831- Mount (
829+ Route (
832830 _alt_path ,
833- app = RequireAuthMiddleware (handle_streamable_http , required_scopes ),
831+ endpoint = RequireAuthMiddleware (handle_streamable_http , required_scopes ),
832+ methods = ["GET" , "POST" , "OPTIONS" ]
834833 )]
835834 )
836835 else :
837836 # Auth is disabled, no wrapper needed
838837 routes .extend ([
839- Mount (
838+ Route (
840839 _main_path ,
841- app = handle_streamable_http ,
840+ endpoint = handle_streamable_http ,
841+ methods = ["GET" , "POST" , "OPTIONS" ]
842842 ),
843- Mount (
843+ Route (
844844 _alt_path ,
845- app = handle_streamable_http ,
845+ endpoint = handle_streamable_http ,
846+ methods = ["GET" , "POST" , "OPTIONS" ]
846847 )]
847848 )
848849
@@ -853,6 +854,7 @@ async def handle_streamable_http(
853854 routes = routes ,
854855 middleware = middleware ,
855856 lifespan = lambda app : self .session_manager .run (),
857+ redirect_slashes = False ,
856858 )
857859
858860 async def list_prompts (self ) -> list [MCPPrompt ]:
0 commit comments