Interface McpToolFactory

  • All Implemented Interfaces:

    
    public interface McpToolFactory
    
                        

    Factory for creating Tools and UnfoldingTools backed by MCP in a consistent way, across MCP providers.

    Provides methods to:

    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.

    • Constructor Detail

    • 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 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
      • 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 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
      • 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 facade
        description - Description explaining when to use this tool category
        toolNames - Exact tool names to include
        removeOnInvoke - Whether to remove the facade after invocation
      • 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