Logo R-Server MCP

R-Server MCP

Cộng đồng
saidsurucu

MCP Server for Running R Language

Nhà phát hànhsaidsurucu
Kho mãrlang-mcp-python
Ngôn ngữPython
Bản fork
4
Sao
19
Công cụ có sẵn
0
Phương thức truyền tảistdio
Danh mục
Liên kết
  • Kết nối công cụ với quy trình làm việc AI

    R-Server MCP cung cấp các khả năng MCP mà ứng dụng khách và tác nhân AI tương thích có thể sử dụng.

  • 0 công cụ có sẵn

    Xem các thao tác có thể gọi bên dưới, kèm tên và mô tả nếu máy chủ cung cấp.

  • Cấu hình sẵn để sao chép

    Dùng các đoạn cấu hình cài đặt mẫu để thiết lập máy chủ này trong ứng dụng khách MCP bạn muốn dùng.

  • Chỉ số quan tâm đến mã nguồn mở

    19 sao và 4 bản fork từ kho mã được liên kết.

Python R-Server MCP

A secure, Docker-based Model Context Protocol (MCP) server for R data visualization and analysis, built with Python and FastMCP.

What is this? This tool allows you to perform statistical analysis in R through natural language conversations with LLM models like Claude. All R code is executed in secure Docker containers, ensuring complete isolation and security.

Key Benefits:

  • 🗣️ Natural Language Interface: Chat with AI to perform complex statistical analyses
  • 🐳 Secure Docker Execution: All R code runs in isolated containers with network disabled
  • 📊 Automatic R Execution: AI runs R code and returns results without you writing code
  • 📁 Multiple Directory Mounting: Mount multiple local directories for R to access
  • 📈 Inline Plot Capture: Plots automatically returned as base64 PNG images
  • 🔒 PII Protection: Optional auto-redaction of personal data before it reaches the LLM
  • 💾 Session Persistence: R variables persist between calls
  • ⚡ Smart Caching: Configurable result caching for instant repeated operations
  • 📦 Auto Library Detection: Missing R packages automatically installed

🌐 Türkçe | English

Overview

This project is inspired by gdbelvin's rlang-mcp-server but is a complete Python reimplementation using the FastMCP framework. While the original Go version provided basic R visualization tools, this Python version extends the functionality with comprehensive security, file management, and data privacy features.

Features

🎨 Visualization & Analysis

  • ggplot2 Rendering: Execute R code with ggplot2 commands and return publication-ready visualizations
  • Inline Plot Capture: Plots automatically detected and returned as base64 PNG
  • R Script Execution: Run any R script with smart file handling and return formatted output
  • Session Persistence: R variables and workspace persist between calls via .RData

📁 File Management

  • Multiple Directory Mounting: Mount multiple local directories with custom mount points
  • Smart File Discovery: Use R scripts to explore and analyze files in mounted directories
  • Unmount Support: Cleanly unmount directories when done

📦 Package Management

  • Auto Library Detection: library() and require() calls parsed, missing packages auto-installed
  • Package Installation: Install R packages on-demand with version control
  • Automatic Dependencies: Smart package dependency resolution
  • Temporary Network: Network temporarily enabled only during package installation

🛡️ Security & Isolation

  • Mandatory Docker: All R code execution in isolated containers
  • Network Disabled by Default: Container cannot access internet during R execution
  • Resource Limits: Configurable memory (default 2GB) and CPU limits
  • PII Redaction: Optional automatic detection and masking of personal data in R output
  • Temporary Network Only: Network enabled only for package installs, then disabled
  • Container Isolation: Complete process and filesystem isolation
  • Enhanced Error Messages: R errors include traceback and call context

🔒 PII Protection (Optional)

  • Regex Detection: TC Kimlik No, phone numbers, email, IBAN, credit cards, patient IDs
  • NER Name Detection: Person names detected via multilingual spaCy model
  • Medical Whitelist: Statistical and medical terms excluded from false positives
  • Fallback Support: Works with or without Presidio installed (regex fallback)
  • Zero Data Leakage: PII redacted before output reaches the LLM API

