Notion MCP Server V2
A comprehensive Model Context Protocol (MCP) server for Notion integration with enhanced functionality, robust error handling, production-ready features, and bulletproof validation.
README
🧠 Agentic Long-Term Memory with Notion Integration
This project explores the concept of long-term memory in AI agents and demonstrates how to build sophisticated agentic memory systems using various approaches and tools. Now featuring complete Notion workspace integration and MCP (Model Context Protocol) implementation!
Feel free to ⭐️ the repo if it helps you understand long-term memory for agents!
🚀 What's New - Enhanced Features
🔥 Complete Notion Integration
- 15+ Notion Functions: Search, read, create, update, and analyze your Notion workspace
- Smart Content Management: Add paragraphs, headings, bullets, todos with intelligent formatting
- Advanced Content Types: Bookmarks and internal page links with URL validation
- Workspace Analytics: Get insights about your Notion usage patterns
- Bulk Operations: Handle multiple pages and operations efficiently with smart pagination
- Function Chaining: Complex multi-step workflows handled automatically
- Production-Ready MCP Server: Complete Notion MCP Server V2.1 with bulletproof validation and comprehensive testing
🎯 MCP (Model Context Protocol) Implementation
- Multiple Transport Support: HTTP and stdio transport protocols
- Production Ready: Deployable MCP servers with fallback strategies
- Tool Discovery: Automatic tool registration and discovery
- Error Handling: Comprehensive error management and recovery
📚 Comprehensive Documentation
📖 Core Documentation
- 🤖 Complete System Explanation - Detailed walkthrough of the entire chatbot system
- 🔧 How MCP Tools Work - Deep dive into MCP implementation and tool mechanics
- 🚀 Notion Integration Guide - Complete Notion ServerV2 integration documentation
- 🔗 Notion MCP Server - Complete Notion MCP Server V2.1 - Production-ready server with bulletproof validation
🔍 Implementation Guides
- 📊 MCP Implementation Comparison - Comparison of different MCP implementation approaches
- 🎯 MCP Notion README - Specific MCP Notion integration setup and usage
- ⚙️ Production Configuration - Production deployment and configuration guide
🧠 Memory System Research
- Memory in LLM Agents - Research paper reference
- MemGPT Paper - PDF available in the repo
📚 What You'll Learn
- How to design a custom agentic long-term memory system
- How to implement long-term memory using Vector DB and Graph DB with LangChain and LangGraph
- How to structure memory into semantic, episodic, and procedural components
- Complete Notion workspace integration with natural language processing
- MCP (Model Context Protocol) implementation for scalable tool integration
- Production-ready MCP server development - see our Notion MCP Server V2.1
- Advanced function chaining for complex multi-step workflows
- Production-ready deployment strategies and configurations
💾 How to Run the Project
⚠️ Note: Please use Python 3.11 as Python 3.12 may cause compatibility issues with some dependencies.
1. Environment Setup
# Create virtual environment
python -m venv venv
source venv/bin/activate # or venv\Scripts\activate on Windows
# Install dependencies
pip install -r requirements.txt
2. Database Preparation
# Setup SQLite DB
python src/prepare_sqldb.py
# Setup Vector DB
python src/prepare_vectordb.py
# Verify databases
python src/check_sqldb.py
python src/check_vectordb.py
3. Environment Variables
# Required
export OPENAI_API_KEY="your_openai_api_key"
export NOTION_TOKEN="your_notion_integration_token"
# Optional
export NOTION_API_KEY="your_notion_integration_token" # Alternative to NOTION_TOKEN
4. Run the Enhanced Chatbot
# Terminal version with full Notion integration
python src/chat_in_terminal.py
# Gradio UI version
python src/chat_in_ui.py
5. Test the Integration
# Test Notion integration
python test_notion_integration.py
# Test MCP functionality
python test_notion_mcp.py
🎯 Available Chatbot Versions
Version 1: Basic Chatbot (basic_chatbot_v1.py)
- Simple conversation handling
- Basic OpenAI integration
Version 2: Agentic Chatbot (chatbot_agentic_v2.py)
- Function calling capabilities
- User information management
- Chat history search
Version 3: Enhanced Agentic Chatbot (chatbot_agentic_v3.py) - ⭐ MAIN VERSION
- Complete Notion integration (15+ functions)
- Advanced memory systems (Vector DB + SQL)
- Smart function chaining
- Production-ready architecture
- MCP protocol support
🔧 Key Features
🧠 Memory Systems
- SQL Database: Structured user information and chat history
- Vector Database: Semantic search through conversation history
- Smart Summarization: Automatic conversation summarization
- Context Management: Intelligent context preservation
🔗 Notion Integration
- Search & Discovery: Full-text search across pages and databases
- Content Management: Create, read, update pages with rich formatting
- Advanced Content Types: Bookmarks and internal page links with validation
- Analytics: Workspace insights and usage patterns
- Bulk Operations: Handle multiple operations efficiently
- Production MCP Server: Complete V2.1 Server with bulletproof validation and 48KB test suite
🎯 Function Chaining
- Multi-step Workflows: Automatic handling of complex tasks
- Context Awareness: Understanding when tasks require multiple steps
- Smart Routing: Intelligent function selection and execution
⚙️ Production Features
- Error Handling: Comprehensive error management
- Fallback Systems: Multiple backup strategies
- Scalable Architecture: Easy to extend and modify
- MCP Protocol: Standard tool integration protocol
🏗️ Project Architecture
┌─────────────────────┐ ┌─────────────────────┐ ┌─────────────────────┐
│ User Interface │───▶│ Chatbot Agentic V3 │───▶│ External Systems │
│ (Terminal/UI) │ │ (Main Controller) │ │ (Notion, DB, etc) │
└─────────────────────┘ └─────────────────────┘ └─────────────────────┘
│
▼
┌─────────────────────────────────────────┐
│ Core Components │
│ ┌─────────────┐ ┌─────────────────┐ │
│ │ OpenAI │ │ Notion │ │
│ │ Agent │ │ ServerV2 │ │
│ └─────────────┘ └─────────────────┘ │
│ ┌─────────────┐ ┌─────────────────┐ │
│ │ Memory │ │ Vector DB │ │
│ │ Systems │ │ (Embeddings) │ │
│ └─────────────┘ └─────────────────┘ │
│ ┌─────────────┐ ┌─────────────────┐ │
│ │ MCP │ │ SQL Database │ │
│ │ Protocol │ │ (Structured) │ │
│ └─────────────┘ └─────────────────┘ │
└─────────────────────────────────────────┘
📂 Updated Project Structure
src/
├── chat_in_terminal.py # Enhanced terminal chatbot
├── chat_in_ui.py # Gradio UI version
├── prepare_sqldb.py # Creates SQLite DB
├── prepare_vectordb.py # Creates Vector DB
├── check_sqldb.py # Checks SQLite DB contents
├── check_vectordb.py # Checks Vector DB contents
├── notion_mcp_server/ # 🆕 Complete Notion MCP Server
│ ├── core_operations.py # Basic Notion operations
│ ├── analytics_operations.py # Workspace analytics
│ ├── bulk_operations.py # Bulk operations
│ ├── update_operations.py # Content updates
│ ├── notion_utils.py # Utility functions
│ ├── api_serverV2.py # HTTP API server
│ ├── serverV2.py # MCP server implementation
│ ├── test_server.py # 🆕 48KB comprehensive test suite
│ └── README.md # 🆕 Complete MCP Server V2.1 documentation
└── utils/
├── basic_chatbot_v1.py # Basic chatbot implementation
├── chatbot_agentic_v2.py # Agentic chatbot v2
├── chatbot_agentic_v3.py # 🆕 Main enhanced chatbot (LATEST)
├── mcp_client_manager.py # 🆕 MCP client management
├── chat_history_manager.py
├── vector_db_manager.py
├── user_manager.py
├── prepare_system_prompt.py
├── search_manager.py
├── sql_manager.py
├── config.py
└── utils.py
# Testing Files
├── test_notion_integration.py # 🆕 Notion integration tests
├── test_notion_mcp.py # 🆕 MCP functionality tests
├── test_chatbot_integration.py # 🆕 Chatbot integration tests
└── [other test files...]
# Documentation
├── HOW_MCP_TOOLS_WORK.md # 🆕 MCP implementation guide
├── NOTION_INTEGRATION_README.md # 🆕 Notion integration docs
├── MCP_IMPLEMENTATION_COMPARISON.md # 🆕 Implementation comparison
├── MCP_NOTION_README.md # 🆕 MCP Notion setup guide
├── PRODUCTION_CONFIG.md # 🆕 Production deployment
└── README.md # This file
# Additional Directories
langgraph/ # LangGraph implementations
letta/ # Letta memory system
docker/ # 🆕 Docker deployment
config/ # Configuration files
data/ # Database storage
🛠️ Technologies Used
Core Technologies
- Python 3.11: Main programming language
- OpenAI API: GPT models for conversation and function calling
- Notion API: Complete workspace integration
Memory & Database
- SQLite: Structured data storage
- ChromaDB: Vector database for semantic search
- Embeddings: OpenAI text-embedding models
Integration & Protocols
- MCP (Model Context Protocol): Standard tool integration
- HTTP/stdio: Multiple transport protocols
- JSON-RPC: Communication protocol
UI & Testing
- Gradio: Web-based user interface
- Terminal: Command-line interface
- Comprehensive Testing: Integration and unit tests
📊 System Schemas
LLM Default Behavior

Concept of Memory

Basic Chatbot Schema

Agentic_Chatbot_v2 Schema

Agentic_Chatbot_v3 Schema (Old Version)

Longterm Memory with Graph DB and Vector DB using LangGraph

Longterm Memory (Semantic, Episodical, and Procedural) with LangGraph

Old Project Structure

🚀 Getting Started
- Read the Documentation: Start with 🤖 Complete System Explanation
- Explore the MCP Server: Check out our Notion MCP Server V2.1 - production-ready with comprehensive testing
- Set up Environment: Follow the installation steps above
- Configure Notion: Set up your Notion integration token
- Run Tests: Verify everything works with the test files
- Start Chatting: Use the enhanced chatbot with natural language
🤝 Contributing
Feel free to contribute by:
- Adding new Notion operations
- Improving memory systems
- Enhancing the MCP implementation
- Adding more test cases
- Improving documentation
📄 License
This project is open source
🎉 This is a complete AI agent system with production-ready Notion integration, advanced memory management, and MCP protocol implementation!
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。