# mcp/umls_rel.py import os, httpx from functools import lru_cache UMLS_API_KEY = os.getenv("UMLS_KEY") REL_URL = "https://uts-ws.nlm.nih.gov/rest/content/current/CUI/{cui}/relations" async def _get_ticket() -> str: from mcp.umls import _get_ticket as fn return await fn() @lru_cache(maxsize=512) async def fetch_relations(cui: str) -> list[dict]: ticket = await _get_ticket() params = {"ticket": ticket, "pageSize": 50} async with httpx.AsyncClient(timeout=10) as c: r = await c.get(REL_URL.format(cui=cui), params=params) r.raise_for_status() rels = r.json().get("result", {}).get("relation", []) return [ {"label": rel["relationLabel"], "cui2": rel["relatedId"], "name2": rel["relatedLabel"]} for rel in rels ]