Notion-Anki MCP Server
Automatically generates Anki flashcards from Notion pages by extracting questions and answers from toggle blocks. Uses OpenAI to enhance card quality and imports them directly into Anki via AnkiConnect for spaced repetition learning.
README
Notion-Anki MCP Server
A Model Context Protocol (MCP) server that automatically generates Anki flashcards from Notion pages. This tool extracts questions and answers from Notion toggle blocks and converts them into structured Anki cards using OpenAI's API, with real-time import via AnkiConnect.
Use Cases
- Students: Convert study notes from Notion into flashcards for spaced repetition
- Professionals: Transform training materials and documentation into memorable cards
- Educators: Quickly create quiz content from lesson plans
- Researchers: Convert paper summaries and key concepts into study materials
Features
- Notion Integration: Extracts content from Notion pages via official API
- Smart Parsing: Recognizes toggle blocks as question-answer pairs
- AI Enhancement: Uses OpenAI to refine and improve flashcard quality
- Real-time Import: Automatically adds cards to Anki via AnkiConnect
- MCP Protocol: Works with MCP-compatible clients like Claude Desktop
Prerequisites
Before setting up this project, ensure you have:
-
Notion API Access
- Create a Notion integration
- Get your API key from the integration settings
-
OpenAI API Access
- Sign up for OpenAI API
- Create an API key with sufficient credits
-
Anki Setup
- Install Anki desktop application
- Install AnkiConnect add-on
- Keep Anki running during flashcard generation
-
Python Environment
- Python 3.8 or higher
- pip package manager
Quick Start
1. Clone the Repository
git clone https://github.com/yourusername/notion-anki-mcp.git
cd notion-anki-mcp
2. Install Dependencies
pip install -r requirements.txt
3. Environment Configuration
cp .env.example .env
Edit .env with your API keys:
NOTION_API_KEY=your_notion_api_key_here
OPENAI_API_KEY=your_openai_api_key_here
4. Start the MCP Server
python server.py
How to Structure Your Notion Pages
For the tool to work effectively, structure your Notion pages as follows:
Toggle Block Format
Create toggle blocks where:
- Toggle title = Your question
- Toggle content = The answer/explanation
Example structure:
📝 Machine Learning Concepts
🔽 What is supervised learning?
Supervised learning is a type of machine learning where...
- Uses labeled training data
- Learns mapping from inputs to outputs
- Examples: classification, regression
🔽 What's the difference between classification and regression?
Classification predicts categories/classes while regression predicts continuous values...
Supported Content Types
Within toggle blocks, the tool supports:
- Plain text paragraphs
- Bulleted lists
- Numbered lists
- Basic formatting (bold, italic, etc.)
Usage
Via MCP Client (Recommended)
- Configure your MCP client to connect to this server
- Use the available tools:
search_page: Find a Notion page by nameextract_page_content: Extract questions and answers from a pagegenerate_flashcards: Create and import Anki cards
Direct Python Usage
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"))
API Reference
MCP Tools
search_page
Searches for a Notion page by name.
Parameters:
page_name(string): The title of the Notion page to search for
Returns:
{
"status": "success",
"page_name": "Page Title",
"result": {
"result": "Found",
"page_id": "page-uuid",
"link": "https://notion.so/..."
}
}
extract_page_content
Extracts questions and answers from a Notion page.
Parameters:
page_id(string): The UUID of the Notion page
Returns:
{
"status": "success",
"topics": ["Topic 1", "Topic 2"],
"content": {
"Question 1?": "Answer 1...",
"Question 2?": "Answer 2..."
}
}
generate_flashcards
Creates Anki flashcards from extracted content.
Parameters:
page_name(string): Name for the Anki decktopics(array): List of topics/headings from the pagecontent(object): Question-answer pairs
Returns:
{
"status": "created",
"cards": [...],
"message": "Created flashdeck and cards for 'Page Name' in Anki"
}
Troubleshooting
Common Issues
"Page not found" Error
- Ensure the page name matches exactly (case-sensitive)
- Verify your Notion integration has access to the page
- Check that the page is in a shared workspace
"AnkiConnect not responding" Error
- Make sure Anki desktop is running
- Verify AnkiConnect add-on is installed and enabled
- Check that Anki isn't in review mode or showing a dialog
"OpenAI API Error" Error
- Verify your OpenAI API key is correct and active
- Check your API usage limits and billing
- Ensure you have access to the GPT-4 models
Empty flashcards generated
- Check that your Notion page uses the toggle block format
- Ensure toggle blocks contain text content
- Verify the page has actual content, not just headers
Debug Mode
Enable debug logging by modifying server.py:
import logging
logging.basicConfig(level=logging.DEBUG)
Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Notion API for excellent documentation
- AnkiConnect for Anki integration
- Model Context Protocol for the MCP standard
- OpenAI for powerful language models
Made with ❤️ for better learning and knowledge retention
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。