Class McpToolFactory
-
- All Implemented Interfaces:
public final class McpToolFactoryFactory for creating Tools and MatryoshkaTools backed by MCP.
Provides methods to:
Get a single MCP tool by name (toolByName, requiredToolByName)
Create MatryoshkaTools that act as facades for groups of MCP tools
Example usage:
val factory = McpToolFactory(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") // MatryoshkaTool with exact tool name whitelist val githubTool = factory.matryoshkaByName( name = "github_operations", description = "GitHub operations. Invoke to access GitHub tools.", toolNames = setOf("create_issue", "list_issues", "get_pull_request") ) // MatryoshkaTool with regex pattern matching val dbTool = factory.matryoshkaMatching( name = "database_operations", description = "Database operations. Invoke to access database tools.", patterns = listOf("^db_".toRegex(), "query.*".toRegex()) ) // MatryoshkaTool with custom filter predicate val webTool = factory.matryoshka( name = "web_operations", description = "Web operations. Invoke to access web tools.", filter = { it.toolDefinition.name().startsWith("web_") } )
-
-
Constructor Summary
Constructors Constructor Description McpToolFactory(List<McpSyncClient> clients)
-
Method Summary
Modifier and Type Method Description final MatryoshkaToolmatryoshka(String name, String description, Function1<ToolCallback, Boolean> filter, Boolean removeOnInvoke)Create a MatryoshkaTool from MCP clients with a filter predicate. final MatryoshkaToolmatryoshka(String name, String description, Function1<ToolCallback, Boolean> filter)Create a MatryoshkaTool from MCP clients with a filter predicate. final MatryoshkaToolmatryoshkaMatching(String name, String description, List<Regex> patterns, Boolean removeOnInvoke)Create a MatryoshkaTool from MCP clients filtering by tool name regex patterns. final MatryoshkaToolmatryoshkaMatching(String name, String description, List<Regex> patterns)Create a MatryoshkaTool from MCP clients filtering by tool name regex patterns. final MatryoshkaToolmatryoshkaByName(String name, String description, Set<String> toolNames, Boolean removeOnInvoke)Create a MatryoshkaTool from MCP clients with an exact tool name whitelist. final MatryoshkaToolmatryoshkaByName(String name, String description, Set<String> toolNames)Create a MatryoshkaTool from MCP clients with an exact tool name whitelist. final TooltoolByName(String toolName)Get a single MCP tool by exact name. final ToolrequiredToolByName(String toolName)Get a single MCP tool by exact name, throwing if not found. -
-
Constructor Detail
-
McpToolFactory
McpToolFactory(List<McpSyncClient> clients)
-
-
Method Detail
-
matryoshka
@JvmOverloads() final MatryoshkaTool matryoshka(String name, String description, Function1<ToolCallback, Boolean> filter, Boolean removeOnInvoke)
Create a MatryoshkaTool from MCP clients with a filter predicate.
- Parameters:
name- Name of the MatryoshkaTool facadedescription- Description explaining when to use this tool categoryfilter- Predicate that returns true to include a toolremoveOnInvoke- Whether to remove the facade after invocation (default true)
-
matryoshka
@JvmOverloads() final MatryoshkaTool matryoshka(String name, String description, Function1<ToolCallback, Boolean> filter)
Create a MatryoshkaTool from MCP clients with a filter predicate.
- Parameters:
name- Name of the MatryoshkaTool facadedescription- Description explaining when to use this tool categoryfilter- Predicate that returns true to include a tool
-
matryoshkaMatching
@JvmOverloads() final MatryoshkaTool matryoshkaMatching(String name, String description, List<Regex> patterns, Boolean removeOnInvoke)
Create a MatryoshkaTool from MCP clients filtering by tool name regex patterns.
- Parameters:
name- Name of the MatryoshkaTool facadedescription- Description explaining when to use this tool categorypatterns- Regex patterns to match against tool namesremoveOnInvoke- Whether to remove the facade after invocation (default true)
-
matryoshkaMatching
@JvmOverloads() final MatryoshkaTool matryoshkaMatching(String name, String description, List<Regex> patterns)
Create a MatryoshkaTool from MCP clients filtering by tool name regex patterns.
- Parameters:
name- Name of the MatryoshkaTool facadedescription- Description explaining when to use this tool categorypatterns- Regex patterns to match against tool names
-
matryoshkaByName
@JvmOverloads() final MatryoshkaTool matryoshkaByName(String name, String description, Set<String> toolNames, Boolean removeOnInvoke)
Create a MatryoshkaTool from MCP clients with an exact tool name whitelist.
- Parameters:
name- Name of the MatryoshkaTool facadedescription- Description explaining when to use this tool categorytoolNames- Exact tool names to includeremoveOnInvoke- Whether to remove the facade after invocation (default true)
-
matryoshkaByName
@JvmOverloads() final MatryoshkaTool matryoshkaByName(String name, String description, Set<String> toolNames)
Create a MatryoshkaTool from MCP clients with an exact tool name whitelist.
- Parameters:
name- Name of the MatryoshkaTool facadedescription- Description explaining when to use this tool categorytoolNames- Exact tool names to include
-
toolByName
final 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
final 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
-
-
-
-