"""Entry point for mcspeak server."""

from .server import mcp
from .settings import settings


def main():
    mcp.run(
        transport="streamable-http",
        host=settings.host,
        port=settings.port,
        stateless_http=True,
        # On SIGTERM, uvicorn drains HTTP handlers first (Phase 1), then runs
        # lifespan shutdown where queue.stop() waits for the consumer (Phase 2).
        # These phases are SEQUENTIAL and share Docker's stop_grace_period budget.
        #
        # Phase 1 (handler drain): 3s — speak() just re-raises CancelledError,
        #   it does not cancel the consumer (audio keeps playing).
        # Phase 2 (queue.stop): shutdown_timeout — consumer finishes current audio.
        # Docker budget: shutdown_timeout + 3s handler drain + 5s safety margin.
        uvicorn_config={"timeout_graceful_shutdown": 3},
    )


if __name__ == "__main__":
    main()
