from fastmcp import FastMCP # from mcp.server.fastmcp import FastMCP import logging import os # Initialize the server mcp = FastMCP("Math-Education-Server") # SENIOR TIP: Use absolute paths relative to the script location # This prevents "File Not Found" errors in Docker. CURRENT_DIR = os.path.dirname(os.path.abspath(__file__)) MARKDOWN_FILE = os.path.join(CURRENT_DIR, "resource", "jemh114-min (1).md") def get_local_resource(): if os.path.exists(MARKDOWN_FILE): with open(MARKDOWN_FILE, "r", encoding="utf-8") as f: return f.read() return "Resource file not found." @mcp.tool() async def generate_chapter_summary(chapter_name: str) -> str: """Provides source material and instructions for a math summary.""" raw_data = get_local_resource() return f""" {raw_data[:4000]} SYSTEM_INSTRUCTION: You are a Mathematics Expert. 1. Summarize in 3 bullets. 2. List formulas like $x = \\frac{{-b \\pm \\sqrt{{b^2-4ac}}}}{{2a}}$. """ @mcp.tool() async def generate_quiz(chapter_name: str, difficulty: str = "medium") -> str: raw_data = get_local_resource() return f"Material: {raw_data[:2000]}\nDifficulty: {difficulty}\nCreate a 3-question quiz." if __name__ == "__main__": # For Hugging Face Spaces, we use transport="sse" or "http" # Port 7860 is the HF default mcp.run( transport="http", port=7860, host="0.0.0.0" )