Skip to content

Commit 3357779

Browse files
committed
use attribute in place of property
1 parent d8e9e97 commit 3357779

File tree

4 files changed

+12
-24
lines changed

4 files changed

+12
-24
lines changed

python/packages/ag-ui/tests/test_tooling.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def test_collect_server_tools_includes_mcp_tools_when_connected() -> None:
7474
mock_mcp = MockMCPTool([mcp_function1, mcp_function2], is_connected=True)
7575

7676
agent = _create_chat_agent_with_tool("regular_tool")
77-
agent._local_mcp_tools = [mock_mcp]
77+
agent.mcp_tools = [mock_mcp]
7878

7979
tools = collect_server_tools(agent)
8080

@@ -91,7 +91,7 @@ def test_collect_server_tools_excludes_mcp_tools_when_not_connected() -> None:
9191
mock_mcp = MockMCPTool([mcp_function], is_connected=False)
9292

9393
agent = _create_chat_agent_with_tool("regular_tool")
94-
agent._local_mcp_tools = [mock_mcp]
94+
agent.mcp_tools = [mock_mcp]
9595

9696
tools = collect_server_tools(agent)
9797

@@ -118,7 +118,7 @@ def test_collect_server_tools_with_mcp_tools_via_public_property() -> None:
118118
mock_mcp = MockMCPTool([mcp_function], is_connected=True)
119119

120120
agent = _create_chat_agent_with_tool("regular_tool")
121-
agent._local_mcp_tools = [mock_mcp]
121+
agent.mcp_tools = [mock_mcp]
122122

123123
# Verify the public property works
124124
assert agent.mcp_tools == [mock_mcp]

python/packages/core/agent_framework/_agents.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ def __init__(
678678
normalized_tools: list[ToolProtocol | Callable[..., Any] | MutableMapping[str, Any]] = ( # type:ignore[reportUnknownVariableType]
679679
[] if tools_ is None else tools_ if isinstance(tools_, list) else [tools_] # type: ignore[list-item]
680680
)
681-
self._local_mcp_tools = [tool for tool in normalized_tools if isinstance(tool, MCPTool)]
681+
self.mcp_tools: list[MCPTool] = [tool for tool in normalized_tools if isinstance(tool, MCPTool)]
682682
agent_tools = [tool for tool in normalized_tools if not isinstance(tool, MCPTool)]
683683

684684
# Build chat options dict
@@ -720,7 +720,7 @@ async def __aenter__(self) -> "Self":
720720
Returns:
721721
The ChatAgent instance.
722722
"""
723-
for context_manager in chain([self.chat_client], self._local_mcp_tools):
723+
for context_manager in chain([self.chat_client], self.mcp_tools):
724724
if isinstance(context_manager, AbstractAsyncContextManager):
725725
await self._async_exit_stack.enter_async_context(context_manager)
726726
return self
@@ -742,18 +742,6 @@ async def __aexit__(
742742
"""
743743
await self._async_exit_stack.aclose()
744744

745-
@property
746-
def mcp_tools(self) -> list["MCPTool"]:
747-
"""Get the list of MCP tools attached to this agent.
748-
749-
MCP tools are stored separately from regular tools for lifecycle management.
750-
Their functions are added to the tools list at runtime during run() or run_stream().
751-
752-
Returns:
753-
List of MCPTool instances attached to this agent.
754-
"""
755-
return self._local_mcp_tools
756-
757745
def _update_agent_name_and_description(self) -> None:
758746
"""Update the agent name in the chat client.
759747
@@ -829,7 +817,7 @@ async def run(
829817
else:
830818
final_tools.append(tool) # type: ignore
831819

832-
for mcp_server in self._local_mcp_tools:
820+
for mcp_server in self.mcp_tools:
833821
if not mcp_server.is_connected:
834822
await self._async_exit_stack.enter_async_context(mcp_server)
835823
final_tools.extend(mcp_server.functions)
@@ -956,7 +944,7 @@ async def run_stream(
956944
else:
957945
final_tools.append(tool)
958946

959-
for mcp_server in self._local_mcp_tools:
947+
for mcp_server in self.mcp_tools:
960948
if not mcp_server.is_connected:
961949
await self._async_exit_stack.enter_async_context(mcp_server)
962950
final_tools.extend(mcp_server.functions)

python/packages/devui/agent_framework_devui/_executor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ async def _ensure_mcp_connections(self, agent: Any) -> None:
114114
Args:
115115
agent: Agent object that may have MCP tools
116116
"""
117-
if not hasattr(agent, "_local_mcp_tools"):
117+
if not hasattr(agent, "mcp_tools"):
118118
return
119119

120-
for mcp_tool in agent._local_mcp_tools:
120+
for mcp_tool in agent.mcp_tools:
121121
if not getattr(mcp_tool, "is_connected", False):
122122
continue
123123

python/packages/devui/agent_framework_devui/_server.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,9 @@ async def _cleanup_entities(self) -> None:
248248
except Exception as e:
249249
logger.warning(f"Error closing credential for {entity_info.id}: {e}")
250250

251-
# Close MCP tools (framework tracks them in _local_mcp_tools)
252-
if entity_obj and hasattr(entity_obj, "_local_mcp_tools"):
253-
for mcp_tool in entity_obj._local_mcp_tools:
251+
# Close MCP tools (framework tracks them in mcp_tools)
252+
if entity_obj and hasattr(entity_obj, "mcp_tools"):
253+
for mcp_tool in entity_obj.mcp_tools:
254254
if hasattr(mcp_tool, "close") and callable(mcp_tool.close):
255255
try:
256256
if inspect.iscoroutinefunction(mcp_tool.close):

0 commit comments

Comments
 (0)