Skip to content

Commit c317d5e

Browse files
authored
Revert "Only list MCP tools once, not at every agent run step" (#3228)
1 parent 2f195dc commit c317d5e

File tree

1 file changed

+4
-7
lines changed
  • pydantic_ai_slim/pydantic_ai

1 file changed

+4
-7
lines changed

pydantic_ai_slim/pydantic_ai/mcp.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ class MCPServer(AbstractToolset[Any], ABC):
113113
_read_stream: MemoryObjectReceiveStream[SessionMessage | Exception]
114114
_write_stream: MemoryObjectSendStream[SessionMessage]
115115
_server_info: mcp_types.Implementation
116-
_tools: list[mcp_types.Tool] | None
117116

118117
def __init__(
119118
self,
@@ -149,7 +148,6 @@ def __post_init__(self):
149148
self._enter_lock = Lock()
150149
self._running_count = 0
151150
self._exit_stack = None
152-
self._tools = None
153151

154152
@abstractmethod
155153
@asynccontextmanager
@@ -196,14 +194,13 @@ def server_info(self) -> mcp_types.Implementation:
196194
async def list_tools(self) -> list[mcp_types.Tool]:
197195
"""Retrieve tools that are currently active on the server.
198196
199-
Note that we don't subscribe to the server to avoid complexity.
197+
Note:
198+
- We don't cache tools as they might change.
199+
- We also don't subscribe to the server to avoid complexity.
200200
"""
201-
if self._tools is not None:
202-
return self._tools
203201
async with self: # Ensure server is running
204202
result = await self._client.list_tools()
205-
self._tools = result.tools
206-
return self._tools
203+
return result.tools
207204

208205
async def direct_call_tool(
209206
self,

0 commit comments

Comments
 (0)