aria-mcp-server 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.
- aria_mcp_server-0.1.0/.env +0 -0
- aria_mcp_server-0.1.0/.gitignore +0 -0
- aria_mcp_server-0.1.0/LICENSE +21 -0
- aria_mcp_server-0.1.0/PKG-INFO +7 -0
- aria_mcp_server-0.1.0/README.md +82 -0
- aria_mcp_server-0.1.0/aria_mcp_server/server.py +279 -0
- aria_mcp_server-0.1.0/aria_mcp_server/tools.py +311 -0
- aria_mcp_server-0.1.0/glama.json +4 -0
- aria_mcp_server-0.1.0/pyproject.toml +18 -0
- aria_mcp_server-0.1.0/requirements.txt +4 -0
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 pkotecha-eng
|
|
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,82 @@
|
|
|
1
|
+
# 🧬 ARIA Clinical Research MCP Server
|
|
2
|
+
A standalone MCP server that gives any Claude agent real-time access to biomedical literature and clinical trials — no API keys required.
|
|
3
|
+
[](https://glama.ai/mcp/servers/pkotecha-eng/aria-mcp-server)
|
|
4
|
+
## Tools
|
|
5
|
+
|
|
6
|
+
| Tool | Description |
|
|
7
|
+
|------|-------------|
|
|
8
|
+
| `search_pubmed` | Search 35M+ peer-reviewed papers via NCBI E-utilities |
|
|
9
|
+
| `search_clinical_trials` | Search 400K+ trials via ClinicalTrials.gov v2 API |
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
## Prompts
|
|
13
|
+
|
|
14
|
+
| Prompt | Description |
|
|
15
|
+
|--------|-------------|
|
|
16
|
+
| `clinical-research-brief` | Comprehensive evidence + trial brief for a condition |
|
|
17
|
+
| `adverse-event-analysis` | Structured AE and safety profile for a drug |
|
|
18
|
+
| `trial-eligibility-checker` | Patient eligibility assessment across recruiting trials |
|
|
19
|
+
|
|
20
|
+
## Resources
|
|
21
|
+
|
|
22
|
+
| Resource | Description |
|
|
23
|
+
|----------|-------------|
|
|
24
|
+
| `info://aria` | Overview of ARIA capabilities and data sources |
|
|
25
|
+
| `reference://trial-phases` | Phase I–IV definitions and FDA special designations |
|
|
26
|
+
| `reference://high-impact-journals` | Curated high-impact journals by specialty |
|
|
27
|
+
| `reference://fda-databases` | FDA databases for drug, safety, and regulatory research |
|
|
28
|
+
|
|
29
|
+
## Example queries
|
|
30
|
+
|
|
31
|
+
Once connected, ask Claude:
|
|
32
|
+
|
|
33
|
+
- "Search PubMed for ketogenic diet pediatric epilepsy outcomes"
|
|
34
|
+
- "Find recruiting trials for lung cancer immunotherapy"
|
|
35
|
+
- "What does the literature say about veliparib in ovarian cancer, and are there active trials?"
|
|
36
|
+
|
|
37
|
+
## Quickstart
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
git clone https://github.com/pkotecha-eng/aria-mcp-server
|
|
41
|
+
cd aria-mcp-server
|
|
42
|
+
pip install -r requirements.txt
|
|
43
|
+
python3 server.py
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Connect to Claude Desktop
|
|
47
|
+
|
|
48
|
+
Add to `~/Library/Application Support/Claude/claude_desktop_config.json`:
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
{
|
|
52
|
+
"mcpServers": {
|
|
53
|
+
"aria-clinical-research": {
|
|
54
|
+
"command": "python3",
|
|
55
|
+
"args": ["/absolute/path/to/aria-mcp-server/server.py"]
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Restart Claude Desktop. The server will appear under Settings → Developer → Local MCP Servers.
|
|
62
|
+
|
|
63
|
+
## Data sources
|
|
64
|
+
|
|
65
|
+
- **PubMed** — NCBI E-utilities (public API, no key required)
|
|
66
|
+
- **ClinicalTrials.gov** — v2 REST API (public API, no key required)
|
|
67
|
+
|
|
68
|
+
## Tech stack
|
|
69
|
+
|
|
70
|
+
- [FastMCP](https://gofastmcp.com) — MCP server framework
|
|
71
|
+
- Python 3.12+
|
|
72
|
+
|
|
73
|
+
## Use cases
|
|
74
|
+
|
|
75
|
+
- Life sciences researchers needing real-time literature access
|
|
76
|
+
- Clinical trial coordinators checking eligibility and recruiting status
|
|
77
|
+
- Drug discovery teams cross-referencing published evidence with active trials
|
|
78
|
+
- Any Claude agent needing grounded biomedical knowledge
|
|
79
|
+
|
|
80
|
+
## Built by
|
|
81
|
+
|
|
82
|
+
Pooja Kotecha · [dinq.me/pkotecha-eng](https://dinq.me/pkotecha-eng)
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ARIA Clinical Research MCP Server
|
|
3
|
+
|
|
4
|
+
Exposes two tools to any MCP-compatible client:
|
|
5
|
+
- search_pubmed: Search 35M+ biomedical papers via NCBI E-utilities
|
|
6
|
+
- search_clinical_trials: Search 400K+ trials via ClinicalTrials.gov v2 API
|
|
7
|
+
|
|
8
|
+
Usage:
|
|
9
|
+
python server.py # stdio (Claude Desktop)
|
|
10
|
+
python server.py --transport http # HTTP (remote clients)
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from fastmcp import FastMCP
|
|
14
|
+
from aria_mcp_server.tools import search_pubmed, search_clinical_trials, format_results_for_claude, format_trials_for_claude
|
|
15
|
+
|
|
16
|
+
mcp = FastMCP(
|
|
17
|
+
name="aria-clinical-research",
|
|
18
|
+
instructions=(
|
|
19
|
+
"ARIA provides real-time access to biomedical literature and clinical trials. "
|
|
20
|
+
"Use search_pubmed for published research, mechanisms, drug studies, and outcomes. "
|
|
21
|
+
"Use search_clinical_trials for active or completed trials, eligibility criteria, and recruiting studies. "
|
|
22
|
+
"Use both together for comprehensive clinical intelligence on any condition or intervention."
|
|
23
|
+
),
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@mcp.tool
|
|
28
|
+
def search_pubmed(
|
|
29
|
+
query: str,
|
|
30
|
+
max_results: int = 5,
|
|
31
|
+
) -> str:
|
|
32
|
+
"""
|
|
33
|
+
Search PubMed for peer-reviewed biomedical literature.
|
|
34
|
+
|
|
35
|
+
Use for: research papers, drug mechanisms, clinical outcomes, disease studies,
|
|
36
|
+
safety/efficacy data, biomarkers, diagnostics, and any scientific question.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
query: Search query (e.g. "velarixin pediatric epilepsy phase 2")
|
|
40
|
+
max_results: Number of papers to return (1-10, default 5)
|
|
41
|
+
"""
|
|
42
|
+
from aria_mcp_server.tools import search_pubmed as _search, format_results_for_claude as _fmt
|
|
43
|
+
max_results = max(1, min(max_results, 10))
|
|
44
|
+
papers = _search(query=query, max_results=max_results)
|
|
45
|
+
return _fmt(papers)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@mcp.tool
|
|
49
|
+
def search_clinical_trials(
|
|
50
|
+
condition: str,
|
|
51
|
+
status: str = "RECRUITING",
|
|
52
|
+
intervention: str = "",
|
|
53
|
+
max_results: int = 5,
|
|
54
|
+
) -> str:
|
|
55
|
+
"""
|
|
56
|
+
Search ClinicalTrials.gov for clinical studies.
|
|
57
|
+
|
|
58
|
+
Use for: active trials, recruiting studies, trial eligibility criteria,
|
|
59
|
+
phase information, sponsor details, and trial locations.
|
|
60
|
+
|
|
61
|
+
Args:
|
|
62
|
+
condition: Disease or condition (e.g. "pediatric epilepsy", "lung cancer")
|
|
63
|
+
status: Trial status — RECRUITING, COMPLETED, or ALL (default: RECRUITING)
|
|
64
|
+
intervention: Optional drug or intervention name to narrow results
|
|
65
|
+
max_results: Number of trials to return (1-10, default 5)
|
|
66
|
+
"""
|
|
67
|
+
from aria_mcp_server.tools import search_clinical_trials as _search, format_trials_for_claude as _fmt
|
|
68
|
+
max_results = max(1, min(max_results, 10))
|
|
69
|
+
trials = _search(
|
|
70
|
+
condition=condition,
|
|
71
|
+
status=status,
|
|
72
|
+
intervention=intervention,
|
|
73
|
+
max_results=max_results,
|
|
74
|
+
)
|
|
75
|
+
return _fmt(trials)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
@mcp.resource("info://aria")
|
|
79
|
+
def aria_info() -> str:
|
|
80
|
+
"""Overview of ARIA's capabilities and data sources."""
|
|
81
|
+
return """
|
|
82
|
+
ARIA Clinical Research MCP Server
|
|
83
|
+
==================================
|
|
84
|
+
Tools:
|
|
85
|
+
- search_pubmed: 35M+ papers from NCBI PubMed (no API key required)
|
|
86
|
+
- search_clinical_trials: 400K+ trials from ClinicalTrials.gov v2 (no API key required)
|
|
87
|
+
|
|
88
|
+
Best used for:
|
|
89
|
+
- Life sciences researchers needing real-time literature access
|
|
90
|
+
- Clinical trial coordinators checking eligibility and recruiting status
|
|
91
|
+
- Drug discovery teams cross-referencing published evidence with active trials
|
|
92
|
+
- Any Claude agent needing grounded biomedical knowledge
|
|
93
|
+
|
|
94
|
+
Data sources: NCBI E-utilities, ClinicalTrials.gov API v2
|
|
95
|
+
Built by: Pooja Kotecha (pkotecha-eng)
|
|
96
|
+
Portfolio: dinq.me/pkotecha-eng
|
|
97
|
+
"""
|
|
98
|
+
|
|
99
|
+
@mcp.resource("reference://trial-phases")
|
|
100
|
+
def trial_phases() -> str:
|
|
101
|
+
"""Clinical trial phase definitions and characteristics."""
|
|
102
|
+
return """
|
|
103
|
+
CLINICAL TRIAL PHASES — Reference Guide
|
|
104
|
+
========================================
|
|
105
|
+
|
|
106
|
+
PHASE I
|
|
107
|
+
Purpose: Safety, dosing, side effects
|
|
108
|
+
Participants: 20–100 healthy volunteers or patients
|
|
109
|
+
Duration: Several months
|
|
110
|
+
Key questions: Is it safe? What is the right dose?
|
|
111
|
+
|
|
112
|
+
PHASE II
|
|
113
|
+
Purpose: Efficacy and side effects
|
|
114
|
+
Participants: 100–300 patients with the condition
|
|
115
|
+
Duration: Several months to 2 years
|
|
116
|
+
Key questions: Does it work? What are the side effects?
|
|
117
|
+
|
|
118
|
+
PHASE III
|
|
119
|
+
Purpose: Efficacy vs. standard treatment, adverse reactions
|
|
120
|
+
Participants: 1,000–3,000 patients
|
|
121
|
+
Duration: 1–4 years
|
|
122
|
+
Key questions: Is it better than existing treatments?
|
|
123
|
+
Note: Required for FDA approval
|
|
124
|
+
|
|
125
|
+
PHASE IV (Post-marketing)
|
|
126
|
+
Purpose: Long-term safety and effectiveness
|
|
127
|
+
Participants: Thousands of patients in real-world settings
|
|
128
|
+
Duration: Ongoing
|
|
129
|
+
Key questions: What are the long-term effects?
|
|
130
|
+
|
|
131
|
+
SPECIAL DESIGNATIONS
|
|
132
|
+
- Breakthrough Therapy: Serious condition, preliminary evidence of substantial improvement
|
|
133
|
+
- Fast Track: Serious condition, unmet medical need
|
|
134
|
+
- Accelerated Approval: Surrogate endpoint used
|
|
135
|
+
- Priority Review: Significant improvement over available therapy
|
|
136
|
+
"""
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
@mcp.resource("reference://high-impact-journals")
|
|
140
|
+
def high_impact_journals() -> str:
|
|
141
|
+
"""Curated list of high-impact biomedical and clinical research journals."""
|
|
142
|
+
return """
|
|
143
|
+
HIGH-IMPACT CLINICAL RESEARCH JOURNALS
|
|
144
|
+
=======================================
|
|
145
|
+
|
|
146
|
+
GENERAL MEDICINE
|
|
147
|
+
- New England Journal of Medicine (NEJM) — IF ~100
|
|
148
|
+
- The Lancet — IF ~170
|
|
149
|
+
- JAMA (Journal of the American Medical Association) — IF ~120
|
|
150
|
+
- BMJ (British Medical Journal) — IF ~93
|
|
151
|
+
|
|
152
|
+
ONCOLOGY
|
|
153
|
+
- Journal of Clinical Oncology (JCO) — IF ~45
|
|
154
|
+
- Nature Cancer — IF ~23
|
|
155
|
+
- Cancer Cell — IF ~38
|
|
156
|
+
- Clinical Cancer Research — IF ~13
|
|
157
|
+
|
|
158
|
+
CARDIOLOGY
|
|
159
|
+
- Circulation — IF ~37
|
|
160
|
+
- Journal of the American College of Cardiology (JACC) — IF ~24
|
|
161
|
+
- European Heart Journal — IF ~35
|
|
162
|
+
|
|
163
|
+
NEUROLOGY
|
|
164
|
+
- Brain — IF ~15
|
|
165
|
+
- Neurology — IF ~12
|
|
166
|
+
- JAMA Neurology — IF ~29
|
|
167
|
+
|
|
168
|
+
RARE DISEASE & PEDIATRICS
|
|
169
|
+
- Orphanet Journal of Rare Diseases — IF ~4
|
|
170
|
+
- Pediatrics — IF ~8
|
|
171
|
+
- JAMA Pediatrics — IF ~26
|
|
172
|
+
|
|
173
|
+
CLINICAL TRIALS METHODOLOGY
|
|
174
|
+
- Clinical Trials — IF ~4
|
|
175
|
+
- Trials — IF ~3
|
|
176
|
+
- Contemporary Clinical Trials — IF ~3
|
|
177
|
+
|
|
178
|
+
Note: Impact factors approximate and updated annually.
|
|
179
|
+
"""
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
@mcp.resource("reference://fda-databases")
|
|
183
|
+
def fda_databases() -> str:
|
|
184
|
+
"""FDA databases and resources relevant to clinical research."""
|
|
185
|
+
return """
|
|
186
|
+
FDA DATABASES & RESOURCES FOR CLINICAL RESEARCH
|
|
187
|
+
================================================
|
|
188
|
+
|
|
189
|
+
DRUG INFORMATION
|
|
190
|
+
- Drugs@FDA: https://www.accessdata.fda.gov/scripts/cder/daf/
|
|
191
|
+
Approved drug products, labels, and approval history
|
|
192
|
+
|
|
193
|
+
- FDA Drug Shortages: https://www.accessdata.fda.gov/scripts/drugshortages/
|
|
194
|
+
Current and resolved drug shortage information
|
|
195
|
+
|
|
196
|
+
CLINICAL TRIALS & SAFETY
|
|
197
|
+
- FDA Adverse Event Reporting System (FAERS):
|
|
198
|
+
https://www.fda.gov/drugs/questions-science-research-drug-approvals/fda-adverse-event-reporting-system-faers
|
|
199
|
+
Post-market safety surveillance data
|
|
200
|
+
|
|
201
|
+
- MedWatch: https://www.fda.gov/safety/medwatch-fda-safety-information-and-adverse-event-reporting-program
|
|
202
|
+
Safety alerts and adverse event reporting
|
|
203
|
+
|
|
204
|
+
REGULATORY GUIDANCE
|
|
205
|
+
- FDA Guidance Documents: https://www.fda.gov/regulatory-information/search-fda-guidance-documents
|
|
206
|
+
ICH guidelines, GCP standards, trial design guidance
|
|
207
|
+
|
|
208
|
+
- Orphan Drug Designations: https://www.accessdata.fda.gov/scripts/opdlisting/oopd/
|
|
209
|
+
Rare disease drug designations and approvals
|
|
210
|
+
|
|
211
|
+
DEVICE & BIOLOGICS
|
|
212
|
+
- 510(k) Database: https://www.accessdata.fda.gov/scripts/cdrh/cfdocs/cfpmn/pmn.cfm
|
|
213
|
+
Medical device clearances
|
|
214
|
+
|
|
215
|
+
- BLA (Biologics License Applications): https://www.fda.gov/vaccines-blood-biologics/development-approval-process-cber
|
|
216
|
+
Biologic product approvals
|
|
217
|
+
|
|
218
|
+
BIOMARKERS & ENDPOINTS
|
|
219
|
+
- FDA Biomarker Qualification Program:
|
|
220
|
+
https://www.fda.gov/drugs/drug-development-tool-qualification-programs/biomarker-qualification-program
|
|
221
|
+
"""
|
|
222
|
+
|
|
223
|
+
@mcp.prompt("clinical-research-brief")
|
|
224
|
+
def clinical_research_brief(condition: str) -> str:
|
|
225
|
+
"""Generate a comprehensive clinical research brief for a given condition."""
|
|
226
|
+
return (
|
|
227
|
+
f"You are a senior clinical research analyst. Using your available tools, "
|
|
228
|
+
f"search for both published literature AND active clinical trials for: {condition}. "
|
|
229
|
+
f"Synthesize a structured brief with these sections:\n\n"
|
|
230
|
+
f"1. EVIDENCE BASE: Key findings from PubMed — efficacy, safety, mechanisms\n"
|
|
231
|
+
f"2. ACTIVE TRIALS: Recruiting trials with NCT IDs, phase, eligibility criteria, and locations\n"
|
|
232
|
+
f"3. EVIDENCE GAPS: What the literature doesn't yet answer that trials are investigating\n"
|
|
233
|
+
f"4. CLINICAL IMPLICATIONS: What this means for trial coordinators or researchers\n\n"
|
|
234
|
+
f"Ground every claim in retrieved data. Flag any limitations in the available evidence."
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
@mcp.prompt("adverse-event-analysis")
|
|
239
|
+
def adverse_event_analysis(drug: str, condition: str) -> str:
|
|
240
|
+
"""Analyze adverse event profile for a drug in a specific condition."""
|
|
241
|
+
return (
|
|
242
|
+
f"You are a pharmacovigilance specialist. Using PubMed, search for adverse event "
|
|
243
|
+
f"and safety data for {drug} in patients with {condition}.\n\n"
|
|
244
|
+
f"Structure your analysis as:\n"
|
|
245
|
+
f"1. COMMON ADVERSE EVENTS: Frequency and severity (Grade 1-4 where reported)\n"
|
|
246
|
+
f"2. SERIOUS/RARE EVENTS: Black box warnings, SAEs, discontinuation rates\n"
|
|
247
|
+
f"3. POPULATION-SPECIFIC RISKS: Pediatric, elderly, renal/hepatic impairment\n"
|
|
248
|
+
f"4. MONITORING RECOMMENDATIONS: What to watch for in clinical practice\n"
|
|
249
|
+
f"5. REGULATORY STATUS: Any FDA safety communications or label updates\n\n"
|
|
250
|
+
f"Cite the specific papers supporting each finding."
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
@mcp.prompt("trial-eligibility-checker")
|
|
255
|
+
def trial_eligibility_checker(condition: str, patient_profile: str) -> str:
|
|
256
|
+
"""Find and assess clinical trial eligibility for a patient profile."""
|
|
257
|
+
return (
|
|
258
|
+
f"You are a clinical trial coordinator. Search ClinicalTrials.gov for recruiting trials "
|
|
259
|
+
f"for {condition}.\n\n"
|
|
260
|
+
f"Patient profile: {patient_profile}\n\n"
|
|
261
|
+
f"For each trial found:\n"
|
|
262
|
+
f"1. STATE the NCT ID, title, phase, and sponsor\n"
|
|
263
|
+
f"2. LIST key inclusion criteria and whether this patient likely meets them\n"
|
|
264
|
+
f"3. LIST key exclusion criteria and flag any potential disqualifiers\n"
|
|
265
|
+
f"4. PROVIDE the trial location(s) and contact information if available\n"
|
|
266
|
+
f"5. RATE eligibility: Likely Eligible / Possibly Eligible / Likely Ineligible\n\n"
|
|
267
|
+
f"Always remind the user that final eligibility must be confirmed with the trial site."
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
def run():
|
|
271
|
+
import sys
|
|
272
|
+
transport = "http" if "--transport" in sys.argv and "http" in sys.argv else "stdio"
|
|
273
|
+
if transport == "http":
|
|
274
|
+
mcp.run(transport="http", port=8000)
|
|
275
|
+
else:
|
|
276
|
+
mcp.run(transport="stdio")
|
|
277
|
+
|
|
278
|
+
if __name__ == "__main__":
|
|
279
|
+
run()
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Clinical research data tools for ARIA MCP Server.
|
|
3
|
+
No API keys required — uses public NCBI and ClinicalTrials.gov APIs.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import requests
|
|
7
|
+
import xmltodict
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
# -------------------------------------------------------------------------
|
|
12
|
+
# PubMed (NCBI E-utilities)
|
|
13
|
+
# -------------------------------------------------------------------------
|
|
14
|
+
|
|
15
|
+
PUBMED_BASE = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _get_text(node: Any) -> str:
|
|
19
|
+
if node is None:
|
|
20
|
+
return ""
|
|
21
|
+
if isinstance(node, str):
|
|
22
|
+
return node.strip()
|
|
23
|
+
if isinstance(node, dict) and "#text" in node:
|
|
24
|
+
return (node["#text"] or "").strip()
|
|
25
|
+
return str(node).strip() if node else ""
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _extract_authors(author_list: Any) -> list[str]:
|
|
29
|
+
if not author_list:
|
|
30
|
+
return []
|
|
31
|
+
authors = author_list.get("Author") if isinstance(author_list, dict) else None
|
|
32
|
+
if not authors:
|
|
33
|
+
return []
|
|
34
|
+
if isinstance(authors, dict):
|
|
35
|
+
authors = [authors]
|
|
36
|
+
names = []
|
|
37
|
+
for a in authors:
|
|
38
|
+
if not isinstance(a, dict):
|
|
39
|
+
continue
|
|
40
|
+
last = _get_text(a.get("LastName"))
|
|
41
|
+
fore = _get_text(a.get("ForeName") or a.get("Initials", ""))
|
|
42
|
+
if last or fore:
|
|
43
|
+
names.append(f"{last} {fore}".strip())
|
|
44
|
+
return names
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _parse_article(article_xml: dict) -> dict | None:
|
|
48
|
+
try:
|
|
49
|
+
medline = article_xml.get("MedlineCitation") or article_xml
|
|
50
|
+
if not medline:
|
|
51
|
+
return None
|
|
52
|
+
pmid_el = medline.get("PMID")
|
|
53
|
+
pmid = _get_text(pmid_el) if isinstance(pmid_el, dict) else str(pmid_el or "").strip()
|
|
54
|
+
if not pmid:
|
|
55
|
+
return None
|
|
56
|
+
article = (medline.get("Article") or {}) if isinstance(medline, dict) else {}
|
|
57
|
+
if isinstance(article, str):
|
|
58
|
+
article = {}
|
|
59
|
+
title = _get_text(article.get("ArticleTitle"))
|
|
60
|
+
author_list = article.get("AuthorList") or {}
|
|
61
|
+
authors = _extract_authors(author_list)
|
|
62
|
+
journal = ""
|
|
63
|
+
year = ""
|
|
64
|
+
journal_el = article.get("Journal")
|
|
65
|
+
if isinstance(journal_el, dict):
|
|
66
|
+
journal = _get_text(journal_el.get("Title"))
|
|
67
|
+
issue = journal_el.get("JournalIssue") or {}
|
|
68
|
+
if isinstance(issue, dict):
|
|
69
|
+
pub_date = issue.get("PubDate") or {}
|
|
70
|
+
if isinstance(pub_date, dict):
|
|
71
|
+
year = _get_text(pub_date.get("Year"))
|
|
72
|
+
abstract_el = article.get("Abstract")
|
|
73
|
+
abstract = ""
|
|
74
|
+
if isinstance(abstract_el, dict):
|
|
75
|
+
abstract_parts = abstract_el.get("AbstractText")
|
|
76
|
+
if isinstance(abstract_parts, list):
|
|
77
|
+
abstract = " ".join(_get_text(p.get("#text") if isinstance(p, dict) else p) for p in abstract_parts)
|
|
78
|
+
elif isinstance(abstract_parts, dict):
|
|
79
|
+
abstract = _get_text(abstract_parts.get("#text") or abstract_parts)
|
|
80
|
+
else:
|
|
81
|
+
abstract = _get_text(abstract_parts)
|
|
82
|
+
else:
|
|
83
|
+
abstract = _get_text(abstract_el)
|
|
84
|
+
if len(abstract) > 500:
|
|
85
|
+
abstract = abstract[:497] + "..."
|
|
86
|
+
return {
|
|
87
|
+
"pmid": pmid,
|
|
88
|
+
"title": title,
|
|
89
|
+
"authors": authors,
|
|
90
|
+
"journal": journal,
|
|
91
|
+
"year": year,
|
|
92
|
+
"abstract": abstract,
|
|
93
|
+
"url": f"https://pubmed.ncbi.nlm.nih.gov/{pmid}/",
|
|
94
|
+
}
|
|
95
|
+
except (KeyError, TypeError, AttributeError):
|
|
96
|
+
return None
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def search_pubmed(query: str, max_results: int = 5) -> list[dict]:
|
|
100
|
+
"""Search PubMed via NCBI E-utilities. No API key required."""
|
|
101
|
+
if not query or not query.strip():
|
|
102
|
+
return []
|
|
103
|
+
query = query.strip()
|
|
104
|
+
max_results = max(1, min(max_results, 100))
|
|
105
|
+
try:
|
|
106
|
+
r = requests.get(
|
|
107
|
+
f"{PUBMED_BASE}/esearch.fcgi",
|
|
108
|
+
params={"db": "pubmed", "term": query, "retmax": max_results, "retmode": "xml"},
|
|
109
|
+
timeout=15,
|
|
110
|
+
)
|
|
111
|
+
r.raise_for_status()
|
|
112
|
+
data = xmltodict.parse(r.content)
|
|
113
|
+
except Exception as e:
|
|
114
|
+
raise RuntimeError(f"PubMed search failed: {e}") from e
|
|
115
|
+
|
|
116
|
+
id_list = (data.get("eSearchResult") or {}).get("IdList") or {}
|
|
117
|
+
id_el = id_list.get("Id") if isinstance(id_list, dict) else None
|
|
118
|
+
if not id_el:
|
|
119
|
+
return []
|
|
120
|
+
pmids = [id_el] if isinstance(id_el, str) else list(id_el)[:max_results]
|
|
121
|
+
if not pmids:
|
|
122
|
+
return []
|
|
123
|
+
|
|
124
|
+
try:
|
|
125
|
+
r2 = requests.get(
|
|
126
|
+
f"{PUBMED_BASE}/efetch.fcgi",
|
|
127
|
+
params={"db": "pubmed", "id": ",".join(pmids), "rettype": "xml"},
|
|
128
|
+
timeout=20,
|
|
129
|
+
)
|
|
130
|
+
r2.raise_for_status()
|
|
131
|
+
fetch_data = xmltodict.parse(r2.content)
|
|
132
|
+
except Exception as e:
|
|
133
|
+
raise RuntimeError(f"PubMed fetch failed: {e}") from e
|
|
134
|
+
|
|
135
|
+
root = fetch_data.get("PubmedArticleSet") or fetch_data
|
|
136
|
+
articles = root.get("PubmedArticle") or root.get("PubmedData")
|
|
137
|
+
if not articles:
|
|
138
|
+
return []
|
|
139
|
+
if isinstance(articles, dict):
|
|
140
|
+
articles = [articles]
|
|
141
|
+
return [p for p in (_parse_article(a) for a in articles) if p]
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def format_results_for_claude(results: list[dict]) -> str:
|
|
145
|
+
"""Format PubMed results as readable text."""
|
|
146
|
+
if not results:
|
|
147
|
+
return "No papers found."
|
|
148
|
+
lines = []
|
|
149
|
+
for i, paper in enumerate(results, 1):
|
|
150
|
+
authors_str = "; ".join(paper.get("authors") or [])
|
|
151
|
+
journal_year = paper.get("journal", "").strip()
|
|
152
|
+
year = paper.get("year", "").strip()
|
|
153
|
+
if journal_year and year:
|
|
154
|
+
journal_year = f"{journal_year} ({year})"
|
|
155
|
+
elif year:
|
|
156
|
+
journal_year = year
|
|
157
|
+
lines.append("\n".join([
|
|
158
|
+
f"[Paper {i}]",
|
|
159
|
+
f"Title: {paper.get('title') or 'N/A'}",
|
|
160
|
+
f"Authors: {authors_str or 'N/A'}",
|
|
161
|
+
f"Journal/Year: {journal_year or 'N/A'}",
|
|
162
|
+
f"Abstract: {paper.get('abstract') or 'N/A'}",
|
|
163
|
+
f"URL: {paper.get('url') or 'N/A'}",
|
|
164
|
+
"",
|
|
165
|
+
]))
|
|
166
|
+
return "\n".join(lines).strip()
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
# -------------------------------------------------------------------------
|
|
170
|
+
# ClinicalTrials.gov v2 API
|
|
171
|
+
# -------------------------------------------------------------------------
|
|
172
|
+
|
|
173
|
+
CT_BASE = "https://clinicaltrials.gov/api/v2/studies"
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def _ct_get(d: Any, *keys, default: str = "") -> str:
|
|
177
|
+
for key in keys:
|
|
178
|
+
if not isinstance(d, dict):
|
|
179
|
+
return default
|
|
180
|
+
d = d.get(key)
|
|
181
|
+
if d is None:
|
|
182
|
+
return default
|
|
183
|
+
if isinstance(d, list):
|
|
184
|
+
return "; ".join(str(i) for i in d if i)
|
|
185
|
+
return str(d).strip()
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def _parse_trial(study: dict) -> dict | None:
|
|
189
|
+
try:
|
|
190
|
+
proto = study.get("protocolSection") or {}
|
|
191
|
+
id_mod = proto.get("identificationModule") or {}
|
|
192
|
+
status_mod = proto.get("statusModule") or {}
|
|
193
|
+
design_mod = proto.get("designModule") or {}
|
|
194
|
+
desc_mod = proto.get("descriptionModule") or {}
|
|
195
|
+
elig_mod = proto.get("eligibilityModule") or {}
|
|
196
|
+
sponsor_mod = proto.get("sponsorCollaboratorsModule") or {}
|
|
197
|
+
conditions_mod = proto.get("conditionsModule") or {}
|
|
198
|
+
interventions_mod = proto.get("armsInterventionsModule") or {}
|
|
199
|
+
contacts_mod = proto.get("contactsLocationsModule") or {}
|
|
200
|
+
|
|
201
|
+
nct_id = _ct_get(id_mod, "nctId")
|
|
202
|
+
if not nct_id:
|
|
203
|
+
return None
|
|
204
|
+
|
|
205
|
+
interventions = interventions_mod.get("interventions") or []
|
|
206
|
+
intervention_names = "; ".join(
|
|
207
|
+
_ct_get(i, "name") for i in interventions if isinstance(i, dict)
|
|
208
|
+
)
|
|
209
|
+
locations = contacts_mod.get("locations") or []
|
|
210
|
+
location_strs = []
|
|
211
|
+
for loc in locations[:3]:
|
|
212
|
+
if not isinstance(loc, dict):
|
|
213
|
+
continue
|
|
214
|
+
parts = [_ct_get(loc, "facility"), _ct_get(loc, "city"), _ct_get(loc, "country")]
|
|
215
|
+
loc_str = ", ".join(p for p in parts if p)
|
|
216
|
+
if loc_str:
|
|
217
|
+
location_strs.append(loc_str)
|
|
218
|
+
|
|
219
|
+
criteria = _ct_get(elig_mod, "eligibilityCriteria")
|
|
220
|
+
if len(criteria) > 600:
|
|
221
|
+
criteria = criteria[:597] + "..."
|
|
222
|
+
|
|
223
|
+
summary = _ct_get(desc_mod, "briefSummary")
|
|
224
|
+
if len(summary) > 400:
|
|
225
|
+
summary = summary[:397] + "..."
|
|
226
|
+
|
|
227
|
+
return {
|
|
228
|
+
"nct_id": nct_id,
|
|
229
|
+
"title": _ct_get(id_mod, "briefTitle"),
|
|
230
|
+
"status": _ct_get(status_mod, "overallStatus"),
|
|
231
|
+
"phase": "; ".join(design_mod.get("phases") or []),
|
|
232
|
+
"conditions": "; ".join(conditions_mod.get("conditions") or []),
|
|
233
|
+
"interventions": intervention_names,
|
|
234
|
+
"brief_summary": summary,
|
|
235
|
+
"eligibility_criteria": criteria,
|
|
236
|
+
"min_age": _ct_get(elig_mod, "minimumAge"),
|
|
237
|
+
"max_age": _ct_get(elig_mod, "maximumAge"),
|
|
238
|
+
"sex": _ct_get(elig_mod, "sex"),
|
|
239
|
+
"sponsor": _ct_get(sponsor_mod, "leadSponsor", "name"),
|
|
240
|
+
"start_date": _ct_get(status_mod, "startDateStruct", "date"),
|
|
241
|
+
"locations": location_strs,
|
|
242
|
+
"url": f"https://clinicaltrials.gov/study/{nct_id}",
|
|
243
|
+
}
|
|
244
|
+
except (KeyError, TypeError, AttributeError):
|
|
245
|
+
return None
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def search_clinical_trials(
|
|
249
|
+
condition: str,
|
|
250
|
+
status: str = "RECRUITING",
|
|
251
|
+
intervention: str = "",
|
|
252
|
+
max_results: int = 5,
|
|
253
|
+
) -> list[dict]:
|
|
254
|
+
"""Search ClinicalTrials.gov v2 API. No API key required."""
|
|
255
|
+
condition = (condition or "").strip()
|
|
256
|
+
if not condition:
|
|
257
|
+
return []
|
|
258
|
+
max_results = max(1, min(max_results, 20))
|
|
259
|
+
params: dict[str, Any] = {
|
|
260
|
+
"format": "json",
|
|
261
|
+
"query.cond": condition,
|
|
262
|
+
"pageSize": max_results,
|
|
263
|
+
"countTotal": "true",
|
|
264
|
+
}
|
|
265
|
+
if intervention:
|
|
266
|
+
params["query.intr"] = intervention.strip()
|
|
267
|
+
if status and status.upper() != "ALL":
|
|
268
|
+
params["filter.overallStatus"] = status.upper()
|
|
269
|
+
|
|
270
|
+
try:
|
|
271
|
+
r = requests.get(CT_BASE, params=params, timeout=15)
|
|
272
|
+
r.raise_for_status()
|
|
273
|
+
data = r.json()
|
|
274
|
+
except Exception as e:
|
|
275
|
+
raise RuntimeError(f"ClinicalTrials.gov search failed: {e}") from e
|
|
276
|
+
|
|
277
|
+
studies = data.get("studies") or []
|
|
278
|
+
return [t for t in (_parse_trial(s) for s in studies) if t]
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
def format_trials_for_claude(trials: list[dict]) -> str:
|
|
282
|
+
"""Format ClinicalTrials.gov results as readable text."""
|
|
283
|
+
if not trials:
|
|
284
|
+
return "No clinical trials found matching those criteria."
|
|
285
|
+
lines = []
|
|
286
|
+
for i, t in enumerate(trials, 1):
|
|
287
|
+
locations_str = "; ".join(t.get("locations") or []) or "N/A"
|
|
288
|
+
lines.append("\n".join([
|
|
289
|
+
f"[Trial {i}]",
|
|
290
|
+
f"NCT ID: {t.get('nct_id') or 'N/A'}",
|
|
291
|
+
f"Title: {t.get('title') or 'N/A'}",
|
|
292
|
+
f"Status: {t.get('status') or 'N/A'}",
|
|
293
|
+
f"Phase: {t.get('phase') or 'N/A'}",
|
|
294
|
+
f"Condition(s): {t.get('conditions') or 'N/A'}",
|
|
295
|
+
f"Intervention(s): {t.get('interventions') or 'N/A'}",
|
|
296
|
+
f"Sponsor: {t.get('sponsor') or 'N/A'}",
|
|
297
|
+
f"Age Range: {t.get('min_age') or 'N/A'} – {t.get('max_age') or 'N/A'}",
|
|
298
|
+
f"Sex: {t.get('sex') or 'N/A'}",
|
|
299
|
+
f"Locations: {locations_str}",
|
|
300
|
+
f"Summary: {t.get('brief_summary') or 'N/A'}",
|
|
301
|
+
f"Eligibility: {t.get('eligibility_criteria') or 'N/A'}",
|
|
302
|
+
f"URL: {t.get('url') or 'N/A'}",
|
|
303
|
+
"",
|
|
304
|
+
]))
|
|
305
|
+
return "\n".join(lines).strip()
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
__all__ = [
|
|
309
|
+
"search_pubmed", "format_results_for_claude",
|
|
310
|
+
"search_clinical_trials", "format_trials_for_claude",
|
|
311
|
+
]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "aria-mcp-server"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
requires-python = ">=3.10"
|
|
9
|
+
dependencies = [
|
|
10
|
+
"fastmcp>=3.2.4",
|
|
11
|
+
"httpx>=0.28.1",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
[project.scripts]
|
|
15
|
+
aria-mcp-server = "aria_mcp_server.server:run"
|
|
16
|
+
|
|
17
|
+
[tool.hatch.build.targets.wheel]
|
|
18
|
+
packages = ["aria_mcp_server"]
|