🚀 Performance & Experience

  • FastMCP Framework: Modern Python MCP implementation (v3.1.1+)
  • Smart Caching: Configurable in-memory caching (size + TTL via environment variables)
  • Persistent Containers: Reuses same container for all operations (no startup overhead)
  • Container Warm-up: Common R packages pre-loaded at container start
  • Pre-compiled Packages: Uses Docker images with pre-installed R packages

Quick Start

Prerequisites

  • Docker (mandatory - must be running)
  • Python 3.12+
  • uv (recommended) or pip

macOS

bash
brew install uv
brew install python@3.12
brew install --cask docker

Windows

powershell
pip install uv
# Install Python 3.12+ from https://www.python.org/downloads/windows/
# Install Docker Desktop from https://www.docker.com/products/docker-desktop

Linux (Ubuntu/Debian)

bash
sudo apt update
sudo apt install python3.12 python3.12-venv python3-pip docker.io
pip install uv
sudo systemctl start docker && sudo systemctl enable docker

Note: Local R installation is not required - all R execution happens inside Docker containers.

Installation

bash
# Method 1: Install directly from GitHub (recommended)
uvx --from git+https://github.com/saidsurucu/rlang-mcp-python rlang-mcp-python

# Method 2: Clone and install locally
git clone https://github.com/saidsurucu/rlang-mcp-python.git
cd rlang-mcp-python
uv sync

# Method 3: Install with pip
pip install git+https://github.com/saidsurucu/rlang-mcp-python

# Optional: Install PII protection
pip install 'rlang-mcp-server[privacy]'
uv pip install https://github.com/explosion/spacy-models/releases/download/xx_ent_wiki_sm-3.8.0/xx_ent_wiki_sm-3.8.0-py3-none-any.whl

Claude Desktop Integration

  1. Open Claude Desktop
  2. Go to Settings > Developer > Edit Config
  3. Add this configuration:
json
{
  "mcpServers": {
    "r-server-python": {
      "command": "uvx",
      "args": [
        "--from",
        "git+https://github.com/saidsurucu/rlang-mcp-python",
        "rlang-mcp-python"
      ]
    }
  }
}

With Environment Variables (Recommended for Sensitive Data)

json
{
  "mcpServers": {
    "r-server-python": {
      "command": "uvx",
      "args": [
        "--from",
        "git+https://github.com/saidsurucu/rlang-mcp-python",
        "rlang-mcp-python"
      ],
      "env": {
        "R_MCP_PII_ENABLED": "true",
        "R_MCP_NETWORK_DISABLED": "true",
        "R_MCP_MEM_LIMIT": "4g"
      }
    }
  }
}

Environment Variables

VariableDefaultDescription
R_MCP_MEM_LIMIT2gContainer memory limit
R_MCP_CPU_QUOTA200000CPU quota (100000 = 1 CPU)
R_MCP_CACHE_TTL3600Cache time-to-live in seconds
R_MCP_CACHE_SIZE100Maximum cached results
R_MCP_SESSIONtruePersist R variables between calls
R_MCP_NETWORK_DISABLEDtrueContainer network isolation
R_MCP_PII_ENABLEDfalsePII redaction on R output

Tools Available

This server provides 7 tools:

ToolDescriptionCategory
mount_directoryMount local directories (supports multiple, custom mount points)Directory
unmount_directoryUnmount directories (single or all)Directory
execute_r_scriptRun R code with plot capture, auto library detection, session persistence, PII redactionExecution
container_statusCheck health, resources, R version, session, cache statsMonitoring
initialize_r_containerStart container with resource limits and warm-upContainer
install_r_packageInstall packages on-demand (temp network enable)Packages
clear_sessionClear R workspace (remove persisted variables)Session

PII Protection

When working with sensitive data (healthcare, financial, personal), enable PII protection to automatically redact personally identifiable information from R output before it reaches the LLM.

How It Works

