Mcp Tool Factory
Factory 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.
Inheritors
Functions
Get a single MCP tool by exact name, throwing if not found.
Get a single MCP tool by exact name.
Create an UnfoldingTool from MCP clients with a filter predicate, with removeOnInvoke=true.
Create an UnfoldingTool from MCP clients with a filter predicate.
Create an UnfoldingTool from MCP clients with an exact tool name whitelist, with removeOnInvoke=true.
Create an UnfoldingTool from MCP clients with an exact tool name whitelist.
Create an UnfoldingTool from MCP clients filtering by tool name regex patterns, with removeOnInvoke=true.
Create an UnfoldingTool from MCP clients filtering by tool name regex patterns.