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:
Lucas Gomide
2025-06-20 10:27:10 -03:00
committed by GitHub
parent 9e92b84bcc
commit 31b3dd2b94
6 changed files with 316 additions and 10 deletions

View File

@@ -4,7 +4,7 @@ import logging
from typing import TYPE_CHECKING, Any
from crewai.tools import BaseTool
from crewai_tools.adapters.tool_collection import ToolCollection
"""
MCPServer for CrewAI.
@@ -114,7 +114,7 @@ class MCPServerAdapter:
self._adapter.__exit__(None, None, None)
@property
def tools(self) -> list[BaseTool]:
def tools(self) -> ToolCollection[BaseTool]:
"""The CrewAI tools available from the MCP server.
Raises:
@@ -127,7 +127,7 @@ class MCPServerAdapter:
raise ValueError(
"MCP server not started, run `mcp_server.start()` first before accessing `tools`"
)
return self._tools
return ToolCollection(self._tools)
def __enter__(self):
"""