notion

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Notion CLI

Notion CLI

A CLI to manage Notion from the command line, using Notion's remote MCP server.
这是一个通过Notion远程MCP server从命令行管理Notion的CLI工具。

Prerequisites

前置条件

The
notion-cli
command must be available on PATH. To check:
bash
notion-cli --version
If not installed:
bash
go install github.com/lox/notion-cli@latest
notion-cli
命令必须在PATH环境变量中可用。可通过以下命令检查:
bash
notion-cli --version
如果未安装,请执行:
bash
go install github.com/lox/notion-cli@latest

Authentication

身份验证

The CLI uses OAuth authentication. On first use, it opens a browser for authorization:
bash
notion-cli auth login      # Authenticate with Notion
notion-cli auth status     # Check authentication status
notion-cli auth logout     # Clear credentials
For CI/headless environments, set
NOTION_ACCESS_TOKEN
environment variable.
该CLI使用OAuth进行身份验证。首次使用时,会打开浏览器进行授权:
bash
notion-cli auth login      # 登录Notion完成身份验证
notion-cli auth status     # 查看身份验证状态
notion-cli auth logout     # 清除凭证
对于CI/无头环境,请设置
NOTION_ACCESS_TOKEN
环境变量。

Available Commands

可用命令

notion-cli auth            # Manage authentication
notion-cli page            # Manage pages (list, view, create, upload, edit)
notion-cli db              # Manage databases (list, query)
notion-cli search          # Search the workspace
notion-cli comment         # Manage comments (list, create)
notion-cli tools           # List available MCP tools
notion-cli auth            # 管理身份验证
notion-cli page            # 管理页面(列出、查看、创建、上传、编辑)
notion-cli db              # 管理数据库(列出、查询)
notion-cli search          # 搜索工作区
notion-cli comment         # 管理评论(列出、创建)
notion-cli tools           # 列出可用的MCP工具

Common Operations

常用操作

Search

搜索

bash
notion-cli search "meeting notes"           # Search workspace
notion-cli search "project" --limit 5       # Limit results
notion-cli search "query" --json            # JSON output
bash
notion-cli search "meeting notes"           # 搜索工作区
notion-cli search "project" --limit 5       # 限制结果数量
notion-cli search "query" --json            # 以JSON格式输出

Pages

页面

All page commands accept a URL, name, or ID to identify pages.
bash
undefined
所有页面命令均接受URL名称ID来指定页面。
bash
undefined

List pages

列出页面

notion-cli page list notion-cli page list --limit 10 notion-cli page list --json
notion-cli page list notion-cli page list --limit 10 notion-cli page list --json

View a page (renders as markdown in terminal)

查看页面(在终端中以markdown格式渲染)

notion-cli page view <page> notion-cli page view <page> --raw # Show raw Notion markup notion-cli page view <page> --json # JSON output notion-cli page view "Meeting Notes" # By name notion-cli page view https://notion.so/... # By URL
notion-cli page view <page> notion-cli page view <page> --raw # 显示原始Notion标记语言 notion-cli page view <page> --json # 以JSON格式输出 notion-cli page view "Meeting Notes" # 通过名称查看 notion-cli page view https://notion.so/... # 通过URL查看

Create a page

创建页面

notion-cli page create --title "New Page" notion-cli page create --title "Doc" --content "# Heading\n\nContent here" notion-cli page create --title "Child" --parent "Engineering" # Parent by name notion-cli page create --title "Child" --parent <page-id> # Parent by ID
notion-cli page create --title "New Page" notion-cli page create --title "Doc" --content "# 标题\n\n内容在此处" notion-cli page create --title "Child" --parent "Engineering" # 通过名称指定父页面 notion-cli page create --title "Child" --parent <page-id> # 通过ID指定父页面

Upload a markdown file as a page

将markdown文件上传为页面

notion-cli page upload ./document.md notion-cli page upload ./doc.md --title "Custom Title" notion-cli page upload ./doc.md --parent "Parent Page Name"
notion-cli page upload ./document.md notion-cli page upload ./doc.md --title "自定义标题" notion-cli page upload ./doc.md --parent "父页面名称"

Sync a markdown file (create or update)

同步markdown文件(创建或更新)

First run creates the page and writes notion-id to the file's frontmatter.

首次运行会创建页面,并将notion-id写入文件的前置元数据中。

Subsequent runs update the page content using the stored notion-id.

后续运行会使用存储的notion-id更新页面内容。

notion-cli page sync ./document.md notion-cli page sync ./document.md --parent "Engineering" # Set parent on first sync notion-cli page sync ./document.md --title "Custom Title"
notion-cli page sync ./document.md notion-cli page sync ./document.md --parent "Engineering" # 首次同步时设置父页面 notion-cli page sync ./document.md --title "自定义标题"

Edit a page

编辑页面

notion-cli page edit <page> --replace "New content" notion-cli page edit <page> --find "old text" --replace-with "new text" notion-cli page edit <page> --find "section" --append "additional content"
undefined
notion-cli page edit <page> --replace "新内容" notion-cli page edit <page> --find "旧文本" --replace-with "新文本" notion-cli page edit <page> --find "章节" --append "附加内容"
undefined

Databases

数据库

bash
notion-cli db list                          # List databases
notion-cli db list --json

notion-cli db query <database-url-or-id>    # Query a database
notion-cli db query <id> --json
bash
notion-cli db list                          # 列出数据库
notion-cli db list --json

notion-cli db query <database-url-or-id>    # 查询数据库
notion-cli db query <id> --json

Comments

评论

bash
notion-cli comment list <page-id>           # List comments on a page
notion-cli comment list <page-id> --json

notion-cli comment create <page-id> --content "Great work!"
bash
notion-cli comment list <page-id>           # 列出页面上的评论
notion-cli comment list <page-id> --json

notion-cli comment create <page-id> --content "做得好!"

Output Formats

输出格式

Most commands support
--json
for machine-readable output:
bash
notion-cli page list --json | jq '.[0].url'
notion-cli search "api" --json | jq '.[] | .title'
大多数命令支持
--json
参数以生成机器可读的输出:
bash
notion-cli page list --json | jq '.[0].url'
notion-cli search "api" --json | jq '.[] | .title'

Tips for Agents

给Agent的提示

  1. Search first - Use
    notion-cli search
    to find pages before operating on them
  2. Use URLs or IDs - Both work for page/database references
  3. Check --help - Every command has detailed help:
    notion-cli page edit --help
  4. Raw output - Use
    --raw
    with
    page view
    to see the original Notion markup
  5. JSON for parsing - Use
    --json
    when you need to extract specific fields
  1. 先搜索 - 在操作页面之前,使用
    notion-cli search
    查找目标页面
  2. 使用URL或ID - 页面/数据库引用支持URL或ID两种方式
  3. 查看--help - 每个命令都有详细帮助信息:
    notion-cli page edit --help
  4. 原始输出 - 结合
    --raw
    参数使用
    page view
    命令可查看原始Notion标记语言
  5. JSON用于解析 - 当需要提取特定字段时,使用
    --json
    参数