File size: 755 Bytes
b4beb5e
 
e78237f
b4beb5e
192721e
b4beb5e
 
 
 
 
 
 
 
 
 
192721e
b4beb5e
 
 
 
192721e
b4beb5e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 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")

    @lru_cache(512)
    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()