@@ -28,6 +28,7 @@ async def handle_list_prompts(ctx: RequestContext, params) -> ListPromptsResult:
2828be instantiated directly by users of the MCP framework.
2929"""
3030
31+ import time
3132from enum import Enum
3233from typing import Any , TypeVar , overload
3334
@@ -40,8 +41,6 @@ async def handle_list_prompts(ctx: RequestContext, params) -> ListPromptsResult:
4041from mcp .server .experimental .session_features import ExperimentalServerSessionFeatures
4142from mcp .server .models import InitializationOptions
4243from mcp .server .validation import validate_sampling_tools , validate_tool_use_result_messages
43- import time
44-
4544from mcp .shared ._otel import record_server_session_duration
4645from mcp .shared ._stream_protocols import ReadStream , WriteStream
4746from mcp .shared .exceptions import StatelessModeNotSupported
@@ -105,12 +104,12 @@ async def __aenter__(self) -> "ServerSession":
105104 self ._session_start_time = time .monotonic ()
106105 return await super ().__aenter__ ()
107106
108- async def __aexit__ (self , exc_type : type [BaseException ] | None , exc_val : BaseException | None , exc_tb : Any ) -> bool | None :
107+ async def __aexit__ (
108+ self , exc_type : type [BaseException ] | None , exc_val : BaseException | None , exc_tb : Any
109+ ) -> bool | None :
109110 if self ._session_start_time is not None :
110111 duration = time .monotonic () - self ._session_start_time
111- mcp_protocol_version : str | None = (
112- self ._client_params .protocol_version if self ._client_params else None
113- )
112+ mcp_protocol_version : str | None = str (self ._client_params .protocol_version ) if self ._client_params else None
114113 # Cancellation exceptions indicate transport close, not a session error.
115114 is_cancellation = exc_val is not None and isinstance (exc_val , anyio .get_cancelled_exc_class ())
116115 error_type : str | None = type (exc_val ).__name__ if exc_val is not None and not is_cancellation else None
0 commit comments