Automatically discovers and registers R functions as MCP tools through roxygen2 parsing.
Scans R files for functions tagged with mcpr_tool keyword and converts documentation
into structured tool specifications. Enables tool discovery and validation for MCP
protocol integration through automated function metadata extraction.
Details
Tool Registry for MCPR Framework
Provides comprehensive tool management:
Automatic Discovery: Scans directories for tagged functions
Documentation Parsing: Converts roxygen2 comments to tool specs
Type Mapping: Maps parameter types to MCPR specifications
Validation: Checks for naming conflicts and protocol compliance
Methods
Method new()
Create a new ToolRegistry instance with specified configuration
Usage
ToolRegistry$new(
tools_dir = "inst",
pattern = "tool-.*\\.R$",
recursive = FALSE,
verbose = FALSE
)
Arguments
tools_dir
Directory path to scan for tool files (default: "inst")
pattern
File pattern to match (regex) (default: "tool-.*\.R$")
recursive
Whether to search subdirectories (default: FALSE)
verbose
Enable verbose output during search (default: FALSE)
Returns
New ToolRegistry instance
Scan configured directory for functions tagged with mcpr_tool keyword
Usage
ToolRegistry$search_tools(force_refresh = FALSE)
Arguments
force_refresh
Force re-scanning even if tools are cached (default: FALSE)
Returns
List of MCPR tool objects
Return currently loaded tools without re-scanning
Returns
List of MCPR tool objects
Generate data.frame summary of loaded tools with metadata
Usage
ToolRegistry$get_tool_summary()
Returns
Data.frame with columns: name, description, parameters
Check if tool with specified name exists in registry
Usage
ToolRegistry$has_tool(name)
Arguments
name
Name of the tool to check
Returns
TRUE if tool exists, FALSE otherwise
Retrieve specific tool by name from registry
Usage
ToolRegistry$get_tool(name)
Arguments
name
Name of the tool to retrieve
Returns
MCPR tool object or NULL if not found
Update search configuration and reset cached tools
Usage
ToolRegistry$configure(tools_dir = NULL, pattern = NULL, recursive = NULL)
Arguments
tools_dir
New directory path (optional)
pattern
New file pattern (optional)
recursive
New recursive setting (optional)
Returns
Self (invisibly) for method chaining
Method set_verbose()
Enable or disable verbose output during search operations
Usage
ToolRegistry$set_verbose(verbose)
Arguments
verbose
TRUE to enable verbose output, FALSE to disable
Returns
Self (invisibly) for method chaining
Print summary of ToolRegistry with directory and tool information
Method clone()
The objects of this class are cloneable with this method.
Usage
ToolRegistry$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
Examples
if (FALSE) { # \dontrun{
# Basic usage
registry <- ToolRegistry$new()
tools <- registry$search_tools()
# Custom configuration
registry <- ToolRegistry$new(
tools_dir = "custom/tools",
pattern = "\\.R$",
recursive = TRUE
)
# Get tool information
summary <- registry$get_tool_summary()
if (registry$has_tool("my_function")) {
tool <- registry$get_tool("my_function")
}
} # }