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
8 changes: 4 additions & 4 deletions src/agents/mcp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ def __init__(
async def _apply_tool_filter(
self,
tools: list[MCPTool],
run_context: RunContextWrapper[Any],
agent: AgentBase,
run_context: RunContextWrapper[Any] | None = None,
agent: AgentBase | None = None,
) -> list[MCPTool]:
"""Apply the tool filter to the list of tools."""
if self.tool_filter is None:
Expand All @@ -163,6 +163,8 @@ async def _apply_tool_filter(

# Handle callable tool filter (dynamic filter)
else:
if run_context is None or agent is None:
raise UserError("run_context and agent are required for dynamic tool filtering")
return await self._apply_dynamic_tool_filter(tools, run_context, agent)

def _apply_static_tool_filter(
Expand Down Expand Up @@ -312,8 +314,6 @@ 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