Build a Real MCP Server: Turn Notion into an AI Knowledge Base
Build a working MCP server in about 30 lines of Python that exposes Notion search and page reading to any MCP client.
📖 Keep reading
MCP has three primitives: tools (model-invoked functions with parameters), resources (read-only data mounted as context), and prompts (reusable templates). A knowledge base mainly needs tools.
Setup: pip install mcp notion-client, Python 3.10+. The official SDK ships FastMCP, so server code resembles FastAPI. On the Notion side, create an internal integration, copy the token, then connect the integration to the target pages. Skipping that connection step is why search returns empty results.
Minimal server: instantiate FastMCP, decorate search_pages and read_page with @mcp.tool(), expose a page as @mcp.resource("notion://page/{page_id}"), then mcp.run(transport="stdio"). Tool docstrings are what the model reads when choosing a tool, so describe when to use it and what it returns.
Register in claude_desktop_config.json or .cursor/mcp.json with command, args and an env block holding NOTION_TOKEN.
Two debugging facts: stdout is the protocol channel in stdio mode, so any print() corrupts the stream and the client shows tools that never execute; send debug output to stderr. Test standalone with npx @modelcontextprotocol/inspector.
Production hardening: filter search to pages, paginate block children, cap returned characters, scope the integration to one knowledge base, return explicit error text the model can read, and log every tool call. Keep the tool count small; a dozen-plus tools in one server measurably degrades tool selection.
Written by our editorial team; tools listed here are tested or verified against public sources. Links point to official sites or GitHub repos for reference only — no paid placements.