mirror of
https://github.com/EvolutionAPI/adk-python.git
synced 2025-07-16 04:02:55 -06:00
fix: fix tool filtering in mcp toolset
PiperOrigin-RevId: 759632573
This commit is contained in:
parent
755ce74550
commit
12507dc6cc
@ -21,6 +21,7 @@ from typing import TextIO
|
|||||||
from typing_extensions import override
|
from typing_extensions import override
|
||||||
|
|
||||||
from ...agents.readonly_context import ReadonlyContext
|
from ...agents.readonly_context import ReadonlyContext
|
||||||
|
from ..base_tool import BaseTool
|
||||||
from ..base_toolset import BaseToolset
|
from ..base_toolset import BaseToolset
|
||||||
from ..base_toolset import ToolPredicate
|
from ..base_toolset import ToolPredicate
|
||||||
from .mcp_session_manager import MCPSessionManager
|
from .mcp_session_manager import MCPSessionManager
|
||||||
@ -100,7 +101,7 @@ class MCPToolset(BaseToolset):
|
|||||||
return self._session
|
return self._session
|
||||||
|
|
||||||
def _is_selected(
|
def _is_selected(
|
||||||
self, tool: ..., readonly_context: Optional[ReadonlyContext]
|
self, tool: BaseTool, readonly_context: Optional[ReadonlyContext]
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""Checks if a tool should be selected based on the tool filter."""
|
"""Checks if a tool should be selected based on the tool filter."""
|
||||||
if self.tool_filter is None:
|
if self.tool_filter is None:
|
||||||
@ -130,12 +131,14 @@ class MCPToolset(BaseToolset):
|
|||||||
if not self._session:
|
if not self._session:
|
||||||
await self._initialize()
|
await self._initialize()
|
||||||
tools_response: ListToolsResult = await self._session.list_tools()
|
tools_response: ListToolsResult = await self._session.list_tools()
|
||||||
return [
|
tools = []
|
||||||
MCPTool(
|
for tool in tools_response.tools:
|
||||||
mcp_tool=tool,
|
mcp_tool = MCPTool(
|
||||||
mcp_session=self._session,
|
mcp_tool=tool,
|
||||||
mcp_session_manager=self._session_manager,
|
mcp_session=self._session,
|
||||||
)
|
mcp_session_manager=self._session_manager,
|
||||||
for tool in tools_response.tools
|
)
|
||||||
if self._is_selected(tool, readonly_context)
|
|
||||||
]
|
if self._is_selected(mcp_tool, readonly_context):
|
||||||
|
tools.append(mcp_tool)
|
||||||
|
return tools
|
||||||
|
Loading…
Reference in New Issue
Block a user