Notion Mcp 伺服器
概覽
什麼是 mcp-notion-server?
mcp-notion-server 是一個開源項目,旨在促進與 Notion API 的互動。它作為一個後端伺服器,允許用戶以編程方式管理他們的 Notion 數據庫和頁面。這個項目對於希望將 Notion 的功能整合到他們的應用程序中或自動化涉及 Notion 的工作流程的開發者特別有用。
mcp-notion-server 的特點
- API 整合:無縫連接 Notion 的 API,使用戶能夠對其 Notion 數據庫執行 CRUD(創建、讀取、更新、刪除)操作。
- 用戶身份驗證:支持安全的用戶身份驗證,以確保只有授權用戶可以訪問和修改其 Notion 數據。
- 實時更新:提供數據變更的實時同步,確保用戶始終擁有最新的信息。
- 可自定義端點:允許開發者創建根據其特定需求量身定制的自定義 API 端點,增強靈活性和可用性。
- 文檔:提供全面的文檔,幫助用戶了解如何有效設置和使用伺服器。
如何使用 mcp-notion-server
-
安裝:從 GitHub 克隆倉庫並使用 npm 或 yarn 安裝必要的依賴。
git clone https://github.com/suekou/mcp-notion-server.git cd mcp-notion-server npm install -
配置:在配置文件中設置您的 Notion API 憑證。這通常涉及在 Notion 中創建一個集成並獲取 API 密鑰。
-
啟動伺服器:使用以下命令啟動伺服器:
npm start -
發送 API 請求:使用 Postman 或 cURL 等工具向伺服器的端點發送請求。您可以執行檢索頁面、更新數據庫條目等操作。
-
與應用程序集成:在您的應用程序中利用 API 自動化任務或增強與 Notion 的功能。
常見問題
mcp-notion-server 是用什麼編程語言構建的?
mcp-notion-server 主要使用 JavaScript(Node.js)構建,對於熟悉網頁技術的開發者來說非常容易上手。
mcp-notion-server 是免費使用的嗎?
是的,mcp-notion-server 是一個開源項目,根據 MIT 許可證免費使用。
我可以為 mcp-notion-server 項目做貢獻嗎?
當然可以!歡迎貢獻。您可以分叉倉庫,進行更改,並提交拉取請求以供審核。
我該如何報告問題或錯誤?
您可以通過在 GitHub 倉庫中打開問題來報告問題。請提供有關您遇到的問題的詳細信息。
我可以在哪裡找到文檔?
文檔可在倉庫的 README 文件中找到,也可以在項目的 docs 目錄中找到。
詳細
Notion MCP Server
MCP Server for the Notion API, enabling LLM to interact with Notion workspaces. Additionally, it employs Markdown conversion to reduce context size when communicating with LLMs, optimizing token usage and making interactions more efficient.
Setup
Here is a detailed explanation of the steps mentioned above in the following articles:
- English Version: https://dev.to/suekou/operating-notion-via-claude-desktop-using-mcp-c0h
- Japanese Version: https://qiita.com/suekou/items/44c864583f5e3e6325d9
-
Create a Notion Integration:
- Visit the Notion Your Integrations page.
- Click "New Integration".
- Name your integration and select appropriate permissions (e.g., "Read content", "Update content").
-
Retrieve the Secret Key:
- Copy the "Internal Integration Token" from your integration.
- This token will be used for authentication.
-
Add the Integration to Your Workspace:
- Open the page or database you want the integration to access in Notion.
- Click the "···" button in the top right corner.
- Click the "Connections" button, and select the the integration you created in step 1 above.
-
Configure Claude Desktop: Add the following to your
claude_desktop_config.json:
{
"mcpServers": {
"notion": {
"command": "npx",
"args": ["-y", "@suekou/mcp-notion-server"],
"env": {
"NOTION_API_TOKEN": "your-integration-token"
}
}
}
}
or
{
"mcpServers": {
"notion": {
"command": "node",
"args": ["your-built-file-path"],
"env": {
"NOTION_API_TOKEN": "your-integration-token"
}
}
}
}
Environment Variables
NOTION_API_TOKEN(required): Your Notion API integration token.NOTION_MARKDOWN_CONVERSION: Set to "true" to enable experimental Markdown conversion. This can significantly reduce token consumption when viewing content, but may cause issues when trying to edit page content.
Command Line Arguments
--enabledTools: Comma-separated list of tools to enable (e.g. "notion_retrieve_page,notion_query_database"). When specified, only the listed tools will be available. If not specified, all tools are enabled.
Read-only tools example (copy-paste friendly):
node build/index.js --enabledTools=notion_retrieve_block,notion_retrieve_block_children,notion_retrieve_page,notion_query_database,notion_retrieve_database,notion_search,notion_list_all_users,notion_retrieve_user,notion_retrieve_bot_user,notion_retrieve_comments
Advanced Configuration
Markdown Conversion
By default, all responses are returned in JSON format. You can enable experimental Markdown conversion to reduce token consumption:
{
"mcpServers": {
"notion": {
"command": "npx",
"args": ["-y", "@suekou/mcp-notion-server"],
"env": {
"NOTION_API_TOKEN": "your-integration-token",
"NOTION_MARKDOWN_CONVERSION": "true"
}
}
}
}
or
{
"mcpServers": {
"notion": {
"command": "node",
"args": ["your-built-file-path"],
"env": {
"NOTION_API_TOKEN": "your-integration-token",
"NOTION_MARKDOWN_CONVERSION": "true"
}
}
}
}
When NOTION_MARKDOWN_CONVERSION is set to "true", responses will be converted to Markdown format (when format parameter is set to "markdown"), making them more human-readable and significantly reducing token consumption. However, since this feature is experimental, it may cause issues when trying to edit page content as the original structure is lost in conversion.
You can control the format on a per-request basis by setting the format parameter to either "json" or "markdown" in your tool calls:
- Use
"markdown"for better readability when only viewing content - Use
"json"when you need to modify the returned content
Troubleshooting
If you encounter permission errors:
- Ensure the integration has the required permissions.
- Verify that the integration is invited to the relevant pages or databases.
- Confirm the token and configuration are correctly set in
claude_desktop_config.json.
Project Structure
The project is organized in a modular way to improve maintainability and readability:
./
├── src/
│ ├── index.ts # Entry point and command-line handling
│ ├── client/
│ │ └── index.ts # NotionClientWrapper class for API interactions
│ ├── server/
│ │ └── index.ts # MCP server setup and request handling
│ ├── types/
│ │ ├── index.ts # Type exports
│ │ ├── args.ts # Tool argument interfaces
│ │ ├── common.ts # Common schema definitions
│ │ ├── responses.ts # API response type definitions
│ │ └── schemas.ts # Tool schema definitions
│ ├── utils/
│ │ └── index.ts # Utility functions
│ └── markdown/
│ └── index.ts # Markdown conversion utilities
Directory Descriptions
- index.ts: Application entry point. Parses command-line arguments and starts the server.
- client/: Module responsible for communication with the Notion API.
- index.ts: NotionClientWrapper class implements all API calls.
- server/: MCP server implementation.
- index.ts: Processes requests received from Claude and calls appropriate client methods.
- types/: Type definition module.
- index.ts: Exports for all types.
- args.ts: Interface definitions for tool arguments.
- common.ts: Definitions for common schemas (ID formats, rich text, etc.).
- responses.ts: Type definitions for Notion API responses.
- schemas.ts: Definitions for MCP tool schemas.
- utils/: Utility functions.
- index.ts: Functions like filtering enabled tools.
- markdown/: Markdown conversion functionality.
- index.ts: Logic for converting JSON responses to Markdown format.
Tools
All tools support the following optional parameter:
format(string, "json" or "markdown", default: "markdown"): Controls the response format. Use "markdown" for human-readable output, "json" for programmatic access to the original data structure. Note: Markdown conversion only works when theNOTION_MARKDOWN_CONVERSIONenvironment variable is set to "true".
-
notion_append_block_children- Append child blocks to a parent block.
- Required inputs:
block_id(string): The ID of the parent block.children(array): Array of block objects to append.
- Returns: Information about the appended blocks.
-
notion_retrieve_block- Retrieve information about a specific block.
- Required inputs:
block_id(string): The ID of the block to retrieve.
- Returns: Detailed information about the block.
-
notion_retrieve_block_children- Retrieve the children of a specific block.
- Required inputs:
block_id(string): The ID of the parent block.
- Optional inputs:
start_cursor(string): Cursor for the next page of results.page_size(number, default: 100, max: 100): Number of blocks to retrieve.
- Returns: List of child blocks.
-
notion_delete_block- Delete a specific block.
- Required inputs:
block_id(string): The ID of the block to delete.
- Returns: Confirmation of the deletion.
-
notion_retrieve_page- Retrieve information about a specific page.
- Required inputs:
page_id(string): The ID of the page to retrieve.
- Returns: Detailed information about the page.
-
notion_update_page_properties- Update properties of a page.
- Required inputs:
page_id(string): The ID of the page to update.properties(object): Properties to update.
- Returns: Information about the updated page.
-
notion_create_database- Create a new database.
- Required inputs:
parent(object): Parent object of the database.properties(object): Property schema of the database.
- Optional inputs:
title(array): Title of the database as a rich text array.
- Returns: Information about the created database.
-
notion_query_database- Query a database.
- Required inputs:
database_id(string): The ID of the database to query.
- Optional inputs:
filter(object): Filter conditions.sorts(array): Sorting conditions.start_cursor(string): Cursor for the next page of results.page_size(number, default: 100, max: 100): Number of results to retrieve.
- Returns: List of results from the query.
-
notion_retrieve_database- Retrieve information about a specific database.
- Required inputs:
database_id(string): The ID of the database to retrieve.
- Returns: Detailed information about the database.
-
notion_update_database- Update information about a database.
- Required inputs:
database_id(string): The ID of the database to update.
- Optional inputs:
title(array): New title for the database.description(array): New description for the database.properties(object): Updated property schema.
- Returns: Information about the updated database.
-
notion_create_database_item- Create a new item in a Notion database.
- Required inputs:
database_id(string): The ID of the database to add the item to.properties(object): The properties of the new item. These should match the database schema.
- Returns: Information about the newly created item.
-
notion_search- Search pages or databases by title.
- Optional inputs:
query(string): Text to search for in page or database titles.filter(object): Criteria to limit results to either only pages or only databases.sort(object): Criteria to sort the resultsstart_cursor(string): Pagination start cursor.page_size(number, default: 100, max: 100): Number of results to retrieve.
- Returns: List of matching pages or databases.
-
notion_list_all_users- List all users in the Notion workspace.
- Note: This function requires upgrading to the Notion Enterprise plan and using an Organization API key to avoid permission errors.
- Optional inputs:
- start_cursor (string): Pagination start cursor for listing users.
- page_size (number, max: 100): Number of users to retrieve.
- Returns: A paginated list of all users in the workspace.
-
notion_retrieve_user- Retrieve a specific user by user_id in Notion.
- Note: This function requires upgrading to the Notion Enterprise plan and using an Organization API key to avoid permission errors.
- Required inputs:
- user_id (string): The ID of the user to retrieve.
- Returns: Detailed information about the specified user.
-
notion_retrieve_bot_user- Retrieve the bot user associated with the current token in Notion.
- Returns: Information about the bot user, including details of the person who authorized the integration.
-
notion_create_comment- Create a comment in Notion.
- Requires the integration to have 'insert comment' capabilities.
- Either specify a
parentobject with apage_idor adiscussion_id, but not both. - Required inputs:
rich_text(array): Array of rich text objects representing the comment content.
- Optional inputs:
parent(object): Must includepage_idif used.discussion_id(string): An existing discussion thread ID.
- Returns: Information about the created comment.
-
notion_retrieve_comments- Retrieve a list of unresolved comments from a Notion page or block.
- Requires the integration to have 'read comment' capabilities.
- Required inputs:
block_id(string): The ID of the block or page whose comments you want to retrieve.
- Optional inputs:
start_cursor(string): Pagination start cursor.page_size(number, max: 100): Number of comments to retrieve.
- Returns: A paginated list of comments associated with the specified block or page.
License
This MCP server is licensed under the MIT License. This means you are free to use, modify, and distribute the software, subject to the terms and conditions of the MIT License. For more details, please see the LICENSE file in the project repository.
伺服器配置
{
"mcpServers": {
"mcp-notion-server": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"ghcr.io/metorial/mcp-container--suekou--mcp-notion-server--mcp-notion-server",
"node build/index.js"
],
"env": {
"NOTION_API_TOKEN": "notion-api-token"
}
}
}
}