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
10 changes: 6 additions & 4 deletions src/agents/mcp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ async def cleanup(self):
@abc.abstractmethod
async def list_tools(
self,
run_context: RunContextWrapper[Any],
agent: Agent[Any],
run_context: RunContextWrapper[Any] | None = None,
agent: Agent[Any] | None = None,
) -> list[MCPTool]:
"""List the tools available on the server."""
pass
Expand Down Expand Up @@ -231,8 +231,8 @@ async def connect(self):

async def list_tools(
self,
run_context: RunContextWrapper[Any],
agent: Agent[Any],
run_context: RunContextWrapper[Any] | None = None,
agent: Agent[Any] | None = None,
) -> list[MCPTool]:
"""List the tools available on the server."""
if not self.session:
Expand All @@ -251,6 +251,8 @@ async def list_tools(
# Filter tools based on tool_filter
filtered_tools = tools
if self.tool_filter is not None:
if run_context is None or agent is None:
raise UserError("run_context and agent are required for dynamic tool filtering")
filtered_tools = await self._apply_tool_filter(filtered_tools, run_context, agent)
return filtered_tools

Expand Down