import os
import sys

import uvicorn
import main as timeedit_main
from mcp.server.transport_security import TransportSecuritySettings

ics_url = os.environ.get("TIMEEDIT_ICS_URL")
if not ics_url:
    sys.exit("TIMEEDIT_ICS_URL environment variable is required")

timeedit_main.config.ics_url = ics_url
timeedit_main.config.output_timezone = os.environ.get("TIMEEDIT_OUTPUT_TIMEZONE")

timeedit_main.mcp.settings.transport_security = TransportSecuritySettings(
    enable_dns_rebinding_protection=False,
    allowed_hosts=["*"],
)

app = timeedit_main.mcp.streamable_http_app()

uvicorn.run(
    app,
    host="0.0.0.0",
    port=int(os.environ.get("PORT", "8888")),
    forwarded_allow_ips="*",
    proxy_headers=True,
)
