#!/usr/bin/env python3
"""Executable entry point for the Firefox RDP MCP server."""
from __future__ import annotations
import asyncio
import logging
import sys
import time
from src.browser_session import BrowserSession
from src.config import Config
from src.errors import ConfigurationError
from src.mcp_server import runServer
from src.rdp_connection import RdpConnection
from src.tool_handlers import ToolHandlers
def main() -> int:
"""Read configuration, construct components, and serve MCP over stdio."""
try:
config = Config.fromEnvironment()
except ConfigurationError as error:
print(f"Configuration error: {error.message}", file=sys.stderr)
return 2
logging.Formatter.converter = time.gmtime
logging.basicConfig(
level=getattr(logging, config.log_level.upper()),
stream=sys.stderr,
format=(
"%(asctime)sZ %(levelname)s %(name)s %(message)s"
),
)
rdp = RdpConnection(
config.host,
config.port,
config.request_timeout_ms,
)
browser = BrowserSession(config, rdp)
handlers = ToolHandlers(browser)
try:
asyncio.run(
runServer(
handlers,
sys.stdin.buffer,
sys.stdout.buffer,
)
)
except KeyboardInterrupt:
return 130
return 0
if __name__ == "__main__":
raise SystemExit(main())