Spaces:
Sleeping
Sleeping
Update server.py
Browse files
server.py
CHANGED
|
@@ -1,60 +1,62 @@
|
|
| 1 |
-
from mcp.server.fastmcp import FastMCP
|
| 2 |
-
import logging
|
| 3 |
-
import os
|
| 4 |
-
|
| 5 |
-
# Initialize the server
|
| 6 |
-
mcp = FastMCP("Math-Education-Server")
|
| 7 |
-
|
| 8 |
-
current_dir = os.path.dirname(os.path.abspath(__file__))
|
| 9 |
-
|
| 10 |
-
# Path to your collected resource
|
| 11 |
-
MARKDOWN_FILE = r"resource\jemh114-min (1).md"
|
| 12 |
-
|
| 13 |
-
def get_local_resource():
|
| 14 |
-
"""Helper to read the markdown file safely."""
|
| 15 |
-
if os.path.exists(MARKDOWN_FILE):
|
| 16 |
-
with open(MARKDOWN_FILE, "r", encoding="utf-8") as f:
|
| 17 |
-
return f.read()
|
| 18 |
-
return "Resource file not found."
|
| 19 |
-
|
| 20 |
-
# --- Task 1: Generate a Summary ---
|
| 21 |
-
@mcp.tool()
|
| 22 |
-
async def generate_chapter_summary(chapter_name: str) -> str:
|
| 23 |
-
"""
|
| 24 |
-
Provides the source material for a chapter.
|
| 25 |
-
The AI should use this to create a summary.
|
| 26 |
-
"""
|
| 27 |
-
raw_data = get_local_resource()
|
| 28 |
-
|
| 29 |
-
# We use XML-style tags. Senior engineers do this because
|
| 30 |
-
# LLMs (especially Claude) are trained to handle tagged data perfectly.
|
| 31 |
-
return f"""
|
| 32 |
-
<source_material>
|
| 33 |
-
{raw_data[:4000]}
|
| 34 |
-
</source_material>
|
| 35 |
-
|
| 36 |
-
SYSTEM_INSTRUCTION: You are a Mathematics Expert.
|
| 37 |
-
1. Read the text inside <source_material>.
|
| 38 |
-
2. Create a summary with 3 bullet points.
|
| 39 |
-
3. List all formulas found in LaTeX format.
|
| 40 |
-
4. Do not repeat the raw text; only provide the summary.
|
| 41 |
-
"""
|
| 42 |
-
|
| 43 |
-
# --- Task 2: Quiz Generator ---
|
| 44 |
-
@mcp.tool()
|
| 45 |
-
async def generate_quiz(chapter_name: str, difficulty: str = "medium") -> str:
|
| 46 |
-
"""
|
| 47 |
-
Extracts formulas from the markdown and asks the LLM to build a quiz.
|
| 48 |
-
"""
|
| 49 |
-
raw_data = get_local_resource()
|
| 50 |
-
|
| 51 |
-
# Using the LLM's ability to pick out formulas from the raw text provided
|
| 52 |
-
return (
|
| 53 |
-
f"Here is the raw material for {chapter_name}:\n"
|
| 54 |
-
f"{raw_data}\n"
|
| 55 |
-
f"Difficulty: {difficulty}\n"
|
| 56 |
-
"Task: Create a 3-question quiz using the formulas found in the text."
|
| 57 |
-
)
|
| 58 |
-
|
| 59 |
-
if __name__ == "__main__":
|
| 60 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
from mcp.server.fastmcp import FastMCP
|
| 2 |
+
import logging
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Initialize the server
|
| 6 |
+
mcp = FastMCP("Math-Education-Server")
|
| 7 |
+
|
| 8 |
+
current_dir = os.path.dirname(os.path.abspath(__file__))
|
| 9 |
+
|
| 10 |
+
# Path to your collected resource
|
| 11 |
+
MARKDOWN_FILE = r"resource\jemh114-min (1).md"
|
| 12 |
+
|
| 13 |
+
def get_local_resource():
|
| 14 |
+
"""Helper to read the markdown file safely."""
|
| 15 |
+
if os.path.exists(MARKDOWN_FILE):
|
| 16 |
+
with open(MARKDOWN_FILE, "r", encoding="utf-8") as f:
|
| 17 |
+
return f.read()
|
| 18 |
+
return "Resource file not found."
|
| 19 |
+
|
| 20 |
+
# --- Task 1: Generate a Summary ---
|
| 21 |
+
@mcp.tool()
|
| 22 |
+
async def generate_chapter_summary(chapter_name: str) -> str:
|
| 23 |
+
"""
|
| 24 |
+
Provides the source material for a chapter.
|
| 25 |
+
The AI should use this to create a summary.
|
| 26 |
+
"""
|
| 27 |
+
raw_data = get_local_resource()
|
| 28 |
+
|
| 29 |
+
# We use XML-style tags. Senior engineers do this because
|
| 30 |
+
# LLMs (especially Claude) are trained to handle tagged data perfectly.
|
| 31 |
+
return f"""
|
| 32 |
+
<source_material>
|
| 33 |
+
{raw_data[:4000]}
|
| 34 |
+
</source_material>
|
| 35 |
+
|
| 36 |
+
SYSTEM_INSTRUCTION: You are a Mathematics Expert.
|
| 37 |
+
1. Read the text inside <source_material>.
|
| 38 |
+
2. Create a summary with 3 bullet points.
|
| 39 |
+
3. List all formulas found in LaTeX format.
|
| 40 |
+
4. Do not repeat the raw text; only provide the summary.
|
| 41 |
+
"""
|
| 42 |
+
|
| 43 |
+
# --- Task 2: Quiz Generator ---
|
| 44 |
+
@mcp.tool()
|
| 45 |
+
async def generate_quiz(chapter_name: str, difficulty: str = "medium") -> str:
|
| 46 |
+
"""
|
| 47 |
+
Extracts formulas from the markdown and asks the LLM to build a quiz.
|
| 48 |
+
"""
|
| 49 |
+
raw_data = get_local_resource()
|
| 50 |
+
|
| 51 |
+
# Using the LLM's ability to pick out formulas from the raw text provided
|
| 52 |
+
return (
|
| 53 |
+
f"Here is the raw material for {chapter_name}:\n"
|
| 54 |
+
f"{raw_data}\n"
|
| 55 |
+
f"Difficulty: {difficulty}\n"
|
| 56 |
+
"Task: Create a 3-question quiz using the formulas found in the text."
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
if __name__ == "__main__":
|
| 60 |
+
# FastMCP handles the --transport sse argument automatically
|
| 61 |
+
# if you use mcp.run()
|
| 62 |
+
mcp.run()
|