shap-mcp
Enables SHAP-based explainability for PyTorch neural networks using DeepExplainer, allowing SHAP values and visualizations to be computed for PyTorch models.
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.
Related MCP server: my-mcp-server2
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 |
|
| Compute SHAP values over dataset |
|
| Global ranking of top features |
|
| Local attribution breakdown for single instance |
|
| Pairwise feature interaction strength (Tree models) |
|
| Render & save PNG visualisation with clickable URL |
|
Runtime Configuration
All runtime configuration is managed via environment variables:
Variable | Default | Description |
|
| HTTP server port (auto-increments if busy; |
| (unset) | Bearer token for HTTP auth; unset = no auth required on localhost |
|
| Root directory for saving generated plot PNGs |
|
| Maximum allowed size cap for URL-based model/dataset downloads |
|
| Structured JSON log level ( |
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-UI Inline Canvas & Local Drag-and-Drop: Direct in-chat canvas rendering via the MCP-UI / MCP Apps specification with local drag-and-drop file ingestion, eliminating external browser tabs and cloud attachment friction.
License
MIT License. See LICENSE for details.
Available Tools
6 toolsexplain_predictionC
Return SHAP breakdown for a single instance.
Parameters
index : int | None Row index in the analyzed dataset. data : dict[str, Any] | None Inline feature dictionary for explaining an arbitrary instance.
Inputs: data, index. Returns: object
get_feature_importanceA
Return global feature importance from stored SHAP values.
Parameters
top_n : int Number of top features to return (default: 10).
Inputs: top_n. Returns: object
get_interactionB
Return SHAP interaction values between two features (Tree models only).
Parameters
feature_a : str Name of the first feature. feature_b : str Name of the second feature.
Inputs: feature_a (required), feature_b (required). Returns: object
get_plotA
Generate a SHAP visualization, save it as a PNG file, and return file path and URL.
Parameters
plot_type : str One of 'summary', 'bar', 'waterfall', 'force', 'dependence', 'heatmap'. index : int | None Row index in dataset (required for waterfall and force). feature_name : str | None Feature name (required for dependence). top_n : int Max features to show (default: 10). color_feature : str | None Feature to color by for dependence plots. output_path : str | None Override default output directory path.
Inputs: plot_type (required), index, top_n, output_path, +2 more. Returns: object
load_modelA
Load a model file and instantiate the appropriate SHAP explainer.
Note: Prompt the user to provide local filesystem paths on their machine, public URLs, or upload via http://localhost:8765/ui/. Files attached directly in chat are stored in a cloud container (/mnt/user-data/) that local tools cannot reach.
Parameters
model_path : str | None Path to a local .joblib or .pkl model file. model_url : str | None Public URL to download a model file. model_type : str One of 'tree', 'linear', 'deep', 'kernel'. Default is 'tree'. background_path : str | None Path to background CSV dataset (optional for tree/kernel, required for deep).
Inputs: model_url, model_path, model_type, background_path. Returns: object
run_analysisB
Run SHAP explainer against a dataset.
Note: Ask the user for local file paths, public URLs (data_url), or use the Web GUI at http://localhost:8765/ui/. For small CSVs (< 500 rows), you may read the table from chat and pass the rows directly in data.
Parameters
data_path : str | None Path to a local CSV file. data_url : str | None Public URL to download a CSV dataset file. data : list[dict] | None Inline dataset passed as a JSON array. sample_size : int | None Override default auto-cap for dataset row sampling.
Inputs: data, data_url, data_path, sample_size. Returns: object
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 6 tools
Each tool has a clearly distinct purpose: model loading, SHAP computation, global importance, local explanation, interaction values, and plotting. There is no overlap or ambiguity in what each tool does, so an agent can reliably select the correct one for a given task.
All tool names follow a consistent verb_noun pattern with lowercase and underscores (load_model, run_analysis, get_feature_importance, etc.). The verbs vary but are semantically appropriate, and the naming style is uniform across the set, making the API predictable.
Six tools provide a well-scoped surface for SHAP analysis. This is an appropriate size that covers the core workflow (load, analyze, query results, plot) without redundancy or unnecessary bloat. Each tool earns its place in the server.
The tool surface covers the full lifecycle of a SHAP analysis: loading a model, running the explainer, retrieving global and local explanations, getting interactions, and generating visualizations. There are no obvious gaps that would block an agent from completing typical analysis tasks.
Maintenance
Related MCP Connectors
Model Context Protocol server for the Apideck Unified API. Connect any MCP-compatible agent framework to 100+ accounting systems, HRIS platforms, file storage providers, and more through one integration. More information https://www.apideck.com/mcp-server
MCP server for your apps' tools and custom tools, plus hosted AI agents and approval-gated workflows
MCP server for building and testing AI agents with multi-model experimentation and insights.
MCP server for progressive tool usage at any scale (see https://klavis.ai)
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol (MCP) server that supports STDIO, SSE and Streamable HTTP protocols for AI model interactions.10 npm1MIT
- FlicenseNot gradedqualityDmaintenanceA Model Context Protocol server built with FastMCP that features dynamic tool loading and modular management via a dedicated tool directory. It supports both stdio and HTTP transport modes, enabling efficient development and deployment of custom MCP tools.-
- AlicenseNot gradedqualityDmaintenanceModel Context Protocol server that standardizes tool discovery, execution, and context management for AI applications.MIT
- AlicenseNot gradedqualityDmaintenanceA robust, lightweight Model Context Protocol (MCP) server designed to empower your AI Agents with context-awareness, safe execution sandboxes, and dedicated thought logs.ISC