CoolFace
Apppublic

jstoppa/mcp_example

sourceHugging Facemitupdated 2y agoView on Hugging Face
0likes
mcp_task_server.py41 linesDownload Raw Back to root
1from mcp.server.fastmcp import FastMCP2import json3 4# Sample tasks with titles and descriptions5tasks = [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 instance12mcp = FastMCP(name="TaskServer")13 14# Define a prompt: template for task creation15@mcp.prompt("task_description")16def 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 list20@mcp.tool("add_task")21def 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 client29@mcp.resource("tasks://list")30def 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 40if __name__ == "__main__":41    mcp.run()