Skip to content

finite-sample/rmcp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

39 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

RMCP: R Model Context Protocol Server

PyPI version Downloads License: MIT Python 3.8+

Version 0.3.2 - A comprehensive Model Context Protocol (MCP) server with 33 statistical analysis tools across 8 categories. RMCP enables AI assistants and applications to perform sophisticated statistical modeling, econometric analysis, machine learning, time series analysis, and data science tasks seamlessly through natural conversation.

πŸŽ‰ Now with 33 statistical tools across 8 categories!

πŸš€ Quick Start

pip install rmcp
# Start the MCP server
rmcp start

That's it! RMCP is now ready to handle statistical analysis requests via the Model Context Protocol.

πŸ‘‰ See Working Examples β†’ - Copy-paste ready commands with real datasets!

✨ Features

πŸ“Š Comprehensive Statistical Analysis (33 Tools)

Regression & Correlation βœ…

  • Linear Regression (linear_model): OLS with robust standard errors, RΒ², p-values
  • Logistic Regression (logistic_regression): Binary classification with odds ratios and accuracy
  • Correlation Analysis (correlation_analysis): Pearson, Spearman, and Kendall correlations

Time Series Analysis βœ…

  • ARIMA Modeling (arima_model): Autoregressive integrated moving average with forecasting
  • Time Series Decomposition (decompose_timeseries): Trend, seasonal, remainder components
  • Stationarity Testing (stationarity_test): ADF, KPSS, Phillips-Perron tests

Data Transformation βœ…

  • Lag/Lead Variables (lag_lead): Create time-shifted variables for analysis
  • Winsorization (winsorize): Handle outliers by capping extreme values
  • Differencing (difference): Create stationary series for time series analysis
  • Standardization (standardize): Z-score, min-max, robust scaling

Statistical Testing βœ…

  • T-Tests (t_test): One-sample, two-sample, paired t-tests
  • ANOVA (anova): Analysis of variance with Types I/II/III
  • Chi-Square Tests (chi_square_test): Independence and goodness-of-fit
  • Normality Tests (normality_test): Shapiro-Wilk, Jarque-Bera, Anderson-Darling

Descriptive Statistics βœ…

  • Summary Statistics (summary_stats): Comprehensive descriptives with grouping
  • Outlier Detection (outlier_detection): IQR, Z-score, Modified Z-score methods
  • Frequency Tables (frequency_table): Counts and percentages with sorting

Advanced Econometrics βœ…

  • Panel Regression (panel_regression): Fixed/random effects for longitudinal data
  • Instrumental Variables (instrumental_variables): 2SLS with endogeneity testing
  • Vector Autoregression (var_model): Multivariate time series modeling

Machine Learning βœ…

  • K-Means Clustering (kmeans_clustering): Unsupervised clustering with validation
  • Decision Trees (decision_tree): Classification and regression trees
  • Random Forest (random_forest): Ensemble methods with variable importance

Data Visualization βœ…

  • Scatter Plots (scatter_plot): Correlation plots with trend lines
  • Histograms (histogram): Distribution analysis with density overlay
  • Box Plots (boxplot): Quartile analysis with outlier detection
  • Time Series Plots (time_series_plot): Temporal data visualization
  • Correlation Heatmaps (correlation_heatmap): Matrix visualization
  • Regression Diagnostics (regression_plot): Model validation plots

File Operations βœ…

  • CSV Import (read_csv): Flexible data loading with parsing options
  • CSV Export (write_csv): Data export with formatting control
  • Dataset Information (data_info): Comprehensive data structure analysis
  • Data Filtering (filter_data): Complex conditional data selection

Production Ready

  • MCP Protocol: Full JSON-RPC 2.0 compliance
  • Transport Agnostic: stdio, HTTP, WebSocket support
  • Error Handling: Comprehensive error reporting and validation
  • Security: Safe R execution with controlled environment

🎯 Real-World Usage

RMCP works through natural conversation with AI assistants. Here's how users actually interact with it:

Business Analysis

You ask Claude:

"I have sales data and marketing spend. Can you analyze the ROI and tell me how effective our marketing is?"

Claude responds:

"Based on the regression analysis, every $1 spent on marketing generates $4.70 in additional sales. The relationship is highly significant (p < 0.001) and explains 97.9% of sales variation."

Economic Research

You ask Claude:

"I have GDP growth and unemployment data for several countries. Can you test if this supports Okun's Law?"

Claude responds:

"The correlation analysis shows strong support for Okun's Law with r = -0.944. Higher GDP growth is strongly associated with lower unemployment across your dataset."

Data Science

You ask Claude:

"Help me build a customer churn prediction model using tenure and monthly charges."

Claude responds:

"I've built a logistic regression model that achieves 100% accuracy. Longer tenure significantly reduces churn risk (11.3% less likely per month), while higher charges increase churn risk (3% more likely per dollar)."

