Implements Model Context Protocol server for persistent R session management. Operates through nanonext sockets for non-blocking message handling between JSON-RPC clients and R sessions, enabling tool execution routing and workspace state persistence.
Details
Server operates through layered message handling:
Client Layer: Handles JSON-RPC communication with MCP clients
Server Layer: Manages tool execution and session routing
Session Layer: Forwards requests to active 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)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"))Examples
if (FALSE) { # \dontrun{
# Basic server initialization
server <- mcprServer$new()
server$start() # Blocking call
# Server with custom tools
my_tool <- tool(
function(x) mean(x),
name = "mean",
description = "Calculate arithmetic mean",
arguments = list(x = "number")
)
registry <- ToolRegistry$new()
registry$add_tool(my_tool)
server <- mcprServer$new(registry = registry)
server$start()
# Using convenience function
registry <- ToolRegistry$new(tools_dir = "path/to/tools")
mcpr_server(registry = registry)
} # }
