Implements a Model Context Protocol server with a private R runtime.
Ordinary tools execute in the server process by default. When manage_r_sessions
is registered, the server can optionally attach to human or secondary R sessions.
Details
Server operates through layered message handling:
Client Layer: Handles JSON-RPC communication with MCP clients
Server Layer: Manages tool execution and active session state
Session Layer: Optionally forwards requests to attached R sessions
Methods
Inherited methods
MCPR::BaseMCPR$cleanup_all()MCPR::BaseMCPR$create_socket()MCPR::BaseMCPR$get_component_name()MCPR::BaseMCPR$initialize_base()MCPR::BaseMCPR$is_initialized()MCPR::BaseMCPR$register_cleanup()MCPR::BaseMCPR$socket_url()MCPR::BaseMCPR$state_clear()MCPR::BaseMCPR$state_get()MCPR::BaseMCPR$state_has()MCPR::BaseMCPR$state_keys_owned()MCPR::BaseMCPR$state_set()
Method new()
Initialize the MCP server with optional tools
Usage
mcprServer$new(
registry = NULL,
.tools_dir = NULL,
log_file = NULL,
execution_timeout_secs = 300L,
resource_registry = NULL
)Arguments
registryA ToolRegistry instance to use for tool discovery
.tools_dirInternal parameter for specifying tools directory path
log_fileOptional log file path for the server logger
execution_timeout_secsDefault seconds before a forwarded request is considered timed out (default: 300). Override per-call via the
timeoutargument in tools likeexecute_r_code.resource_registryAn MCPResourceRegistry instance. If NULL (default), a built-in registry with the MCPR plot viewer is created automatically.
Method start()
Start the MCP server and begin listening for connections
Method stop()
Method get_tools()
Get server tools in the specified format
Usage
mcprServer$get_tools(format = c("list", "json"))Method session_management_enabled()
Return whether this server exposes session-management capability.
Examples
if (FALSE) { # \dontrun{
# Basic server initialization
server <- mcprServer$new()
server$start() # Blocking call
# Server with tools discovered from a package or directory
registry <- ToolRegistry$new(tools_dir = "path/to/tools")
registry$search_tools()
server <- mcprServer$new(registry = registry)
server$start()
# Using convenience function
registry <- ToolRegistry$new(tools_dir = "path/to/tools")
mcpr_server(registry = registry)
} # }
