SHAP MCP Server (shap-mcp)
A lightweight, focused Model Context Protocol (MCP) server that exposes SHAP (SHapley Additive exPlanations) model explainability as agent-callable tools.
Designed for AI assistants (like Claude Desktop) and human data scientists to collaborate seamlessly across a shared in-memory session.
Key Features
- Dual Simultaneous Transports: Standard
stdiotransport for Claude Desktop alongside a StarletteHTTPtransport on port8765serving the Web GUI and generated visualisations. - Unified In-Memory Session: Run analysis via the Web GUI and ask questions in Claude, or have Claude trigger analysis and view generated plots instantly in the GUI gallery.
- Universal Model Support:
tree: Exact TreeExplainer for XGBoost, LightGBM, CatBoost, RandomForest, ExtraTrees.linear: Fast closed-form LinearExplainer for Logistic Regression, Ridge, Lasso.deep: DeepExplainer for PyTorch neural networks.kernel: Model-agnostic KernelExplainer with automatic kmeans clustering.
- Publication-Ready Visualisations: Generate and save 6 plot types (
summary,bar,waterfall,force,dependence,heatmap) with pre-formatted clickable browser and local file links. - URL & File Ingestion: Ingest models and CSV datasets from local paths or public HTTP/HTTPS URLs with streaming downloads, automatic size caps (
SHAP_MCP_MAX_DOWNLOAD_MB), and temp-file cleanup. - Security: Optional API key authentication via
SHAP_MCP_API_KEYfor HTTP endpoints.
Installation
# Standard installation
pip install shap-mcp
# Optional extra for PyTorch DeepExplainer support
pip install shap-mcp[deep]
Claude Desktop Configuration
Add shap-mcp to your claude_desktop_config.json:
Universal Recommended Setup (via uvx)
{
"mcpServers": {
"shap-mcp": {
"command": "uvx",
"args": ["shap-mcp", "--no-ui"]
}
}
}
Direct Pip / Pipx Setup
{
"mcpServers": {
"shap-mcp": {
"command": "shap-mcp",
"args": ["--no-ui"]
}
}
}
Tool Reference
| Tool | Purpose | Key Inputs |
|---|---|---|
load_model |
Load .joblib/.pkl model and configure explainer |
model_path or model_url, model_type, background_path |
run_analysis |
Compute SHAP values over dataset | data_path or data_url or inline data, sample_size |
get_feature_importance |
Global ranking of top features | top_n (default 10) |
explain_prediction |
Local attribution breakdown for single instance | index or arbitrary data record |
get_interaction |
Pairwise feature interaction strength (Tree models) | feature_a, feature_b |
get_plot |
Render & save PNG visualisation with clickable URL | plot_type, index, feature_name, color_feature, top_n |
Runtime Configuration
All runtime configuration is managed via environment variables:
| Variable | Default | Description |
|---|---|---|
SHAP_MCP_PORT |
8765 |
HTTP server port (auto-increments if busy; --port flag overrides) |
SHAP_MCP_API_KEY |
(unset) | Bearer token for HTTP auth; unset = no auth required on localhost |
SHAP_MCP_OUTPUT_DIR |
./outputs/ |
Root directory for saving generated plot PNGs |
SHAP_MCP_MAX_DOWNLOAD_MB |
500 |
Maximum allowed size cap for URL-based model/dataset downloads |
SHAP_MCP_LOG_LEVEL |
INFO |
Structured JSON log level (DEBUG, INFO, WARNING, ERROR) |
Web GUI
When started directly via shap-mcp, the server automatically opens the Web GUI at http://localhost:8765/ui/:
- Configuration Form: Input local paths or URLs, pick model architecture, and run analysis.
- Real-Time Badges: Live model loaded status, rows analyzed count, and active explainer type.
- Dynamic Plot Gallery: Thumbnails appear automatically as Claude or the GUI generates visualisations.
- Instance Explainer: Interactive table of individual feature contributions.
Upcoming Features & Roadmap
The following capabilities are planned for upcoming releases:
save_analysis/load_analysis: Serialize computed SHAP values to.npzfiles to skip re-computation on reload and share results across teams.- Auth-Protected Remote Ingestion: Support for Hugging Face tokens, private S3/GCS buckets, and presigned URLs.
- Tabbed GUI & Progressive Disclosure: Redesign the Web GUI into clean, focused tabs with progressive unlocking as analysis completes.
- Interactive Visualisations: Pan, zoom, and tooltip hover support on matplotlib charts via
mpld3. - Plot-Specific Guided Prompts: Dedicated MCP prompts tailored for each of the 6 visualization types.
- Multi-Tenant Session Isolation: Connection-isolated session states for shared multi-user server deployments.
- Additional Model Formats: Native support for ONNX runtime, MLflow models, and Weights & Biases model registries.
- Fairness & Bias Disaggregation: Per-subgroup demographic parity and slice-based SHAP analysis.
- MCP Inline UI / Canvases: Direct inline rendering within supported MCP host clients.
License
MIT License. See LICENSE for details.
Metadata
Release files for shap-mcp 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| shap_mcp-0.1.0.tar.gz | 55.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| shap_mcp-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 101.2 kB
Release files / shap_mcp-0.1.0.tar.gz
| Download URL | shap_mcp-0.1.0.tar.gz |
|---|---|
| Size | 55.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b42e0772604861a65c8e915317ed79c9c5e10e1ba208def0d1fdcf32326c9bcd
|
|
BLAKE2b-256 checksum How to use checksums |
47e951f4efc79e98bc8c134dfba6a4b23fda8ff4f4feae606fc70ec873a1502a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.0
|
Release files / shap_mcp-0.1.0-py3-none-any.whl
| Download URL | shap_mcp-0.1.0-py3-none-any.whl |
|---|---|
| Size | 46.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a27bdb848fe97bf7d1601b248110a80ba2b79f423aebc9ff4a1000264ac05d7c
|
|
BLAKE2b-256 checksum How to use checksums |
3caf6bdf72dcbcd7ca9cfa6b654cf866ba2aa9dac3578089b39935763fae4503
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.0
|
Security for shap-mcp 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.