R code runs in Docker (local, network disabled)
    ↓
R output (stdout)
    ↓ R_MCP_PII_ENABLED=true
[Presidio Regex] → TC, phone, email, IBAN, credit card, patient ID
[spaCy NER]      → Person names (Ali Yılmaz, Mehmet Öz...)
[Whitelist]      → Filter false positives (medical/statistical terms)
    ↓
Sanitized output → LLM API (no PII leaves your machine)

What Gets Redacted

PII TypeExampleRedacted As
TC Kimlik No12345678901<TR_TC_KIMLIK>
Phone0532 456 7890<TR_PHONE>
Emailali@mail.com<EMAIL>
IBANTR33000610...<TR_IBAN>
Credit Card4532-1234-5678-9012<CREDIT_CARD>
Patient IDHasta No: 2024-15832<TR_HASTA_NO>
Person NameAli Yılmaz<PERSON>

What Passes Through (No False Positives)

  • mean=45.2, sd=12.3, n=150 — aggregate statistics
  • table(data$diagnosis) — frequency tables
  • HbA1c, Tip 2 Diyabet — medical terms
  • Min. 1st Qu. Median Mean — R output

Fallback Behavior

InstalledDetection
presidio + xx_ent_wiki_smFull: regex + name detection
presidio onlyRegex: TC, phone, email, IBAN, credit card
NeitherPure regex fallback (no extra dependencies)

Security Model

┌─────────────────────────────────────────────────┐
│                 Security Layers                  │
├─────────────────────────────────────────────────┤
│ 1. Docker Isolation    │ All R code in container │
│ 2. Network Disabled    │ No internet by default  │
│ 3. Resource Limits     │ Memory + CPU caps       │
│ 4. PII Redaction       │ Output sanitized        │
│ 5. Temp Network Only   │ Package installs only   │
└─────────────────────────────────────────────────┘

Usage Examples

Basic Analysis

"Mount my data directory at /Users/me/data and analyze the sales_data.xlsx file. Show summary statistics and monthly trends."

Visualization

"Create a publication-ready boxplot comparing revenue by quarter using my data."

Sensitive Data (with PII enabled)

"Load the patient data and show me aggregate statistics: mean age, diagnosis distribution, and HbA1c levels by treatment group."

R output is automatically sanitized — even if raw data is accidentally printed, personal information is redacted before reaching the AI.

Session Workflow

python
# Step 1: Load data (persists in session)
execute_r_script("data <- read_excel('/data/patients.xlsx')")

# Step 2: Analyze (data variable still available)
execute_r_script("summary(data)")

# Step 3: Visualize (still in session)
execute_r_script("ggplot(data, aes(x=age)) + geom_histogram()")

# Step 4: Clean up
clear_session()

Docker Support

Docker is mandatory for security. The server uses pre-built Docker images:

  1. semoss/docker-r-packages (primary — comprehensive R packages)
  2. rocker/tidyverse (fallback — data science packages)
  3. r-base (final fallback — minimal R)

Images are automatically pulled on first use. The container:

  • Runs with network disabled (re-enabled only for package installs)
  • Has memory and CPU limits enforced
  • Persists across all operations in the session
  • Is automatically cleaned up on server shutdown

Development

bash
# Install development dependencies
uv sync --dev

# Install PII protection for testing
uv pip install presidio-analyzer presidio-anonymizer spacy
uv pip install https://github.com/explosion/spacy-models/releases/download/xx_ent_wiki_sm-3.8.0/xx_ent_wiki_sm-3.8.0-py3-none-any.whl

# Run linting
uv run ruff check
uv run black --check .

Troubleshooting

Docker Issues

bash
# Ensure Docker is running
docker --version

# Start Docker (Linux)
sudo systemctl start docker

# macOS/Windows: Ensure Docker Desktop is running

PII Protection Issues

bash
# Check if presidio is installed
python -c "import presidio_analyzer; print('OK')"

