Discovers and registers R functions as MCP tools through roxygen2 parsing. Scans one or more directories for functions tagged with the mcpr_tool keyword, converts documentation into structured tool specifications, and supports post-discovery filtering.
Details
Provides comprehensive tool management:
Multi-Directory Discovery: Scans directories for tagged functions
Documentation Parsing: Converts roxygen2 comments to tool specs
Type Mapping: Maps parameter types to MCPR specifications
Filtering: Include/exclude tools by name for tailored server profiles
Provenance: Tracks which directory contributed each tool
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_dirCharacter vector of directory paths to scan for tool files (default: "inst"). Each path is scanned independently; missing directories are skipped with a warning.
patternFile pattern to match (regex) (default: "tool-.*\.R$")
recursiveWhether to search subdirectories (default: FALSE)
verboseEnable verbose output during search (default: FALSE)
Method search_tools()
Scan configured directories for functions tagged with mcpr_tool keyword. Applies any active include/exclude filters before returning results.
Method configure()
Update search configuration and reset cached tools.
Accepts a character vector for tools_dir to enable
multi-directory discovery. Filters set via filter() are
preserved across configure() calls.
Method filter()
Set include/exclude filters for tool names.
Filters are applied immediately to already-discovered tools and
persist across subsequent search_tools() calls.
Call with no arguments to clear all filters.
Method print()
Print summary of ToolRegistry with directory, filter, and tool information
Examples
if (FALSE) { # \dontrun{
# Basic usage - single directory
registry <- ToolRegistry$new()
tools <- registry$search_tools()
# Multi-directory discovery
registry <- ToolRegistry$new(
tools_dir = c(
system.file(package = "MCPR"),
system.file("tools", package = "myPkg")
)
)
# Filter after discovery
registry$search_tools()
registry$filter(exclude = "execute_r_code")
# Cherry-pick tools from MCPR + all from another package
registry$filter(include = c("manage_r_sessions", "my_tool_a", "my_tool_b"))
# Inspect what you got
registry$get_tool_summary()
} # }
