calibra-mcp
# calibra-mcp
[](https://github.com/DanieleSantoro/calibra-mcp/actions/workflows/ci.yml)
[](pyproject.toml)
[](LICENSE)
**An MCP server + AI agent that audits the confidence calibration of ML classifiers.**
A model that says *"95% sure"* should be right 95% of the time. Most modern neural networks
aren't: they are **overconfident**, which is dangerous in medicine, finance and any system that
acts on predicted probabilities. `calibra-mcp` lets any LLM agent (Claude Desktop, Claude Code,
Cursor, your own agent) measure, visualise and fix miscalibration from your model's saved
predictions.
<!-- TODO: replace with a GIF of Claude Desktop running an audit -->

## Features
| Tool | What it does |
|---|---|
| `evaluate_calibration` | Accuracy, **ECE**, MCE, Brier, NLL + plain-language diagnosis |
| `reliability_diagram` | Confidence-vs-accuracy plot (returned as an image to the LLM) |
| `fit_temperature` | Temperature scaling (Guo et al., 2017), before/after metrics |
| `compare_models` | Ranks several models by ECE |
| `generate_demo` | Synthetic calibrated / over- / under-confident predictions |
Plus an `audit` prompt and **`calibra-audit`**, a standalone agent that connects to the server
over stdio and writes a Markdown audit report.
## Architecture
```
┌──────────────┐ MCP (stdio / HTTP) ┌──────────────────────────────┐
│ Claude / any │ ───────────────────▶ │ calibra-mcp server │
│ MCP client │ ◀─────────────────── │ metrics · plots · scaling │
└──────────────┘ tools, images └──────────────┬───────────────┘
▲ │ reads
│ calibra-audit (agent loop) ▼
└──────────── Markdown report preds.npz / preds.csv
```
The server is **model-agnostic**: it audits predictions, not weights. Export your model's
outputs on a held-out set and you're done, whatever framework you use.
## Quickstart
```bash
pip install "calibra-mcp[agent]" # or: uv tool install "calibra-mcp[agent]"
export ANTHROPIC_API_KEY=sk-...
python -c "from calibra_mcp import data; data.save(data.make_demo('overconfident'), 'demo.npz')"
calibra-audit demo.npz --out reports/audit.md
```
### Use it from Claude Desktop / Claude Code
```json
{
"mcpServers": {
"calibra": { "command": "uvx", "args": ["calibra-mcp"] }
}
}
```
Claude Code: `claude mcp add calibra -- uvx calibra-mcp`
Then ask: *"Audit the calibration of ~/experiments/resnet_test.npz"*.
## Input format
`.npz` with `labels` (N,) and either `logits` (N, K) (preferred: enables temperature scaling)
or `probs` (N, K). Or a `.csv` with columns `label,p_0,...,p_{K-1}`.
```python
# PyTorch
logits = torch.cat([model(x) for x, _ in test_loader]).cpu().numpy()
np.savez("preds.npz", logits=logits, labels=test_labels)
```
## Development
```bash
uv venv && uv pip install -e ".[dev,agent]"
pytest # unit + end-to-end MCP tests
ruff check . && ruff format .
```
## Roadmap
- [ ] Classwise ECE, adaptive binning, KS calibration error
- [ ] More recalibrators: Platt, isotonic, vector/matrix scaling, Dirichlet
- [ ] Direct loaders for HuggingFace models and datasets
- [ ] Agent benchmark: detection accuracy over N seeded miscalibrated models
- [ ] Publish on PyPI and the MCP Registry
## References
- Guo et al., *On Calibration of Modern Neural Networks*, ICML 2017
- Naeini et al., *Obtaining Well Calibrated Probabilities Using Bayesian Binning*, AAAI 2015
- [Model Context Protocol](https://modelcontextprotocol.io)
## License
MIT © Daniele Santoro
TDQS
Scored across 5 tools
Each tool has a clearly distinct purpose: metric computation, diagram rendering, temperature fitting, multi-model comparison, and demo data generation. Although evaluate_calibration and compare_models both involve evaluation, compare_models is explicitly scoped to side-by-side ranking, so boundaries remain clear.
All names use consistent snake_case, and four follow a verb_noun pattern (evaluate_calibration, fit_temperature, compare_models, generate_demo). reliability_diagram is a noun phrase rather than a verb-led name, which is a minor deviation but still readable and predictable.
Five tools are well-scoped for a focused calibration toolkit. Each tool covers a distinct part of the workflow, and there is no obvious redundancy or bloat.
The surface covers core calibration evaluation, visualization, recalibration via temperature scaling, model comparison, and demo generation. Minor gaps exist, such as alternative recalibration methods (e.g., isotonic/Platt scaling) or explicit data splitting utilities, but the stated purpose is well served.