mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-03 00:02:36 +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 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):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user