1111from collections .abc import Callable
1212from dataclasses import dataclass
1313from types import TracebackType
14- from typing import Any , Literal , TypeAlias , overload
14+ from typing import Any , Literal , TypeAlias , cast , overload
1515
1616import anyio
1717import httpx
@@ -371,7 +371,7 @@ async def _establish_session(
371371 async def _aggregate_components (self , server_info : types .Implementation , session : mcp .ClientSession ) -> None :
372372 """Aggregates prompts, resources, and tools from a given session."""
373373
374- capabilities = session . initialize_result . capabilities if session .initialize_result else None
374+ capabilities = cast ( types . ServerCapabilities , session .server_capabilities )
375375
376376 # Create a reverse index so we can find all prompts, resources, and
377377 # tools belonging to this session. Used for removing components from
@@ -386,7 +386,7 @@ async def _aggregate_components(self, server_info: types.Implementation, session
386386 tool_to_session_temp : dict [str , mcp .ClientSession ] = {}
387387
388388 # Query the server for its prompts and aggregate to list.
389- if capabilities is None or capabilities .prompts is not None :
389+ if capabilities .prompts is not None :
390390 try :
391391 prompts = (await session .list_prompts ()).prompts
392392 for prompt in prompts :
@@ -397,7 +397,7 @@ async def _aggregate_components(self, server_info: types.Implementation, session
397397 logging .warning (f"Could not fetch prompts: { err } " )
398398
399399 # Query the server for its resources and aggregate to list.
400- if capabilities is None or capabilities .resources is not None :
400+ if capabilities .resources is not None :
401401 try :
402402 resources = (await session .list_resources ()).resources
403403 for resource in resources :
@@ -408,7 +408,7 @@ async def _aggregate_components(self, server_info: types.Implementation, session
408408 logging .warning (f"Could not fetch resources: { err } " )
409409
410410 # Query the server for its tools and aggregate to list.
411- if capabilities is None or capabilities .tools is not None :
411+ if capabilities .tools is not None :
412412 try :
413413 tools = (await session .list_tools ()).tools
414414 for tool in tools :
0 commit comments