johnhalloran321/mcp_safety_training — explained in plain English
Analysis updated 2026-05-18
Train a tool-using language model with DPO or SafeDPO to refuse disguised harmful tool requests
Evaluate how often a model refuses attacks versus genuinely benign requests using the included test sets
Try the training-free RAG-Pref method to improve refusal rates without fine-tuning a model
Reproduce the refusal-rate results reported in the accompanying research papers
| johnhalloran321/mcp_safety_training | 1038lab/agnes-ai | 3eyedtiger/video2vrcemote | |
|---|---|---|---|
| Stars | 4 | 4 | 4 |
| Language | Python | Python | Python |
| Setup difficulty | hard | easy | easy |
| Complexity | 5/5 | 2/5 | 1/5 |
| Audience | researcher | vibe coder | vibe coder |
Figures from each repo's GitHub metadata at analysis time.
Requires a CUDA GPU, Python 3.11, matched PyTorch and flash-attention builds, and Hugging Face login for the gated dataset.
This repository is the companion code for two research papers on making AI models that use external tools safer. It focuses on a specific problem: some requests to a tool-using AI model look completely harmless on the surface but are actually designed to trick the model into misusing its tools in a harmful way, a category the authors call falsely-benign MCP exploits, referring to attacks that use the Model Context Protocol that AI tools rely on to interact with files and other resources. The code trains and evaluates several methods for teaching a model to recognize and refuse these disguised attacks while still responding normally to genuinely harmless requests. It includes standard preference alignment training methods called DPO and SafeDPO, which fine-tune a model using pairs of good and bad example responses, plus two methods that need no training at all: OPAD, which changes how the model generates text on the fly based on stated safety principles, and RAG-Pref, which looks up similar past examples of attacks and safe requests at the moment of generation and feeds them into the model's instructions to guide its response. According to the README, models tested without any of these defenses refused fewer than 35 percent of the disguised attacks, standard DPO and SafeDPO training only raised that to about 48 percent, while RAG-Pref roughly tripled the refusal rate on its own and nearly quadrupled it when combined with DPO or SafeDPO training. The project includes its own training and evaluation dataset hosted on Hugging Face, containing preference pairs for training plus separate held-out sets of disguised attacks and genuinely benign prompts for measuring both refusal of attacks and over-refusal of safe requests. Running the training scripts requires a CUDA capable GPU, Python 3.11, and several machine learning libraries including PyTorch and a flash-attention build matched to that PyTorch version. The project is released under the Apache 2.0 license.
Research code that trains and evaluates methods for teaching tool-using AI models to refuse harmful requests disguised as ordinary, harmless-sounding ones.
Mainly Python. The stack also includes Python, PyTorch, CUDA.
Use freely for any purpose, including commercial use, as long as you keep the copyright and license notices.
Setup difficulty is rated hard, with roughly 1day+ to a first successful run.
Mainly researcher.
This repo across BitVibe Labs
double-check against the repo, no cap.