Skip to main content

MCP server for mapping biomedical text to standardized ontology terms

Project description

MCP Ontology Annotator

An MCP (Model Context Protocol) server for mapping biomedical text to standardized ontology terms.

Features

  • annotate_ontology_terms — Map specific terms to ontology IDs via a multi-stage pipeline:
    1. Exact label match (OLS)
    2. Synonym match (OLS)
    3. Fuzzy search (OLS)
    4. BioPortal fallback (optional, requires API key)
  • extract_and_annotate — Extract biomedical entities from free text using Claude, then annotate each entity.
  • Supports domains: disease, chemical, gene, phenotype, anatomy, organism
  • Configurable default ontologies per domain
  • Retry with exponential back-off on API failures

Requirements

  • Python 3.10+
  • uv for dependency management

Setup

# Clone the repo
git clone <repo-url>
cd mcp-ontology-annotator

# Create and activate virtual environment with uv
uv venv
source .venv/bin/activate   # Linux/macOS
# .venv\Scripts\activate    # Windows

# Install the package and dependencies
uv pip install -e ".[dev]"    # includes dev/test dependencies
# or just the runtime:
uv pip install -e .

Environment Variables

Copy .env.example to .env and fill in values:

cp .env.example .env
Variable Default Required
ANTHROPIC_API_KEY For extract_and_annotate
OLS_API_URL https://www.ebi.ac.uk/ols4/api No
BIOPORTAL_API_KEY For BioPortal fallback
BIOPORTAL_API_URL https://data.bioontology.org No
DEFAULT_DISEASE_ONTOLOGIES mondo,doid,hp No
DEFAULT_CHEMICAL_ONTOLOGIES chebi,drugbank No
DEFAULT_GENE_ONTOLOGIES hgnc,ncbigene No
DEFAULT_PHENOTYPE_ONTOLOGIES hp,mp No
DEFAULT_ANATOMY_ONTOLOGIES uberon,fma No
DEFAULT_ORGANISM_ONTOLOGIES ncbitaxon No

Running the MCP Server

# After installing with uv pip install -e .
ontology-annotator
# or
python -m ontology_annotator.server

The server communicates over stdio, as required by the MCP protocol.

Claude Desktop Configuration

Add to ~/Library/Application Support/Claude/claude_desktop_config.json (macOS):

{
  "mcpServers": {
    "ontology-annotator": {
      "command": "uv",
      "args": [
        "run",
        "--directory", "/path/to/ontology-annotator-mcp",
        "ontology-annotator"
      ],
      "env": {
        "ANTHROPIC_API_KEY": "sk-ant-...",
        "BIOPORTAL_API_KEY": ""
      }
    }
  }
}

Running Tests

pytest

Linting

ruff check src tests
ruff format src tests

Example Usage

python examples/example_usage.py

Tool Reference

annotate_ontology_terms

Parameter Type Default Description
texts string | string[] required Term(s) to annotate
domain string Biomedical domain (narrows ontology search)
preferred_ontologies string[] Override default ontologies
use_bioportal_fallback boolean true Fall back to BioPortal
min_confidence number 0.7 Minimum confidence (0–1)

extract_and_annotate

Parameter Type Default Description
text string required Natural language text
domains string[] all Entity types to extract
preferred_ontologies object Per-domain ontology preferences
use_bioportal_fallback boolean true Fall back to BioPortal
min_confidence number 0.7 Minimum confidence

Project Structure

ontology-annotator-mcp/
├── src/
│   └── ontology_annotator/
│       ├── __init__.py
│       ├── server.py           # MCP server
│       ├── annotator.py        # Multi-stage annotation pipeline
│       ├── extractor.py        # LLM entity extraction
│       ├── ols_client.py       # OLS4 API client
│       ├── bioportal_client.py # BioPortal API client (optional)
│       └── config.py           # Settings via env vars
├── tests/
│   └── test_annotator.py
├── examples/
│   └── example_usage.py
├── pyproject.toml
├── .env.example
└── README.md

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_ontology_annotator-0.1.0.tar.gz (78.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_ontology_annotator-0.1.0-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

Details for the file mcp_ontology_annotator-0.1.0.tar.gz.

File metadata

  • Download URL: mcp_ontology_annotator-0.1.0.tar.gz
  • Upload date:
  • Size: 78.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for mcp_ontology_annotator-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9c59a4579143e2ef9fce1fea5909f974853a76ccba2c9f72801f08e2446214ef
MD5 80d7a29defa521d191e8f8995417471e
BLAKE2b-256 bf28c7a7c08db9bf3cd4380833d30fe8913813b3dbc8294157234840924f4095

See more details on using hashes here.

File details

Details for the file mcp_ontology_annotator-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mcp_ontology_annotator-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d28c5b3fecfd1a0b5fa0cc610322d60f50c48b3430d6f72eef55e5c0bc3a3a41
MD5 658fafca457a70725d8e8d33f0e00c01
BLAKE2b-256 2b5c3819653dbfecdd45eb09f07358c056c0d437b36a77eb70249de1cea51a02

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page