1111from collections .abc import Callable
1212from dataclasses import dataclass
1313from types import TracebackType
14- from typing import Any , TypeAlias
14+ from typing import Any , TypeAlias , cast
1515
1616import anyio
1717import httpx
@@ -332,7 +332,7 @@ async def _establish_session(
332332 async def _aggregate_components (self , server_info : types .Implementation , session : mcp .ClientSession ) -> None :
333333 """Aggregates prompts, resources, and tools from a given session."""
334334
335- capabilities = session . initialize_result . capabilities if session .initialize_result else None
335+ capabilities = cast ( types . InitializeResult , session .initialize_result ). capabilities
336336
337337 # Create a reverse index so we can find all prompts, resources, and
338338 # tools belonging to this session. Used for removing components from
@@ -347,7 +347,7 @@ async def _aggregate_components(self, server_info: types.Implementation, session
347347 tool_to_session_temp : dict [str , mcp .ClientSession ] = {}
348348
349349 # Query the server for its prompts and aggregate to list.
350- if capabilities is None or capabilities .prompts is not None :
350+ if capabilities .prompts is not None :
351351 try :
352352 prompts = (await session .list_prompts ()).prompts
353353 for prompt in prompts :
@@ -358,7 +358,7 @@ async def _aggregate_components(self, server_info: types.Implementation, session
358358 logging .warning (f"Could not fetch prompts: { err } " )
359359
360360 # Query the server for its resources and aggregate to list.
361- if capabilities is None or capabilities .resources is not None :
361+ if capabilities .resources is not None :
362362 try :
363363 resources = (await session .list_resources ()).resources
364364 for resource in resources :
@@ -369,7 +369,7 @@ async def _aggregate_components(self, server_info: types.Implementation, session
369369 logging .warning (f"Could not fetch resources: { err } " )
370370
371371 # Query the server for its tools and aggregate to list.
372- if capabilities is None or capabilities .tools is not None :
372+ if capabilities .tools is not None :
373373 try :
374374 tools = (await session .list_tools ()).tools
375375 for tool in tools :
0 commit comments