#!/usr/bin/env python3
"""
MCP Server cho quản lý công việc (Todo List)
Cung cấp các công cụ để thêm, xem, hoàn thành và xóa công việc
"""
import json
import os
from datetime import datetime
from pathlib import Path
from typing import Any
from mcp.server.models import InitializationOptions
import mcp.types as types
from mcp.server import NotificationOptions, Server
import mcp.server.stdio
# File lưu trữ danh sách công việc
TODO_FILE = Path.home() / ".todo_mcp_data.json"
# Khởi tạo server
server = Server("todo-manager")
def load_todos() -> list[dict[str, Any]]:
"""Đọc danh sách công việc từ file"""
if not TODO_FILE.exists():
return []
try:
with open(TODO_FILE, "r", encoding="utf-8") as f:
return json.load(f)
except Exception:
return []
def save_todos(todos: list[dict[str, Any]]) -> None:
"""Lưu danh sách công việc vào file"""
with open(TODO_FILE, "w", encoding="utf-8") as f:
json.dump(todos, f, ensure_ascii=False, indent=2)
@server.list_tools()
async def handle_list_tools() -> list[types.Tool]:
"""Liệt kê các công cụ có sẵn"""
return [
types.Tool(
name="add_todo",
description="Thêm một công việc mới vào danh sách",
inputSchema={
"type": "object",
"properties": {
"title": {
"type": "string",
"description": "Tiêu đề công việc"
},
"description": {
"type": "string",
"description": "Mô tả chi tiết công việc (tùy chọn)"
},
"priority": {
"type": "string",
"enum": ["low", "medium", "high"],
"description": "Mức độ ưu tiên (low/medium/high)"
}
},
"required": ["title"]
}
),