@@ -124,20 +124,10 @@ async def lifespan(app: Starlette) -> AsyncIterator[None]:
124124 # Clear any remaining server instances
125125 self ._server_instances .clear ()
126126
127- async def handle_request (
128- self ,
129- scope : Scope ,
130- receive : Receive ,
131- send : Send ,
132- ) -> None :
127+ async def handle_request (self , scope : Scope , receive : Receive , send : Send ) -> None :
133128 """Process ASGI request with proper session handling and transport setup.
134129
135130 Dispatches to the appropriate handler based on stateless mode.
136-
137- Args:
138- scope: ASGI scope
139- receive: ASGI receive function
140- send: ASGI send function
141131 """
142132 if self ._task_group is None :
143133 raise RuntimeError ("Task group is not initialized. Make sure to use run()." )
@@ -148,19 +138,8 @@ async def handle_request(
148138 else :
149139 await self ._handle_stateful_request (scope , receive , send )
150140
151- async def _handle_stateless_request (
152- self ,
153- scope : Scope ,
154- receive : Receive ,
155- send : Send ,
156- ) -> None :
157- """Process request in stateless mode - creating a new transport for each request.
158-
159- Args:
160- scope: ASGI scope
161- receive: ASGI receive function
162- send: ASGI send function
163- """
141+ async def _handle_stateless_request (self , scope : Scope , receive : Receive , send : Send ) -> None :
142+ """Process request in stateless mode - creating a new transport for each request."""
164143 logger .debug ("Stateless mode: Creating new transport for this request" )
165144 # No session ID needed in stateless mode
166145 http_transport = StreamableHTTPServerTransport (
@@ -196,19 +175,8 @@ async def run_stateless_server(*, task_status: TaskStatus[None] = anyio.TASK_STA
196175 # Terminate the transport after the request is handled
197176 await http_transport .terminate ()
198177
199- async def _handle_stateful_request (
200- self ,
201- scope : Scope ,
202- receive : Receive ,
203- send : Send ,
204- ) -> None :
205- """Process request in stateful mode - maintaining session state between requests.
206-
207- Args:
208- scope: ASGI scope
209- receive: ASGI receive function
210- send: ASGI send function
211- """
178+ async def _handle_stateful_request (self , scope : Scope , receive : Receive , send : Send ) -> None :
179+ """Process request in stateful mode - maintaining session state between requests."""
212180 request = Request (scope , receive )
213181 request_mcp_session_id = request .headers .get (MCP_SESSION_ID_HEADER )
214182
@@ -248,11 +216,8 @@ async def run_server(*, task_status: TaskStatus[None] = anyio.TASK_STATUS_IGNORE
248216 self .app .create_initialization_options (),
249217 stateless = False , # Stateful mode
250218 )
251- except Exception as e :
252- logger .error (
253- f"Session { http_transport .mcp_session_id } crashed: { e } " ,
254- exc_info = True ,
255- )
219+ except Exception :
220+ logger .exception (f"Session { http_transport .mcp_session_id } crashed" )
256221 finally :
257222 # Only remove from instances if not terminated
258223 if ( # pragma: no branch
@@ -262,8 +227,7 @@ async def run_server(*, task_status: TaskStatus[None] = anyio.TASK_STATUS_IGNORE
262227 ):
263228 logger .info (
264229 "Cleaning up crashed session "
265- f"{ http_transport .mcp_session_id } from "
266- "active instances."
230+ f"{ http_transport .mcp_session_id } from active instances."
267231 )
268232 del self ._server_instances [http_transport .mcp_session_id ]
269233
0 commit comments