1616from concurrent import futures
1717from datetime import timedelta
1818from types import TracebackType
19- from typing import Any , Callable , Coroutine , Dict , List , Optional , TypeVar , Union
19+ from typing import Any , Callable , Coroutine , Dict , Optional , TypeVar , Union
2020
2121from mcp import ClientSession , ListToolsResult
2222from mcp .types import CallToolResult as MCPCallToolResult
2323from mcp .types import ImageContent as MCPImageContent
2424from mcp .types import TextContent as MCPTextContent
2525
26+ from ...types import PaginatedList
2627from ...types .exceptions import MCPClientInitializationError
2728from ...types .media import ImageFormat
2829from ...types .tools import ToolResult , ToolResultContent , ToolResultStatus
@@ -140,7 +141,7 @@ async def _set_close_event() -> None:
140141 self ._background_thread = None
141142 self ._session_id = uuid .uuid4 ()
142143
143- def list_tools_sync (self ) -> List [MCPAgentTool ]:
144+ def list_tools_sync (self , pagination_token : Optional [ str ] = None ) -> PaginatedList [MCPAgentTool ]:
144145 """Synchronously retrieves the list of available tools from the MCP server.
145146
146147 This method calls the asynchronous list_tools method on the MCP session
@@ -154,14 +155,14 @@ def list_tools_sync(self) -> List[MCPAgentTool]:
154155 raise MCPClientInitializationError (CLIENT_SESSION_NOT_RUNNING_ERROR_MESSAGE )
155156
156157 async def _list_tools_async () -> ListToolsResult :
157- return await self ._background_thread_session .list_tools ()
158+ return await self ._background_thread_session .list_tools (cursor = pagination_token )
158159
159160 list_tools_response : ListToolsResult = self ._invoke_on_background_thread (_list_tools_async ()).result ()
160161 self ._log_debug_with_thread ("received %d tools from MCP server" , len (list_tools_response .tools ))
161162
162163 mcp_tools = [MCPAgentTool (tool , self ) for tool in list_tools_response .tools ]
163164 self ._log_debug_with_thread ("successfully adapted %d MCP tools" , len (mcp_tools ))
164- return mcp_tools
165+ return PaginatedList [ MCPAgentTool ]( mcp_tools , token = list_tools_response . nextCursor )
165166
166167 def call_tool_sync (
167168 self ,
0 commit comments