mgbam commited on
Commit
7cd5aef
·
verified ·
1 Parent(s): 472b6ea

Update mcp/mygene.py

Browse files
Files changed (1) hide show
  1. mcp/mygene.py +11 -18
mcp/mygene.py CHANGED
@@ -1,21 +1,14 @@
1
- import os, httpx
2
  from functools import lru_cache
 
3
 
4
- _KEY = os.getenv("MYGENE_KEY")
5
- _URL = "https://mygene.info/v3/query"
 
6
 
7
- @lru_cache(maxsize=512)
8
- async def fetch_gene_info(sym: str) -> dict:
9
- if not sym:
10
- return {}
11
- params = {
12
- "q" : sym,
13
- "fields": "symbol,name,summary,alias,entrezgene,location",
14
- "size" : 1,
15
- }
16
- if _KEY:
17
- params["api_key"] = _KEY
18
- async with httpx.AsyncClient(timeout=8) as c:
19
- r = await c.get(_URL, params=params)
20
- r.raise_for_status()
21
- return r.json().get("hits", [{}])[0]
 
1
+ # mcp/mygene.py
2
  from functools import lru_cache
3
+ from mcp.clients import BaseClient
4
 
5
+ class MyGeneClient(BaseClient):
6
+ def __init__(self):
7
+ super().__init__("https://mygene.info/v3", api_key_env="MYGENE_KEY")
8
 
9
+ @lru_cache(512)
10
+ async def fetch(self, symbol: str) -> Dict:
11
+ q = {"q": symbol, "fields": "symbol,name,summary,alias,entrezgene,location", "size": 1}
12
+ return (await self.request("GET", "query", params=q))["hits"][0]
13
+
14
+ mygene = MyGeneClient()