# Install NER model for name detection
uv pip install https://github.com/explosion/spacy-models/releases/download/xx_ent_wiki_sm-3.8.0/xx_ent_wiki_sm-3.8.0-py3-none-any.whl

# Verify NER model works
python -c "import spacy; nlp = spacy.load('xx_ent_wiki_sm'); print('NER OK')"

Common Issues

  • First run slow: Normal — Docker image pull + container setup (~15-30s)
  • Package install fails: Network temporarily enabled, check Docker network
  • Container unresponsive: Restart the MCP server
  • PII not detected: Ensure R_MCP_PII_ENABLED=true is set

Comparison with Original

FeatureOriginal (Go)This Version (Python)
Core Tools27
Directory Mounting❌✅ (multiple)
Plot CaptureBasic✅ (auto base64 PNG)
Session Persistence❌✅ (.RData)
Auto Library Install❌✅
Network Isolation❌✅ (default)
PII Protection❌✅ (Presidio + NER)
Resource Limits❌✅ (memory + CPU)
Container Healthcheck❌✅
Modern Framework❌✅ (FastMCP 3.1+)

Contributing

Contributions are welcome! Please submit pull requests for any enhancements.

License

Creative Commons Attribution-NonCommercial 4.0 International (CC-BY-NC 4.0)

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.

Acknowledgments

Cài đặt

TypingMind
Yêu cầu:

Node.js 18+

{
  "mcpServers": {
    "saidsurucu-rlang-mcp-python": {
      "command": "npx",
      "args": [
        "-y",
        "rlang-mcp-server"
      ]
    }
  }
}

Dùng MCP R-Server MCP với nhiều mô hình AI

TypingMind kết nối các công cụ MCP ở cấp không gian làm việc, nên sau khi kết nối R-Server MCP, bạn có thể dùng với nhiều mô hình AI khác nhau trong TypingMind thay vì phải thiết lập riêng cho từng mô hình. MCP này chạy cục bộ thông qua trình kết nối MCP của TypingMind trên thiết bị của bạn.

Hướng dẫn thiết lập để dùng trình kết nối cục bộ

Dùng cách này khi máy chủ MCP cần truy cập các tệp, ứng dụng hoặc tài nguyên riêng tư trên máy tính của bạn.

1

Mở cài đặt MCP

Trong TypingMind, vào Cài đặt, Cài đặt nâng cao, rồi đến Giao thức ngữ cảnh mô hình và chọn Cài trình kết nối.

  1. Mở TypingMind trong trình duyệt của bạn.
  2. Nhấp vào biểu tượng Cài đặt.
  3. Vào Cài đặt nâng cao.
  4. Mở mục Giao thức ngữ cảnh mô hình.
  5. Nhấp vào Cài trình kết nối rồi chọn Thiết bị này.
Màn hình thiết lập trình kết nối MCP của TypingMind với tùy chọn Thiết bị này được chọn
2

Chạy lệnh trình kết nối

Chọn Thiết bị này, sao chép lệnh từ TypingMind và chạy trong Terminal. Giữ tiến trình chạy trong khi bạn dùng MCP.

  1. Sao chép lệnh thiết lập hiển thị trong TypingMind.
  2. Mở Terminal trên macOS hoặc Windows Terminal trên Windows.
  3. Dán và chạy lệnh.
  4. Xác nhận cài đặt gói nếu Terminal hỏi bạn có muốn tiếp tục không.
  5. Giữ tiến trình trong cửa sổ Terminal chạy trong khi dùng các công cụ MCP.
3

Thêm R-Server MCP làm máy chủ

Khi trạng thái trình kết nối là Sẵn sàng, nhấp vào Sửa máy chủ và dán cấu hình máy chủ MCP.

  1. Đợi đến khi trạng thái trình kết nối hiển thị Sẵn sàng.
  2. Nhấp vào Sửa máy chủ.
  3. Dán cấu hình máy chủ MCP của R-Server MCP.
  4. Lưu danh sách máy chủ.
  5. Làm mới nếu bạn muốn xác nhận trình kết nối vẫn sẵn sàng.
