opentargets-mcp 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- opentargets_mcp-0.1.0/LICENSE +21 -0
- opentargets_mcp-0.1.0/PKG-INFO +217 -0
- opentargets_mcp-0.1.0/README.md +186 -0
- opentargets_mcp-0.1.0/pyproject.toml +47 -0
- opentargets_mcp-0.1.0/setup.cfg +4 -0
- opentargets_mcp-0.1.0/src/opentargets_mcp/__init__.py +3 -0
- opentargets_mcp-0.1.0/src/opentargets_mcp/queries.py +116 -0
- opentargets_mcp-0.1.0/src/opentargets_mcp/server.py +141 -0
- opentargets_mcp-0.1.0/src/opentargets_mcp/tools/__init__.py +55 -0
- opentargets_mcp-0.1.0/src/opentargets_mcp/tools/disease.py +180 -0
- opentargets_mcp-0.1.0/src/opentargets_mcp/tools/drug/__init__.py +31 -0
- opentargets_mcp-0.1.0/src/opentargets_mcp/tools/drug/associations.py +82 -0
- opentargets_mcp-0.1.0/src/opentargets_mcp/tools/drug/identity.py +118 -0
- opentargets_mcp-0.1.0/src/opentargets_mcp/tools/drug/safety.py +125 -0
- opentargets_mcp-0.1.0/src/opentargets_mcp/tools/evidence.py +174 -0
- opentargets_mcp-0.1.0/src/opentargets_mcp/tools/meta.py +188 -0
- opentargets_mcp-0.1.0/src/opentargets_mcp/tools/search.py +287 -0
- opentargets_mcp-0.1.0/src/opentargets_mcp/tools/study.py +319 -0
- opentargets_mcp-0.1.0/src/opentargets_mcp/tools/target/__init__.py +34 -0
- opentargets_mcp-0.1.0/src/opentargets_mcp/tools/target/associations.py +167 -0
- opentargets_mcp-0.1.0/src/opentargets_mcp/tools/target/biology.py +342 -0
- opentargets_mcp-0.1.0/src/opentargets_mcp/tools/target/identity.py +94 -0
- opentargets_mcp-0.1.0/src/opentargets_mcp/tools/target/safety.py +159 -0
- opentargets_mcp-0.1.0/src/opentargets_mcp/tools/variant.py +325 -0
- opentargets_mcp-0.1.0/src/opentargets_mcp.egg-info/PKG-INFO +217 -0
- opentargets_mcp-0.1.0/src/opentargets_mcp.egg-info/SOURCES.txt +36 -0
- opentargets_mcp-0.1.0/src/opentargets_mcp.egg-info/dependency_links.txt +1 -0
- opentargets_mcp-0.1.0/src/opentargets_mcp.egg-info/entry_points.txt +2 -0
- opentargets_mcp-0.1.0/src/opentargets_mcp.egg-info/requires.txt +9 -0
- opentargets_mcp-0.1.0/src/opentargets_mcp.egg-info/top_level.txt +1 -0
- opentargets_mcp-0.1.0/tests/test_disease_tools.py +40 -0
- opentargets_mcp-0.1.0/tests/test_drug_tools.py +64 -0
- opentargets_mcp-0.1.0/tests/test_evidence_tools.py +28 -0
- opentargets_mcp-0.1.0/tests/test_meta_tools.py +50 -0
- opentargets_mcp-0.1.0/tests/test_search_tools.py +86 -0
- opentargets_mcp-0.1.0/tests/test_study_tools.py +45 -0
- opentargets_mcp-0.1.0/tests/test_target_tools.py +158 -0
- opentargets_mcp-0.1.0/tests/test_variant_tools.py +46 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Nick Ren
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: opentargets-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: MCP server for Open Targets Platform biomedical data access
|
|
5
|
+
Author: Nick Ren
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/nickzren/opentargets-mcp
|
|
8
|
+
Project-URL: Repository, https://github.com/nickzren/opentargets-mcp
|
|
9
|
+
Project-URL: Documentation, https://github.com/nickzren/opentargets-mcp#readme
|
|
10
|
+
Keywords: mcp,open-targets,biomedical,drug-discovery,genetics
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
|
|
18
|
+
Requires-Python: >=3.12
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: mcp
|
|
22
|
+
Requires-Dist: aiohttp
|
|
23
|
+
Requires-Dist: pytest
|
|
24
|
+
Requires-Dist: pytest-asyncio
|
|
25
|
+
Requires-Dist: black
|
|
26
|
+
Requires-Dist: ruff
|
|
27
|
+
Requires-Dist: openai
|
|
28
|
+
Requires-Dist: python-dotenv
|
|
29
|
+
Requires-Dist: thefuzz
|
|
30
|
+
Dynamic: license-file
|
|
31
|
+
|
|
32
|
+
# Open Targets MCP Server
|
|
33
|
+
|
|
34
|
+
[](https://github.com/nickzren/opentargets-mcp/actions/workflows/ci.yml)
|
|
35
|
+
[](https://www.python.org/)
|
|
36
|
+
[](https://github.com/modelcontextprotocol)
|
|
37
|
+
[](https://platform.opentargets.org/)
|
|
38
|
+
[](LICENSE)
|
|
39
|
+
[](tests/)
|
|
40
|
+
[](README.md)
|
|
41
|
+
|
|
42
|
+
A Model Context Protocol (MCP) server that exposes the Open Targets Platform GraphQL API as a set of tools for use with Claude Desktop and other MCP-compatible clients.
|
|
43
|
+
|
|
44
|
+
<!-- mcp-name: io.github.nickzren/opentargets -->
|
|
45
|
+
|
|
46
|
+
## Quick Install
|
|
47
|
+
|
|
48
|
+
### For Claude Desktop
|
|
49
|
+
|
|
50
|
+
#### Option 1: Using MCPM (Recommended)
|
|
51
|
+
```bash
|
|
52
|
+
# Install mcpm package manager
|
|
53
|
+
pip install mcpm
|
|
54
|
+
|
|
55
|
+
# Install the server
|
|
56
|
+
mcpm install opentargets
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
#### Option 2: Manual Setup
|
|
60
|
+
```bash
|
|
61
|
+
# Clone and setup
|
|
62
|
+
git clone https://github.com/nickzren/opentargets-mcp
|
|
63
|
+
cd opentargets-mcp
|
|
64
|
+
pip install uv
|
|
65
|
+
uv sync
|
|
66
|
+
|
|
67
|
+
# Import to Claude Desktop
|
|
68
|
+
mcpm import stdio opentargets \
|
|
69
|
+
--command "$(uv run which python)" \
|
|
70
|
+
--args "-m opentargets_mcp.server"
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Then restart Claude Desktop to start using the Open Targets tools.
|
|
74
|
+
|
|
75
|
+
### For Other MCP Clients
|
|
76
|
+
```bash
|
|
77
|
+
git clone https://github.com/nickzren/opentargets-mcp
|
|
78
|
+
cd opentargets-mcp
|
|
79
|
+
pip install uv
|
|
80
|
+
uv sync
|
|
81
|
+
|
|
82
|
+
# Option 1: Use the simple runner script (thin wrapper around uv run)
|
|
83
|
+
./run.sh
|
|
84
|
+
|
|
85
|
+
# Option 2: Run directly
|
|
86
|
+
uv run python -m opentargets_mcp.server
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Features
|
|
90
|
+
|
|
91
|
+
### Core Capabilities
|
|
92
|
+
|
|
93
|
+
- **Target Analysis**: Search genes/proteins by Ensembl ID or symbol. Access expression data, genetic constraints, pathways, protein interactions, safety profiles, and mouse phenotypes
|
|
94
|
+
- **Disease Analysis**: Query diseases by EFO ID. Find associated targets, phenotypes (HPO), and research projects
|
|
95
|
+
- **Drug Discovery**: Search drugs by ChEMBL ID. Access safety data, adverse events, indications, and mechanism of action
|
|
96
|
+
- **Evidence Mining**: Explore target-disease associations with scored evidence from multiple sources
|
|
97
|
+
- **Variant Analysis**: Query genetic variants, GWAS credible sets, and pharmacogenomics data
|
|
98
|
+
- **Study Exploration**: Access GWAS studies with L2G predictions and fine-mapped loci
|
|
99
|
+
- **Smart Search**: Entity resolution with synonym handling, autocomplete, and ID mapping
|
|
100
|
+
|
|
101
|
+
### Data Sources
|
|
102
|
+
|
|
103
|
+
The Open Targets Platform integrates evidence from 22+ primary data sources:
|
|
104
|
+
|
|
105
|
+
- **Genetics**: Open Targets Genetics, ClinVar, UK Biobank, FinnGen, Gene2Phenotype, Orphanet, COSMIC
|
|
106
|
+
- **Functional**: CRISPR screens, DepMap, GeneBass
|
|
107
|
+
- **Drugs**: ChEMBL, FDA/EMA approvals, chemical probes
|
|
108
|
+
- **Expression**: GTEx, Human Protein Atlas, Expression Atlas
|
|
109
|
+
- **Pathways**: Reactome, Signor, IntAct
|
|
110
|
+
- **Literature**: Europe PMC text mining
|
|
111
|
+
- **Safety**: FAERS, pharmacogenomics data
|
|
112
|
+
- **Models**: Mouse (MGI, IMPC) phenotypes
|
|
113
|
+
|
|
114
|
+
## Architecture
|
|
115
|
+
|
|
116
|
+
```mermaid
|
|
117
|
+
graph LR
|
|
118
|
+
subgraph "Clients"
|
|
119
|
+
A[Claude Desktop]
|
|
120
|
+
B[Python Scripts]
|
|
121
|
+
C[AI Agents]
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
subgraph "MCP Server"
|
|
125
|
+
D[Open Targets<br/>MCP Server]
|
|
126
|
+
E[Tool Categories<br/>Target • Disease • Drug<br/>Evidence • Search • Variant • Study]
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
subgraph "Open Targets"
|
|
130
|
+
F[GraphQL API]
|
|
131
|
+
G[22+ Data Sources]
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
A <-->|MCP Protocol| D
|
|
135
|
+
B <-->|Direct API| D
|
|
136
|
+
C <-->|Function Calls| D
|
|
137
|
+
D <-->|GraphQL| F
|
|
138
|
+
F <--> G
|
|
139
|
+
|
|
140
|
+
E --> D
|
|
141
|
+
|
|
142
|
+
style D fill:#e1f5fe
|
|
143
|
+
style F fill:#fff3e0
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
The MCP server acts as a bridge between client applications and the Open Targets Platform. It translates tool calls into GraphQL queries and provides structured access to biomedical data from 22+ integrated sources.
|
|
147
|
+
|
|
148
|
+
## Prerequisites
|
|
149
|
+
|
|
150
|
+
- Python 3.12+ with pip
|
|
151
|
+
|
|
152
|
+
## Usage
|
|
153
|
+
|
|
154
|
+
### Running the Server Standalone
|
|
155
|
+
```bash
|
|
156
|
+
# Using the convenience script (automatically handles uv setup)
|
|
157
|
+
./run.sh
|
|
158
|
+
|
|
159
|
+
# Or run directly with uv
|
|
160
|
+
uv run python -m opentargets_mcp.server
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Example Scripts
|
|
164
|
+
```bash
|
|
165
|
+
uv run python examples/target_validation_profile.py EGFR
|
|
166
|
+
uv run python examples/disease_to_drug.py "schizophrenia"
|
|
167
|
+
uv run python examples/drug_safety_profile.py "osimertinib"
|
|
168
|
+
uv run python examples/genetic_target_prioritization.py "inflammatory bowel disease"
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### AI Agent Example
|
|
172
|
+
|
|
173
|
+
The ReAct Agent provides an interactive terminal interface for exploring Open Targets data:
|
|
174
|
+
|
|
175
|
+

|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
# Create .env file with your OpenAI API key
|
|
179
|
+
echo "OPENAI_API_KEY=your_key_here" > .env
|
|
180
|
+
|
|
181
|
+
# Run agent
|
|
182
|
+
uv run python examples/react_agent.py
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
The agent uses a ReAct (Reasoning and Acting) pattern to break down complex biomedical queries into steps, making it easy to explore drug targets, diseases, and their relationships.
|
|
186
|
+
|
|
187
|
+
## Available Tools
|
|
188
|
+
|
|
189
|
+
The server wraps **45** GraphQL operations from the [Open Targets Platform](https://platform-docs.opentargets.org/). Every tool returns structured JSON that mirrors the official schema, and you can inspect the full machine-readable list with the MCP `list_tools` request.
|
|
190
|
+
|
|
191
|
+
### Quick-start shortcuts
|
|
192
|
+
- `get_target_info` – Core target identity record (Ensembl IDs, synonyms, genomic coordinates)
|
|
193
|
+
- `get_disease_info` – Disease/EFO summary with therapeutic area context
|
|
194
|
+
- `get_drug_info` – ChEMBL-backed drug profile and mechanism data
|
|
195
|
+
- `search_entities` – Unified entity search with synonym handling
|
|
196
|
+
- `get_target_associated_diseases` – High-confidence target-disease links with scores
|
|
197
|
+
- `get_disease_associated_targets` – Prioritised target list for an EFO disease
|
|
198
|
+
- `get_target_known_drugs` – Approved and investigational agents for a target
|
|
199
|
+
- `get_target_disease_evidence` – Evidence details across genetics, expression, and literature
|
|
200
|
+
|
|
201
|
+
### Full catalog by category
|
|
202
|
+
- **Target identity & biology (20 tools)** — `get_target_info`, `get_target_class`, `get_target_alternative_genes`, `get_target_associated_diseases`, `get_target_known_drugs`, `get_target_literature_occurrences`, `get_target_expression`, `get_target_pathways_and_go_terms`, `get_target_homologues`, `get_target_subcellular_locations`, `get_target_genetic_constraint`, `get_target_mouse_phenotypes`, `get_target_hallmarks`, `get_target_depmap_essentiality`, `get_target_interactions`, `get_target_safety_information`, `get_target_tractability`, `get_target_chemical_probes`, `get_target_tep`, `get_target_prioritization`.
|
|
203
|
+
- **Disease analytics (4 tools)** — `get_disease_info`, `get_disease_associated_targets`, `get_disease_phenotypes`, `get_disease_otar_projects`.
|
|
204
|
+
- **Drug profiling (7 tools)** — `get_drug_info`, `get_drug_cross_references`, `get_drug_linked_diseases`, `get_drug_linked_targets`, `get_drug_adverse_events`, `get_drug_pharmacovigilance`, `get_drug_warnings`.
|
|
205
|
+
- **Evidence synthesis (2 tools)** — `get_target_disease_evidence`, `get_target_disease_biomarkers`.
|
|
206
|
+
- **Search & discovery (4 tools)** — `search_entities`, `search_suggestions`, `get_similar_targets`, `search_facets`.
|
|
207
|
+
- **Variant interpretation (4 tools)** — `get_variant_info`, `get_variant_credible_sets`, `get_variant_pharmacogenomics`, `get_variant_evidences`.
|
|
208
|
+
- **Study exploration (4 tools)** — `get_study_info`, `get_studies_by_disease`, `get_study_credible_sets`, `get_credible_set_by_id`.
|
|
209
|
+
|
|
210
|
+
Each grouping matches the data domains described in the Open Targets docs (targets, diseases, drugs, evidence, variants, and studies). For high-volume workloads, respect the platform's throttling guidance from the official API FAQ and cache downstream where possible.
|
|
211
|
+
|
|
212
|
+
## Development
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
# Run tests
|
|
216
|
+
uv run pytest tests/ -v
|
|
217
|
+
```
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# Open Targets MCP Server
|
|
2
|
+
|
|
3
|
+
[](https://github.com/nickzren/opentargets-mcp/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.python.org/)
|
|
5
|
+
[](https://github.com/modelcontextprotocol)
|
|
6
|
+
[](https://platform.opentargets.org/)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
[](tests/)
|
|
9
|
+
[](README.md)
|
|
10
|
+
|
|
11
|
+
A Model Context Protocol (MCP) server that exposes the Open Targets Platform GraphQL API as a set of tools for use with Claude Desktop and other MCP-compatible clients.
|
|
12
|
+
|
|
13
|
+
<!-- mcp-name: io.github.nickzren/opentargets -->
|
|
14
|
+
|
|
15
|
+
## Quick Install
|
|
16
|
+
|
|
17
|
+
### For Claude Desktop
|
|
18
|
+
|
|
19
|
+
#### Option 1: Using MCPM (Recommended)
|
|
20
|
+
```bash
|
|
21
|
+
# Install mcpm package manager
|
|
22
|
+
pip install mcpm
|
|
23
|
+
|
|
24
|
+
# Install the server
|
|
25
|
+
mcpm install opentargets
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
#### Option 2: Manual Setup
|
|
29
|
+
```bash
|
|
30
|
+
# Clone and setup
|
|
31
|
+
git clone https://github.com/nickzren/opentargets-mcp
|
|
32
|
+
cd opentargets-mcp
|
|
33
|
+
pip install uv
|
|
34
|
+
uv sync
|
|
35
|
+
|
|
36
|
+
# Import to Claude Desktop
|
|
37
|
+
mcpm import stdio opentargets \
|
|
38
|
+
--command "$(uv run which python)" \
|
|
39
|
+
--args "-m opentargets_mcp.server"
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Then restart Claude Desktop to start using the Open Targets tools.
|
|
43
|
+
|
|
44
|
+
### For Other MCP Clients
|
|
45
|
+
```bash
|
|
46
|
+
git clone https://github.com/nickzren/opentargets-mcp
|
|
47
|
+
cd opentargets-mcp
|
|
48
|
+
pip install uv
|
|
49
|
+
uv sync
|
|
50
|
+
|
|
51
|
+
# Option 1: Use the simple runner script (thin wrapper around uv run)
|
|
52
|
+
./run.sh
|
|
53
|
+
|
|
54
|
+
# Option 2: Run directly
|
|
55
|
+
uv run python -m opentargets_mcp.server
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Features
|
|
59
|
+
|
|
60
|
+
### Core Capabilities
|
|
61
|
+
|
|
62
|
+
- **Target Analysis**: Search genes/proteins by Ensembl ID or symbol. Access expression data, genetic constraints, pathways, protein interactions, safety profiles, and mouse phenotypes
|
|
63
|
+
- **Disease Analysis**: Query diseases by EFO ID. Find associated targets, phenotypes (HPO), and research projects
|
|
64
|
+
- **Drug Discovery**: Search drugs by ChEMBL ID. Access safety data, adverse events, indications, and mechanism of action
|
|
65
|
+
- **Evidence Mining**: Explore target-disease associations with scored evidence from multiple sources
|
|
66
|
+
- **Variant Analysis**: Query genetic variants, GWAS credible sets, and pharmacogenomics data
|
|
67
|
+
- **Study Exploration**: Access GWAS studies with L2G predictions and fine-mapped loci
|
|
68
|
+
- **Smart Search**: Entity resolution with synonym handling, autocomplete, and ID mapping
|
|
69
|
+
|
|
70
|
+
### Data Sources
|
|
71
|
+
|
|
72
|
+
The Open Targets Platform integrates evidence from 22+ primary data sources:
|
|
73
|
+
|
|
74
|
+
- **Genetics**: Open Targets Genetics, ClinVar, UK Biobank, FinnGen, Gene2Phenotype, Orphanet, COSMIC
|
|
75
|
+
- **Functional**: CRISPR screens, DepMap, GeneBass
|
|
76
|
+
- **Drugs**: ChEMBL, FDA/EMA approvals, chemical probes
|
|
77
|
+
- **Expression**: GTEx, Human Protein Atlas, Expression Atlas
|
|
78
|
+
- **Pathways**: Reactome, Signor, IntAct
|
|
79
|
+
- **Literature**: Europe PMC text mining
|
|
80
|
+
- **Safety**: FAERS, pharmacogenomics data
|
|
81
|
+
- **Models**: Mouse (MGI, IMPC) phenotypes
|
|
82
|
+
|
|
83
|
+
## Architecture
|
|
84
|
+
|
|
85
|
+
```mermaid
|
|
86
|
+
graph LR
|
|
87
|
+
subgraph "Clients"
|
|
88
|
+
A[Claude Desktop]
|
|
89
|
+
B[Python Scripts]
|
|
90
|
+
C[AI Agents]
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
subgraph "MCP Server"
|
|
94
|
+
D[Open Targets<br/>MCP Server]
|
|
95
|
+
E[Tool Categories<br/>Target • Disease • Drug<br/>Evidence • Search • Variant • Study]
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
subgraph "Open Targets"
|
|
99
|
+
F[GraphQL API]
|
|
100
|
+
G[22+ Data Sources]
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
A <-->|MCP Protocol| D
|
|
104
|
+
B <-->|Direct API| D
|
|
105
|
+
C <-->|Function Calls| D
|
|
106
|
+
D <-->|GraphQL| F
|
|
107
|
+
F <--> G
|
|
108
|
+
|
|
109
|
+
E --> D
|
|
110
|
+
|
|
111
|
+
style D fill:#e1f5fe
|
|
112
|
+
style F fill:#fff3e0
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
The MCP server acts as a bridge between client applications and the Open Targets Platform. It translates tool calls into GraphQL queries and provides structured access to biomedical data from 22+ integrated sources.
|
|
116
|
+
|
|
117
|
+
## Prerequisites
|
|
118
|
+
|
|
119
|
+
- Python 3.12+ with pip
|
|
120
|
+
|
|
121
|
+
## Usage
|
|
122
|
+
|
|
123
|
+
### Running the Server Standalone
|
|
124
|
+
```bash
|
|
125
|
+
# Using the convenience script (automatically handles uv setup)
|
|
126
|
+
./run.sh
|
|
127
|
+
|
|
128
|
+
# Or run directly with uv
|
|
129
|
+
uv run python -m opentargets_mcp.server
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Example Scripts
|
|
133
|
+
```bash
|
|
134
|
+
uv run python examples/target_validation_profile.py EGFR
|
|
135
|
+
uv run python examples/disease_to_drug.py "schizophrenia"
|
|
136
|
+
uv run python examples/drug_safety_profile.py "osimertinib"
|
|
137
|
+
uv run python examples/genetic_target_prioritization.py "inflammatory bowel disease"
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### AI Agent Example
|
|
141
|
+
|
|
142
|
+
The ReAct Agent provides an interactive terminal interface for exploring Open Targets data:
|
|
143
|
+
|
|
144
|
+

|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
# Create .env file with your OpenAI API key
|
|
148
|
+
echo "OPENAI_API_KEY=your_key_here" > .env
|
|
149
|
+
|
|
150
|
+
# Run agent
|
|
151
|
+
uv run python examples/react_agent.py
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
The agent uses a ReAct (Reasoning and Acting) pattern to break down complex biomedical queries into steps, making it easy to explore drug targets, diseases, and their relationships.
|
|
155
|
+
|
|
156
|
+
## Available Tools
|
|
157
|
+
|
|
158
|
+
The server wraps **45** GraphQL operations from the [Open Targets Platform](https://platform-docs.opentargets.org/). Every tool returns structured JSON that mirrors the official schema, and you can inspect the full machine-readable list with the MCP `list_tools` request.
|
|
159
|
+
|
|
160
|
+
### Quick-start shortcuts
|
|
161
|
+
- `get_target_info` – Core target identity record (Ensembl IDs, synonyms, genomic coordinates)
|
|
162
|
+
- `get_disease_info` – Disease/EFO summary with therapeutic area context
|
|
163
|
+
- `get_drug_info` – ChEMBL-backed drug profile and mechanism data
|
|
164
|
+
- `search_entities` – Unified entity search with synonym handling
|
|
165
|
+
- `get_target_associated_diseases` – High-confidence target-disease links with scores
|
|
166
|
+
- `get_disease_associated_targets` – Prioritised target list for an EFO disease
|
|
167
|
+
- `get_target_known_drugs` – Approved and investigational agents for a target
|
|
168
|
+
- `get_target_disease_evidence` – Evidence details across genetics, expression, and literature
|
|
169
|
+
|
|
170
|
+
### Full catalog by category
|
|
171
|
+
- **Target identity & biology (20 tools)** — `get_target_info`, `get_target_class`, `get_target_alternative_genes`, `get_target_associated_diseases`, `get_target_known_drugs`, `get_target_literature_occurrences`, `get_target_expression`, `get_target_pathways_and_go_terms`, `get_target_homologues`, `get_target_subcellular_locations`, `get_target_genetic_constraint`, `get_target_mouse_phenotypes`, `get_target_hallmarks`, `get_target_depmap_essentiality`, `get_target_interactions`, `get_target_safety_information`, `get_target_tractability`, `get_target_chemical_probes`, `get_target_tep`, `get_target_prioritization`.
|
|
172
|
+
- **Disease analytics (4 tools)** — `get_disease_info`, `get_disease_associated_targets`, `get_disease_phenotypes`, `get_disease_otar_projects`.
|
|
173
|
+
- **Drug profiling (7 tools)** — `get_drug_info`, `get_drug_cross_references`, `get_drug_linked_diseases`, `get_drug_linked_targets`, `get_drug_adverse_events`, `get_drug_pharmacovigilance`, `get_drug_warnings`.
|
|
174
|
+
- **Evidence synthesis (2 tools)** — `get_target_disease_evidence`, `get_target_disease_biomarkers`.
|
|
175
|
+
- **Search & discovery (4 tools)** — `search_entities`, `search_suggestions`, `get_similar_targets`, `search_facets`.
|
|
176
|
+
- **Variant interpretation (4 tools)** — `get_variant_info`, `get_variant_credible_sets`, `get_variant_pharmacogenomics`, `get_variant_evidences`.
|
|
177
|
+
- **Study exploration (4 tools)** — `get_study_info`, `get_studies_by_disease`, `get_study_credible_sets`, `get_credible_set_by_id`.
|
|
178
|
+
|
|
179
|
+
Each grouping matches the data domains described in the Open Targets docs (targets, diseases, drugs, evidence, variants, and studies). For high-volume workloads, respect the platform's throttling guidance from the official API FAQ and cache downstream where possible.
|
|
180
|
+
|
|
181
|
+
## Development
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
# Run tests
|
|
185
|
+
uv run pytest tests/ -v
|
|
186
|
+
```
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "opentargets-mcp"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "MCP server for Open Targets Platform biomedical data access"
|
|
5
|
+
authors = [{name = "Nick Ren"}]
|
|
6
|
+
license = {text = "MIT"}
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
keywords = ["mcp", "open-targets", "biomedical", "drug-discovery", "genetics"]
|
|
9
|
+
classifiers = [
|
|
10
|
+
"Development Status :: 4 - Beta",
|
|
11
|
+
"Intended Audience :: Science/Research",
|
|
12
|
+
"License :: OSI Approved :: MIT License",
|
|
13
|
+
"Programming Language :: Python :: 3",
|
|
14
|
+
"Programming Language :: Python :: 3.12",
|
|
15
|
+
"Topic :: Scientific/Engineering :: Bio-Informatics",
|
|
16
|
+
"Topic :: Scientific/Engineering :: Medical Science Apps.",
|
|
17
|
+
]
|
|
18
|
+
requires-python = ">=3.12"
|
|
19
|
+
dependencies = [
|
|
20
|
+
"mcp",
|
|
21
|
+
"aiohttp",
|
|
22
|
+
"pytest",
|
|
23
|
+
"pytest-asyncio",
|
|
24
|
+
"black",
|
|
25
|
+
"ruff",
|
|
26
|
+
"openai",
|
|
27
|
+
"python-dotenv",
|
|
28
|
+
"thefuzz",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[project.scripts]
|
|
32
|
+
opentargets-mcp = "opentargets_mcp.server:main"
|
|
33
|
+
|
|
34
|
+
[project.urls]
|
|
35
|
+
Homepage = "https://github.com/nickzren/opentargets-mcp"
|
|
36
|
+
Repository = "https://github.com/nickzren/opentargets-mcp"
|
|
37
|
+
Documentation = "https://github.com/nickzren/opentargets-mcp#readme"
|
|
38
|
+
|
|
39
|
+
[build-system]
|
|
40
|
+
requires = ["setuptools>=61.0"]
|
|
41
|
+
build-backend = "setuptools.build_meta"
|
|
42
|
+
|
|
43
|
+
[tool.setuptools.packages.find]
|
|
44
|
+
where = ["src"]
|
|
45
|
+
|
|
46
|
+
[tool.pytest.ini_options]
|
|
47
|
+
asyncio_mode = "auto"
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# src/opentargets_mcp/queries.py
|
|
2
|
+
import aiohttp
|
|
3
|
+
import asyncio
|
|
4
|
+
from typing import Any, Dict, List, Optional
|
|
5
|
+
import time
|
|
6
|
+
import logging
|
|
7
|
+
|
|
8
|
+
# Configure basic logging for the client
|
|
9
|
+
logger = logging.getLogger(__name__)
|
|
10
|
+
# Set a default logging level if not configured elsewhere
|
|
11
|
+
if not logger.hasHandlers():
|
|
12
|
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class OpenTargetsClient:
|
|
16
|
+
"""
|
|
17
|
+
An asynchronous client for interacting with the Open Targets Platform GraphQL API.
|
|
18
|
+
Includes caching functionality to reduce redundant API calls.
|
|
19
|
+
"""
|
|
20
|
+
def __init__(self, base_url: str = "https://api.platform.opentargets.org/api/v4/graphql", cache_ttl: int = 3600):
|
|
21
|
+
"""
|
|
22
|
+
Initializes the OpenTargetsClient.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
base_url (str): The base URL for the Open Targets GraphQL API.
|
|
26
|
+
cache_ttl (int): Time-to-live for cache entries in seconds (default is 1 hour).
|
|
27
|
+
"""
|
|
28
|
+
self.base_url = base_url
|
|
29
|
+
self.session = None
|
|
30
|
+
self._cache = {}
|
|
31
|
+
self._cache_ttl = cache_ttl
|
|
32
|
+
|
|
33
|
+
async def _ensure_session(self):
|
|
34
|
+
"""Ensures an active aiohttp.ClientSession is available."""
|
|
35
|
+
if self.session is None or self.session.closed:
|
|
36
|
+
self.session = aiohttp.ClientSession()
|
|
37
|
+
|
|
38
|
+
async def _query(self, query: str, variables: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
|
39
|
+
"""
|
|
40
|
+
Executes a GraphQL query against the Open Targets API.
|
|
41
|
+
"""
|
|
42
|
+
await self._ensure_session()
|
|
43
|
+
|
|
44
|
+
cache_key = f"{query}:{str(sorted(variables.items())) if variables else ''}"
|
|
45
|
+
|
|
46
|
+
if cache_key in self._cache:
|
|
47
|
+
cached_data, timestamp = self._cache[cache_key]
|
|
48
|
+
if time.time() - timestamp < self._cache_ttl:
|
|
49
|
+
return cached_data
|
|
50
|
+
else:
|
|
51
|
+
del self._cache[cache_key]
|
|
52
|
+
|
|
53
|
+
payload = {"query": query}
|
|
54
|
+
if variables:
|
|
55
|
+
payload["variables"] = variables
|
|
56
|
+
|
|
57
|
+
response_text_for_error = "" # Variable to store response text in case of error
|
|
58
|
+
|
|
59
|
+
try:
|
|
60
|
+
async with self.session.post(
|
|
61
|
+
self.base_url,
|
|
62
|
+
json=payload,
|
|
63
|
+
headers={"Content-Type": "application/json"}
|
|
64
|
+
) as response:
|
|
65
|
+
response_text_for_error = await response.text() # Read text early for logging
|
|
66
|
+
|
|
67
|
+
if not response.ok:
|
|
68
|
+
logger.error(
|
|
69
|
+
f"HTTP Error {response.status} for {response.url}. "
|
|
70
|
+
f"Query: {query[:200]}... Variables: {variables}. "
|
|
71
|
+
f"Response Body: {response_text_for_error}"
|
|
72
|
+
)
|
|
73
|
+
response.raise_for_status() # This will now raise ClientResponseError
|
|
74
|
+
|
|
75
|
+
result = await response.json() # If .ok, this should succeed. If not .ok, raise_for_status handled it.
|
|
76
|
+
# However, response.json() might fail if body was not valid JSON even on 200.
|
|
77
|
+
|
|
78
|
+
if "errors" in result and result["errors"]:
|
|
79
|
+
logger.error(
|
|
80
|
+
f"GraphQL API errors: {result['errors']}. "
|
|
81
|
+
f"Query: {query[:200]}... Variables: {variables}."
|
|
82
|
+
)
|
|
83
|
+
# Depending on strictness, you might want to raise an exception here.
|
|
84
|
+
# For now, we return data if present, which might be partial.
|
|
85
|
+
# raise Exception(f"GraphQL API errors: {result['errors']}")
|
|
86
|
+
|
|
87
|
+
data = result.get("data", {})
|
|
88
|
+
self._cache[cache_key] = (data, time.time())
|
|
89
|
+
return data
|
|
90
|
+
|
|
91
|
+
except aiohttp.ClientResponseError as e: # Handles errors from response.raise_for_status()
|
|
92
|
+
# The response_text_for_error should have been populated above if not response.ok
|
|
93
|
+
# If it was an ok response but .json() failed, this specific exception might not have the body easily.
|
|
94
|
+
logger.error(
|
|
95
|
+
f"ClientResponseError during GraphQL query: {e}. "
|
|
96
|
+
f"URL: {e.request_info.url if e.request_info else 'N/A'}, Status: {e.status}. "
|
|
97
|
+
f"Query: {query[:200]}... Variables: {variables}. "
|
|
98
|
+
f"Response Body (if captured): {response_text_for_error}",
|
|
99
|
+
exc_info=True
|
|
100
|
+
)
|
|
101
|
+
raise Exception(f"HTTP request failed: {e.status}, {e.message}. Response: {response_text_for_error}") from e
|
|
102
|
+
|
|
103
|
+
except Exception as e: # Catch-all for other unexpected errors (e.g., JSONDecodeError if response.ok but not JSON)
|
|
104
|
+
logger.error(
|
|
105
|
+
f"An unexpected error occurred during GraphQL query: {e}. "
|
|
106
|
+
f"Query: {query[:200]}... Variables: {variables}. "
|
|
107
|
+
f"Response Body (if captured): {response_text_for_error}",
|
|
108
|
+
exc_info=True
|
|
109
|
+
)
|
|
110
|
+
raise
|
|
111
|
+
|
|
112
|
+
async def close(self):
|
|
113
|
+
"""Closes the aiohttp.ClientSession."""
|
|
114
|
+
if self.session and not self.session.closed:
|
|
115
|
+
await self.session.close()
|
|
116
|
+
self.session = None
|