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

Update mcp/mygene.py

Browse files
Files changed (1) hide show
  1. mcp/mygene.py +24 -9
mcp/mygene.py CHANGED
@@ -1,13 +1,28 @@
 
 
 
 
 
1
  import httpx, asyncio
 
2
 
3
  _BASE = "https://mygene.info/v3"
4
 
5
- async def fetch_gene(symbol: str) -> dict:
6
- async with httpx.AsyncClient(timeout=10) as cli:
7
- r = await cli.get(f"{_BASE}/query", params={
8
- "q": symbol, "fields": "symbol,name,summary,go,entrezgene,clinvar",
9
- "size": 1
10
- })
11
- r.raise_for_status()
12
- hits = r.json().get("hits", [])
13
- return hits[0] if hits else {}
 
 
 
 
 
 
 
 
 
 
1
+ """Async wrapper for MyGene.info API (https://mygene.info)
2
+ Exposes `fetch_gene_info` which returns the top hit for a free‑text query.
3
+ No API‑key required; 500 QPS community quota.
4
+ """
5
+
6
  import httpx, asyncio
7
+ from functools import lru_cache
8
 
9
  _BASE = "https://mygene.info/v3"
10
 
11
+ @lru_cache(maxsize=128)
12
+ async def fetch_gene_info(query: str) -> dict: # noqa: C901 – simple IO fn
13
+ """Return first hit dict or {} if nothing found.
14
+
15
+ Parameters
16
+ ----------
17
+ query : str – gene symbol / keyword / Entrez id / HGNC etc.
18
+ """
19
+ params = {
20
+ "q": query,
21
+ "fields": "symbol,name,summary,alias,entrezgene,clinvar,location,go",
22
+ "size": 1,
23
+ }
24
+ async with httpx.AsyncClient(timeout=10) as client:
25
+ resp = await client.get(f"{_BASE}/query", params=params)
26
+ resp.raise_for_status()
27
+ hits = resp.json().get("hits", [])
28
+ return hits[0] if hits else {}