MCPcopy Create free account
hub / github.com/IBM/mcp-cli / DynamicToolProvider

Class DynamicToolProvider

src/mcp_cli/tools/dynamic_tools.py:53–255  ·  view source on GitHub ↗

MCP-CLI specific dynamic tool provider. Extends BaseDynamicToolProvider with: - ToolManager integration for MCP tool execution - State-aware filtering (blocks tools requiring computed values) - MCP result unwrapping ENHANCED: Uses intelligent search engine from chuk-tool-proces

Source from the content-addressed store, hash-verified

51
52
53class DynamicToolProvider(BaseDynamicToolProvider[ToolInfo]):
54 """MCP-CLI specific dynamic tool provider.
55
56 Extends BaseDynamicToolProvider with:
57 - ToolManager integration for MCP tool execution
58 - State-aware filtering (blocks tools requiring computed values)
59 - MCP result unwrapping
60
61 ENHANCED: Uses intelligent search engine from chuk-tool-processor with:
62 - Synonym expansion for natural language queries
63 - Tokenized OR semantics (partial matches score)
64 - Fuzzy matching fallback for typos
65 - Namespace aliasing for flexible tool resolution
66 - Always returns results (never empty)
67 """
68
69 def __init__(self, tool_manager: ToolManager) -> None:
70 """Initialize with a tool manager.
71
72 Args:
73 tool_manager: ToolManager instance to query for tools
74 """
75 super().__init__()
76 self.tool_manager = tool_manager
77
78 # =========================================================================
79 # Required implementations from BaseDynamicToolProvider
80 # =========================================================================
81
82 async def get_all_tools(self) -> list[ToolInfo]:
83 """Get all available tools from the tool manager.
84
85 Returns:
86 List of ToolInfo objects
87 """
88 return await self.tool_manager.get_all_tools()
89
90 async def execute_tool(
91 self,
92 tool_name: str,
93 arguments: dict[str, Any],
94 ) -> dict[str, Any]:
95 """Execute a tool via the tool manager.
96
97 Handles MCP-specific result unwrapping.
98
99 Args:
100 tool_name: Name of the tool to execute
101 arguments: Arguments to pass to the tool
102
103 Returns:
104 Execution result dict
105 """
106 try:
107 result = await self.tool_manager.execute_tool(
108 tool_name=tool_name,
109 arguments=arguments,
110 namespace=None, # Let tool manager figure out the namespace

Calls

no outgoing calls