Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit db85a6d

Browse files
authored
Fix openai#976 MCP filtering, make agent and run ctx optional (openai#977)
This is a patch to address the most pressing issue of openai#976 while we discuss whether or not these parameters should exist in `list_tools` or should be migrated elsewhere. Resolves openai#976
1 parent c92fe77 commit db85a6d

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/agents/mcp/server.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ async def cleanup(self):
5252
@abc.abstractmethod
5353
async def list_tools(
5454
self,
55-
run_context: RunContextWrapper[Any],
56-
agent: Agent[Any],
55+
run_context: RunContextWrapper[Any] | None = None,
56+
agent: Agent[Any] | None = None,
5757
) -> list[MCPTool]:
5858
"""List the tools available on the server."""
5959
pass
@@ -243,8 +243,8 @@ async def connect(self):
243243

244244
async def list_tools(
245245
self,
246-
run_context: RunContextWrapper[Any],
247-
agent: Agent[Any],
246+
run_context: RunContextWrapper[Any] | None = None,
247+
agent: Agent[Any] | None = None,
248248
) -> list[MCPTool]:
249249
"""List the tools available on the server."""
250250
if not self.session:
@@ -263,6 +263,8 @@ async def list_tools(
263263
# Filter tools based on tool_filter
264264
filtered_tools = tools
265265
if self.tool_filter is not None:
266+
if run_context is None or agent is None:
267+
raise UserError("run_context and agent are required for dynamic tool filtering")
266268
filtered_tools = await self._apply_tool_filter(filtered_tools, run_context, agent)
267269
return filtered_tools
268270

0 commit comments

Comments
 (0)