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:- Exact label match (OLS)
- Synonym match (OLS)
- Fuzzy search (OLS)
- 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
Metadata
Release files for mcp-ontology-annotator 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mcp_ontology_annotator-0.1.0.tar.gz | 78.9 kB | Without provenance | Details for mcp_ontology_annotator-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mcp_ontology_annotator-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for mcp_ontology_annotator-0.1.0-py3-none-any.whl |
Total release size: 93.7 kB
Release files / mcp_ontology_annotator-0.1.0.tar.gz
| Download URL | mcp_ontology_annotator-0.1.0.tar.gz |
|---|---|
| Size | 78.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9c59a4579143e2ef9fce1fea5909f974853a76ccba2c9f72801f08e2446214ef
|
|
BLAKE2b-256 checksum How to use checksums |
bf28c7a7c08db9bf3cd4380833d30fe8913813b3dbc8294157234840924f4095
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.5
|
Release files / mcp_ontology_annotator-0.1.0-py3-none-any.whl
| Download URL | mcp_ontology_annotator-0.1.0-py3-none-any.whl |
|---|---|
| Size | 14.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d28c5b3fecfd1a0b5fa0cc610322d60f50c48b3430d6f72eef55e5c0bc3a3a41
|
|
BLAKE2b-256 checksum How to use checksums |
2b5c3819653dbfecdd45eb09f07358c056c0d437b36a77eb70249de1cea51a02
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.5
|
Security for mcp-ontology-annotator 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.