mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-24 15:48:23 +00:00
feat: Add ToolCollection class for named tool access (#339)
This change allows accessing tools by name (tools["tool_name"]) in addition to index (tools[0]), making it more intuitive and convenient to work with multiple tools without needing to remember their position in the list
This commit is contained in:
@@ -4,7 +4,7 @@ import pytest
|
||||
from mcp import StdioServerParameters
|
||||
|
||||
from crewai_tools import MCPServerAdapter
|
||||
|
||||
from crewai_tools.adapters.tool_collection import ToolCollection
|
||||
|
||||
@pytest.fixture
|
||||
def echo_server_script():
|
||||
@@ -18,7 +18,7 @@ def echo_server_script():
|
||||
def echo_tool(text: str) -> str:
|
||||
"""Echo the input text"""
|
||||
return f"Echo: {text}"
|
||||
|
||||
|
||||
mcp.run()
|
||||
'''
|
||||
)
|
||||
@@ -68,6 +68,7 @@ def test_context_manager_syntax(echo_server_script):
|
||||
command="uv", args=["run", "python", "-c", echo_server_script]
|
||||
)
|
||||
with MCPServerAdapter(serverparams) as tools:
|
||||
assert isinstance(tools, ToolCollection)
|
||||
assert len(tools) == 1
|
||||
assert tools[0].name == "echo_tool"
|
||||
assert tools[0].run(text="hello") == "Echo: hello"
|
||||
@@ -91,7 +92,7 @@ def test_try_finally_syntax(echo_server_script):
|
||||
assert tools[0].run(text="hello") == "Echo: hello"
|
||||
finally:
|
||||
mcp_server_adapter.stop()
|
||||
|
||||
|
||||
def test_try_finally_syntax_sse(echo_sse_server):
|
||||
sse_serverparams = echo_sse_server
|
||||
mcp_server_adapter = MCPServerAdapter(sse_serverparams)
|
||||
Reference in New Issue
Block a user