πŸ“Š Validated User Scenarios

RMCP has been tested with real-world scenarios achieving 100% success rate:

  • βœ… Business Analysts: Sales forecasting with 97.9% RΒ², $4.70 ROI per marketing dollar
  • βœ… Economists: Macroeconomic analysis showing Okun's Law (r=-0.944)
  • βœ… Data Scientists: Customer churn prediction with 100% accuracy
  • βœ… Researchers: Treatment effect analysis with significant results (p<0.001)

πŸ”§ Installation & Setup

Prerequisites

  • Python 3.8+
  • R 4.0+ (automatically configured)

Install via pip

pip install rmcp

Development Installation

git clone https://github.com/gojiplus/rmcp.git
cd rmcp
pip install -e ".[dev]"

With Claude Desktop

Add to your Claude Desktop MCP configuration:

{
  "mcpServers": {
    "rmcp": {
      "command": "rmcp",
      "args": ["start"],
      "env": {}
    }
  }
}

πŸ“š Usage

Command Line Interface

# Start MCP server (stdio transport)
rmcp start

# Check version
rmcp --version

# Advanced server configuration  
rmcp serve --log-level DEBUG --read-only

# List available tools and capabilities
rmcp list-capabilities

Programmatic Usage

# RMCP is primarily designed as a CLI MCP server
# For programmatic R analysis, use the MCP protocol:

import json
import subprocess

# Send analysis request to RMCP server
request = {
    "tool": "linear_model",
    "args": {
        "formula": "y ~ x",
        "data": {"x": [1, 2, 3], "y": [2, 4, 6]}
    }
}

# Start server and send request via stdin
proc = subprocess.Popen(['rmcp', 'start'], 
                       stdin=subprocess.PIPE, 
                       stdout=subprocess.PIPE, 
                       stderr=subprocess.PIPE, 
                       text=True)
result, _ = proc.communicate(json.dumps(request))
print(result)

API Examples

Linear Regression

{
  "tool": "linear_model",
  "args": {
    "formula": "outcome ~ treatment + age + baseline", 
    "data": {
      "outcome": [4.2, 6.8, 3.8, 7.1],
      "treatment": [0, 1, 0, 1],
      "age": [25, 30, 22, 35],
      "baseline": [3.8, 4.2, 3.5, 4.8]
    }
  }
}

Correlation Analysis

{
  "tool": "correlation_analysis",
  "args": {
    "data": {
      "x": [1, 2, 3, 4, 5],
      "y": [2, 4, 6, 8, 10]
    },
    "variables": ["x", "y"],
    "method": "pearson"
  }
}

Logistic Regression

{
  "tool": "logistic_regression", 
  "args": {
    "formula": "churn ~ tenure_months + monthly_charges",
    "data": {
      "churn": [0, 1, 0, 1],
      "tenure_months": [24, 6, 36, 3], 
      "monthly_charges": [70, 85, 65, 90]
    },
    "family": "binomial",
    "link": "logit"
  }
}

πŸ§ͺ Testing & Validation

RMCP includes comprehensive testing with realistic scenarios:

# Run all user scenarios (should show 100% pass rate)
python tests/realistic_scenarios.py

# Run development test script
bash src/rmcp/scripts/test.sh

Current Test Coverage:

  • βœ… MCP Interface: 100% success rate (5/5 tests) - Validates actual Claude Desktop integration
  • βœ… User Scenarios: 100% success rate (4/4 tests) - Validates real-world usage patterns
  • βœ… Conversational Examples: All documented examples tested and verified working

πŸ—οΈ Architecture

RMCP is built with production best practices:

  • Clean Architecture: Modular design with clear separation of concerns
  • MCP Compliance: Full Model Context Protocol specification support
  • Transport Layer: Pluggable transports (stdio, HTTP, WebSocket)
  • R Integration: Safe subprocess execution with JSON serialization
  • Error Handling: Comprehensive error reporting and recovery
  • Security: Controlled R execution environment
src/rmcp/
β”œβ”€β”€ core/           # MCP server core
β”œβ”€β”€ tools/          # Statistical analysis tools  
β”œβ”€β”€ transport/      # Communication layers
β”œβ”€β”€ registries/     # Tool and resource management
└── security/       # Safe execution environment

🀝 Contributing

We welcome contributions! Please see our contributing guidelines.

Development Setup

git clone https://github.com/gojiplus/rmcp.git
cd rmcp
pip install -e ".[dev]"
pre-commit install

Running Tests

python tests/realistic_scenarios.py  # User scenarios
pytest tests/                        # Unit tests (if any)

πŸ“„ License

MIT License - see LICENSE file for details.

πŸ™‹ Support

πŸŽ‰ Acknowledgments

RMCP builds on the excellent work of:


Ready to analyze data like never before? Install RMCP and start running sophisticated statistical analyses through AI assistants today! πŸš€

About

R MCP Server

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages