loading…
Search for a command to run...
loading…
ModelSafetyMCP is an MCP server for scanning machine learning model artifacts for unsafe serialization, malicious model patterns, risky packaging, URL-based art
ModelSafetyMCP is an MCP server for scanning machine learning model artifacts for unsafe serialization, malicious model patterns, risky packaging, URL-based artifact scanning, and directory-level triage.
Malicious or unsafe ML artifacts are a real supply-chain problem. There have already been real cases of malicious or suspicious models being discovered in the wild, including models hosted on public platforms and larger batches of unsafe AI/ML artifacts. See RL identifies malware ML model hosted on Hugging Face and Over 100 Malicious AI/ML Models Found on Hugging Face.
One of the biggest reasons this matters is deserialization risk. Many model formats, especially pickle-based and framework-specific formats, can execute code or invoke unsafe logic while being loaded or reconstructed. That means a model file can become an execution vector, not just a passive blob of weights.
model-safety is an MCP server for inspecting machine learning model artifacts before you load, ship, or trust them.
It is designed for practical triage:
The server currently exposes these tools:
available_scanners
Shows which scanner backends are installed and ready.artifact_safety_report
Runs the broadest scan available on one model artifact and returns per-scanner results, normalized findings, highest severity, and recommended actions.modelscan_scan
Runs ModelScan directly against a local file or URL.picklescan_scan
Runs PickleScan directly against a local file or URL.deep_model_inspect
Runs lightweight structural checks for risky extensions, embedded pickle members, and suspicious packaging patterns.scan_directory
Runs artifact_safety_report across every file in a directory and aggregates the risky files.artifact_safety_report on a local file or direct URL.normalized_findings, highest_severity, and recommended_actions.scan_directory when you need to triage a whole model drop.Minimal Cursor config:
{
"mcpServers": {
"model-safety": {
"type": "stdio",
"command": "C:/Users/Lenovo/Documents/ModelSafetyMCP/python312/python.exe",
"args": ["C:/Users/Lenovo/Documents/ModelSafetyMCP/run_server.py"]
}
}
}
This MCP is strongest when scanning:
.pt and .pth.pkl, .pickle, and .joblib.h5It currently combines:
modelscan
Best general-purpose backend, especially for model-specific unsafe patterns like Keras Lambda.picklescan
Best supporting backend for pickle-oriented artifacts.deep_model_inspect
Fast heuristic fallback that catches risky packaging even when specialized scanners are quiet.You can scan either:
http or https artifact URLFor Hugging Face specifically, use the direct file URL:
https://huggingface.co/<repo>/resolve/main/model.h5https://huggingface.co/<repo>/blob/main/model.h5blob URLs usually return an HTML page, while resolve URLs return the real artifact bytes.
This repo includes a local Python 3.12 runtime in python312. That is the supported runtime because it works with:
mcpmodelscanpicklescanh5pyIf you ever need to rebuild that runtime manually:
python312\python.exe -m pip install mcp picklescan modelscan h5py
Run the MCP server with:
python312\python.exe run_server.py
The launcher is repo-local and uses the runtime already bundled in this project.
Add the server in Cursor MCP settings with:
model-safetystdioC:/Users/Lenovo/Documents/ModelSafetyMCP/python312/python.exeC:/Users/Lenovo/Documents/ModelSafetyMCP/run_server.pyEquivalent JSON:
{
"mcpServers": {
"model-safety": {
"type": "stdio",
"command": "C:/Users/Lenovo/Documents/ModelSafetyMCP/python312/python.exe",
"args": ["C:/Users/Lenovo/Documents/ModelSafetyMCP/run_server.py"]
}
}
}
A copy-paste example also lives in cursor.mcp.example.json.
Add the server with:
claude mcp add model-safety -- C:/Users/Lenovo/Documents/ModelSafetyMCP/python312/python.exe C:/Users/Lenovo/Documents/ModelSafetyMCP/run_server.py
In your MCP client, ask:
Use available_scanners from the model-safety MCP server
You should see the installed backends, including modelscan and picklescan.
For a local file:
Use artifact_safety_report with path="C:/path/to/model.pth"
For a direct URL:
Use artifact_safety_report with url="https://example.com/model.h5"
This is the default entrypoint for single-artifact scans.
artifact_safety_report returns:
normalized_findingshighest_severityfinding_countrecommended_actionsThat means the tool is useful both for detailed investigation and for quick decision-making.
Use:
modelscan_scan when you want the dedicated ModelScan outputpicklescan_scan when you want pickle-specific detaildeep_model_inspect when you want lightweight packaging and archive heuristicsIf you have a whole drop of models:
Use scan_directory with path="C:/path/to/model-folder"
This returns:
risky_files for quick prioritizationscan_directory works best on folders that mostly contain model artifacts rather than general source code.
Use artifact_safety_report with path="C:/Users/Lenovo/Documents/ModelSafetyMCP/credit-risk-pytorch-v1.1.pth"
Typical result shape:
.pthUse artifact_safety_report with url="https://huggingface.co/MrKrauzer/FacenetRetweeted/resolve/main/facenet-retrained.h5"
Typical result shape:
.h5H5LambdaDetectScan findingLambda layer before deserializingThe server treats the scanners as complementary:
modelscan is the primary security backendpicklescan is a specialized supporting backenddeep_model_inspect is a fast structural fallbackInstead of forcing users to interpret each tool separately, the server also produces normalized findings with:
scannerseveritycategoryevidencesourcerecommended_actionThis tool helps triage risk. It does not prove a model is safe.
Important limits:
Quick verification:
python312\python.exe -m compileall src run_server.py
Добавь это в claude_desktop_config.json и перезапусти Claude Desktop.
{
"mcpServers": {
"model-safety-mcp": {
"command": "npx",
"args": []
}
}
}