A Model Context Protocol (MCP) server that provides statistical modeling and regression analysis capabilities to LLMs. Built with FastMCP, this server enables data loading, statistical modeling, diagnostics, and visualization through a simple, session-based interface.
- Multi-format data loading: CSV, Excel (.xlsx/.xls), JSON, Parquet, and SQLite databases
- Session-based workflow: Create isolated analysis sessions for different datasets
- Data description: Dataset overview with statistics and missing value analysis
- Linear Regression (OLS): Ordinary least squares regression with patsy formula syntax (
Y ~ X1 + X2 + X3) - Logistic Regression: Binary classification modeling
- Model comparison: Side-by-side comparison of multiple models with performance metrics
- Residual analysis: 4-panel diagnostic plots (residuals vs fitted, Q-Q plot, scale-location, leverage)
- Assumption testing: Jarque-Bera normality test and Breusch-Pagan homoscedasticity test
- Influence diagnostics: Cook's distance and leverage plots to identify outliers
- Multicollinearity detection: Variance Inflation Factor (VIF) analysis
- Partial dependence plots: Visualize feature effects on model predictions
To use this MCP server with common MCP clients, you need to add it to their configuration.
Here we describe how to add mcp-ols to Claude Desktop and VS Code, you can find how to configure MCP servers in other clients in their documentation.
It uses uvx to run the server, which requires uv installed.
Add to your Claude Desktop configuration file:
{
"mcpServers": {
"mcp-ols": {
"command": "uvx",
"args": ["mcp-ols"]
}
}
}For local development:
{
"mcpServers": {
"mcp-ols": {
"mcp-ols": {
"command": "uvx",
"args": ["--refresh", "--from", "/path/to/repo", "mcp-ols"]
}
}
}Add to your workspace settings (.vscode/settings.json):
{
"mcp": {
"servers": {
"mcp-ols": {
"command": "uvx",
"args": ["mcp-ols"]
}
}
}
}For local development:
{
"mcp": {
"servers": {
"mcp-ols": {
"command": "uvx",
"args": ["--refresh", "--from", "/path/to/repo", "mcp-ols"]
}
}
}
}The easiest way to run the MCP server separate from a client is also through uvx, which handles dependencies automatically:
uvx mcp-olsThis command will automatically download and run the server with all required dependencies in an isolated environment.
For development:
git clone https://github.com/mathpn/mcp-ols
cd mcp-ols
# Install with development dependencies
uv sync --group dev
# Run the server
uv run mcp_ols.py- Create a session
- Load your data from various formats
- Run statistical models using formula syntax
- Generate diagnostics and visualizations
- Compare models and analyze results
Creates a new isolated analysis session.
- Returns:
{"session_id": "1"}
Loads data into a session from various formats.
- Supported formats: CSV, Excel, JSON, Parquet, SQLite
- SQLite syntax:
sqlite:///path/to/db.sqlite/table_name
Returns dataset overview including data types, missing values, and summary statistics.
Performs linear regression using patsy formula syntax.
- Example:
"Sales ~ TV + Radio + Newspaper" - Returns: Model ID and HTML summary
Performs logistic regression for binary outcomes.
- Example:
"passed ~ hours_studied + practice_exams"
Generates 4-panel residual diagnostic plots.
Tests model assumptions (normality, homoscedasticity).
Creates Cook's distance and leverage plots.
Computes Variance Inflation Factors for multicollinearity detection.
Creates partial dependence plots showing feature effects.
Compares multiple models with performance metrics table.
Creates comprehensive model comparison visualizations.
Lists all fitted models in a session with key statistics.
import asyncio
from fastmcp import Client
from mcp_ols import mcp
async def example():
async with Client(mcp) as client:
# Create session
result = await client.call_tool("create_analysis_session", {})
session_id = result["session_id"]
# Load data
await client.call_tool("load_data", {
"session_id": session_id,
"file_path": "data.csv"
})
# Run regression
result = await client.call_tool("run_ols_regression", {
"session_id": session_id,
"formula": "Sales ~ TV + Radio"
})
model_id = result["model_id"]
# Generate diagnostics
await client.call_tool("create_residual_plots", {
"session_id": session_id,
"model_id": model_id
})mcp_ols.py: Main server implementation with all MCP toolstest_mcp_server.py: Test suitepyproject.toml: Project configuration and dependencies
uv run pytest
# Run specific test
uv run pytest test_mcp_server.py::test_ols_regression -v# Install development dependencies
uv sync --group dev
# Add new dependency
uv add <package>uv run fastmcp dev mcp_ols.pyThis launches MCP Inspector, a web-based interactive developer tool for testing and debugging MCP servers.
The server supports loading data from multiple file formats:
- CSV files (.csv) - with automatic dialect detection
- Excel files (.xlsx, .xls)
- JSON files (.json)
- Parquet files (.parquet)
- SQLite databases - using
sqlite:///path/to/db.sqlite/table_namesyntax
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run the test suite
- Commit your changes
- Open a Pull Request
This project is under the Apache-2.0 license.