MCP server to add linear regression capabilities to LLMs.
Project description
MCP-OLS: Statistical Analysis Server
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.
Features
Data Management
- 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
Statistical Modeling
- 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
Model Diagnostics
- 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
Installation & Usage
MCP Client Configuration
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.
Claude Desktop
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"]
}
}
}
VS Code
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"]
}
}
}
}
Running with uvx (Recommended)
The easiest way to run the MCP server separate from a client is also through uvx, which handles dependencies automatically:
uvx mcp-ols
This command will automatically download and run the server with all required dependencies in an isolated environment.
Full Installation for Development
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
Basic Usage Workflow
- Create a session
- Load your data from various formats
- Run statistical models using formula syntax
- Generate diagnostics and visualizations
- Compare models and analyze results
API Reference
Core Tools
create_analysis_session()
Creates a new isolated analysis session.
- Returns:
{"session_id": "1"}
load_data(session_id: str, file_path: str)
Loads data into a session from various formats.
- Supported formats: CSV, Excel, JSON, Parquet, SQLite
- SQLite syntax:
sqlite:///path/to/db.sqlite/table_name
describe_data(session_id: str)
Returns dataset overview including data types, missing values, and summary statistics.
Statistical Modeling
run_ols_regression(session_id: str, formula: str)
Performs linear regression using patsy formula syntax.
- Example:
"Sales ~ TV + Radio + Newspaper" - Returns: Model ID and HTML summary
run_logistic_regression(session_id: str, formula: str)
Performs logistic regression for binary outcomes.
- Example:
"passed ~ hours_studied + practice_exams"
Model Diagnostics
create_residual_plots(session_id: str, model_id: str)
Generates 4-panel residual diagnostic plots.
model_assumptions_test(session_id: str, model_id: str)
Tests model assumptions (normality, homoscedasticity).
influence_diagnostics(session_id: str, model_id: str)
Creates Cook's distance and leverage plots.
vif_table(session_id: str, model_id: str)
Computes Variance Inflation Factors for multicollinearity detection.
Advanced Analysis
create_partial_dependence_plot(session_id: str, model_id: str, feature: str)
Creates partial dependence plots showing feature effects.
compare_models(session_id: str, model_ids: List[str])
Compares multiple models with performance metrics table.
visualize_model_comparison(session_id: str, model_ids: list[str])
Creates comprehensive model comparison visualizations.
list_models(session_id: str)
Lists all fitted models in a session with key statistics.
Example Client Usage
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
})
Development
Project Structure
mcp_ols.py: Main server implementation with all MCP toolstest_mcp_server.py: Test suitepyproject.toml: Project configuration and dependencies
Running Tests
uv run pytest
# Run specific test
uv run pytest test_mcp_server.py::test_ols_regression -v
Development Commands
# Install development dependencies
uv sync --group dev
# Add new dependency
uv add <package>
Debugging with MCP Inspector
uv run fastmcp dev mcp_ols.py
This launches MCP Inspector, a web-based interactive developer tool for testing and debugging MCP servers.
Supported Data Formats
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
Contributing
- 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
License
This project is under the Apache-2.0 license.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcp_ols-0.2.2.tar.gz.
File metadata
- Download URL: mcp_ols-0.2.2.tar.gz
- Upload date:
- Size: 85.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
159fc9d73850465b88f1cff69863e38fdfe8919aa5d43461e09edf7fc85e640d
|
|
| MD5 |
6a302dbb4acc0049ebf07e93376eedb1
|
|
| BLAKE2b-256 |
60f072f2e0a2db4e497a6087ec916778deaf6d976ad8a9aee98346911fa556f2
|
Provenance
The following attestation bundles were made for mcp_ols-0.2.2.tar.gz:
Publisher:
publish.yml on mathpn/mcp-ols
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mcp_ols-0.2.2.tar.gz -
Subject digest:
159fc9d73850465b88f1cff69863e38fdfe8919aa5d43461e09edf7fc85e640d - Sigstore transparency entry: 303583594
- Sigstore integration time:
-
Permalink:
mathpn/mcp-ols@879efcf8e125d23a3a7df94c180f9623dc47ca19 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/mathpn
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@879efcf8e125d23a3a7df94c180f9623dc47ca19 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file mcp_ols-0.2.2-py3-none-any.whl.
File metadata
- Download URL: mcp_ols-0.2.2-py3-none-any.whl
- Upload date:
- Size: 13.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d8d8962d0f338940e1101bd349474a434fbaec4b7e935f8a3f976f7c85870228
|
|
| MD5 |
8341403ca11d583c4d2a750f2b1d0d4b
|
|
| BLAKE2b-256 |
dce8560605860c88cd5c0ff3e94c015e400e59a40ee6e5962fc696302c833ffe
|
Provenance
The following attestation bundles were made for mcp_ols-0.2.2-py3-none-any.whl:
Publisher:
publish.yml on mathpn/mcp-ols
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mcp_ols-0.2.2-py3-none-any.whl -
Subject digest:
d8d8962d0f338940e1101bd349474a434fbaec4b7e935f8a3f976f7c85870228 - Sigstore transparency entry: 303583620
- Sigstore integration time:
-
Permalink:
mathpn/mcp-ols@879efcf8e125d23a3a7df94c180f9623dc47ca19 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/mathpn
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@879efcf8e125d23a3a7df94c180f9623dc47ca19 -
Trigger Event:
workflow_dispatch
-
Statement type: