Spaces:
Sleeping
Sleeping
File size: 1,476 Bytes
ede15c7 7108607 a829887 7108607 8c6eb1d 17e6a4f 7108607 8c6eb1d d2244e1 7108607 8c6eb1d 7108607 8c6eb1d 7108607 8c6eb1d 7108607 8c6eb1d 7108607 e7f94e7 | 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 | 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"""
<source_material>
{raw_data[:4000]}
</source_material>
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"
) |