寫好了 MCP 伺服器的骨架,也用 MCP Inspector 確認它的介面 (Interface) 沒問題後,我們就要進入下一步:
補全 Tools、Resources、Prompts 的程式碼
讓它成為一個真的能幫助我們管理個人會議的助理。
簡化版資料庫
在動手寫 MCP 邏輯之前,我們要先解決會議資料存在哪的問題。
在生產環境中,這可以是 Postgres、Google Sheet、或者是某個 SaaS 服務,但為了不讓複雜的資料庫連線或驗證程式碼模糊了焦點,我退而求其次採用了一個頗為簡化的選項,用一個本地的 JSON 文件來當資料庫。
這是該 JSON 文件的範例:
{
"meetings": [
{
"id": "meet-001",
"title": "Q2 Planning Session",
"date": "2026-05-15T10:00:00",
"attendees": [
"alice@example.com",
"bob@example.com",
"carol@example.com"
],
"action_items": [
{
"id": "ai-001",
"meeting_id": "meet-001",
"description": "Draft Q2 roadmap document",
"assignee": "alice@example.com",
"due_date": "2026-05-22",
"status": "done"
},
{
"id": "ai-002",
"meeting_id": "meet-001",
"description": "Schedule follow-up with stakeholders",
"assignee": "bob@example.com",
"due_date": "2026-05-20",
"status": "done"
}
]
},
{
"id": "meet-002",
"title": "Sprint Retrospective - Sprint 14",
"date": "2026-05-20T14:00:00",
"attendees": [
"bob@example.com",
"dave@example.com",
"eve@example.com",
"frank@example.com"
],
"action_items": [
{
"id": "ai-003",
"meeting_id": "meet-002",
"description": "Update CI pipeline to reduce build times",
"assignee": "dave@example.com",
"due_date": "2026-05-27",
"status": "in_progress"
}
]
},
{
"id": "meet-003",
"title": "Customer Feedback Review",
"date": "2026-05-30T09:30:00",
"attendees": [
"carol@example.com",
"frank@example.com",
"grace@example.com"
],
"action_items": [
{
"id": "ai-004",
"meeting_id": "meet-003",
"description": "Compile top 10 customer pain points into a report",
"assignee": "grace@example.com",
"due_date": "2026-06-05",
"status": "open"
},
{
"id": "ai-005",
"meeting_id": "meet-003",
"description": "Share feedback summary with product team",
"assignee": "carol@example.com",
"due_date": "2026-06-09",
"status": "open"
}
]
}
]
}最外層是 meetings 陣列,每一個會議都有自己的 id、標題 (title)、日期 (date)、與會者清單 (attendees),和行動事項 (action_items)。
而每項行動事項也有自己的 id、所屬的會議 id (meeting_id)、描述 (description)、負責人 (assignee)、到期日 (due_date),和狀態 (status)。
我們把這個 JSON 文件當成資料庫,需要新增會議就在 meetings 陣列中增加、需要新增行動事項就在會議中的 action_items 陣列中增加。
這 MCP 的不少功能都會讀取及覆寫這文件,所以要先定義以下 2 個輔助函數:
DATA_FILE = Path(__file__).parent / "meetings.json"
def _load_data() -> dict:
with DATA_FILE.open("r", encoding="utf-8") as f:
return json.load(f)
def _save_data(data: dict) -> None:
with DATA_FILE.open("w", encoding="utf-8") as f:
json.dump(data, f, indent=2)
