import os from mcp.server.fastmcp import FastMCP from starlette.responses import JSONResponse from starlette.requests import Request import moore_num import logging # Configure logging logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) # Get port and host from environment port = int(os.getenv("PORT", 7860)) host = "0.0.0.0" logger.info(f"Initializing Moore-num MCP Server on {host}:{port}") # Initialize FastMCP server with correct settings mcp = FastMCP( "Moore-num Server", host=host, port=port ) @mcp.tool() def convert_to_moore(number: int, is_money: bool = False) -> str: """ Convert an integer to its Mooré text representation. Args: number: The integer to convert. is_money: Whether the number represents money (CFA). """ try: return moore_num.convert_to_text(number, is_money=is_money) except Exception as e: logger.error(f"Error in convert_to_moore: {e}") return f"Error: {str(e)}" @mcp.tool() def convert_from_moore(text: str, is_money: bool = False) -> int: """ Convert Mooré text representation of a number back to an integer. Args: text: The Mooré text to convert. is_money: Whether the text represents money. """ try: return moore_num.text_to_num(text, is_money=is_money) except Exception as e: logger.error(f"Error in convert_from_moore: {e}") return f"Error: {str(e)}" @mcp.custom_route("/", methods=["GET"]) async def root_handler(request: Request): logger.info("Root endpoint accessed") return JSONResponse({ "status": "running", "mcp_server": "Moore-num", "sse_endpoint": "/sse" }) if __name__ == "__main__": logger.info("Starting FastMCP server with SSE transport") mcp.run(transport="sse")