Skip to main content
Glama
description-to-ontology-plus-mcp

description-to-ontology-plus-mcp

by djportUCD
README.md
# description-to-ontology-plus-mcp

**Ever get tired of reading a description and wondering which disease, function, gene, tissue,
ontology term, medical code or ID it refers to?**

Here's some help. Give `description-to-ontology-plus-mcp` the text (an abstract, an assay
protocol, a mouse model, a gene summary, a clinical note), or give it to your AI, and ask:

> *"What does this refer to?"*

You get back the answer grouped by category. Every item has an ID that was checked against the
real source:

| You read… | It tells you… |
|---|---|
| "boys lose muscle strength in early childhood" | **disease** MONDO:0010679 Duchenne muscular dystrophy · **phenotype** HP:0001324 Muscle weakness |
| "Nrf2", "DMD", "the leptin gene" | **gene** NCBIGene:4780 NFE2L2 (human), with HGNC, OMIM, Ensembl and UniProt IDs |
| "chloride transport across the apical membrane" | **function / process** GO terms · **cell location** GO cellular components |
| "the Keap1-Nrf2-ARE pathway" | **pathway** Reactome:R-HSA-9755511 KEAP1-NFE2L2 pathway |
| "HaCaT keratinocytes", "bovine cells" | **cell type** CL · **organism** NCBITaxon:9913 *Bos taurus* |
| "cinnamaldehyde", "CAS 60-18-4" | **chemical** CHEBI:16731 (E)-cinnamaldehyde · CHEBI:17895 L-tyrosine |
| "a cell viability assay", "genotoxicity testing" | **assay / method** BAO:0003009 · BAO:0002167 |
| "OMIM 219700", "ICD-10 E84.0", "ORPHA:586", "rs113993960" | **IDs already in the text, resolved**: cystic fibrosis (MONDO:0009061); rs113993960 sits in CFTR |
| any disease it finds | its **medical codes**: OMIM, ICD-10-CM, ICD-10 (WHO), ICD-11, ICD-9, MeSH, UMLS, SNOMED CT, Orphanet, NCI Thesaurus, MedDRA, MedGen, GARD, Disease Ontology |
| the whole set | **how they connect in the literature**: "cinnamaldehyde *cause* allergic contact dermatitis (12 papers)", "cinnamaldehyde *positive_correlate* NFE2L2 (34 papers)", with example PubMed IDs |

It also works out **what the thing does, how and why**: its function, mechanism and purpose, and
the subject → predicate → object relations between the concepts. It **never makes up an ID**. Every ID
comes from a live search and is verified before you see it.

It runs as an **MCP server** (Claude Desktop, Claude Code or any MCP client) and as a **REST API**.

**The "plus":** AIs don't only *use* it, they *teach* it. Every confident mapping an AI makes (and
anything it adds on purpose with `learn_term`) goes into a **learning dictionary**, a plain YAML
file, so the same phrase is answered better next time. People stay in charge: a curator's
*confirmed* or *rejected* verdict always wins over anything learned automatically.

