r function exposure via json-rpc mcp server
Launches a long-running MCP server process that listens for JSON-RPC 2.0 requests over stdio or HTTP transport, maintains a registry of R functions as callable tools, and routes execution requests to appropriate R session contexts via nanonext socket connections. The server decouples tool definition from execution environment, allowing AI assistants like Claude Desktop to invoke R functions within isolated session contexts.
Unique: Implements dual-process architecture where mcp_server() runs as a separate process managing JSON-RPC routing while mcp_session() registers interactive R sessions via nanonext sockets, enabling tool execution within specific project contexts rather than a single monolithic server — this separation allows AI assistants to target different R environments (dev, prod, analysis) without restarting the server.
vs alternatives: Unlike generic MCP server implementations, mcptools' session-based routing enables context-aware R execution (accessing local variables, loaded packages) while maintaining server stability through process isolation.
interactive r session registration and management
Registers running R sessions with the MCP server via nanonext socket connections, enabling those sessions to execute tools and maintain state across multiple AI assistant requests. Sessions advertise themselves to the server with metadata (session ID, R version, loaded packages) and receive tool execution requests routed by the server, returning results within their local environment context.
Unique: Uses nanonext socket protocol for bidirectional communication between sessions and server, allowing sessions to register themselves dynamically and receive tool execution requests in real-time while maintaining their local R environment state — this is distinct from stateless function-as-a-service approaches that spawn new processes per request.
vs alternatives: Preserves R session state across multiple tool invocations, enabling stateful workflows where tools can access previously computed variables and loaded packages, unlike serverless approaches that require full environment reconstruction per call.
error handling and response serialization for tool execution
Handles errors during tool execution, serializes R objects to JSON for JSON-RPC responses, and manages type conversion between R and JSON representations. The system catches execution errors, formats them as JSON-RPC error responses with stack traces, and handles edge cases like circular references and non-serializable objects.
Unique: Implements comprehensive error handling that catches R execution errors and converts them to JSON-RPC error responses with stack traces, while also handling serialization of complex R objects to JSON — this provides both robustness and debuggability for tool execution.
vs alternatives: Detailed error responses with stack traces enable faster debugging compared to generic error messages, and automatic serialization reduces boilerplate error handling code.
configuration management for server startup and transport selection
Manages MCP server configuration including transport selection (stdio vs HTTP), port binding, environment variables, and startup arguments. The configuration system allows declarative specification of server behavior through function parameters and environment variables, enabling flexible deployment across different environments without code changes.
Unique: Provides flexible configuration through function parameters and environment variables, allowing the same R code to deploy to different environments without modification — this follows R's convention of environment-based configuration.
vs alternatives: Environment-based configuration is more flexible than hardcoded settings and easier to manage than separate configuration files, enabling seamless deployment across dev/staging/prod environments.
tool schema definition and parameter validation
Defines R functions as MCP tools with structured schemas including name, description, and typed parameters, enabling AI assistants to understand tool capabilities and constraints before invocation. The schema system validates parameter types (string, number, boolean, object, array) and enforces required vs optional parameters, preventing malformed tool calls from reaching R execution contexts.
Unique: Integrates with roxygen2 documentation system to extract parameter descriptions and types, converting R function signatures into JSON-Schema tool definitions that MCP clients can parse — this bridges R's dynamic typing with JSON-RPC's strict schema requirements through documentation-driven schema generation.
vs alternatives: Leverages existing roxygen2 ecosystem familiar to R developers, reducing schema definition overhead compared to tools requiring separate schema files or manual JSON specification.
external mcp server consumption and tool import
Spawns and manages external MCP server processes (via processx), discovers their available tools through JSON-RPC introspection, and wraps those tools as native R functions that can be called directly or integrated with ellmer Chat objects. The client maintains a registry of imported tools with their schemas and handles JSON serialization/deserialization for cross-process communication.
Unique: Uses processx to spawn external MCP servers as child processes and wraps their tools as native R functions through dynamic function generation, enabling seamless integration with R's functional programming model — this allows R code to call external tools using standard R syntax (e.g., `external_tool(param1, param2)`) rather than manual JSON-RPC calls.
vs alternatives: Abstracts away JSON-RPC complexity and process management, making external MCP tools feel native to R developers compared to manual HTTP/stdio client implementations that require explicit serialization and error handling.
ellmer chat integration with mcp tools
Integrates imported MCP tools directly into ellmer::Chat objects, enabling LLM-powered R chat applications to invoke external tools during conversation. The integration handles tool call parsing from LLM responses, parameter extraction, tool execution, and result injection back into the conversation context for multi-turn reasoning.
Unique: Provides tight integration with ellmer's Chat API, allowing MCP tools to be passed directly to chat objects where the LLM framework handles tool call parsing and execution orchestration — this eliminates manual tool call handling code and leverages ellmer's built-in multi-turn reasoning loop.
vs alternatives: Reduces boilerplate compared to manual tool call handling, as ellmer manages the full cycle of parsing LLM responses, extracting tool calls, executing tools, and injecting results back into context.
json-rpc 2.0 protocol implementation with stdio and http transport
Implements the JSON-RPC 2.0 specification for bidirectional communication between MCP clients and servers, supporting both stdio (for local processes) and HTTP (for remote servers) transports. The implementation handles message framing, request/response correlation, error handling, and asynchronous notification delivery according to the MCP specification (version 2025-06-18).
Unique: Implements full JSON-RPC 2.0 specification with dual transport support (stdio for local, HTTP for remote), handling message framing, request correlation, and error responses according to MCP 2025-06-18 spec — this enables mcptools to interoperate with any MCP-compliant client or server regardless of transport choice.
vs alternatives: Standards-compliant implementation ensures compatibility with the broader MCP ecosystem, unlike custom protocol implementations that require custom client/server pairs.
+4 more capabilities