Coverage for mt_mcp/config.py: 69.23%
13 statements
« prev ^ index » next coverage.py v7.10.6, created at 2026-11-30 15:03 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2026-11-30 15:03 +0000
1"""mt-mcp configuration, all from the environment (SB-1302).
3MT_MCP_ENABLED=true mount /mcp, and let MT AI call it (default off)
4MT_MCP_INTERNAL_URL=... how MT AI reaches it: loopback into this process
5MT_MCP_ALLOWED_HOSTS=a,b Host headers accepted besides loopback
6"""
8import os
10MOUNT_PATH = "/mcp"
12# Loopback is always allowed (MT AI's own calls); public names come from config.
13LOOPBACK_HOSTS = ["127.0.0.1:*", "localhost:*", "[::1]:*", "127.0.0.1", "localhost"]
14DEFAULT_PUBLIC_HOSTS = "api.missingtable.com"
17def mcp_enabled() -> bool:
18 return os.getenv("MT_MCP_ENABLED", "false").strip().lower() == "true"
21def internal_url() -> str:
22 # The trailing slash is the mount's own route; without it Starlette redirects.
23 return os.getenv("MT_MCP_INTERNAL_URL", f"http://127.0.0.1:8000{MOUNT_PATH}/")
26def allowed_hosts() -> list[str]:
27 raw = os.getenv("MT_MCP_ALLOWED_HOSTS", DEFAULT_PUBLIC_HOSTS)
28 return LOOPBACK_HOSTS + [h.strip() for h in raw.split(",") if h.strip()]
31def issuer_url() -> str:
32 """Where MT's tokens come from: Supabase auth. Advertised, never contacted."""
33 return os.getenv("SUPABASE_URL", "http://127.0.0.1:55321").rstrip("/") + "/auth/v1"