Notion MCP Server for ChatGPT
A Model Context Protocol (MCP) server that connects your Notion account with ChatGPT, allowing controlled access to specific Notion pages.
Features
- 🔒 Page-specific access control - Only grant access to specific Notion pages
- 🔍 Search functionality - Search across your authorized Notion pages
- 📄 Fetch full content - Retrieve complete page content including blocks
- 🔐 OAuth support - Secure authentication with Notion
- 🚀 FastMCP powered - Built with FastMCP for easy deployment
Architecture
This MCP server implements two required tools:
-
search- Search across authorized Notion pages
- Returns:{results: [{id, title, url}]} -
fetch- Retrieve full content of a specific page
- Returns:{id, title, text, url, metadata}
Setup
Prerequisites
- Python 3.8+
- Notion account
- Notion Integration (API key)
Installation
- Clone this repository:```bash
git clone <your-repo-url>
cd ChatGPT\ Notion\ MCP\ Server
2. Install dependencies:```bash
pip install -r requirements.txt
- Create a
.envfile with your configuration:```env
NOTION_API_KEY=your_notion_api_key
ALLOWED_PAGE_IDS=page_id_1,page_id_2,page_id_3
PORT=8000
### Getting Your Notion API Key
1. Go to https://www.notion.so/my-integrations
2. Click "New integration"
3. Give it a name (e.g., "ChatGPT MCP Server")
4. Copy the "Internal Integration Token"
5. Share specific pages with your integration:
- Open each page you want to grant access to
- Click "Share" → "Invite" → Select your integration
### Getting Page IDs
1. Open a Notion page in your browser
2. The URL will look like: `https://www.notion.so/Page-Title-32charPageID`
3. Copy the 32-character ID at the end
4. Add multiple page IDs to `ALLOWED_PAGE_IDS` (comma-separated)
## Running the Server
### Local Development```bash
python server.py
The server will start on http://localhost:8000
Deploy to Replit
- Import this repository to Replit
- Add environment variables in Replit Secrets
- Run the project
Connecting to ChatGPT
Via ChatGPT Settings
- Open ChatGPT Settings → Connectors
- Add a new MCP server
- Enter your server URL (e.g.,
https://your-server.repl.co/sse/) - Add the
searchandfetchtools
Via API (Deep Research)```bash
curl https://api.openai.com/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "o4-mini-deep-research",
"input": [...],
"tools": [
{
"type": "mcp",
"server_label": "notion",
"server_url": "https://your-server.com/sse/",
"allowed_tools": ["search", "fetch"],
"require_approval": "never"
}
]
}'
## Security Considerations
- ⚠️ Only add page IDs for pages you want ChatGPT to access
- 🔒 Keep your `NOTION_API_KEY` secret
- 🛡️ Review the OpenAI MCP Security Guidelines
- ✅ Use HTTPS in production
- 🔐 Consider implementing OAuth for multi-user scenarios
## Testing
Test your server locally:```bash
# Search test
curl http://localhost:8000/test-search?query=test
# Fetch test
curl http://localhost:8000/test-fetch?page_id=YOUR_PAGE_ID
Troubleshooting
"Page not found" error
- Ensure the page is shared with your integration
- Verify the page ID is in
ALLOWED_PAGE_IDS
"Unauthorized" error
- Check your
NOTION_API_KEYis correct - Verify the integration has access to the pages
Connection issues
- Ensure your server is publicly accessible
- Check firewall settings
- Verify HTTPS is enabled (required for production)
