RStudio MCP Server

RStudio MCP Server

Enables AI assistants to deeply integrate with RStudio for environment management, code execution, project management, and package management.

Category
访问服务器

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:

  1. Start the MCP server in the background:

    # In RStudio Terminal
    rstudio-mcp --daemon --port 3000
    
  2. Configure your AI assistant to connect via SSE:

    # Server endpoint for SSE connections
    http://localhost:3000/sse
    
  3. Available tools in RStudio context:

    • create_environment - Create R environments
    • execute_r_code - Run R code with result capture
    • create_project - Create RStudio projects
    • install_package - Manage R packages
    • get_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

  1. Connection Issues:

    # Check if MCP server is running
    rstudio-mcp --status
    
    # Test connection
    curl http://localhost:3000/health
    
  2. Permission Issues:

    # Ensure proper permissions
    chmod +x $(which rstudio-mcp)
    chown -R $USER ~/.rstudio-mcp/
    
  3. 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 environment
  • list_environments: List all available environments
  • switch_environment: Switch to a different environment
  • delete_environment: Delete an environment

Code Execution

  • execute_r_code: Execute R code in a specified environment
  • get_execution_history: Get history of executed code

Project Management

  • create_project: Create a new RStudio project
  • open_project: Open an existing project
  • get_project_info: Get project information

Package Management

  • install_package: Install R packages
  • update_package: Update packages
  • list_packages: List installed packages

MCP Resources

The server exposes the following resources:

  • rstudio-project://: Access to project files and configuration
  • rstudio-workspace://: Access to workspace objects and variables
  • rstudio-environment://: Access to environment information
  • rstudio-plot://: Access to generated plots and visualizations

MCP Prompts

Pre-built prompts for common R development tasks:

  • analyze_data: Data analysis guidance
  • create_visualization: Visualization creation help
  • debug_r_code: R code debugging assistance
  • optimize_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:

  1. MCP Server Core: Handles MCP protocol communication
  2. Tool Manager: Manages available tools and their execution
  3. Resource Manager: Handles resource access and URI schemes
  4. Prompt Manager: Manages prompt templates
  5. RStudio API Wrapper: Interfaces with RStudio and R
  6. Configuration System: Manages server configuration
  7. Logging System: Handles logging and error reporting

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Run the test suite
  6. Submit a pull request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

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

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选