Skip to content

BitingSnakes/statsmodels-mcp

Repository files navigation

statsmodels-mcp

statsmodels-mcp is an MCP server for people writing code with statsmodels. It helps an MCP client choose an estimator, generate starter formulas and code, suggest diagnostics and post-estimation checks, and search the bundled statsmodels docs with a local BM25 index.

Features

  • Recommend statsmodels estimators from task characteristics.
  • Profile row-oriented sample data and infer likely estimator families.
  • Inspect supported model families and compare nearby alternatives.
  • Generate Patsy formulas for formula-capable models.
  • Generate runnable starter code and fit templates for common statsmodels workflows.
  • Rewrite model code and append diagnostics blocks.
  • Suggest covariance strategies for heteroskedastic, autocorrelated, or clustered settings.
  • Debug fitting failures and explain pasted summary output.
  • Suggest diagnostics, robustness checks, and post-estimation analyses.
  • Search the vendored docs/*.rst corpus locally with bm25s and extract doc examples.
  • Expose MCP tools, resources, prompts, plus HTTP health/readiness routes.

Tools

  • list_model_families
  • recommend_models
  • get_model_details
  • profile_dataframe
  • infer_model_from_dataframe
  • generate_formula_template
  • generate_code_example
  • fit_model_template
  • debug_fit_failure
  • explain_summary_table
  • add_diagnostics_to_code
  • rewrite_model_code
  • suggest_covariance_strategy
  • suggest_diagnostics
  • suggest_post_estimation
  • compare_models
  • search_docs
  • extract_doc_examples
  • read_doc_page
  • get_docs_for_model
  • list_statsmodels_apis

Resources

  • statsmodels://server/capabilities
  • statsmodels://project/settings
  • statsmodels://models/catalog
  • statsmodels://docs/manifest
  • statsmodels://docs/{doc_path}
  • statsmodels://reference/overview

Prompts

  • choose statsmodels model
  • generate statsmodels workflow
  • debug model fit
  • interpret regression results

Run

Install dependencies:

uv sync

Run over stdio:

uv run python mcp_server.py --transport stdio

Run over HTTP:

uv run python mcp_server.py --transport http --host 127.0.0.1 --port 8000

Health endpoints:

  • GET /healthz
  • GET /readyz

Configuration

Important environment variables:

  • STATSMODELS_MCP_DOCS_DIR
  • STATSMODELS_MCP_DOCS_TOP_K
  • STATSMODELS_MCP_TRANSPORT
  • STATSMODELS_MCP_HOST
  • STATSMODELS_MCP_PORT
  • STATSMODELS_MCP_HTTP_HEALTH_PATH
  • STATSMODELS_MCP_HTTP_READY_PATH

Example:

STATSMODELS_MCP_DOCS_DIR=./docs \
STATSMODELS_MCP_DOCS_TOP_K=8 \
uv run python mcp_server.py --transport stdio

Testing

just test

About

A full-featured MCP for statsmodels

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages