MCP_Res / mcp /mygene.py
mgbam's picture
Update mcp/mygene.py
686ea1e verified
import os, httpx
from functools import lru_cache
_KEY = os.getenv("MYGENE_KEY")
_URL = "https://mygene.info/v3/query"
@lru_cache(maxsize=512)
async def fetch_gene_info(sym: str) -> dict:
if not sym:
return {}
params = {
"q" : sym,
"fields": "symbol,name,summary,alias,entrezgene,location",
"size" : 1,
}
if _KEY:
params["api_key"] = _KEY
async with httpx.AsyncClient(timeout=8) as c:
r = await c.get(_URL, params=params)
r.raise_for_status()
return r.json().get("hits", [{}])[0]