"""
Google Workspace MCP Server — main entry point.

Multi-account support for Gmail, Google Drive, Sheets & Calendar.
Uses FastMCP composition to mount service-specific sub-servers.
"""

from __future__ import annotations

from fastmcp import FastMCP

from .tools.profiles import mcp as profiles_mcp
from .tools.gmail import mcp as gmail_mcp
from .tools.drive import mcp as drive_mcp
from .tools.sheets import mcp as sheets_mcp
from .tools.calendar import mcp as calendar_mcp
from .middleware.error_handler import GoogleApiErrorHandler

# ---------------------------------------------------------------------------
# Main server with composition
# ---------------------------------------------------------------------------
mcp = FastMCP(
    "Google Workspace",
    instructions=(
        "Multi-account Google Workspace MCP server. "
        "Every tool accepts an optional 'profile' parameter to select which "
        "Google account to use. Use list_google_profiles to see available accounts. "
        "If profile is omitted, the first configured profile is used."
    ),
)

# Add error handling middleware
mcp.add_middleware(GoogleApiErrorHandler())

# Mount sub-servers — tools are auto-namespaced
mcp.mount(profiles_mcp)
mcp.mount(gmail_mcp)
mcp.mount(drive_mcp)
mcp.mount(sheets_mcp)
mcp.mount(calendar_mcp)


def main():
    """Entry point for the CLI command."""
    mcp.run()


if __name__ == "__main__":
    main()
