R MCP Server
Enables AI assistants to execute R code, create visualizations, analyze data, and manage packages through a local Rscript CLI.
README
R MCP Server
An MCP (Model Context Protocol) server that lets AI assistants execute R code, create visualizations, analyze data, and manage packages — all through a local Rscript CLI.
Features — 62 Tools
Execution (3 tools)
| Tool | Description |
|---|---|
evaluate_r_code |
Execute inline R code and return console output |
run_r_file |
Run an .R script file |
run_r_test_file |
Run testthat tests and report pass/fail |
Visualization (5 tools)
| Tool | Description |
|---|---|
create_r_plot |
Execute base R plotting code and save as PNG |
create_ggplot |
Create ggplot2 plots with auto-theme and save as PNG |
create_correlation_heatmap |
Generate a correlation heatmap from a data file |
create_multi_plot |
Arrange multiple ggplots into a multi-panel figure |
render_rmarkdown |
Render .Rmd files to HTML or PDF |
Statistical Analysis (5 tools)
| Tool | Description |
|---|---|
fit_linear_model |
Fit lm/glm and return coefficients, R-squared, p-values |
correlation_matrix |
Compute correlation matrix with p-values |
hypothesis_test |
Run t-test, Wilcoxon, chi-squared, Shapiro-Wilk, etc. |
descriptive_stats |
Per-column mean, sd, quartiles, skewness, kurtosis |
pca_analysis |
Principal Component Analysis with loadings and variance |
Data Wrangling (5 tools)
| Tool | Description |
|---|---|
read_data |
Read CSV, TSV, Excel, JSON, Parquet, or RDS files |
write_data |
Execute R code and save results to CSV/TSV/RDS/JSON |
reshape_data |
Pivot data between wide and long formats (tidyr) |
merge_datasets |
Join two data files (inner, left, right, full) |
generate_sample_data |
Load built-in R datasets (mtcars, iris, etc.) as CSV |
Time Series (4 tools)
| Tool | Description |
|---|---|
forecast_timeseries |
Fit ARIMA/ETS/TBATS/Holt-Winters and forecast with plot |
decompose_timeseries |
Decompose into trend, seasonal, and remainder (STL/classical) |
stationarity_test |
Unit root tests — ADF, KPSS, Phillips-Perron |
acf_pacf_plot |
Plot ACF and PACF side by side with significance bounds |
Clustering (2 tools)
| Tool | Description |
|---|---|
kmeans_clustering |
K-means with elbow plot, silhouette score, PCA projection |
hierarchical_clustering |
Hierarchical clustering with dendrogram and cophenetic correlation |
Advanced Statistics (7 tools)
| Tool | Description |
|---|---|
anova_test |
One-way and two-way ANOVA with post-hoc tests |
mixed_effects_model |
Fit linear mixed-effects models (lme4) |
bootstrap_ci |
Bootstrap confidence intervals for any statistic |
normality_tests |
Shapiro-Wilk, Anderson-Darling, Kolmogorov-Smirnov, Lilliefors |
outlier_detection |
Grubbs, Dixon, Rosner, IQR, and Z-score methods |
quantile_regression |
Fit quantile regression at specified quantiles |
survival_analysis |
Kaplan-Meier survival curves and Cox proportional hazards |
Interactive & Publication Plots (5 tools)
| Tool | Description |
|---|---|
create_plotly |
Create interactive plotly visualizations saved as HTML |
create_publication_plot |
Publication-ready plots using ggpubr |
create_corrplot |
Correlation matrix visualization (corrplot package) |
create_paired_comparison_plot |
Group comparisons with statistical significance |
create_diagnostic_plots |
Regression diagnostic plots (residuals, Q-Q, Cook's distance) |
Probability Distributions (5 tools)
| Tool | Description |
|---|---|
distribution_calculator |
Compute d/p/q/r for 16 distributions (normal, binomial, t, F, chi-sq, etc.) |
distribution_plot |
Histogram of random samples with theoretical density overlay |
random_sample |
Sample from any population with/without replacement |
qq_plot |
Q-Q plot to assess distributional fit with Shapiro-Wilk test |
simulate_clt |
Central Limit Theorem simulation for any distribution |
Proportion & Contingency Tests (5 tools)
| Tool | Description |
|---|---|
proportion_test |
One-sample and two-sample proportion tests (prop.test) |
binomial_test |
Exact binomial test for small samples |
chi_squared_test |
Chi-squared test for goodness of fit, independence, homogeneity |
fisher_test |
Fisher's exact test on 2x2 contingency tables |
contingency_table |
Create contingency table with mosaic plot and chi-squared test |
Regression & Post-hoc (6 tools)
| Tool | Description |
|---|---|
robust_regression |
Robust regression (MASS::rlm/lqs) resistant to outliers |
polynomial_regression |
Fit and compare polynomial models of different degrees |
predict_with_ci |
Predictions with confidence and prediction intervals |
tukey_hsd |
Tukey's HSD post-hoc pairwise comparisons after ANOVA |
kruskal_wallis_test |
Kruskal-Wallis nonparametric test for group differences |
power_analysis |
Compute sample size or power for t-test and proportion test |
Exploratory Data Analysis (5 tools)
| Tool | Description |
|---|---|
pairs_plot |
Scatterplot matrix with correlations and histograms |
density_plot |
Kernel density estimation plot with multiple kernels |
ecdf_plot |
Empirical CDF plot with optional normal overlay |
stem_and_leaf |
Text-based stem-and-leaf display with five-number summary |
variance_test |
F-test, Bartlett's, and Fligner-Killeen variance equality tests |
Utilities (5 tools)
| Tool | Description |
|---|---|
check_r_code |
Static analysis via lintr |
get_data_summary |
Load CSV/TSV/RDS and return summary stats |
detect_r_packages |
List all installed R packages |
get_r_version |
Return R version and session info |
install_r_package |
Install a CRAN package |
Prerequisites
- R (>= 4.0) with
Rscripton your PATH - Python (>= 3.10)
Install R from CRAN or via Homebrew:
brew install r
Installation
git clone https://github.com/sergiudanstan/r-mcp.git
cd r-mcp
pip install -e .
Usage
With Claude Code
Add to your Claude Code MCP settings (~/.claude/settings.json):
{
"mcpServers": {
"r": {
"command": "python",
"args": ["-m", "r_mcp"],
"cwd": "/path/to/r-mcp"
}
}
}
Standalone
python -m r_mcp
The server communicates over stdio using the MCP protocol.
How It Works
The server wraps the Rscript --vanilla CLI. Each tool call spawns a fresh R session, executes the code, and returns structured JSON results. Code is wrapped in tryCatch for clean error reporting.
- Workspace: Output files (plots, rendered docs) are saved to
~/r-mcp-workspace/ - Timeout: Default 60s per execution (configurable per call)
- Safety: Path traversal prevention on file outputs; output truncation at 50K chars
Examples
Run R code
# Via the evaluate_r_code tool
x <- rnorm(100)
cat("Mean:", mean(x), "\nSD:", sd(x), "\n")
Create a plot
# Via the create_r_plot tool
library(ggplot2)
df <- data.frame(x = rnorm(200), y = rnorm(200))
ggplot(df, aes(x, y)) + geom_point(alpha = 0.5) + theme_minimal()
Probability distributions
# Via the distribution_calculator tool
# Compute P(X <= 1.96) for standard normal
pnorm(1.96, mean=0, sd=1)
# Via the distribution_plot tool
# Visualize chi-squared(5) distribution with 1000 samples
Hypothesis testing
# Via the proportion_test tool
# Test if 42 out of 100 differs from 50%
prop.test(42, 100, p = 0.5)
# Via the hypothesis_test tool
# Two-sample t-test
t.test(x, y, alternative = "two.sided")
Analyze a CSV
Use get_data_summary with a file path to get dimensions, column types, summary statistics, and a preview.
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。