Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions pydantic_ai_slim/pydantic_ai/mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class MCPServer(AbstractToolset[Any], ABC):
_read_stream: MemoryObjectReceiveStream[SessionMessage | Exception]
_write_stream: MemoryObjectSendStream[SessionMessage]
_server_info: mcp_types.Implementation
_tools: list[mcp_types.Tool] | None

def __init__(
self,
Expand Down Expand Up @@ -148,6 +149,7 @@ def __post_init__(self):
self._enter_lock = Lock()
self._running_count = 0
self._exit_stack = None
self._tools = None

@abstractmethod
@asynccontextmanager
Expand Down Expand Up @@ -194,13 +196,14 @@ def server_info(self) -> mcp_types.Implementation:
async def list_tools(self) -> list[mcp_types.Tool]:
"""Retrieve tools that are currently active on the server.

Note:
- We don't cache tools as they might change.
- We also don't subscribe to the server to avoid complexity.
Note that we don't subscribe to the server to avoid complexity.
"""
if self._tools is not None:
return self._tools
async with self: # Ensure server is running
result = await self._client.list_tools()
return result.tools
self._tools = result.tools
return self._tools

async def direct_call_tool(
self,
Expand Down