#!/usr/bin/env python3
"""
Main entry point for Django Firebase MCP server.
This allows running the MCP server via uvx or direct python execution.
"""
import sys
import os

# Add the project root to the path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

# Set Django settings module
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_firebase_mcp.settings')

# Import Django and setup
import django
django.setup()

# Import and run the MCP server
from firebase_admin_mcp.management.commands.run_mcp import Command


def main():
    """Main entry point for the MCP server."""
    # Check for transport argument in command line
    transport = 'stdio'
    if '--transport' in sys.argv:
        idx = sys.argv.index('--transport')
        if idx + 1 < len(sys.argv):
            transport = sys.argv[idx + 1]

    # Set environment variable for transport
    os.environ['MCP_TRANSPORT'] = transport

    command = Command()
    command.handle(transport=transport)


if __name__ == '__main__':
    main()