Interface McpToolFactory
-
- All Implemented Interfaces:
public interface McpToolFactoryFactory for creating Tools and UnfoldingTools backed by MCP in a consistent way, across MCP providers.
Provides methods to:
Get a single MCP tool by name (toolByName, requiredToolByName)
Create UnfoldingTools that act as facades for groups of MCP tools
Example usage:
val factory: McpToolFactory = SpringAiMcpToolFactory(mcpSyncClients) // Single tool by name (returns null if not found) val searchTool = factory.toolByName("brave_search") // Single tool by name (throws if not found) val requiredTool = factory.requiredToolByName("brave_search") // UnfoldingTool with exact tool name whitelist val githubTool = factory.unfoldingByName( name = "github_operations", description = "GitHub operations. Invoke to access GitHub tools.", toolNames = setOf("create_issue", "list_issues", "get_pull_request") ) // UnfoldingTool with regex pattern matching val dbTool = factory.unfoldingMatching( name = "database_operations", description = "Database operations. Invoke to access database tools.", patterns = listOf("^db_".toRegex(), "query.*".toRegex()) ) // UnfoldingTool with custom filter predicate val webTool = factory.unfolding( name = "web_operations", description = "Web operations. Invoke to access web tools.", filter = { it.toolDefinition.name().startsWith("web_") } )See com.embabel.agent.spi.support.springai.SpringAiMcpToolFactory for a Spring-based implementation that creates tools from MCP clients.
-
-
Method Summary
Modifier and Type Method Description abstract UnfoldingToolunfolding(String name, String description, Function1<ToolCallback, Boolean> filter, Boolean removeOnInvoke)Create an UnfoldingTool from MCP clients with a filter predicate. UnfoldingToolunfolding(String name, String description, Function1<ToolCallback, Boolean> filter)Create an UnfoldingTool from MCP clients with a filter predicate, with removeOnInvoke=true. UnfoldingToolunfoldingMatching(String name, String description, List<Regex> patterns, Boolean removeOnInvoke)Create an UnfoldingTool from MCP clients filtering by tool name regex patterns. UnfoldingToolunfoldingMatching(String name, String description, List<Regex> patterns)Create an UnfoldingTool from MCP clients filtering by tool name regex patterns, with removeOnInvoke=true. UnfoldingToolunfoldingByName(String name, String description, Set<String> toolNames, Boolean removeOnInvoke)Create an UnfoldingTool from MCP clients with an exact tool name whitelist. UnfoldingToolunfoldingByName(String name, String description, Set<String> toolNames)Create an UnfoldingTool from MCP clients with an exact tool name whitelist, with removeOnInvoke=true. abstract TooltoolByName(String toolName)Get a single MCP tool by exact name. ToolrequiredToolByName(String toolName)Get a single MCP tool by exact name, throwing if not found. UnfoldingToolmatryoshka(String name, String description, Function1<ToolCallback, Boolean> filter, Boolean removeOnInvoke)UnfoldingToolmatryoshka(String name, String description, Function1<ToolCallback, Boolean> filter)UnfoldingToolmatryoshkaMatching(String name, String description, List<Regex> patterns, Boolean removeOnInvoke)UnfoldingToolmatryoshkaMatching(String name, String description, List<Regex> patterns)UnfoldingToolmatryoshkaByName(String name, String description, Set<String> toolNames, Boolean removeOnInvoke)UnfoldingToolmatryoshkaByName(String name, String description, Set<String> toolNames)-
-
Method Detail
-
unfolding
abstract UnfoldingTool unfolding(String name, String description, Function1<ToolCallback, Boolean> filter, Boolean removeOnInvoke)
Create an UnfoldingTool from MCP clients with a filter predicate.
- Parameters:
name- Name of the UnfoldingTool facadedescription- Description explaining when to use this tool categoryfilter- Predicate that returns true to include a toolremoveOnInvoke- Whether to remove the facade after invocation
-
unfolding
UnfoldingTool unfolding(String name, String description, Function1<ToolCallback, Boolean> filter)
Create an UnfoldingTool from MCP clients with a filter predicate, with removeOnInvoke=true.
-
unfoldingMatching
UnfoldingTool unfoldingMatching(String name, String description, List<Regex> patterns, Boolean removeOnInvoke)
Create an UnfoldingTool from MCP clients filtering by tool name regex patterns.
- Parameters:
name- Name of the UnfoldingTool facadedescription- Description explaining when to use this tool categorypatterns- Regex patterns to match against tool namesremoveOnInvoke- Whether to remove the facade after invocation
-
unfoldingMatching
UnfoldingTool unfoldingMatching(String name, String description, List<Regex> patterns)
Create an UnfoldingTool from MCP clients filtering by tool name regex patterns, with removeOnInvoke=true.
-
unfoldingByName
UnfoldingTool unfoldingByName(String name, String description, Set<String> toolNames, Boolean removeOnInvoke)
Create an UnfoldingTool from MCP clients with an exact tool name whitelist.
- Parameters:
name- Name of the UnfoldingTool facadedescription- Description explaining when to use this tool categorytoolNames- Exact tool names to includeremoveOnInvoke- Whether to remove the facade after invocation
-
unfoldingByName
UnfoldingTool unfoldingByName(String name, String description, Set<String> toolNames)
Create an UnfoldingTool from MCP clients with an exact tool name whitelist, with removeOnInvoke=true.
-
toolByName
abstract Tool toolByName(String toolName)
Get a single MCP tool by exact name.
- Parameters:
toolName- The exact name of the MCP tool- Returns:
The tool, or null if not found
-
requiredToolByName
Tool requiredToolByName(String toolName)
Get a single MCP tool by exact name, throwing if not found.
- Parameters:
toolName- The exact name of the MCP tool- Returns:
The tool
-
matryoshka
@Deprecated(message = "Use unfolding() instead", replaceWith = @ReplaceWith(imports = {}, expression = "unfolding(name, description, filter, removeOnInvoke)")) UnfoldingTool matryoshka(String name, String description, Function1<ToolCallback, Boolean> filter, Boolean removeOnInvoke)
-
matryoshka
@Deprecated(message = "Use unfolding() instead", replaceWith = @ReplaceWith(imports = {}, expression = "unfolding(name, description, filter)")) UnfoldingTool matryoshka(String name, String description, Function1<ToolCallback, Boolean> filter)
-
matryoshkaMatching
@Deprecated(message = "Use unfoldingMatching() instead", replaceWith = @ReplaceWith(imports = {}, expression = "unfoldingMatching(name, description, patterns, removeOnInvoke)")) UnfoldingTool matryoshkaMatching(String name, String description, List<Regex> patterns, Boolean removeOnInvoke)
-
matryoshkaMatching
@Deprecated(message = "Use unfoldingMatching() instead", replaceWith = @ReplaceWith(imports = {}, expression = "unfoldingMatching(name, description, patterns)")) UnfoldingTool matryoshkaMatching(String name, String description, List<Regex> patterns)
-
matryoshkaByName
@Deprecated(message = "Use unfoldingByName() instead", replaceWith = @ReplaceWith(imports = {}, expression = "unfoldingByName(name, description, toolNames, removeOnInvoke)")) UnfoldingTool matryoshkaByName(String name, String description, Set<String> toolNames, Boolean removeOnInvoke)
-
matryoshkaByName
@Deprecated(message = "Use unfoldingByName() instead", replaceWith = @ReplaceWith(imports = {}, expression = "unfoldingByName(name, description, toolNames)")) UnfoldingTool matryoshkaByName(String name, String description, Set<String> toolNames)
-
-
-
-