> **Licence:** free for **academic research and teaching only**. Commercial use needs separate
> permission. See [Licence](#licence).

---

## The question, and the ways it answers it

"Which identifier does this description refer to?" comes in several forms. Each form has its own tool:

| You want to know | MCP tool | REST | CLI |
|---|---|---|---|
| **Everything this text refers to**, grouped by category (start here) | `what_does_this_refer_to` | `POST /refer` | `refer "…"` |
| What the **IDs already written in the text** mean (OMIM, ICD-10, Orphanet, MeSH, UMLS CUI, rsID, NCBI Gene, HGNC, Ensembl, UniProt, CAS, Reactome, ontology CURIEs, PMIDs) | `identify_ids` | `POST /identify` | `identify "…"` |
| The **medical codes** for a disease or gene it found | included in every annotation (`codes`) | same | same |
| How the findings are **connected in published papers** | `find_literature_connections` | `POST /connections` | `connect ID ID … / --run RUN` |
| What **outside text annotators** see in the text (PubTator3, BioPortal) | `scan_text_with_sources` → `get_scan_result` | `POST /sources/scan` → `GET /sources/scan/{id}` | – |
| The best ID for **one concept you already have** | `ground_terms` | `POST /ground` | `ground "…" --kind …` |
| Details of **one ID** | `lookup_term` | `GET /terms/{curie}` | `lookup ID` |
| The **equivalent** ID in another ontology (MONDO ⇄ DOID, …) | `crosswalk_term` | `GET /crosswalk/{curie}` | – |
| What a **lab's jargon or abbreviation** means (as learned before) | `lookup_dictionary` | `GET /dictionary/lookup` | – |

### Example

```text
$ description-to-ontology-plus-mcp identify "Cystic fibrosis (OMIM 219700; ICD-10 E84.0; ORPHA:586) from
  CFTR rs113993960; HGNC:1884; ENSG00000001626; tyrosine CAS 60-18-4; MeSH D003550; PMID 31740819."

OMIM 219700     -> MONDO:0009061  cystic fibrosis
ICD-10 E84.0    -> MONDO:0009061  cystic fibrosis   (matched the parent code E84)
ORPHA:586       -> MONDO:0009061  cystic fibrosis
rs113993960     -> dbSNP:rs113993960  rs113993960 (CFTR, CFTR-AS1)
HGNC:1884       -> NCBIGene:1080  CFTR (human): CF transmembrane conductance regulator
ENSG00000001626 -> NCBIGene:1080  CFTR (human)
60-18-4         -> CHEBI:17895    L-tyrosine          (CAS check digit verified)
MeSH D003550    -> MONDO:0009061  cystic fibrosis
PMID 31740819   -> recognised; not something this service resolves

$ description-to-ontology-plus-mcp connect NCBIGene:4780 MONDO:0006525 CHEBI:16731

(E)-cinnamaldehyde | positive_correlate | NFE2L2            34 papers
(E)-cinnamaldehyde | cause              | allergic contact dermatitis   12 papers
(E)-cinnamaldehyde | associate          | NFE2L2             8 papers
allergic contact dermatitis | associate | NFE2L2             5 papers
```

The full answer from `what_does_this_refer_to` (or `analyze_text`) looks like this:

```text
"Lep ob/ob mice make no functional leptin ... overeat, become severely obese ..."
        │
        ▼
 summary    A mouse strain lacking leptin that models monogenic obesity
 function   Leptin reports fat stores to the brain and suppresses appetite
 mechanism  Adipocytes secrete leptin ∝ fat mass; it acts on hypothalamic neurons ...
 why        Matches food intake to energy stores ...
 relations  Lep loss ─causes→ polyphagia, polyphagia ─leads to→ obesity, ...
 answer
   genes      leptin gene    → NCBIGene:16846  Lep (mouse)   codes: MGI 104663
   phenotypes overeat        → MP:0001433      polyphagia
              severely obese → MP:0001261      obese
   diseases   (implied)      → MONDO:0013991   obesity due to congenital leptin deficiency  codes: OMIM, Orphanet, …
   functions  satiety signal → GO:0032099      negative regulation of appetite
 literature   Lep ─associate→ obesity  (n papers, example PMIDs …)
```

## Why this exists

Turning a description into "this means DOID:x / MONDO:y / GO:z / OMIM n" usually means asking an
AI and hoping the IDs are real, or searching five websites by hand. Existing tools each do part of
the job:

| Tool | What it does | What it doesn't do |
|---|---|---|
| [OLS](https://www.ebi.ac.uk/ols4), [ols-mcp-server](https://github.com/seandavi/ols-mcp-server), [OntoMCP](https://github.com/jeanlouishoneine-tech/OntoMCP), [mondo-link](https://github.com/berntpopp/mondo-link) | Look up a **term you already have** | Read a description and work out function, mechanism or implied concepts |
| [OntoGPT / SPIRES](https://github.com/monarch-initiative/ontogpt) | LLM extraction grounded to ontologies | Isn't an MCP server; doesn't learn from curator corrections |
| [CurateGPT](https://github.com/monarch-initiative/curategpt) | AI-assisted curation workbench | Isn't a "what does this refer to?" service |
| [PubTator3](https://www.ncbi.nlm.nih.gov/research/pubtator3/), [BioPortal Annotator](https://bioportal.bioontology.org/annotator) | Tag entities in text | Don't reason about meaning, implied concepts or medical codes |

description-to-ontology-plus-mcp joins these together. It reasons about the text, grounds
against live ontologies and biomedical APIs, never invents IDs, adds the medical codes, looks up
the literature, and has a second route for teaching it.

## How it works

```
 text ──► 0. SPOT IDs            identifiers already in the text (OMIM, ICD, rsID, CAS, …) resolved
            │                    fast outside annotators run; PubTator3 starts in the background
            ▼
          1. READ (brain)        what / function / mechanism / why / relations,
            │                    concepts named + implied, with good search queries
            │   ◄── similar worked examples, guidelines, learning-dictionary entries, annotator hints
            ▼
          2. RETRIEVE            live search of EBI OLS (+ MyGene.info for genes)
            │                    + the outside helpers for that kind of concept (sources.yaml);
            │                    IDs several sources agree on rank higher;
            │                    dictionary: confirmed ≫ learned boosted, rejected demoted
            ▼
          3. CHOOSE (brain)      one ID per concept, *only from the retrieved candidates*
            ▼
          4. VERIFY + CODE       every ID re-checked at its source; invented or obsolete IDs dropped;
            │                    MONDO ⇄ DOID equivalents; medical codes grouped from cross-references
            ▼
          5. CONNECT             PubTator3: how the genes, diseases and chemicals are related in PubMed;
            │                    concepts the outside annotators found that the reading missed
            ▼
          6. SAVE + FLAG         run saved with run_id; low-confidence items go to a review queue
            ▼
          7. LEARN               confident, exact, unflagged mappings go into the dictionary
```

**No hard-coded terms.** Ontology content always comes live from the sources, so new releases are
picked up automatically. What the service *knows how to do* is kept as plain files in
[`knowledge/`](knowledge/). Anyone can read them, edit them and send changes as a pull request:

| File | What it is | How it's used |
|---|---|---|
| `examples/*.yaml` | Worked examples: input text + what a good answer looks like | The most similar ones are shown to the brain as few-shot examples |
| `guidelines.yaml` | Plain-language rules ("mouse phenotypes go to MP") | Shown to the brain on every request |
| `dictionary.yaml` | The learning dictionary: "this phrase → this ID", each `confirmed`, `learned` or `rejected` | Priors in ranking and precedent for the brain, *not* a lookup table |
| `sources.yaml` | The catalogue of outside APIs: what each is good for, which kinds it is asked about, keys, terms | Read by the AI through `list_sources`; edit to turn helpers on/off or add a new API |
| `config.yaml` | Ontologies per concept kind; `code_systems` (which cross-reference prefixes are which medical code); `identifier_patterns` (how to spot and resolve IDs in text); literature settings; thresholds | Edit to add an ontology, a code system or a new kind of identifier, with no code changes |

## Medical codes and identifiers

**Codes for what it found.** Diseases are grounded to MONDO, which carries curated cross-references
to other vocabularies. `code_systems` in `config.yaml` names them, and every annotation gets a
`codes` block. For example, for Duchenne muscular dystrophy: `{"OMIM": ["310200"], "ICD-10-CM":
["G71.01"], "MeSH": ["D020388"], "UMLS": ["C0013264"], "SNOMED CT": [...], "Orphanet": [...]}`.
Genes get HGNC / MGI, OMIM, Ensembl and UniProt IDs from MyGene.info.

**IDs already in the text.** `identifier_patterns` in `config.yaml` is a list of regular
expressions, each with how to resolve the match: as an ontology ID, through MyDisease's
cross-reference index, as a fielded MyGene or MyChem query, or through any source in the catalogue.
ICD-10 sub-codes fall back to their parent code, and the answer says when it did. CAS numbers must
pass their check digit. To add a new kind of identifier, add an entry to that list.

These codes are **passed on from the sources' cross-references**, not issued by this project. Some
code systems (SNOMED CT, UMLS, ICD, MedDRA) have their own licence terms for some uses. See
[Data licences](#data-licences).

## Literature connections (PubTator3)

When an analysis finishes, the grounded genes, diseases and chemicals are mapped to PubTator3's
entities. PubTator3 then reports the **relations it has mined from PubMed** between each pair (treat,
cause, associate, inhibit, stimulate, interact, positive/negative correlation, …), with the
number of papers and a few example PMIDs for the strongest ones. The PubTator3 text annotator also
runs over your text in the background. Concepts it finds that the reading missed come back under
`possibly_missed`.

These connections are **evidence that papers discuss things together, not curated facts**. Read
the example papers before you rely on one. You can tune them or turn them off in `config.yaml` →
`literature`. PubTator3 asks for at most 3 requests a second, and the service keeps to that.

## The learning dictionary

Each entry in `knowledge/dictionary.yaml` looks like this:

```yaml
- phrase: Nrf2
  curie: NCBIGene:4780
  status: learned        # confirmed | learned | rejected
  source: usage          # curator | usage (a confident analysis) | ai (added with learn_term)
  kind: gene
  label: NFE2L2 (human): NFE2 like bZIP transcription factor 2
  count: 3               # times it has been seen; learned entries get stronger as this grows
```

| Status | Comes from | Effect on ranking |
|---|---|---|
| `confirmed` | A person (`refine_feedback`, `refine_confirm_run`, `refine_review_entry`) | Strong boost; always beats anything learned |
| `learned` | Automatically, from confident analyses, or from an AI calling `learn_term` | Boost; much larger when the wording is identical, grows with `count` |
| `rejected` | A person | Strong penalty; automatic learning never overwrites a rejection |

Learning is careful about what it keeps. It only learns an exact match that is not implied, at or
above `learning.min_confidence` (default 0.85), not flagged for review, and only where the phrase
says more than the label does. Every ID is checked at its source before it is stored, and obsolete or
invented IDs are refused. Set `learning.auto_learn: false` to turn automatic learning off.
Curators review what was learned with `refine_list_dictionary status=learned`, then
`refine_review_entry` with `confirmed` or `rejected`.

## Outside help: the source catalogue

OLS and MyGene.info are always searched. Each concept is also sent to the outside helpers that cover
its kind. A helper can only add IDs from ontologies that kind allows, or IDs it is the authority
for (such as Reactome pathways). Every chosen ID is still verified. When several sources find the
same candidate, it lists them all (for example `source: ols,mydisease,monarch`) and ranks higher.

| Source | Helps with | Key |
|---|---|---|
| `ols` (EMBL-EBI Ontology Lookup Service) | Every ontology: search, term details, cross-references | none |
| `mygene` (MyGene.info) | Genes in any species → NCBI Gene, with HGNC / MGI / OMIM / Ensembl / UniProt | none |
| `mydisease` (MyDisease.info) | Diseases → MONDO; reverse lookups from OMIM / Orphanet / ICD / MeSH / UMLS | none |
| `monarch` (Monarch Initiative) | Second opinion on diseases and phenotypes | none |
| `mychem` (MyChem.info) | Chemicals, drug names and CAS numbers → ChEBI, with PubChem / DrugBank | none |
| `myvariant` (MyVariant.info) | Variants (rsIDs) → gene and ClinVar conditions | none |
| `reactome` | Named signalling and metabolic pathways → `Reactome:R-HSA-…` | none |
| `ncbi_taxonomy` (NCBI E-utilities) | Organisms by common name ("bovine", "zebrafish") → NCBITaxon | optional (`NCBI_API_KEY`) |
| `pubtator` (NCBI PubTator3) | How papers name genes, diseases and chemicals; **literature connections** | none |
| `pubtator_text` (PubTator3 annotator) | Tags genes, diseases, chemicals, species and variants in your whole text (slow; background) | none |
| `bioportal` (NCBO BioPortal) | 1,000+ ontologies, and a fast **text annotator** | **required** (free) |
| `uniprot` | Proteins by name. Off by default; a template for adding any JSON API without code | none |

The catalogue is [`knowledge/sources.yaml`](knowledge/sources.yaml). Each entry says, in plain words,
what the source is good for and not good for, which concept kinds it covers, which IDs it returns, its rate
limits and its terms of use. The AI reads it with `list_sources` and can call `ask_source` itself
when a concept is hard to ground. To add another JSON REST API, copy the `uniprot` entry
(`adapter: rest_json`) and describe its URL and fields.

### API keys

Some services need a key. **Keys are never typed into the AI chat.** When a source needs one, the
MCP's `request_api_key` tool tells the AI to ask you to run a command in your own terminal:

```bash
description-to-ontology-plus-mcp keys set bioportal     # asks for the key with hidden input
description-to-ontology-plus-mcp keys list              # which sources have a key, and where (never the key)
description-to-ontology-plus-mcp keys remove bioportal
```

Keys are kept in your operating system's credential store (Windows Credential Manager, macOS
Keychain, or Secret Service on Linux). If none is available, they go in a private file,
`~/.description-to-ontology-plus-mcp/keys.json`, readable only by you. On a server, set the
environment variable named in `sources.yaml` instead (for example `BIOPORTAL_API_KEY`), which takes
precedence. Keys never go in the repository. Each key is sent only to its own service. No key is
ever logged or returned from a tool.

## All tools

**Route 1: analyze** (use it)

| MCP tool | REST | Purpose |
|---|---|---|
| `what_does_this_refer_to` | `POST /refer` | **Start here.** The grouped answer (server brain) or the context and steps for the calling AI (client brain) |
| `analyze_text` | `POST /analyze` | Whole pipeline in one call, full detail (needs a server-side brain) |
| `identify_ids` | `POST /identify` | IDs written in the text, and what each refers to |
| `find_literature_connections` | `POST /connections` | PubTator3 relations between a run's terms or a list of IDs |
| `get_learning_context` | `POST /context` | Similar examples, guidelines, earlier verdicts for a text |
| `ground_terms` | `POST /ground` | Ranked live candidates for concepts you give it |
| `lookup_term` | `GET /terms/{curie}` | Label, definition, synonyms, xrefs, obsolete status (any source's IDs) |
| `crosswalk_term` | `GET /crosswalk/{curie}?target=DOID` | Verified equivalents (MONDO ⇄ DOID, …) |
| `record_analysis` | `POST /runs` | Save an analysis the calling AI reasoned out; IDs verified, codes added, grouped `references` returned |
| `get_run`, `list_runs` | `GET /runs[/{id}]` | Past runs; `status=needs_review` is the review queue |
| `list_sources` | `GET /sources` | The outside-API catalogue and what is active |
| `ask_source` | `POST /sources/{id}/ask` | Ask one helper directly |
| `scan_text_with_sources` | `POST /sources/scan` | Run the text annotators over the whole text |
| `get_scan_result` | `GET /sources/scan/{scan_id}` | Collect a background scan (PubTator3 often takes 1–2 minutes) |
| `request_api_key` | `GET /sources/{id}/key-help` | How a person enables a source that needs a key |
| `learn_term` | `POST /learn` | Teach it: "*this phrase* means *this ID*" (verified, stored as `learned`) |
| `lookup_dictionary` | `GET /dictionary/lookup?phrase=…` | What the dictionary already knows about a phrase |

**Route 2: refine** (make it better)

| MCP tool | REST | Purpose |
|---|---|---|
| `refine_feedback` | `POST /refine/feedback` | "For *this mention*, the right ID is X / Y was wrong, because …" |
| `refine_confirm_run` | `POST /refine/runs/{id}/confirm` | Mark a run correct; its mappings become `confirmed` entries |
| `refine_promote_to_example` | `POST /refine/runs/{id}/promote` | Turn a reviewed run into a worked example |
| `refine_add_example` / `_update_` / `_delete_` / `_list_` / `_get_` | `/refine/examples` | Manage worked examples |
| `refine_add_guideline` / `_remove_` / `_list_` | `/refine/guidelines` | Manage plain-language rules |
| `refine_list_dictionary` | `GET /refine/dictionary?status=learned` | Inspect the dictionary |
| `refine_review_entry` | `POST /refine/dictionary/review` | Confirm or reject a dictionary entry |
| `refine_remove_entry` | `DELETE /refine/dictionary` | Forget an entry |
| `refine_update_source` | `PATCH /refine/sources/{id}` | Turn a helper on/off, change its kinds, note what it is good or bad at |
| `refine_evaluate` | `POST /refine/evaluate` | Re-run every example (hidden from itself) and report precision / recall |

The learning loop: **analyze (the dictionary grows by itself) → review the queue and the learned
entries → feedback / confirm / reject → promote good runs to examples → evaluate.**

## Two brains

| Mode | When | Who reasons |
|---|---|---|
| `anthropic` | `ANTHROPIC_API_KEY` is set | The server calls Claude (default `claude-opus-5-5`). `what_does_this_refer_to` does everything in one call. |
| `client` | No key (default) | **The AI calling the MCP server reasons.** `what_does_this_refer_to` gives it the IDs found in the text, the context, a background scan and the steps. It reads the text, then calls `ground_terms` and `record_analysis`. The server does the grounding, verification, codes, connections and learning. The `curate` MCP prompt walks it through. |

Client mode means you can use it from Claude Desktop or Claude Code with **no API key and no cost
beyond your own Claude subscription**.

## Quick start

Requires Python 3.15 or newer (the current stable release).

```bash
git clone https://github.com/djportUCD/description-to-ontology-plus-mcp.git
cd description-to-ontology-plus-mcp
python -m venv .venv
. .venv/bin/activate            # Windows: .venv\Scripts\activate
pip install -e .
description-to-ontology-plus-mcp status
description-to-ontology-plus-mcp identify "OMIM 310200, ICD-10 G71.0, rs113993960"
description-to-ontology-plus-mcp ground "Duchenne muscular dystrophy" --kind disease
description-to-ontology-plus-mcp connect NCBIGene:1756 MONDO:0010679
description-to-ontology-plus-mcp refer "CFTR is an ATP-gated chloride channel ..."   # full answer needs ANTHROPIC_API_KEY
```

### Use it from Claude Code

```bash
claude mcp add description-to-ontology-plus-mcp -- /full/path/to/description-to-ontology-plus-mcp/.venv/bin/description-to-ontology-plus-mcp mcp
```

### Use it from Claude Desktop

Add this to `claude_desktop_config.json` (Settings → Developer → Edit Config):

```json
{
  "mcpServers": {
    "description-to-ontology-plus-mcp": {
      "command": "/full/path/to/description-to-ontology-plus-mcp/.venv/bin/description-to-ontology-plus-mcp",
      "args": ["mcp"],
      "env": { "DESCRIPTION_TO_ONTOLOGY_KNOWLEDGE_DIR": "/full/path/to/description-to-ontology-plus-mcp/knowledge" }
    }
  }
}
```

On Windows the command is `C:\\path\\to\\description-to-ontology-plus-mcp\\.venv\\Scripts\\description-to-ontology-plus-mcp.exe`.
Add `"ANTHROPIC_API_KEY": "..."` to `env` to switch on the server-side brain.

Then ask it things like:

> What does this abstract refer to? …
>
> Which disease is "ORPHA:586", and what are its ICD-10 and MeSH codes?
>
> How are the genes and chemicals in that run connected in the literature?
>
> That run mapped "loss of speech" to Aphasia; the right term is HP:0002371. Record that feedback.
>
> Remember that in our assay descriptions "IVM" means in vitro maturation.

### REST API

```bash
description-to-ontology-plus-mcp api --port 8000         # docs at http://localhost:8000/docs
curl -s localhost:8000/identify -H 'content-type: application/json' -d '{"text":"OMIM 219700 and CAS 60-18-4"}'
curl -s localhost:8000/refer    -H 'content-type: application/json' -d '{"text":"CFTR is an ATP-gated chloride channel ..."}'
curl -s localhost:8000/connections -H 'content-type: application/json' -d '{"curies":["NCBIGene:1080","MONDO:0009061"]}'
```

### MCP over HTTP (for a shared server)

```bash
DESCRIPTION_TO_ONTOLOGY_ROUTES=analyze description-to-ontology-plus-mcp mcp --transport streamable-http --host 0.0.0.0 --port 8765
```

### Podman (container)

The repository ships a `Containerfile`. It works with [Podman](https://podman.io/) (no daemon, rootless by default):

```bash
podman build -t description-to-ontology-plus-mcp .
podman run --rm -p 8000:8000 -e ANTHROPIC_API_KEY=... -e DESCRIPTION_TO_ONTOLOGY_ADMIN_TOKEN=change-me description-to-ontology-plus-mcp
podman run --rm -p 8765:8765 description-to-ontology-plus-mcp description-to-ontology-plus-mcp mcp --transport streamable-http --host 0.0.0.0 --port 8765
```

On Windows and macOS, run `podman machine init` and `podman machine start` once first. To keep
learned dictionary entries and saved runs between containers, mount a folder over the knowledge
directory: `-v ./knowledge:/app/knowledge:Z`.

## Configuration

| Variable | Default | Meaning |
|---|---|---|
| `ANTHROPIC_API_KEY` | – | Enables the server-side brain |
| `DESCRIPTION_TO_ONTOLOGY_BRAIN` | auto | Force `anthropic` or `client` |
| `DESCRIPTION_TO_ONTOLOGY_MODEL` | `claude-opus-5-5` | Claude model for the server-side brain |
| `DESCRIPTION_TO_ONTOLOGY_EFFORT` | `high` | Reasoning effort: `low` / `medium` / `high` / `xhigh` / `max` |
| `DESCRIPTION_TO_ONTOLOGY_FALLBACKS` | `default` | If Claude declines a request, re-run it on a fallback model; `off` disables this |
| `DESCRIPTION_TO_ONTOLOGY_KNOWLEDGE_DIR` | `./knowledge` | Where examples, guidelines, the dictionary and runs live |
| `DESCRIPTION_TO_ONTOLOGY_ROUTES` | `analyze,refine` | Which routes to expose; use `analyze` on a public server |
| `DESCRIPTION_TO_ONTOLOGY_ADMIN_TOKEN` | – | If set, REST `/refine/*` needs `Authorization: Bearer <token>` |
| `DESCRIPTION_TO_ONTOLOGY_OLS_URL` | EBI OLS4 | Point at a local OLS instance if you run one |
| `BIOPORTAL_API_KEY`, `NCBI_API_KEY` | – | Keys for outside sources (or store them with `keys set`) |

`knowledge/config.yaml` also holds `learning`, `literature`, `code_systems` and `identifier_patterns`.

**Running it publicly:** the refine route writes files, and so does learning. On a shared server,
either expose only `analyze` or set `DESCRIPTION_TO_ONTOLOGY_ADMIN_TOKEN`, and consider
`auto_learn: false`. The MCP HTTP transport has no built-in auth, so put it behind a reverse
proxy that adds auth. The outside sources are free public services, so don't hammer them. Each
source has its own rate limit in `sources.yaml`. The client caches results, limits concurrency and
retries with backoff. A lookup that still fails is reported as a warning and the run is flagged for
review, so a failure never looks like "no such term".

## Contributing

The quickest way to help is a pull request that adds a worked example to
[`knowledge/examples/`](knowledge/examples/), a rule to `guidelines.yaml`, a code system or
identifier pattern to `config.yaml`, or a source to `sources.yaml`. See [CONTRIBUTING.md](CONTRIBUTING.md).

```bash
pip install -e ".[dev]"
pytest -m "not live"      # offline: every outside service and Claude are faked
pytest -m live            # hits the real services
```

## Limitations

- **Not for clinical use.** The answers are machine-generated and can be wrong. Use the review
  queue: anything below `review_threshold`, ungrounded, dropped or obsolete is flagged.
- Medical codes are only as complete as the sources' cross-references. MONDO maps many diseases
  to OMIM, Orphanet, MeSH, UMLS, ICD and SNOMED CT, but not all of them. An ICD-10 sub-code may only
  match its parent, and the answer says so when it does.
- OLS search needs every word of a query to match, so "thyroid hormone synthesis" doesn't find GO's
  "thyroid hormone generation". The reading step is asked to give alternative queries, and outside
  helpers such as Reactome cover some of the gap. Some general concepts (for example "cardiac
  arrhythmia" as a disease) have no single MONDO term.
- Literature connections come from text mining. Two entities can co-occur for many reasons.
  PubTator3's text annotator sometimes picks an unexpected species for a gene (it uses context).
- The PubTator3 text annotator is queued and often takes a minute or two.
- Outside helpers are only as current as their services. If one fails, the failure is noted and the core
  search still runs. `pytest -m live` checks that each still answers the way its adapter expects.
- The bundled examples are a starting point, not a gold standard.

---

## Sources and citations

This project stands on the work below. If you use description-to-ontology-plus-mcp in published
work, **please cite the sources you relied on** as well as this repository. Licences and terms are
summarised here; the source's own page is authoritative.

### Ontologies (searched live through OLS)

| Ontology | Used for | Cite | Licence |
|---|---|---|---|
| **MONDO** (Mondo Disease Ontology) | diseases; source of the disease medical-code cross-references | Vasilevsky NA et al. (2026) *Genetics* 232(4):iyaf215. [doi:10.1093/genetics/iyaf215](https://doi.org/10.1093/genetics/iyaf215) | CC BY 4.0 |
| **DO** (Human Disease Ontology) | diseases, MONDO ⇄ DOID | Baron JA et al. (2026) *Nucleic Acids Res* 54(D1):D1425–D1436. [doi:10.1093/nar/gkaf1213](https://doi.org/10.1093/nar/gkaf1213) | CC0 1.0 |
| **GO** (Gene Ontology) | functions, processes, cell locations | Ashburner M et al. (2000) *Nat Genet* 25(1):25–29. [doi:10.1038/75556](https://doi.org/10.1038/75556); The Gene Ontology Consortium (2026) *Nucleic Acids Res* 54(D1):D1779–D1792. [doi:10.1093/nar/gkaf1292](https://doi.org/10.1093/nar/gkaf1292) (correction [doi:10.1093/nar/gkag678](https://doi.org/10.1093/nar/gkag678)) | CC BY 4.0; please report the GO release used |
| **HPO** (Human Phenotype Ontology) | human phenotypes | Gargano MA et al. (2024) *Nucleic Acids Res* 52(D1):D1333–D1346. [doi:10.1093/nar/gkad1005](https://doi.org/10.1093/nar/gkad1005) | HPO licence: free to use with attribution and the version shown; do not modify the ontology |
| **MP** (Mammalian Phenotype Ontology) | mouse and other mammalian phenotypes | Bello SM et al. (2025) *Dis Model Mech* 18(10):dmm052385. [doi:10.1242/dmm.052385](https://doi.org/10.1242/dmm.052385); Smith CL, Eppig JT (2012) *Mamm Genome* 23(9–10):653–668. [doi:10.1007/s00335-012-9421-3](https://doi.org/10.1007/s00335-012-9421-3) | CC BY 4.0 |
| **Uberon** | tissues and anatomy | Mungall CJ et al. (2012) *Genome Biol* 13(1):R5. [doi:10.1186/gb-2012-13-1-r5](https://doi.org/10.1186/gb-2012-13-1-r5); Haendel MA et al. (2014) *J Biomed Semantics* 5:21. [doi:10.1186/2041-1480-5-21](https://doi.org/10.1186/2041-1480-5-21) | CC BY 3.0 |
| **CL** (Cell Ontology) | cell types | Tan SZK et al. (2026) *Sci Data* 13(1):946. [doi:10.1038/s41597-026-07173-8](https://doi.org/10.1038/s41597-026-07173-8); Diehl AD et al. (2016) *J Biomed Semantics* 7(1):44. [doi:10.1186/s13326-016-0088-7](https://doi.org/10.1186/s13326-016-0088-7) | CC BY 4.0 |
| **ChEBI** | chemicals | Malik A et al. (2026) *Nucleic Acids Res* 54(D1):D1768–D1778. [doi:10.1093/nar/gkaf1271](https://doi.org/10.1093/nar/gkaf1271) | CC BY 4.0 |
| **NCBI Taxonomy** | organisms | Schoch CL et al. (2020) *Database* baaa062. [doi:10.1093/database/baaa062](https://doi.org/10.1093/database/baaa062) | Public domain (US government work) |
| **BAO** (BioAssay Ontology) | assays and test methods | Glenny-Pescov J et al. (2026) *J Biomed Semantics* 17(1):6. [doi:10.1186/s13326-025-00342-5](https://doi.org/10.1186/s13326-025-00342-5); Abeyruwan S et al. (2014) *J Biomed Semantics* 5(Suppl 1):S5. [doi:10.1186/2041-1480-5-S1-S5](https://doi.org/10.1186/2041-1480-5-S1-S5) | CC BY 4.0 |
| **OBI** (Ontology for Biomedical Investigations) | assays, methods, instruments | Bandrowski A et al. (2016) *PLoS One* 11(4):e0154556. [doi:10.1371/journal.pone.0154556](https://doi.org/10.1371/journal.pone.0154556) | CC BY 4.0 |

Any other ontology you add in `config.yaml` keeps its own citation and licence.

### Services and databases queried

| Service | Used for | Cite | Terms |
|---|---|---|---|
| **EMBL-EBI Ontology Lookup Service (OLS4)** | ontology search, term details, cross-references | McLaughlin J et al. (2025) *Bioinformatics* 41(5):btaf279. [doi:10.1093/bioinformatics/btaf279](https://doi.org/10.1093/bioinformatics/btaf279) | Software Apache-2.0; [EMBL-EBI terms of use](https://www.ebi.ac.uk/about/terms-of-use) |
| **BioThings APIs**: MyGene.info, MyDisease.info, MyChem.info, MyVariant.info | genes, diseases and reverse code lookups, chemicals and CAS numbers, variants | Xin J et al. (2016) *Genome Biol* 17(1):91. [doi:10.1186/s13059-016-0953-9](https://doi.org/10.1186/s13059-016-0953-9); Lelong S et al. (2022) *Bioinformatics* 38(7):2077–2079. [doi:10.1093/bioinformatics/btac017](https://doi.org/10.1093/bioinformatics/btac017); Wu C et al. (2013) *Nucleic Acids Res* 41(D1):D561–D565. [doi:10.1093/nar/gks1114](https://doi.org/10.1093/nar/gks1114) | Scripps Research terms of use (no open licence); aggregated data keep each source's licence |
| **NCBI Gene** (via MyGene.info) | gene IDs | Brown GR et al. (2015) *Nucleic Acids Res* 43(D1):D36–D42. [doi:10.1093/nar/gku1055](https://doi.org/10.1093/nar/gku1055) | Public domain |
| **dbSNP** (via MyVariant.info) | rsIDs | Sherry ST et al. (2001) *Nucleic Acids Res* 29(1):308–311. [doi:10.1093/nar/29.1.308](https://doi.org/10.1093/nar/29.1.308) | Public domain |
| **ClinVar** (via MyVariant.info) | variant–condition links | Landrum MJ et al. (2018) *Nucleic Acids Res* 46(D1):D1062–D1067. [doi:10.1093/nar/gkx1153](https://doi.org/10.1093/nar/gkx1153) | Public domain |
| **Monarch Initiative** | diseases and phenotypes (second opinion) | Putman TE et al. (2024) *Nucleic Acids Res* 52(D1):D938–D949. [doi:10.1093/nar/gkad1082](https://doi.org/10.1093/nar/gkad1082) | Software BSD-3-Clause; data under each source's licence |
| **Reactome** | pathways | Ragueneau E et al. (2026) *Nucleic Acids Res* 54(D1):D673–D681. [doi:10.1093/nar/gkaf1223](https://doi.org/10.1093/nar/gkaf1223) | CC0 |
| **NCBI E-utilities** | NCBI Taxonomy queries | Entrez Programming Utilities Help, NCBI, [ncbi.nlm.nih.gov/books/NBK25497](https://www.ncbi.nlm.nih.gov/books/NBK25497/); Sayers EW et al. (2026) Database resources of the NCBI, *Nucleic Acids Res* 54(D1):D20–D27. [doi:10.1093/nar/gkaf1060](https://doi.org/10.1093/nar/gkaf1060) | Public domain; [NCBI usage policies](https://www.ncbi.nlm.nih.gov/home/about/policies/) |
| **PubTator3** | entity names, literature relations, example papers, text annotation | Wei CH et al. (2024) *Nucleic Acids Res* 52(W1):W540–W546. [doi:10.1093/nar/gkae235](https://doi.org/10.1093/nar/gkae235) | Public domain; at most 3 requests/second |
| **PubMed** | the papers PubTator3 links to (PMIDs) | National Library of Medicine, [pubmed.ncbi.nlm.nih.gov](https://pubmed.ncbi.nlm.nih.gov/) | Citations are public; article text keeps its publisher's copyright |
| **NCBO BioPortal** and its Annotator (optional, needs a key) | 1,000+ ontologies, text annotation | Vendetti J et al. (2025) *Nucleic Acids Res* 53(W1):W84–W94. [doi:10.1093/nar/gkaf402](https://doi.org/10.1093/nar/gkaf402); Whetzel PL et al. (2011) *Nucleic Acids Res* 39:W541–W545. [doi:10.1093/nar/gkr469](https://doi.org/10.1093/nar/gkr469); Jonquet C, Shah NH, Musen MA (2009) *Summit Transl Bioinform* 2009:56–60 ([PMID 21347171](https://pubmed.ncbi.nlm.nih.gov/21347171/)) | [BioPortal terms](https://bioportal.bioontology.org/); each ontology keeps its own licence |
| **UniProt** (optional, off by default) | protein names | The UniProt Consortium (2025) *Nucleic Acids Res* 53(D1):D609–D617. [doi:10.1093/nar/gkae1010](https://doi.org/10.1093/nar/gkae1010) | CC BY 4.0 |
| **Anthropic Claude** (optional server-side brain) | reading the text and choosing among candidates | [Anthropic API](https://docs.anthropic.com/) | [Anthropic terms](https://www.anthropic.com/legal) |

### Code systems passed through as cross-references

These identifiers are **not looked up from the code systems themselves**. They are copied from the
cross-references that MONDO, MyGene.info and MyChem.info publish, and named by `code_systems` in
`config.yaml`. They belong to their owners, and some need a licence for some uses:
[OMIM](https://www.omim.org/) (Johns Hopkins University) ·
[Orphanet](https://www.orpha.net/) (INSERM) ·
[ICD-10 / ICD-11](https://icd.who.int/) (WHO) and [ICD-10-CM / ICD-9-CM](https://www.cdc.gov/nchs/icd/) (CDC/NCHS) ·
[MeSH](https://www.nlm.nih.gov/mesh/) (NLM) ·
[UMLS](https://www.nlm.nih.gov/research/umls/) (NLM; UMLS licence) ·
[SNOMED CT](https://www.snomed.org/) (SNOMED International; affiliate licence) ·
[NCI Thesaurus](https://ncit.nci.nih.gov/) (NCI) ·
[MedDRA](https://www.meddra.org/) (ICH; subscription) ·
[MedGen](https://www.ncbi.nlm.nih.gov/medgen/) (NCBI) ·
[GARD](https://rarediseases.info.nih.gov/) (NIH NCATS) ·
[HGNC](https://www.genenames.org/) ·
[MGI](https://www.informatics.jax.org/) ·
[Ensembl](https://www.ensembl.org/) ·
[CAS Registry](https://www.cas.org/) (American Chemical Society) ·
[DrugBank](https://go.drugbank.com/) (restricted licence) ·
[PubChem](https://pubchem.ncbi.nlm.nih.gov/) ·
[KEGG](https://www.kegg.jp/) (licence for some uses) ·
[HMDB](https://hmdb.ca/) ·
[FMA](http://si.washington.edu/projects/fma).

### Standards and inspiration

- **Model Context Protocol** specification, [modelcontextprotocol.io/specification/2026-07-28](https://modelcontextprotocol.io/specification/2026-07-28).
- **RE-Place** ([re-place.be](https://www.re-place.be)), the Belgian platform for New Approach
  Methodologies coordinated by Sciensano and the Vrije Universiteit Brussel. Its way of describing
  test methods (in vitro, ex vivo, in chemico, in silico, lower-organism in vivo) inspired the
  `test-methods` guideline and the `assay` concept kind. No RE-Place content is copied or scraped.
- [OntoGPT / SPIRES](https://github.com/monarch-initiative/ontogpt) and
  [CurateGPT](https://github.com/monarch-initiative/curategpt) (Monarch Initiative), as prior work on
  LLM-assisted, ontology-grounded curation.

### Software

Built with [Python](https://www.python.org/), the [MCP Python SDK](https://github.com/modelcontextprotocol/python-sdk) (MIT),
the [Anthropic Python SDK](https://github.com/anthropics/anthropic-sdk-python) (MIT),
[FastAPI](https://fastapi.tiangolo.com/) (MIT), [Uvicorn](https://www.uvicorn.org/) (BSD-3-Clause),
[HTTPX](https://www.python-httpx.org/) (BSD-3-Clause), [Pydantic](https://docs.pydantic.dev/) (MIT),
[PyYAML](https://pyyaml.org/) (MIT) and [keyring](https://github.com/jaraco/keyring) (MIT); tested with
[pytest](https://pytest.org/) (MIT) and [RESPX](https://lundberg.github.io/respx/) (BSD-3-Clause).

### Data licences

This project's licence covers its own code and knowledge files only. **Everything it fetches stays
under its source's licence and terms**, as summarised above. In particular: BioThings APIs are
provided under Scripps Research's terms of use; HPO must not be modified and its version should be
shown; DrugBank, SNOMED CT, UMLS, MedDRA, KEGG and some ICD uses need their own licences. Check
these before you redistribute results.

## Licence

**Academic Research and Education Use Licence 1.0**: see [LICENSE](LICENSE).

- ✅ Free for non-commercial **academic research, teaching and scholarly publication** by
  individuals and non-profit academic or research institutions.
- ✅ You may modify it and share it under the same licence; cite it and the sources you used.
- ❌ **No commercial use** (companies, paid services, contract research) without separate written
  permission from the copyright holders.
- No warranty. **Not for clinical decisions.**

This is not an OSI open-source licence, because it restricts the field of use.