mgbam commited on
Commit
c9d29cb
·
verified ·
1 Parent(s): 8e8bfa6

Update mcp/ctgov.py

Browse files
Files changed (1) hide show
  1. mcp/ctgov.py +18 -10
mcp/ctgov.py CHANGED
@@ -1,13 +1,21 @@
1
- import httpx, asyncio, datetime
 
 
 
 
 
 
2
 
3
  _BASE = "https://clinicaltrials.gov/api/v2/studies"
4
 
5
- async def search_trials(query: str, max_n: int = 20) -> list[dict]:
6
- async with httpx.AsyncClient(timeout=15) as cli:
7
- r = await cli.get(_BASE, params={
8
- "query": query,
9
- "pageSize": max_n,
10
- "fields": "nctId,briefTitle,phase,status,startDate"
11
- })
12
- r.raise_for_status()
13
- return r.json().get("studies", [])
 
 
 
1
+ """ClinicalTrials.gov v2 async helper.
2
+ Docs: https://clinicaltrials.gov/api/gui/ref/api_urls#v2
3
+ Provides `search_trials_v2` which returns a list of study dicts.
4
+ """
5
+
6
+ import httpx, asyncio
7
+ from typing import List, Dict
8
 
9
  _BASE = "https://clinicaltrials.gov/api/v2/studies"
10
 
11
+ async def search_trials_v2(query: str, *, max_n: int = 20) -> List[Dict]:
12
+ """Search CT.gov v2 endpoint and return list of studies."""
13
+ params = {
14
+ "query": query,
15
+ "pageSize": max_n,
16
+ "fields": "nctId,briefTitle,phase,status,startDate,conditions,interventions",
17
+ }
18
+ async with httpx.AsyncClient(timeout=15) as client:
19
+ resp = await client.get(_BASE, params=params)
20
+ resp.raise_for_status()
21
+ return resp.json().get("studies", [])