from mcp.server.fastmcp import FastMCP
import logging
import os
# Initialize the server
mcp = FastMCP("Math-Education-Server")
current_dir = os.path.dirname(os.path.abspath(__file__))
# Path to your collected resource
MARKDOWN_FILE = r"resource\jemh114-min (1).md"
def get_local_resource():
"""Helper to read the markdown file safely."""
if os.path.exists(MARKDOWN_FILE):
with open(MARKDOWN_FILE, "r", encoding="utf-8") as f:
return f.read()
return "Resource file not found."
# --- Task 1: Generate a Summary ---
@mcp.tool()
async def generate_chapter_summary(chapter_name: str) -> str:
"""
Provides the source material for a chapter.
The AI should use this to create a summary.
"""
raw_data = get_local_resource()
# We use XML-style tags. Senior engineers do this because
# LLMs (especially Claude) are trained to handle tagged data perfectly.
return f"""
{raw_data[:4000]}
SYSTEM_INSTRUCTION: You are a Mathematics Expert.
1. Read the text inside .
2. Create a summary with 3 bullet points.
3. List all formulas found in LaTeX format.
4. Do not repeat the raw text; only provide the summary.
"""
# --- Task 2: Quiz Generator ---
@mcp.tool()
async def generate_quiz(chapter_name: str, difficulty: str = "medium") -> str:
"""
Extracts formulas from the markdown and asks the LLM to build a quiz.
"""
raw_data = get_local_resource()
# Using the LLM's ability to pick out formulas from the raw text provided
return (
f"Here is the raw material for {chapter_name}:\n"
f"{raw_data}\n"
f"Difficulty: {difficulty}\n"
"Task: Create a 3-question quiz using the formulas found in the text."
)
if __name__ == "__main__":
# FastMCP handles the --transport sse argument automatically
# if you use mcp.run()
mcp.run()