# mcp/opentargets.py | |
import textwrap | |
from functools import lru_cache | |
from mcp.clients import BaseClient | |
class OTClient(BaseClient): | |
QUERY = textwrap.dedent(""" | |
query ($g: String!, $n: Int!){ | |
associations(geneSymbol: $g, size: $n) { | |
rows { score datatypeId datasourceId disease { id name } target { id symbol } } | |
} | |
} | |
""") | |
def __init__(self): | |
super().__init__("https://api.platform.opentargets.org/api/v4/graphql", api_key_env="OT_KEY") | |
async def fetch(self, symbol: str, n: int = 30): | |
payload = {"query": self.QUERY, "variables": {"g": symbol, "n": n}} | |
return (await self.request("POST", "", json=payload))["data"]["associations"]["rows"] | |
ot = OTClient() | |