Cài đặt MCP của TypingMind hiển thị máy chủ đang hoạt động và nút Sửa máy chủ
{
  "mcpServers": {
    "saidsurucu-rlang-mcp-python": {
      "command": "npx",
      "args": [
        "-y",
        "rlang-mcp-server"
      ]
    }
  }
}
4

Dùng kết nối với nhiều mô hình

Lưu danh sách máy chủ, mở Plugin, bật các công cụ MCP của R-Server MCP, sau đó chọn bất kỳ mô hình AI nào được hỗ trợ trong TypingMind và dùng các công cụ trong cuộc trò chuyện hoặc gán chúng cho một tác nhân AI.

  1. Mở trang Plugin trong TypingMind.
  2. Bật các công cụ MCP của R-Server MCP.
  3. Bắt đầu cuộc trò chuyện và chọn mô hình AI bạn muốn dùng.
  4. Dùng các công cụ MCP trong cuộc trò chuyện hoặc gán chúng cho một tác nhân AI.
  5. Chuyển sang mô hình AI khác bất cứ khi nào cần mà không phải kết nối lại MCP.
Cuộc trò chuyện TypingMind dùng các công cụ MCP đã bật với một mô hình AI được chọn
Bạn có thể dùng R-Server MCP giúp tôi làm việc này không?
R-Server MCP
Được. Tôi đã đọc.
Đây là kết quả tôi tìm được bằng R-Server MCP.

Câu hỏi thường gặp

Máy chủ MCP R-Server MCP dùng để làm gì?

R-Server MCP là máy chủ MCP cho phép các ứng dụng AI tương thích kết nối với công cụ và ngữ cảnh bên ngoài. Trong TypingMind, bạn chỉ cần thêm máy chủ MCP này một lần để các công cụ của nó có sẵn trong không gian làm việc AI của bạn.

Bạn có thể dùng MCP R-Server MCP với nhiều mô hình AI trong TypingMind không?

Có. TypingMind kết nối các công cụ MCP ở cấp không gian làm việc, nên bạn có thể dùng R-Server MCP với nhiều mô hình AI như Claude, ChatGPT, Gemini hoặc các mô hình khác đã cấu hình trong TypingMind mà không cần thiết lập máy chủ MCP riêng cho từng mô hình.

Vì sao nên dùng MCP R-Server MCP với TypingMind?

TypingMind là một trong những giao diện trò chuyện với LLM tốt nhất vì tập hợp nhiều mô hình AI, prompt, plugin, tác nhân AI, khóa API và công cụ MCP vào một không gian làm việc. Khi kết nối R-Server MCP, bạn có thể dùng các công cụ MCP của dịch vụ này với những mô hình ưa thích, đồng thời giữ quy trình trò chuyện gọn gàng trong TypingMind.

Làm cách nào để kết nối MCP R-Server MCP với TypingMind?

R-Server MCP hoạt động thông qua trình kết nối MCP cục bộ của TypingMind. Đây là lựa chọn phù hợp nhất khi máy chủ MCP cần truy cập tệp cục bộ, ứng dụng máy tính, công cụ dòng lệnh hoặc tài nguyên riêng trên máy tính của bạn.

MCP R-Server MCP cung cấp những công cụ nào trong TypingMind?

R-Server MCP cung cấp các chức năng MCP mà bạn có thể bật từ trang Plugin của TypingMind để dùng trong trò chuyện hoặc gán cho tác nhân AI.

Bạn có cần chia sẻ khóa API với TypingMind để dùng MCP R-Server MCP không?

Không. TypingMind ưu tiên xử lý cục bộ và cho phép bạn kiểm soát nhà cung cấp mô hình, khóa API, prompt và cấu hình MCP. Nếu R-Server MCP yêu cầu xác thực, hãy thêm các header, cài đặt OAuth hoặc cấu hình cục bộ cần thiết cho máy chủ MCP đó khi tạo kết nối.

Máy chủ MCP liên quan

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