@@ -129,7 +129,7 @@ def __init__(
129129 self ._session_exit_stacks = {}
130130 self ._component_name_hook = component_name_hook
131131
132- async def __aenter__ (self ) -> Self :
132+ async def __aenter__ (self ) -> Self : # pragma: no cover
133133 # Enter the exit stack only if we created it ourselves
134134 if self ._owns_exit_stack :
135135 await self ._exit_stack .__aenter__ ()
@@ -140,7 +140,7 @@ async def __aexit__(
140140 _exc_type : type [BaseException ] | None ,
141141 _exc_val : BaseException | None ,
142142 _exc_tb : TracebackType | None ,
143- ) -> bool | None :
143+ ) -> bool | None : # pragma: no cover
144144 """Closes session exit stacks and main exit stack upon completion."""
145145
146146 # Only close the main exit stack if we created it
@@ -155,7 +155,7 @@ async def __aexit__(
155155 @property
156156 def sessions (self ) -> list [mcp .ClientSession ]:
157157 """Returns the list of sessions being managed."""
158- return list (self ._sessions .keys ())
158+ return list (self ._sessions .keys ()) # pragma: no cover
159159
160160 @property
161161 def prompts (self ) -> dict [str , types .Prompt ]:
@@ -192,7 +192,7 @@ async def disconnect_from_server(self, session: mcp.ClientSession) -> None:
192192 )
193193 )
194194
195- if session_known_for_components :
195+ if session_known_for_components : # pragma: no cover
196196 component_names = self ._sessions .pop (session ) # Pop from _sessions tracking
197197
198198 # Remove prompts associated with the session.
@@ -212,8 +212,8 @@ async def disconnect_from_server(self, session: mcp.ClientSession) -> None:
212212
213213 # Clean up the session's resources via its dedicated exit stack
214214 if session_known_for_stack :
215- session_stack_to_close = self ._session_exit_stacks .pop (session )
216- await session_stack_to_close .aclose ()
215+ session_stack_to_close = self ._session_exit_stacks .pop (session ) # pragma: no cover
216+ await session_stack_to_close .aclose () # pragma: no cover
217217
218218 async def connect_with_session (
219219 self , server_info : types .Implementation , session : mcp .ClientSession
@@ -270,7 +270,7 @@ async def _establish_session(
270270 await self ._exit_stack .enter_async_context (session_stack )
271271
272272 return result .serverInfo , session
273- except Exception :
273+ except Exception : # pragma: no cover
274274 # If anything during this setup fails, ensure the session-specific
275275 # stack is closed.
276276 await session_stack .aclose ()
@@ -298,7 +298,7 @@ async def _aggregate_components(self, server_info: types.Implementation, session
298298 name = self ._component_name (prompt .name , server_info )
299299 prompts_temp [name ] = prompt
300300 component_names .prompts .add (name )
301- except McpError as err :
301+ except McpError as err : # pragma: no cover
302302 logging .warning (f"Could not fetch prompts: { err } " )
303303
304304 # Query the server for its resources and aggregate to list.
@@ -308,7 +308,7 @@ async def _aggregate_components(self, server_info: types.Implementation, session
308308 name = self ._component_name (resource .name , server_info )
309309 resources_temp [name ] = resource
310310 component_names .resources .add (name )
311- except McpError as err :
311+ except McpError as err : # pragma: no cover
312312 logging .warning (f"Could not fetch resources: { err } " )
313313
314314 # Query the server for its tools and aggregate to list.
@@ -319,26 +319,26 @@ async def _aggregate_components(self, server_info: types.Implementation, session
319319 tools_temp [name ] = tool
320320 tool_to_session_temp [name ] = session
321321 component_names .tools .add (name )
322- except McpError as err :
322+ except McpError as err : # pragma: no cover
323323 logging .warning (f"Could not fetch tools: { err } " )
324324
325325 # Clean up exit stack for session if we couldn't retrieve anything
326326 # from the server.
327327 if not any ((prompts_temp , resources_temp , tools_temp )):
328- del self ._session_exit_stacks [session ]
328+ del self ._session_exit_stacks [session ] # pragma: no cover
329329
330330 # Check for duplicates.
331331 matching_prompts = prompts_temp .keys () & self ._prompts .keys ()
332332 if matching_prompts :
333- raise McpError (
333+ raise McpError ( # pragma: no cover
334334 types .ErrorData (
335335 code = types .INVALID_PARAMS ,
336336 message = f"{ matching_prompts } already exist in group prompts." ,
337337 )
338338 )
339339 matching_resources = resources_temp .keys () & self ._resources .keys ()
340340 if matching_resources :
341- raise McpError (
341+ raise McpError ( # pragma: no cover
342342 types .ErrorData (
343343 code = types .INVALID_PARAMS ,
344344 message = f"{ matching_resources } already exist in group resources." ,
0 commit comments