Spaces:
Runtime error
Runtime error
Create mcp_task_server.py
Browse files- mcp_task_server.py +41 -0
mcp_task_server.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from mcp.server.fastmcp import FastMCP
|
| 2 |
+
import json
|
| 3 |
+
|
| 4 |
+
# Sample tasks with titles and descriptions
|
| 5 |
+
tasks = [
|
| 6 |
+
{"title": "Plan meeting", "description": "Schedule team sync meeting"},
|
| 7 |
+
{"title": "Write report", "description": "Complete quarterly report"},
|
| 8 |
+
{"title": "Call client", "description": "Follow up on project requirements"}
|
| 9 |
+
]
|
| 10 |
+
|
| 11 |
+
# Create a FastMCP server instance
|
| 12 |
+
mcp = FastMCP(name="TaskServer")
|
| 13 |
+
|
| 14 |
+
# Define a prompt: template for task creation
|
| 15 |
+
@mcp.prompt("task_description")
|
| 16 |
+
def task_description(task_title="Unnamed task"):
|
| 17 |
+
return f"Based on the task title '{task_title}', generate a detailed description"
|
| 18 |
+
|
| 19 |
+
# Define a tool: add a new task to the list
|
| 20 |
+
@mcp.tool("add_task")
|
| 21 |
+
def add_task(params):
|
| 22 |
+
task_title = params.get("task_title", "Unnamed task")
|
| 23 |
+
task_description = params.get("description", "No description provided")
|
| 24 |
+
new_task = {"title": task_title, "description": task_description}
|
| 25 |
+
tasks.append(new_task)
|
| 26 |
+
return {"task": new_task, "success": True}
|
| 27 |
+
|
| 28 |
+
# Define a resource: expose a list of task titles to the client
|
| 29 |
+
@mcp.resource("tasks://list")
|
| 30 |
+
def get_task_titles():
|
| 31 |
+
return {
|
| 32 |
+
"meta": None,
|
| 33 |
+
"contents": [{
|
| 34 |
+
"uri": "tasks://list",
|
| 35 |
+
"mime_type": "application/json",
|
| 36 |
+
"text": json.dumps({"tasks": tasks, "count": len(tasks)})
|
| 37 |
+
}]
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
if __name__ == "__main__":
|
| 41 |
+
mcp.run()
|