Usage: MCPR (Model Context Protocol Tools for R) addresses the limitations of stateless execution in AI-assisted R programming. Traditional agents invoke Rscript for every command and cannot preserve workspace state, making them unsuitable for iterative, state-dependent data analysis. MCPR enables AI agents to establish persistent interactive sessions in a live R environment, preserving workspace state and supporting multi-step analysis workflows.
Main capabilities: Communicates asynchronously and cross-platform via JSON-RPC 2.0 and nanonext sockets. Exposes functionality as tools: execute_r_code executes arbitrary R code and returns results, output, warnings, and errors; show_plot generates and displays plots, with target optionally being user (default, displayed to the user) or agent (returns a base64 image and token usage); manage_r_sessions manages sessions, supporting list, join, start, detach, close; view is used for environment inspection, allowing viewing of session, terminal, workspace, installed_packages. Plotting prioritizes offscreen rendering with httpgd, falls back to grDevices, and includes token management to prevent images from becoming too large.
How to use: First install R, then install the MCPR package from GitHub. install_mcpr() can be used to automatically complete package installation and agent MCP configuration, supporting Claude, Gemini, Copilot, Codex. Manual configuration is also possible, for example Claude Desktop's claude_desktop_config.json. To collaborate within an existing R console, run mcpr_session_start() in that console, then attach using manage_r_sessions('list') and manage_r_sessions('join', session=ID); regular tools do not take a session parameter, attachment is controlled separately by manage_r_sessions, and after detach you return to a private session.
Applicable scenarios: R data analysis, modeling, and validation workflows that require long-running, multi-step, state-accumulating work, as well as scenarios where AI and human R sessions are expected to collaborate.
Limitations: Requires an existingR installation; for plotting errors, ensure the expression is valid, dependent libraries are loaded, and httpgd is installed; for attachment failures, confirm that mcpr_session_start() is running, and you can set MCPTOOLS_LOG_FILE to view logs; for tool-not-found, check the user_mcp.json path and restart the agent. The project uses the CC BY 4.0 license.