这是一个基于模型上下文协议(MCP)的服务器,它能够自动从 Notion 页面生成 Anki 抽认卡。该工具通过 OpenAI 的 API 从 Notion 的折叠块中提取问题和答案,并将其转换为结构化的 Anki 卡片,同时借助 AnkiConnect 实现实时导入。
git clone https://github.com/yourusername/notion-anki-mcp.git
cd notion-anki-mcp
pip install -r requirements.txt
cp .env.example .env
编辑 .env 文件,填入你的 API 密钥:
NOTION_API_KEY=your_notion_api_key_here
OPENAI_API_KEY=your_openai_api_key_here
python server.py
在设置此项目之前,请确保你具备以下条件:
search_page:按名称查找 Notion 页面。extract_page_content:从页面中提取问题和答案。generate_flashcards:创建并导入 Anki 卡片。import asyncio
from server import search_notion_page, fetch_page_content, generate_flashcards_gpt
async def create_flashcards(page_name):
# Search for the page
page_result = await search_notion_page(page_name)
if not page_result:
print(f"Page '{page_name}' not found")
return
# Extract content
topics, content = await fetch_page_content(page_result['page_id'])
# Generate and import flashcards
cards = await generate_flashcards_gpt(page_name, topics, content)
print(f"Created {len(cards)} flashcards for '{page_name}'")
# Run the example
asyncio.run(create_flashcards("Your Page Name"))
为使工具有效工作,请按以下方式构建你的 Notion 页面:
创建折叠块,其中:
示例结构:
📝 机器学习概念
🔽 什么是监督学习?
监督学习是一种机器学习类型,其中...
- 使用带标签的训练数据
- 学习从输入到输出的映射
- 示例:分类、回归
🔽 分类和回归有什么区别?
分类预测类别/类,而回归预测连续值...
在折叠块内,该工具支持:
search_page按名称搜索 Notion 页面。 参数:
page_name(字符串):要搜索的 Notion 页面的标题。
返回值:{
"status": "success",
"page_name": "Page Title",
"result": {
"result": "Found",
"page_id": "page-uuid",
"link": "https://notion.so/..."
}
}
extract_page_content从 Notion 页面提取问题和答案。 参数:
page_id(字符串):Notion 页面的 UUID。
返回值:{
"status": "success",
"topics": ["Topic 1", "Topic 2"],
"content": {
"Question 1?": "Answer 1...",
"Question 2?": "Answer 2..."
}
}
generate_flashcards根据提取的内容创建 Anki 抽认卡。 参数:
page_name(字符串):Anki 牌组的名称。topics(数组):页面中的主题/标题列表。content(对象):问答对。
返回值:{
"status": "created",
"cards": [...],
"message": "Created flashdeck and cards for 'Page Name' in Anki"
}
通过修改 server.py 启用调试日志:
import logging
logging.basicConfig(level=logging.DEBUG)
git checkout -b feature/amazing-feature)。git commit -m 'Add amazing feature')。git push origin feature/amazing-feature)。本项目采用 MIT 许可证 - 有关详细信息,请参阅 LICENSE 文件。
❤️ 为更好的学习和知识留存而打造