McpToolFactory

class McpToolFactory(clients: List<<Error class: unknown class>>)

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_") }
)

Constructors

Link copied to clipboard
constructor(clients: List<<Error class: unknown class>>)

Functions

Link copied to clipboard
fun matryoshka(name: String, description: String, filter: (<Error class: unknown class>) -> Boolean, removeOnInvoke: Boolean = true): MatryoshkaTool

Create a MatryoshkaTool from MCP clients with a filter predicate.

Link copied to clipboard
fun matryoshkaByName(name: String, description: String, toolNames: Set<String>, removeOnInvoke: Boolean = true): MatryoshkaTool

Create a MatryoshkaTool from MCP clients with an exact tool name whitelist.

Link copied to clipboard
fun matryoshkaMatching(name: String, description: String, patterns: List<<Error class: unknown class>>, removeOnInvoke: Boolean = true): MatryoshkaTool

Create a MatryoshkaTool from MCP clients filtering by tool name regex patterns.

Link copied to clipboard

Get a single MCP tool by exact name, throwing if not found.

Link copied to clipboard
fun toolByName(toolName: String): Tool?

Get a single MCP tool by exact name.