Class McpToolFactory

  • All Implemented Interfaces:

    
    public final class McpToolFactory
    
                        

    Factory for creating Tools and MatryoshkaTools backed by MCP.

    Provides methods to:

    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 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 facade
        description - Description explaining when to use this tool category
        filter - Predicate that returns true to include a tool
        removeOnInvoke - 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 facade
        description - Description explaining when to use this tool category
        filter - 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 facade
        description - Description explaining when to use this tool category
        patterns - Regex patterns to match against tool names
        removeOnInvoke - 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 facade
        description - Description explaining when to use this tool category
        patterns - 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 facade
        description - Description explaining when to use this tool category
        toolNames - Exact tool names to include
        removeOnInvoke - 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 facade
        description - Description explaining when to use this tool category
        toolNames - 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