Stats & R MCP Server
by amul100
README.md
# Stats & R MCP Server
An MCP (Model Context Protocol) server that gives Claude access to a comprehensive statistics knowledge base and R library expertise for research projects.
## What It Does
When connected to Claude (via Claude Desktop, Claude Code, or the API), this server provides:
### Tools (14 tools Claude can call)
| Tool | Purpose |
|------|---------|
| `select_statistical_test` | Recommends the right test based on your study design |
| `get_test_details` | Deep-dive into any test — assumptions, R code, effect sizes |
| `list_all_tests` | Browse all 29 tests by category |
| `check_assumptions` | Step-by-step assumption checking with R code |
| `generate_analysis_script` | Complete R analysis script from study parameters |
| `power_analysis_guide` | Sample size / power calculations with R code |
| `effect_size_calculator` | Effect size formulas and R code |
| `convert_effect_sizes` | Convert between effect size metrics (d, r, η², f, OR) |
| `missing_data_guide` | Missing data diagnosis and imputation with R code |
| `multiple_comparisons_guide` | Correction methods (Bonferroni, Holm, Tukey, FDR) with R code |
| `mediation_analysis_guide` | Mediation, moderation, and moderated mediation with R code |
| `get_r_package_info` | Detailed info on 34 R packages |
| `recommend_r_packages` | Package recommendations by task |
| `list_r_packages` | Browse the full R package database |
### Resources (read-only knowledge bases)
- `stats://knowledge-base` — Decision table + all test details
- `stats://r-packages` — Complete R package reference
- `stats://sample-sizes` — Sample size rules of thumb
### Prompts (workflow templates)
- `research_analysis_workflow` — Full analysis pipeline from question to APA report
- `statistical_test_selection` — Interactive test selection guide
- `r_package_recommendation` — Package recommendations for a task
## Statistical Tests Covered
**Comparing Means:** t-tests (independent, paired, Welch's), ANOVA (one-way, two-way, repeated measures)
**Correlation:** Pearson, Spearman
**Categorical:** Chi-square, Fisher's exact
**Regression:** Linear, multiple, logistic, ordinal, Poisson
**Nonparametric:** Mann-Whitney U, Kruskal-Wallis, Friedman
**Mixed Models:** LMM (lmer), GLMM (glmer)
**Survival:** Cox regression, Kaplan-Meier, log-rank
**Multivariate:** PCA, Exploratory Factor Analysis
## R Packages Covered
tidyverse, ggplot2, dplyr, lme4, lmerTest, car, emmeans, performance, effectsize, survival, survminer, broom, psych, rstatix, pwr, report, brms, gt, gtsummary, mice, naniar, lavaan, mediation, interactions, and more (34 total)
## Setup
### Prerequisites
- Python 3.10+
- [uv](https://docs.astral.sh/uv/) (recommended) or pip
### Install
```bash
# Clone or copy the project
cd stats-r-mcp
# Using uv (recommended)
uv venv
source .venv/bin/activate # macOS/Linux
# .venv\Scripts\activate # Windows
uv pip install -e .
# Or using pip
pip install -e .
```
### Connect to Claude Desktop
Add this to your Claude Desktop config file:
**macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json`
**Windows:** `%APPDATA%\Claude\claude_desktop_config.json`
```json
{
"mcpServers": {
"stats-r-research": {
"command": "uv",
"args": [
"--directory", "/FULL/PATH/TO/stats-r-mcp",
"run", "server.py"
]
}
}
}
```
Replace `/FULL/PATH/TO/stats-r-mcp` with the actual path on your machine.
**Alternative (using python directly):**
```json
{
"mcpServers": {
"stats-r-research": {
"command": "/FULL/PATH/TO/stats-r-mcp/.venv/bin/python",
"args": ["/FULL/PATH/TO/stats-r-mcp/server.py"]
}
}
}
```
### Connect to Claude Code
```bash
claude mcp add stats-r-research -- uv --directory /FULL/PATH/TO/stats-r-mcp run server.py
```
### Test with MCP Inspector
```bash
cd stats-r-mcp
uv run mcp dev server.py
```
This opens a browser-based inspector where you can test all tools interactively.
## Example Usage
Once connected, you can ask Claude things like:
- *"I have pre and post scores for 45 patients across 3 treatment groups. What test should I use?"*
- *"Generate an R script for a mixed-design ANOVA with treatment as between-subjects and time as within-subjects"*
- *"What R packages do I need for survival analysis?"*
- *"How do I check the assumptions for a linear mixed model?"*
- *"I need to calculate sample size for a two-sample t-test with a medium effect size"*
- *"Walk me through a complete analysis for my RCT data"*
## Extending the Knowledge Base
The server is designed to be easily extended. To add new tests or packages, edit the `STATISTICAL_TESTS` or `R_PACKAGES_DB` dictionaries in `server.py`. Each entry follows a consistent schema so new additions integrate automatically with all tools.
## License
MIT
This server cannot be deployed
Maintenance
ActivityInactive
ResponsivenessNo recent community issues