r-stats-mcp
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@r-stats-mcpPerform a t-test on the built-in iris dataset comparing petal length between species."
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
r-stats-mcp
An MCP server that gives an LLM the whole of R's statistical toolkit — hypothesis tests, regression, psychometrics, survival analysis, time series and plots — over a persistent R session.
繁體中文說明請見 README.zh-TW.md。
What makes it different
One R session, kept alive. Load a dataset once and every later tool call sees it. Fitted models are saved back into that session under a name, so you can fit a model, diagnose it, compare it against another, and then run arbitrary R on it — all without re-reading the data.
Results written for a reader, not a parser. Tools return formatted markdown tables rather than raw JSON: p-values as <.001, effect sizes with magnitude labels, confidence intervals already assembled. When an assumption is violated the output says what to do about it — a significant Levene's test points you at Welch, sparse expected counts bring in Fisher's exact test automatically.
No dead ends. 28 structured tools cover the common ground, and r_run executes arbitrary R in the same session for everything else.
You: Load survey.csv and check whether the two groups differ on score.
data_load(path="survey.csv", name="df")
data_inspect(data="df")
data_transform(data="df", to_factor=["group"])
check_assumptions(data="df", variables=["score"], group="group")
test_ttest(data="df", y="score", group="group", nonparametric=true)Related MCP server: StatTools
Requirements
Version | Notes | |
R | ≥ 4.0 | Must be on |
Python | ≥ 3.12 | Managed by uv |
uv | any |
Required R packages: jsonlite and evaluate. Everything else is needed only by the tools that use it, and each tool tells you exactly what to install when something is missing.
install.packages(c("jsonlite", "evaluate"))For full coverage of every tool:
install.packages(c(
"ggplot2", "ragg", "corrplot", # plotting
"car", "emmeans", "rstatix", # ANOVA, post-hoc, VIF
"psych", "GPArotation", "lavaan", # scales, factor analysis, SEM
"lme4", "lmerTest", # mixed models
"survival", "forecast", "tseries", # survival, time series
"mgcv", "MASS", "nnet", # GAM, ordinal, multinomial
"haven", "readxl", "openxlsx", # SPSS/Stata/Excel
"sandwich", "lmtest" # robust standard errors
))Install
Claude Code
claude mcp add r-stats -- uvx --from git+https://github.com/Ian3738/r-stats-mcp r-stats-mcpClaude Desktop
Add to claude_desktop_config.json (macOS: ~/Library/Application Support/Claude/, Windows: %APPDATA%\Claude\):
{
"mcpServers": {
"r-stats": {
"command": "uvx",
"args": ["--from", "git+https://github.com/Ian3738/r-stats-mcp", "r-stats-mcp"]
}
}
}If the client cannot find uvx, give the absolute path (which uvx).
From a clone
git clone https://github.com/Ian3738/r-stats-mcp
cd r-stats-mcp
uv sync
claude mcp add r-stats -- "$(pwd)/run-server.sh"Configuration
Variable | Default | Purpose |
|
| Path to the R executable |
| Startup directory (home if | Where relative paths in |
|
| Default per-call timeout in seconds |
Verify the setup by asking the model to call r_session_info.
Tools
Session and code
Tool | Purpose |
| Execute arbitrary R code; returns console output and plots |
| Install packages from CRAN |
| R version, platform, which statistics packages are available |
Data
Tool | Purpose |
| CSV, TSV, Excel, SPSS, Stata, SAS, RDS, RData, JSON, Parquet |
| Datasets bundled with R or an installed package |
| Datasets and fitted models currently in the session |
| Types, missing counts, distinct counts, first rows |
| Filter, derive, recode, factor conversion, sort, long/wide reshape |
| Write out as CSV, TSV, Excel or RDS |
Descriptives and assumptions
Tool | Purpose |
| n, mean, SD, SE, CI, median, quartiles, skew, kurtosis — optionally by group |
| Frequency tables and cross-tabulations with row percentages |
| Normality, homogeneity of variance, outliers, VIF, residual diagnostics |
Hypothesis tests
Tool | Purpose |
| One-sample, independent and paired t-tests, with Levene, Cohen's d and rank-based equivalents |
| One-way, factorial, ANCOVA, repeated-measures and mixed designs, with effect sizes and post-hoc comparisons |
| Chi-square independence and goodness-of-fit, Fisher, McNemar, Cramér's V, odds ratios |
| One-sample and multi-group proportion tests, including the exact binomial |
| Pearson, Spearman, Kendall; partial correlations; multiple-comparison adjustment |
Regression and models
Tool | Purpose |
| Linear, logistic, Poisson, negative binomial, ordinal, multinomial, mixed-effects, GAM |
| Residual normality, heteroscedasticity, autocorrelation, VIF, influential cases |
| AIC, BIC, log-likelihood, ΔAIC, plus nested-model tests |
| Estimated marginal means, or predictions on new data |
Scales and questionnaires
Tool | Purpose |
| Cronbach's α, McDonald's ω, item-total correlations, α-if-dropped |
| EFA and PCA with KMO, Bartlett, parallel analysis, rotated loadings, scree plot |
| lavaan CFA / SEM / path / growth models with fit indices, CR and AVE |
| Bootstrap confidence intervals for indirect effects, multiple mediators supported |
| Interaction models with ΔR², simple slopes and an interaction plot |
Survival and time series
Tool | Purpose |
| Kaplan-Meier with log-rank, Cox regression with the proportional-hazards test |
| Stationarity tests, STL decomposition, automatic ARIMA/ETS, forecasts |
Plotting
Tool | Purpose |
| ggplot2 histogram, density, box, violin, scatter, line, bar, Q-Q, correlation heatmap |
Examples
Regression with model comparison
regression(data="df", dv="score", predictors=["age","sex","group"], save_as="full")
regression(data="df", dv="score", predictors=["age"], save_as="base")
model_compare(models=["base","full"])
model_diagnostics(model="full")Scale validation
reliability(data="df", items=["q1",...,"q10"], reverse=["q3","q7"], scale_max=5)
factor_analysis(data="df", variables=["q1",...,"q10"])
sem(data="df", type="cfa", model="anxiety =~ q1 + q2 + q3\ndepression =~ q4 + q5 + q6")Repeated measures
data_transform(data="df", reshape={
"direction": "long", "value_cols": ["t1","t2","t3"],
"id_cols": ["id"], "names_to": "time", "values_to": "score"
})
test_anova(data="df", dv="score", within=["time"], id="id", posthoc="bonferroni")Survival
survival_analysis(data="df", time="days", event="died", group="treatment",
type="km", times_of_interest=[180, 365])
survival_analysis(data="df", time="days", event="died",
covariates=["age","sex","stage"], type="cox")How it works
MCP client ──stdio/JSON-RPC──▶ Python server ──NDJSON over pipes──▶ Rscript worker
(tool schemas) (.GlobalEnv)Transport. A long-lived Rscript process reads newline-delimited JSON requests and writes sentinel-delimited JSON responses. Plots are captured with the evaluate package — the same machinery knitr uses — so base graphics, ggplot2 and lattice all work, and are returned as inline PNGs.
Namespace hygiene. User objects live in .GlobalEnv; the server's own machinery lives in a separate .rmcp_sys environment. data_list and r_run therefore see only your data and models.
Timeouts. Two layers: R enforces its own limit with setTimeLimit(), and Python applies a hard timeout on the pipe. If the session has to be restarted, the tool says so explicitly rather than silently losing your data.
Failure messages are actionable. Passing a three-level factor to a t-test does not produce a stack trace — it tells you the levels it found and points you at test_anova.
Development
uv sync
uv run python -c "
import asyncio
from r_stats_mcp.server import server
print(len(asyncio.run(server.list_tools())), 'tools')
"Adding a statistical tool means two edits: an R helper in src/r_stats_mcp/R/ returning list(md=, plots=), and a decorated function in server.py describing its parameters. The R files are sourced in filename order at worker startup.
src/r_stats_mcp/
├── server.py MCP tool definitions and schemas
├── session.py persistent R subprocess, transport, timeouts
└── R/
├── worker.R protocol loop, plot capture
├── 00-util.R markdown tables, formatting, session objects
├── 10-data.R loading, inspection, reshaping
├── 20-descriptive.R descriptives, frequencies, assumptions
├── 30-htest.R t-tests, ANOVA, categorical, correlation
├── 40-regression.R regression family, diagnostics, comparison
├── 50-psychometrics.R reliability, factor analysis, SEM, mediation
├── 60-survival-ts.R survival analysis, time series
└── 70-viz.R ggplot2 chartsLicense
MIT — see LICENSE.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/Ian3738/r-stats-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server