rstudiomcp
MCP (Model Context Protocol) server for RStudio - Bridge your RStudio session with Claude Code
claude mcp add --transport stdio zygi-rstudiomcp python -m rstudiomcp \ --env R_ENV="Path to your R installation if required by the package" \ --env RSTUDIO_PORT="16751 (default) or your chosen port"
How to use
This MCP server integrates Claude Code with your active RStudio session, allowing Claude Code to execute R code in your session, inspect objects and environments, read and edit open documents, source R scripts, capture plots from the Plots pane, and access HTML content from the Viewer pane. After starting the MCP server inside RStudio, Claude Code can discover and connect to it automatically when you open Claude Code in the same project folder. The available tools are organized into sections for Code Execution (eval_r, source_active_document), Environment Inspection (list_environments, list_objects, get_object, get_console_history), Document Editing (create_document, open_document_file, get_active_document, insert_text, replace_text_range), and Visualization (get_current_plot, get_latest_viewer_content). You can manage the server with the provided RStudio Addins or direct R code (start_mcp_server, configure_mcp_server, restart_mcp_server, disable_autoload).
How to install
Prerequisites:
- R and RStudio installed on your system.
- Internet access to reach GitHub and CRAN.
Step-by-step installation:
- In RStudio, install the remotes package if you don’t have it: install.packages("remotes")
- Load remotes and install the rstudiomcp package from GitHub: library(remotes) remotes::install_github("zygi/rstudiomcp")
- Start the MCP server from RStudio: library(rstudiomcp) start_mcp_server()
- By default the server runs on http://localhost:16751. If needed, you can change the port with: start_mcp_server(port = 12345)
Notes:
- The server writes a .mcp.json file in your project directory to help Claude Code discover the server.
- If you need to use Claude Code across multiple RStudio sessions, you may start servers on different ports per session as described in the README.
Additional notes
Tips and common issues:
- Ensure Claude Code is opened within the same project folder that contains the .mcp.json generated by the server for automatic connection.
- If you see “Address already in use” when starting the server, restart the server or configure a different port with configure_mcp_server().
- The server may require wrapping the Viewer function to access viewer content; this is noted as a hacky but working approach.
- If concurrent sessions are required, you can manually run start_mcp_server(port=...) in separate RStudio sessions and connect Claude Code to each corresponding port.
- To verify status, use mcp_status() or the MCP Server Status addin in RStudio.
- The available tools (code execution, environment inspection, document editing, and visualization) are designed to work on the active R session and the currently active document.
Related MCP Servers
Remote
A type-safe solution to remote MCP communication, enabling effortless integration for centralized management of Model Context.
mongodb-lens
🍃🔎 MongoDB Lens: Full Featured MCP Server for MongoDB Databases
ClaudeR
Connect RStudio to Claude, Codex, Gemini, and other AI assistants via MCP. Multi-agent orchestration, async execution, and zero-config setup with uvx.
openapi
OpenAPI definitions, converters and LLM function calling schema composer.
comfy-pilot
MCP server + embedded terminal that lets Claude Code see and edit your ComfyUI workflows
mcp-tasks
A comprehensive and efficient MCP server for task management with multi-format support (Markdown, JSON, YAML)