Update mcp/mygene.py
Browse files- mcp/mygene.py +11 -18
mcp/mygene.py
CHANGED
|
@@ -1,21 +1,14 @@
|
|
| 1 |
-
|
| 2 |
from functools import lru_cache
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
-
@lru_cache(
|
| 8 |
-
async def
|
| 9 |
-
|
| 10 |
-
return
|
| 11 |
-
|
| 12 |
-
|
| 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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|