Skip to content

Commit 02f0f27

Browse files
committed
feat!: make run_context required in Agent.get_mcp_tools()
1 parent bfc48e8 commit 02f0f27

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/agents/agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ async def get_prompt(
257257
return await PromptUtil.to_model_input(self.prompt, run_context, self)
258258

259259
async def get_mcp_tools(
260-
self, run_context: RunContextWrapper[TContext] | None = None
260+
self, run_context: RunContextWrapper[TContext]
261261
) -> list[Tool]:
262262
"""Fetches the available tools from the MCP servers."""
263263
convert_schemas_to_strict = self.mcp_config.get("convert_schemas_to_strict", False)

tests/mcp/test_mcp_util.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ async def test_agent_convert_schemas_true():
144144
agent = Agent(
145145
name="test_agent", mcp_servers=[server], mcp_config={"convert_schemas_to_strict": True}
146146
)
147-
tools = await agent.get_mcp_tools()
147+
run_context = RunContextWrapper(context=None)
148+
tools = await agent.get_mcp_tools(run_context)
148149

149150
foo_tool = next(tool for tool in tools if tool.name == "foo")
150151
assert isinstance(foo_tool, FunctionTool)
@@ -208,7 +209,8 @@ async def test_agent_convert_schemas_false():
208209
agent = Agent(
209210
name="test_agent", mcp_servers=[server], mcp_config={"convert_schemas_to_strict": False}
210211
)
211-
tools = await agent.get_mcp_tools()
212+
run_context = RunContextWrapper(context=None)
213+
tools = await agent.get_mcp_tools(run_context)
212214

213215
foo_tool = next(tool for tool in tools if tool.name == "foo")
214216
assert isinstance(foo_tool, FunctionTool)
@@ -245,7 +247,8 @@ async def test_agent_convert_schemas_unset():
245247
server.add_tool("bar", non_strict_schema)
246248
server.add_tool("baz", possible_to_convert_schema)
247249
agent = Agent(name="test_agent", mcp_servers=[server])
248-
tools = await agent.get_mcp_tools()
250+
run_context = RunContextWrapper(context=None)
251+
tools = await agent.get_mcp_tools(run_context)
249252

250253
foo_tool = next(tool for tool in tools if tool.name == "foo")
251254
assert isinstance(foo_tool, FunctionTool)

0 commit comments

Comments
 (0)