"""MCPServer with Kafka integration example.

Run from the repository root:
    uv run main.py
    kk-mcp
"""

import logging
from mcp.server.fastmcp import FastMCP

# Import Kafka modules
from kafka_integration import create_kafka_module
from kafka_tools import register_kafka_tools
from kafka_resources import register_kafka_resources

# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

# Create an MCP server
mcp = FastMCP("Kafka MCP Server")

# Create and initialize Kafka module
try:
    kafka_module = create_kafka_module(mcp)
    logger.info("Kafka module initialized successfully")
except Exception as e:
    logger.error(f"Failed to initialize Kafka module: {e}")
    # Create a dummy module for fallback
    kafka_module = None

# Register Kafka tools if module is available
if kafka_module:
    register_kafka_tools(kafka_module, mcp)
    register_kafka_resources(kafka_module, mcp)
    logger.info("Kafka tools and resources registered")


def main():
    """Entry point for the kk-mcp command."""
    logger.info("Starting Kafka MCP Server...")
    mcp.run(transport="stdio")


# Run with streamable HTTP transport
if __name__ == "__main__":
    main()