RStudio MCP Server
Enables AI assistants to deeply integrate with RStudio for environment management, code execution, project management, and package management.
README
RStudio MCP Server
A Model Context Protocol (MCP) server that provides AI assistants with deep RStudio integration capabilities, including environment management, code execution, project management, and more.
Features
- Environment Management: Create, switch, and manage R environments
- Code Execution: Execute R code in specified environments with result capture
- Project Management: Create and manage RStudio projects
- Package Management: Install, update, and manage R packages
- Version Control: Git integration for RStudio projects
- Visualization: Capture and manage R plots and visualizations
- MCP Compliance: Full compliance with MCP 2025-06-18 specification
Installation
Prerequisites
- Python 3.8 or higher
- R 4.0 or higher
- RStudio (optional, but recommended)
Install from Source
git clone https://github.com/rstudio/rstudio-mcp.git
cd rstudio-mcp
pip install -e .
Install Dependencies
pip install -r requirements.txt
Quick Start
1. Initialize Configuration
rstudio-mcp --init-config
This creates a default configuration file at ~/.rstudio-mcp/config.yaml.
2. Edit Configuration (Optional)
Edit the configuration file to customize settings:
nano ~/.rstudio-mcp/config.yaml
3. Run the Server
# Run with default configuration
rstudio-mcp
# Run with custom configuration
rstudio-mcp --config /path/to/config.yaml
# Run in debug mode
rstudio-mcp --debug
Configuration
The server uses YAML configuration files. Here's an example configuration:
# Server settings
name: "rstudio-mcp"
version: "1.0.0"
debug: false
# Logging configuration
logging:
level: "INFO"
file: "~/.rstudio-mcp/logs/server.log"
max_size: "10MB"
backup_count: 5
# RStudio configuration
rstudio:
installation_path: null # Auto-detect
default_r_version: "4.3.0"
# Environment management
environments:
default_location: "~/.rstudio-mcp/environments"
auto_cleanup: true
max_environments: 10
# Security settings
security:
allowed_packages:
- "base"
- "utils"
- "stats"
- "graphics"
blocked_functions:
- "system"
- "shell"
execution_timeout: 300
Integration with AI Coding Assistants
This MCP server is designed to work seamlessly with popular AI coding assistants in RStudio's terminal environment. The server supports the Model Context Protocol (MCP) specification and can be integrated with various AI clients.
Supported AI Clients
Based on the MCP client compatibility matrix, the following AI coding assistants support MCP integration:
- Claude Code - Supports prompts and tools
- VS Code GitHub Copilot - Full MCP support with dynamic tool discovery
- Continue - Supports tools, prompts, and resources
- Cursor - Supports tools via Composer
- Cline - Supports tools and resources
- JetBrains AI Assistant - Supports tools for all JetBrains IDEs
Configuration for AI Assistants
1. Claude Code Integration
Claude Code can connect to this MCP server to enhance R development workflows:
{
"mcpServers": {
"rstudio-mcp": {
"command": "rstudio-mcp",
"args": ["--config", "~/.rstudio-mcp/config.yaml"],
"env": {
"RSTUDIO_MCP_DEBUG": "false"
}
}
}
}
2. VS Code GitHub Copilot
Configure in VS Code settings or workspace settings:
{
"github.copilot.chat.mcp.servers": {
"rstudio-mcp": {
"command": "rstudio-mcp",
"args": ["--stdio"],
"env": {
"RSTUDIO_MCP_CONFIG": "~/.rstudio-mcp/config.yaml"
}
}
}
}
3. Continue Extension
Add to your Continue configuration (~/.continue/config.json):
{
"mcpServers": [
{
"name": "rstudio-mcp",
"command": "rstudio-mcp",
"args": ["--stdio"],
"env": {
"RSTUDIO_MCP_CONFIG": "~/.rstudio-mcp/config.yaml"
}
}
]
}
4. RStudio Terminal Integration
To use with AI assistants directly in RStudio's terminal:
-
Start the MCP server in the background:
# In RStudio Terminal rstudio-mcp --daemon --port 3000 -
Configure your AI assistant to connect via SSE:
# Server endpoint for SSE connections http://localhost:3000/sse -
Available tools in RStudio context:
create_environment- Create R environmentsexecute_r_code- Run R code with result capturecreate_project- Create RStudio projectsinstall_package- Manage R packagesget_project_info- Access project metadata
Environment Variables
Set these environment variables for optimal integration:
# RStudio MCP Configuration
export RSTUDIO_MCP_CONFIG="~/.rstudio-mcp/config.yaml"
export RSTUDIO_MCP_LOG_LEVEL="INFO"
export RSTUDIO_MCP_PORT="3000"
# R Environment
export R_HOME="/usr/local/lib/R"
export R_LIBS_USER="~/.rstudio-mcp/libraries"
Usage Examples
With Claude Code in RStudio Terminal
# Start MCP server
rstudio-mcp --daemon
# Claude Code can now:
# - Create R environments: "Create a new R environment for data analysis"
# - Execute R code: "Run this statistical analysis and show results"
# - Manage projects: "Set up a new RStudio project for machine learning"
With GitHub Copilot in VS Code
# In VS Code terminal connected to RStudio server
# Copilot can access:
# - R workspace objects via rstudio-workspace:// resources
# - Project files via rstudio-project:// resources
# - Environment info via rstudio-environment:// resources
# - Generated plots via rstudio-plot:// resources
Troubleshooting
-
Connection Issues:
# Check if MCP server is running rstudio-mcp --status # Test connection curl http://localhost:3000/health -
Permission Issues:
# Ensure proper permissions chmod +x $(which rstudio-mcp) chown -R $USER ~/.rstudio-mcp/ -
R Environment Issues:
# Verify R installation rstudio-mcp --check-r # Reset environments rstudio-mcp --reset-environments
MCP Tools
The server provides the following MCP tools:
Environment Management
create_environment: Create a new R environmentlist_environments: List all available environmentsswitch_environment: Switch to a different environmentdelete_environment: Delete an environment
Code Execution
execute_r_code: Execute R code in a specified environmentget_execution_history: Get history of executed code
Project Management
create_project: Create a new RStudio projectopen_project: Open an existing projectget_project_info: Get project information
Package Management
install_package: Install R packagesupdate_package: Update packageslist_packages: List installed packages
MCP Resources
The server exposes the following resources:
rstudio-project://: Access to project files and configurationrstudio-workspace://: Access to workspace objects and variablesrstudio-environment://: Access to environment informationrstudio-plot://: Access to generated plots and visualizations
MCP Prompts
Pre-built prompts for common R development tasks:
analyze_data: Data analysis guidancecreate_visualization: Visualization creation helpdebug_r_code: R code debugging assistanceoptimize_performance: Performance optimization suggestions
Development
Project Structure
rstudio-mcp/
├── src/rstudio_mcp/ # Main package
│ ├── __init__.py
│ ├── server.py # MCP server implementation
│ ├── config.py # Configuration management
│ ├── cli.py # Command-line interface
│ ├── exceptions.py # Exception classes
│ ├── logging_config.py # Logging setup
│ └── config/
│ └── default.yaml # Default configuration
├── tests/ # Test suite
├── docs/ # Documentation
├── pyproject.toml # Project configuration
└── README.md
Running Tests
# Run all tests
python -m pytest
# Run with coverage
python -m pytest --cov=src/rstudio_mcp
# Run specific test file
python -m pytest tests/test_server.py -v
Code Quality
# Format code
black src/ tests/
# Sort imports
isort src/ tests/
# Type checking
mypy src/
# Linting
flake8 src/ tests/
Architecture
The RStudio MCP Server follows a modular architecture:
- MCP Server Core: Handles MCP protocol communication
- Tool Manager: Manages available tools and their execution
- Resource Manager: Handles resource access and URI schemes
- Prompt Manager: Manages prompt templates
- RStudio API Wrapper: Interfaces with RStudio and R
- Configuration System: Manages server configuration
- Logging System: Handles logging and error reporting
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run the test suite
- Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
- Documentation: docs/
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Roadmap
- [x] Basic MCP server framework
- [ ] RStudio API integration
- [ ] Environment management tools
- [ ] Code execution capabilities
- [ ] Project management features
- [ ] Package management tools
- [ ] Version control integration
- [ ] Visualization handling
- [ ] Advanced security features
- [ ] Performance optimizations
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.