This workshop will guide you through building an MCP server that helps you manage your content database in Notion.
We will cover the basics of setting up a Notion API integration, creating a basic MCP server, and implementing core functionality such as querying and creating entries in the database.
If you don't have uv installed, you can install it using this command:
curl -LsSf https://astral.sh/uv/install.sh | sh
Make sure to restart your terminal afterwards to ensure that the uv command gets picked up.
- Create and set up our project:
# Create a new directory for our project
uv init content-database-mcp
cd content-database-mcp
# Create virtual environment and activate it
uv venv
source .venv/bin/activate
# Install dependencies
uv add "mcp[cli]" httpx
# Create our server file
touch main.py
- Add the MCP boilerplate code to main.py:
from typing import Any
import httpx
from mcp.server.fastmcp import FastMCP
# Initialize FastMCP server
mcp = FastMCP("content-database-mcp")
@mcp.tool()
async def my_tool() -> str:
"""My awesome tool."""
print("I am going to do something awesome today!")
if __name__ == "__main__":
# Initialize and run the server
print("Starting MCP server...")
mcp.run(transport='stdio')
- Test the server by running it:
uv run main.py
Great. We can kill the server with ctrl+c
, and connect this MCP server to cursor agent:
- Connect MCP server to Claude or Cursor.
Go to Settings
> MCP
and click on Add new Global MCP Server
. It will open an mcp.json
file. Configure your server with Cursor by adding the code below.
Open claude_desktop_config.json
file using the following command:
code ~/Library/Application\ Support/Claude/claude_desktop_config.json
Configure your server with Cursor by adding the code below.
{
"mcpServers": {
"content-database-mcp": {
"command": "uv",
"args": [
"--directory",
"/PATH/to/content-database-mcp",
"run",
"main.py"
]
}
}
}
This should output:
print("Starting MCP server...")
-
Duplicate the following Notion Template in your workspace: Content Database
-
Design the desired tools in our MCP server.
- Find Posts
- Create New Post
- Add content to post
-
Create Notion API Token at Notion Integrations
-
Provide your integration access to the desired database.
-
Configure environment by adding an .env file:
# .env file NOTION_TOKEN=your-notion-api-token
-
Install notion dependency:
uv add notion-client
-
Code simple query to fetch all posts in the database.
(Optional) Show how to test api calls ourside quickly
-
Implement the
find_posts
tool to fetch posts from the database. -
Implement the
create_post
tool to create a new post in the database. -
Implement the
add_content_to_post
tool to add content to a post in the database. -
Test the MCP server with an agent.