mcpField
N
notion

notion

github.com/openhands生产力17582 次安装1 天前更新
代码仓库

关于 notion

用于操作 Notion 页面和数据库的技能,可通过已认证的 MCP 工具或 Notion REST API 执行操作。提供 API 示例,并说明凭据、共享设置及 Windows PowerShell 写法。

主要功能

  1. 01优先使用已认证的 Notion MCP 工具
  2. 02按标题搜索页面
  3. 03创建页面并追加区块
  4. 04直接调用 REST API 的示例
  5. 05Windows PowerShell 等效写法

适用场景

  1. 01按标题查找 Notion 页面
  2. 02在父页面下创建页面
  3. 03向现有页面追加内容

MCP 相关

环境提供已认证的 Notion MCP 工具时,技能建议优先使用这些工具。MCP 不可用或需要直接访问原始 API 时,也说明了如何使用 REST API。

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/openhands/extensions --skill notion

安装后在 Claude Code 中输入/notion确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

README.md
.plugin/
plugin.json
references/
windows.md

详细介绍

Notion

重复使用的 Notion REST curl、环境变量和 JSON 请求体片段的 Windows PowerShell 等效写法位于 references/windows.md。

如果环境中提供了经过身份验证的 Notion MCP 工具,请优先使用。MCP 工具无需将 `NOTION_INTEGRATION_KEY` 作为工具参数传递;身份验证由已配置的 MCP 集成处理。

仅当 MCP 不可用或你明确需要原始 API/curl 访问时,才使用以下直接调用 Notion REST API 的示例。对于直接调用 API 的方式,请先检查是否已设置所需的环境变量:

[ -n "$NOTION_INTEGRATION_KEY" ] && echo "NOTION_INTEGRATION_KEY is set" || echo "NOTION_INTEGRATION_KEY is NOT set"

如果该变量缺失,且你需要使用直接调用 API 的方式,请在继续前让用户提供该变量(或连接 Notion 集成):

  • NOTION_INTEGRATION_KEY:Notion 集成密钥(以 ntn_... 开头)

无论使用 MCP 还是直接调用 API,都请确认已在 Notion 中将已配置的集成共享给目标页面/数据库。

直接调用 API 时的基本请求头

-H "Authorization: Bearer ${NOTION_INTEGRATION_KEY}" \
-H "Notion-Version: 2022-06-28" \
-H "Content-Type: application/json"

查找页面(搜索)

使用 Notion 的搜索端点按标题查找页面。

curl -s https://api.notion.com/v1/search \
  -H "Authorization: Bearer ${NOTION_INTEGRATION_KEY}" \
  -H "Notion-Version: 2022-06-28" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "OpenHands Wiki",
    "page_size": 10
  }' | jq .

在父页面下创建页面

PARENT_PAGE_ID="<parent_page_id>"

curl -s https://api.notion.com/v1/pages \
  -H "Authorization: Bearer ${NOTION_INTEGRATION_KEY}" \
  -H "Notion-Version: 2022-06-28" \
  -H "Content-Type: application/json" \
  -d '{
    "parent": {"type": "page_id", "page_id": "'"${PARENT_PAGE_ID}"'"},
    "properties": {
      "title": {
        "title": [{"type": "text", "text": {"content": "My new page"}}]
      }
    },
    "children": [
      {
        "object": "block",
        "type": "paragraph",
        "paragraph": {
          "rich_text": [{"type": "text", "text": {"content": "Hello from OpenHands."}}]
        }
      }
    ]
  }' | jq .

向现有页面追加块

使用页面的块 ID(与页面 ID 相同)来追加子项。

PAGE_ID="<page_id>"

curl -s -X PATCH "https://api.notion.com/v1/blocks/${PAGE_ID}/children" \
  -H "Authorization: Bearer ${NOTION_INTEGRATION_KEY}" \
  -H "Notion-Version: 2022-06-28" \
  -H "Content-Type: application/json" \
  -d '{
    "children": [
      {
        "object": "block",
        "type": "heading_2",
        "heading_2": {"rich_text": [{"type": "text", "text": {"content": "Appended section"}}]}
      }
    ]
  }' | jq .

提示/注意事项

  • 必须共享:即使密钥有效,在 Notion 界面中将页面/数据库共享给该集成之前,集成也无法查看它们。
  • 速率限制:保持请求较小;对于较大的页面,请先创建页面,然后分批追加块。
  • ID 格式:Notion ID 返回时可能带有连字符;在 API 调用中,带连字符和不带连字符的形式通常都可用。

文档

评论

支持 Markdown