Get the FREE Ultimate OpenClaw Setup Guide →

MCPR

MCPR enables AI agents to participate in interactive R sessions for professional analysis workflows.

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio phisanti-mcpr R --quiet --slave -e MCPR::mcpr_server()

How to use

MCPR enables a persistent, interactive R session that an AI agent can connect to and issue commands against. This framework preserves the workspace state across requests, allowing iterative exploration, modeling, and visualization without restarting R for each step. The MCPR package exposes tools to manage sessions, execute arbitrary R code, and generate graphics in a collaborative setting. The core workflow is to start the MCPR server within R, expose the session on the local machine, and have your AI agent discover and join that session to run code and retrieve results, plots, and workspace state in real time.

Once connected, you can use the execute_r_code tool to run R expressions within the live session, the create_plot tool to render visualizations (with optional width/height parameters and format), and manage_r_sessions to list available sessions or join a specific one. This design gives the AI agent structured, well-defined endpoints for common R operations, while maintaining the stateful context needed for meaningful, multi-step analysis. For example, an agent can execute data transformations, generate plots, and then query the workspace to review results, all within the same session.

How to install

Prerequisites:

  1. Install the MCPR package from GitHub:
# Install remotes if needed
if (!require("remotes")) install.packages("remotes")

# Install MCPR from GitHub
remotes::install_github("phisanti/MCPR")
  1. Install the MCPR server integration so the agent can connect to R:
library(MCPR)
# Optional: install any required system dependencies for your setup
install_mcpr(agent = "claude") # Example for Claude; supported agents may include claude, gemini, copilot, codex
  1. Start the MCPR server inside an R session (the server exposes a session discoverable on the local machine):
library(MCPR)
mcpr_session_start()
  1. If using the manual MCP configuration method (Claude Desktop), create or update the MCP configuration file with:
{
  "mcpServers": {
    "mcpr": {
      "command": "R",
      "args": ["--quiet", "--slave", "-e", "MCPR::mcpr_server()"]
    }
  }
}
  1. Verify the session discovery and connection from your AI agent, following the agent-specific instructions to list and join sessions (e.g., manage_r_sessions('list') and manage_r_sessions('join', session_id)).

Additional notes

Tips and considerations:

  • Ensure that the R session running MCPR has network access if your agent is remote (the default setup uses local discovery). If you run into port or firewall issues, you may need to adjust network bindings.
  • The create_plot tool relies on a graphics subsystem (httpgd when available) for efficient off-screen rendering; if httpgd is not installed, MCPR will fall back to base graphics devices.
  • For large results or plots, be mindful of payload sizes and token usage; the plotting tool returns base64-encoded images with metadata.
  • If you encounter authentication or discovery problems, re-run mcpr_session_start() and confirm that the R process remains active and reachable by the agent.
  • Keep your MCPR version up to date to benefit from improvements in session management and tool capabilities.

Related MCP Servers

Sponsor this space

Reach thousands of developers