File size: 1,843 Bytes
e96a492
 
85811d4
4e86845
e96a492
4e86845
e96a492
4e86845
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e96a492
 
 
 
 
 
 
 
 
 
 
 
 
4e86845
e96a492
 
 
 
 
 
 
 
 
 
 
 
 
 
4e86845
e96a492
 
4e86845
 
 
85811d4
 
 
 
 
 
4e86845
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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")