Skip to main content
Glama
TOXTRUST-MCP

TOXTRUST-MCP

Official
by phi-grib
README.md
# TOXTRUST-MCP

[Model Context Protocol](https://modelcontextprotocol.io) server exposing
[TOXTRUST](https://github.com/phi-grib/TOXTRUST) (Kopańska & Pastor, PharmacoInformatics Lab, Universitat Pompeu Fabra),
a Dempster–Shafer theory (DST) tool that turns toxicological evidence pieces (QSAR predictions, structural alerts,
in vitro / in vivo results, read-across, expert judgement) into belief masses and combines them for **one binary hazard
question** (for example: "Is the substance mutagenic in the Ames test?").

- Upstream pinned: TOXTRUST commit `185b6e8` (package `toxtrust==0.2`).
- Stateless: no endpoint repository or configuration file is written.
- Transports: stdio (default) or streamable HTTP.
- License: GPL-3.0-only (it imports GPL-3.0 TOXTRUST).

## Tools

| Tool | Purpose |
|---|---|
| `toxtrust_info` | Semantics, relevance scale, rules, decision thresholds, deviations from upstream, caveats |
| `toxtrust_assess_evidence` | One piece → masses {negative, uncertain, positive}, belief, plausibility, decision |
| `toxtrust_combine_evidence` | ≥2 independent pieces for one question → rule (auto/Dempster/Yager/Inagaki), conflict K, fused masses, decision, exact-arithmetic shadow values, upstream cross-check, warnings |
| `toxtrust_rule_sensitivity` | All rules + Inagaki scale 0–1 + leave-one-out + one piece per independence group → `robust` flag |
| `toxtrust_compare_substances` | One endpoint question, a target and candidate substitutes → per-substance integration and interval comparison of the hazard (positive) class |

Every response carries `inputs_sha256`, a UTC timestamp, the server and upstream versions, and methodological caveats,
so results can be archived in an audit trail.

### Evidence piece

```json
{"id": "qsar-ames", "source": "in silico", "outcome": "positive",
 "probability_positive": 0.82, "reliability_positive": 0.78, "relevance": "probable",
 "independence_group": "ames-public-training-set", "provenance": {"model": "...", "applicability_domain": "inside"}}
```

`m(pos) = p_pos · rel_pos · relevance`, `m(neg) = p_neg · rel_neg · relevance`, `m(Θ) = 1 − m(pos) − m(neg)`
(2-decimal rounding as upstream). Relevance: certain 1, probable 0.9, plausible 0.75, equivocal 0.5, doubted 0.25,
improbable 0.1, impossible 0. Reliabilities and probabilities must be in [0, 1].

### Comparison relations (`toxtrust_compare_substances`)

- `lower_hazard_supported`: Pl(pos | candidate) < Bel(pos | target) **and** the candidate decision is `negative`
- `lower_hazard_indicated_weak`: interval separation, but the candidate evidence is not decisive → a data gap, not an advantage
- `higher_hazard_supported`: Bel(pos | candidate) > Pl(pos | target)
- `not_distinguishable`, `unknown` (no evidence ≠ negative)

## Engine design

The server computes with `engine.py`, a port of the upstream `evidence.py` / `combination.py` /
`Endpoint.makeDecision` formulas with input validation, and by default re-runs the **unmodified upstream package** in a
`forkserver` subprocess (hard timeout, stdout captured), reporting `upstream_check.agreement`. The test suite asserts
identical negative/positive masses against upstream on random inputs.

### Deliberate deviations from upstream

1. The upstream renormalisation step can fail to terminate when rounded masses do not sum to 1 ± 0.01; here the rounding
   residual is assigned to the uncertainty mass in one step.
2. Inputs are validated strictly: reliabilities/probabilities outside [0, 1] are rejected (no silent percentage
   handling), and outcome `both` requires both class probabilities and both reliabilities.
3. Reliabilities are given per class (`reliability_positive`, `reliability_negative`) rather than by list position.
4. Upstream reports Pl(c) = 0 whenever Bel(c) = 0; the textbook DST plausibility Pl(c) = Bel(c) + m(Θ) is returned
   alongside as `plausibility_dst` and is the one to use as the hazard upper bound.
5. Source labels: the upstream vocabulary (`in silico`, `in vitro`, `expert`, `alert`, `read-across`) plus
   `in vivo`, `human data`, `regulatory`, `literature`, `supplier`. Labels do not change the arithmetic; extended labels
   are mapped to `expert` for the upstream cross-check.

## Methodological caveats

- DST combination assumes **independent** sources. Tag pieces of shared origin (same study, a study and the
  classification based on it, QSAR models trained on overlapping data) with the same `independence_group`.
- Weight of evidence (`woe=true`) replicates a piece `weight` times and self-combines it, which inflates certainty;
  prefer reliability/relevance.
- Results are integrated weight-of-evidence statements for one binary question, not measurements, potencies or
  classifications. `uncertain` never means `negative`.
- Reliability values (PPV/NPV, sensitivity/specificity, expert confidence) are design choices that drive the result;
  record their origin in `provenance`.

## Installation

Requires Python ≥ 3.10.

```bash
git clone https://github.com/phi-grib/TOXTRUST-MCP.git
cd TOXTRUST-MCP
uv venv --python 3.12 .venv
uv pip install --python .venv/bin/python -e ".[test]"   # pulls TOXTRUST at the pinned commit
```

(`python -m venv .venv && .venv/bin/pip install -e ".[test]"` works as well.)

## Running

```bash
.venv/bin/toxtrust-mcp                                         # stdio
.venv/bin/toxtrust-mcp --transport streamable-http --port 8005 # HTTP on 127.0.0.1:8005/mcp
```

Example MCP client configuration (stdio):

```json
{"mcpServers": {"toxtrust": {"command": "/path/to/TOXTRUST-MCP/.venv/bin/toxtrust-mcp"}}}
```

Environment: `TOXTRUST_UPSTREAM_TIMEOUT` (seconds, default 8). Pass `upstream_check=false` to skip the cross-check.
Scripts that import `toxtrust_mcp.server` and run the cross-check need an `if __name__ == "__main__":` guard
(the runner uses a multiprocessing forkserver).

## Tests

```bash
.venv/bin/python -m pytest -q                                   # ~80 s (runs upstream subprocesses)
.venv/bin/python tests/smoke_stdio.py "$PWD/.venv/bin/toxtrust-mcp"
.venv/bin/python scripts/worked_example.py worked_example.json  # synthetic substitution example
```

## Acknowledgements

TOXTRUST was developed at the PharmacoInformatics Lab (http://phi.upf.edu) within eTRANSAFE (IMI2 JU Grant Agreement
No. 777365) and RISK-HUNT3R (EU H2020 Grant Agreement No. 964537, ASPIS cluster).

## License

GNU General Public License v3.0 only — see [LICENSE](LICENSE).

TDQS

A3.7/5.0

Scored across 5 tools

Disambiguation5/5

Each tool occupies a distinct stage of the workflow: orientation (toxtrust_info), single-piece conversion (toxtrust_assess_evidence), multi-piece fusion (toxtrust_combine_evidence), robustness testing (toxtrust_rule_sensitivity), and cross-substance comparison (toxtrust_compare_substances). The descriptions explicitly constrain scope (ONE evidence piece vs. >=2 pieces vs. ONE endpoint), so an agent can route unambiguously.

Naming Consistency4/5

All names are snake_case with a uniform toxtrust_ prefix and mostly verb_noun structure (assess_evidence, combine_evidence, compare_substances, rule_sensitivity). The only deviation is toxtrust_info, a bare noun with no verb, but the shared prefix keeps the set predictable.

Tool Count5/5

Five tools map cleanly onto a narrow, specialized pipeline (info -> assess -> combine -> sensitivity -> compare), and each has a clear, non-redundant role. No filler or near-duplicate tools are present.

Completeness4/5

The surface covers the full Dempster-Shafer workflow: orientation, per-piece mass conversion, combination with conflict handling, robustness variants, and substitution comparison, with explicit upstream cross-checks. Minor gaps remain—no tool to aggregate or summarize results across multiple endpoints (explicitly forbidden by design) or to validate/prepare raw evidence inputs before assessment—but these are workable given the stated scope.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues