10
10
11
11
from fastapi_mcp .openapi .convert import convert_openapi_to_mcp_tools
12
12
from fastapi_mcp .transport .sse import FastApiSseTransport
13
- from fastapi_mcp .transport .http import FastApiStreamableHttpTransport
13
+ from fastapi_mcp .transport .http import FastApiHttpSessionManager
14
14
from fastapi_mcp .types import HTTPRequestInfo , AuthConfig
15
15
16
16
import logging
@@ -119,6 +119,7 @@ def __init__(
119
119
)
120
120
121
121
self ._forward_headers = {h .lower () for h in headers }
122
+ self ._http_transport : FastApiHttpSessionManager | None = None # Store reference to HTTP transport for cleanup
122
123
123
124
self .setup_server ()
124
125
@@ -230,7 +231,7 @@ def _register_mcp_endpoints_sse(
230
231
def _register_mcp_http_endpoint (
231
232
self ,
232
233
router : FastAPI | APIRouter ,
233
- transport : FastApiStreamableHttpTransport ,
234
+ transport : FastApiHttpSessionManager ,
234
235
mount_path : str ,
235
236
dependencies : Optional [Sequence [params .Depends ]],
236
237
):
@@ -247,7 +248,7 @@ async def handle_mcp_streamable_http(request: Request):
247
248
def _register_mcp_endpoints_http (
248
249
self ,
249
250
router : FastAPI | APIRouter ,
250
- transport : FastApiStreamableHttpTransport ,
251
+ transport : FastApiHttpSessionManager ,
251
252
mount_path : str ,
252
253
dependencies : Optional [Sequence [params .Depends ]],
253
254
):
@@ -347,11 +348,12 @@ def mount_http(
347
348
348
349
assert isinstance (router , (FastAPI , APIRouter )), f"Invalid router type: { type (router )} "
349
350
350
- http_transport = FastApiStreamableHttpTransport (mcp_server = self .server )
351
+ http_transport = FastApiHttpSessionManager (mcp_server = self .server )
351
352
dependencies = self ._auth_config .dependencies if self ._auth_config else None
352
353
353
354
self ._register_mcp_endpoints_http (router , http_transport , mount_path , dependencies )
354
355
self ._setup_auth ()
356
+ self ._http_transport = http_transport # Store reference
355
357
356
358
# HACK: If we got a router and not a FastAPI instance, we need to re-include the router so that
357
359
# FastAPI will pick up the new routes we added. The problem with this approach is that we assume
0 commit comments