{"slug": "build-a-local-notion-mcp-server-with-an-explicit-write-allowlist", "title": "Build a local Notion MCP server with an explicit write allowlist", "summary": "A developer published a guide for building a local Notion MCP server that exposes only two narrowly scoped tools to Claude or Cursor: reading a page title and creating a child page. The server enforces two independent allowlists via NOTION_READ_PAGES and NOTION_WRITE_PARENTS environment variables, so read permission never implies write permission, and callers can supply only a title and parent ID, not the destination URL, token, or arbitrary page properties. It runs on Node 22+ with the Model Context Protocol SDK over stdio, though the developer notes the bridge still calls the hosted Notion API and does not make the workspace or model session offline.", "body_md": "A local MCP server can give Claude or Cursor two narrowly scoped Notion tools: read a page title and create a child page. The client launches Node and communicates with it over standard input and output. The server calls the hosted Notion API, and the MCP client receives the returned title or new page ID. Running the bridge locally does not make the workspace or the model session offline.\n\nCreate an internal Notion integration with read-content capabilities. Enable insert-content capabilities only if you intend to create pages. Share the relevant pages with the integration in Notion. Use a disposable parent for your first write. Format the 32-character page IDs as hyphenated UUIDs rather than pasting full URLs. The server applies two independent lists: permission to read a title never grants permission to write under that page.\n\nUse Node 22 or newer. In an empty directory run:\n\n```\nnpm init -y\nnpm install --save-exact @modelcontextprotocol/sdk@1.32.2 zod@3.25.76\n```\n\nSupply NOTION_TOKEN through the local process environment using your existing secret manager. Set NOTION_READ_PAGES to a comma-separated list of page UUIDs. Leave NOTION_WRITE_PARENTS empty initially. A malformed ID stops startup. For clients launched from a desktop shortcut, verify that the launched server inherits these variables. Keep the token out of shared client configuration and source control.\n\nSave the following as server.js in that directory. The parent ID is checked before the server builds the outbound POST. Callers can supply a title and parent ID only. They cannot choose the destination URL, integration token, or arbitrary page properties.\n\n``` js\nconst { McpServer } = require(\"@modelcontextprotocol/sdk/server/mcp.js\");\nconst { StdioServerTransport } = require(\"@modelcontextprotocol/sdk/server/stdio.js\");\nconst { z } = require(\"zod\");\n\nconst id = z.string().uuid().transform(value => value.toLowerCase());\nconst title = z.string().trim().min(1).max(200);\nfunction allowedPages(variable) {\n  const raw = process.env[variable];\n  if (!raw || !raw.trim()) return new Set();\n  return new Set(raw.split(\",\").map(value => id.parse(value.trim())));\n}\n\nasync function main() {\n  const reads = allowedPages(\"NOTION_READ_PAGES\");\n  const writes = allowedPages(\"NOTION_WRITE_PARENTS\");\n  const token = process.env.NOTION_TOKEN;\n  if (!token) throw new Error(\"Set NOTION_TOKEN\");\n  const server = new McpServer({ name: \"local-notion\", version: \"1.0.0\" });\n\n  async function notion(path, options = {}) {\n    const response = await fetch(\"https://api.notion.com/v1/\" + path, {\n      ...options,\n      headers: {\n        Authorization: \"Bearer \" + token,\n        \"Notion-Version\": \"2025-09-03\",\n        \"Content-Type\": \"application/json\"\n      },\n      redirect: \"error\",\n      signal: AbortSignal.timeout(10000)\n    });\n    if (!response.ok) throw new Error(\"Notion returned HTTP \" + response.status);\n    return response.json();\n  }\n  function result(text) {\n    return { content: [{ type: \"text\", text }] };\n  }\n  server.registerTool(\"read_title\", {\n    description: \"Read the title of an allowed page\",\n    inputSchema: { page_id: id }\n  }, async ({ page_id }) => {\n    if (!reads.has(page_id)) throw new Error(\"Page is outside the read allowlist\");\n    const page = await notion(\"pages/\" + page_id);\n    const property = Object.values(page.properties).find(p => p.type === \"title\");\n    return result((property?.title || []).map(t => t.plain_text).join(\"\"));\n  });\n  server.registerTool(\"create_child\", {\n    description: \"Create one child page under an allowed parent\",\n    inputSchema: { parent_id: id, title }\n  }, async ({ parent_id, title }) => {\n    if (!writes.has(parent_id)) throw new Error(\"Parent is outside the write allowlist\");\n    const page = await notion(\"pages\", {\n      method: \"POST\",\n      body: JSON.stringify({\n        parent: { type: \"page_id\", page_id: parent_id },\n        properties: { title: { type: \"title\", title: [{ type: \"text\", text: { content: title } }] } }\n      })\n    });\n    return result(page.id);\n  });\n  await server.connect(new StdioServerTransport());\n}\nmain().catch(error => {\n  console.error(error.message);\n  process.exitCode = 1;\n});\n```\n\nConfigure your MCP client's local stdio server entry with the absolute path to the Node executable as the command and the absolute path to server.js as its sole argument. Restart the server after changing its environment. Tool discovery should show read_title and create_child. Because it uses stdio transport, no HTTP listener or background daemon is required.\n\nFirst call read_title with an ID from the read list. Then request create_child with that same ID while the write list is empty. Expect an allowlist error and no outbound write. To enable one write destination, put the disposable parent UUID in NOTION_WRITE_PARENTS, restart the server and request a child titled “MCP smoke test”. Check the returned ID against the child in Notion. Another parent must still be denied. A successful local allowlist check cannot override Notion's own page-sharing rules or integration capabilities.\n\nIf a create request times out, inspect the intended parent before retrying. Notion may have created the page before the response was lost. The server makes one request and has no idempotency ledger. A caller that needs automatic retries must reconcile the first attempt.\n\nThe example was tested with a real MCP client and server over stdio and a fixture in place of the Notion API. The checks covered tool discovery, allowed reads, malformed input, denied destinations, an empty write list and the exact outgoing parent and title for an allowed write. Live workspace writes and desktop-client setup were outside that test.", "url": "https://wpnews.pro/news/build-a-local-notion-mcp-server-with-an-explicit-write-allowlist", "canonical_source": "https://dev.to/ai_automationblueprint_8/build-a-local-notion-mcp-server-with-an-explicit-write-allowlist-lf2", "published_at": "2026-11-28 17:06:00+00:00", "updated_at": "2026-11-28 17:13:52.076256+00:00", "lang": "en", "topics": ["ai-agents", "agent-protocols", "ai-tools", "developer-tools"], "entities": ["Notion", "Claude", "Cursor", "Model Context Protocol", "Node.js", "Zod"], "also_reported_by": [], "takeaway": "Enforce separate read and write allowlists (NOTION_READ_PAGES vs NOTION_WRITE_PARENTS) checked before any outbound Notion API call, and expose only title and parent ID as tool inputs so callers cannot choose the destination URL, token, or page properties.", "recommendation": {"advice": "Scope MCP tools with independent read and write allowlists validated before each API call, and keep tokens in the process environment rather than shared client config.", "playbook": "agent-security", "playbook_url": "https://wpnews.pro/playbooks/agent-security"}, "alternates": {"html": "https://wpnews.pro/news/build-a-local-notion-mcp-server-with-an-explicit-write-allowlist", "markdown": "https://wpnews.pro/news/build-a-local-notion-mcp-server-with-an-explicit-write-allowlist.md", "text": "https://wpnews.pro/news/build-a-local-notion-mcp-server-with-an-explicit-write-allowlist.txt", "jsonld": "https://wpnews.pro/news/build-a-local-notion-mcp-server-with-an-explicit-write-allowlist.jsonld"}}