File size: 2,856 Bytes
f103ad7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
"""
API key and environment configuration management.
Keys are stored in session state only — never written to disk.
"""

import os
from dotenv import load_dotenv

# All supported API keys with metadata
API_KEYS = {
    "NCBI_API_KEY": {
        "label": "NCBI API Key",
        "description": "Improves PubTator/PMC OA rate limits (3→10 req/sec)",
        "url": "https://www.ncbi.nlm.nih.gov/account/settings/",
        "required": False,
    },
    "S2_API_KEY": {
        "label": "Semantic Scholar API Key",
        "description": "Dedicated S2 quota (1 req/sec) for article search/TLDR/citations",
        "url": "https://www.semanticscholar.org/product/api",
        "required": False,
    },
    "ONCOKB_TOKEN": {
        "label": "OncoKB Token",
        "description": "Production OncoKB variant therapy & level evidence",
        "url": "https://www.oncokb.org/account/register",
        "required": False,
    },
    "OPENFDA_API_KEY": {
        "label": "OpenFDA API Key",
        "description": "Better OpenFDA rate limits for drug safety/adverse event lookups",
        "url": "https://open.fda.gov/apis/authentication/",
        "required": False,
    },
    "NCI_API_KEY": {
        "label": "NCI CTS API Key",
        "description": "NCI Clinical Trials Search (--source nci)",
        "url": "https://clinicaltrialsapi.cancer.gov/",
        "required": False,
    },
    "DISGENET_API_KEY": {
        "label": "DisGeNET API Key",
        "description": "Scored gene-disease associations in gene/disease lookups",
        "url": "https://www.disgenet.com/",
        "required": False,
    },
    "UMLS_API_KEY": {
        "label": "UMLS API Key",
        "description": "Clinical crosswalk enrichment in discover command",
        "url": "https://uts.nlm.nih.gov/uts/signup-login",
        "required": False,
    },
    "ALPHAGENOME_API_KEY": {
        "label": "AlphaGenome API Key",
        "description": "Variant effect prediction (get variant ... predict)",
        "url": "https://deepmind.google/science/alphagenome/",
        "required": False,
    },
}

# Additional config env vars
CONFIG_VARS = {
    "BIOMCP_STUDY_DIR": {
        "label": "Study Directory",
        "description": "Local study root for cBioPortal datasets (leave blank for default)",
    },
}


def load_env_keys() -> dict[str, str]:
    """Load API keys from .env file and environment, return as dict."""
    load_dotenv()
    keys = {}
    for key_name in API_KEYS:
        keys[key_name] = os.environ.get(key_name, "")
    for key_name in CONFIG_VARS:
        keys[key_name] = os.environ.get(key_name, "")
    return keys


def build_env_overrides(session_keys: dict[str, str]) -> dict[str, str]:
    """
    Build env overrides dict from session keys.
    Only includes non-empty values.
    """
    return {k: v for k, v in session_keys.items() if v}