概念cli
](https://golang.org/) 
Notion使用远程MCP(模型上下文协议)的命令行界面。
受到启发 线性气候 -在管理Notion工作区时,请留在终端中。
与AI代理配合得很好 --包括a 技能 它允许代理在代码旁边搜索、创建和管理您的Notion工作区。
安装
源自
go install github.com/lox/notion-cli@latest本地建设
git clone https://github.com/lox/notion-cli
cd notion-cli
mise run build快速开始
# Authenticate with Notion (opens browser for OAuth)
notion-cli auth login
# Search your workspace
notion-cli search "meeting notes"
# View a page with open comments inline by default
notion-cli page view "https://notion.so/My-Page-abc123"
# Hide page and block comments when you only want the body
notion-cli page view "Meeting Notes" --no-comments
# List your pages
notion-cli page list
# Create a page
notion-cli page create --title "New Page" --content "# Hello World"命令
认证
notion-cli auth login # Authenticate with Notion via OAuth
notion-cli auth refresh # Refresh the access token
notion-cli auth status # Show authentication status
notion-cli auth logout # Clear stored credentials
# Official API fallback auth for features MCP cannot handle directly
notion-cli auth api setup # Opens the internal integrations page, prompts for token, warns if format looks wrong
notion-cli auth api status
notion-cli auth api verify
notion-cli auth api unset页面
notion-cli page list # List pages
notion-cli page list --limit 50 # Limit results
notion-cli page list --json # Output as JSON
notion-cli page view
# View page content with comments
notion-cli page view
--no-comments # Hide page and block comments
notion-cli page view
--raw # View raw Notion markup
notion-cli page view
--json # Output as JSON
notion-cli page create --title "Title" # Create a page
notion-cli page create --title "T" --content "Body text"
notion-cli page create --title "T" --parent
notion-cli page archive
# Archive a page via the official API
# Upload a markdown file as a new page
notion-cli page upload ./document.md # Title from # heading or filename
notion-cli page upload ./document.md --title "Custom Title" # Explicit title
notion-cli page upload ./document.md --parent "Engineering" # Parent by name or ID
notion-cli page upload ./document.md --parent-db # Upload as database entry
notion-cli page upload ./document.md --icon "📄" # Set emoji icon
notion-cli page upload ./document.md # Uploads standalone local images when configured
notion-cli page upload ./document.md --skip-local-images # Strips standalone local image lines instead
# Sync a markdown file (create or update)
notion-cli page sync ./document.md # Creates page, writes notion-id to frontmatter
notion-cli page sync ./document.md # Updates page using notion-id from frontmatter
notion-cli page sync ./document.md --parent "Engineering" # Set parent on first sync
notion-cli page sync ./document.md --parent-db # Sync as database entry
notion-cli page sync ./document.md # Uploads standalone local images when configured
notion-cli page sync ./document.md --skip-local-images # Strips standalone local image lines instead
# Edit an existing page
notion-cli page edit
--replace "New content" # Replace all content
notion-cli page edit
--replace "New content" --allow-deleting-content # Allow replacing pages with child content
notion-cli page edit
--find "old text" --replace-with "new text" # Find and replace
notion-cli page edit
--find "section" --append "extra content" # Append after match
notion-cli page edit
-P "Status=Done" -P "Priority=1" # Update page properties这 参数接受URL、ID或页面名称。
page archive 接受页面URL或页面ID,并通过官方API将该页面移到垃圾桶中。这需要通过配置官方API令牌 auth api setup 或 NOTION_API_TOKEN.
page view 默认情况下,显示打开页面级别的评论和内联块讨论。内联讨论在上下文中呈现,锚文本包裹在 [[...]] 下面显示的讨论。使用 --no-comments 为了抑制评论, --raw 检查原始Notion标记,以及 --json 返回页面加上a Comments 阵列。
page upload 和 page sync 支持本地图像上传,用于独立的markdown图像行,如 当存在局部图像时, notion-cli 通过官方的Notion API上传这些文件,并按文档顺序保存。这需要通过配置官方API令牌 auth api setup 或 NOTION_API_TOKEN.通行证 --skip-local-images 默默地删除独立的本地图像行,而不是上传它们。内联或混合内容本地图像语法被拒绝,而不是被猜测。
搜索
notion-cli search "query" # Search workspace
notion-cli search "query" --limit 10 # Limit results
notion-cli search "query" --json # Output as JSON数据库
notion-cli db list # List databases
notion-cli db list -q "project" # Filter by name
notion-cli db list --json # Output as JSON
notion-cli db query # Query database
notion-cli db query --json # Output as JSON
# Create an entry in a database
notion-cli db create --title "Entry Title"
notion-cli db create -t "Title" --prop "Status=Not started"
notion-cli db create -t "Title" --prop "Status=Done" --prop "date:Due:start=2026-03-01"
notion-cli db create -t "Title" --content "Body text"
notion-cli db create -t "Title" --file ./notes.md
notion-cli db create -t "Title" --json这 ` 参数接受URL、ID或名称。日期属性使用扩展密钥格式: date: :start, date: :end`.
评论
notion-cli comment list
# List open page and block comments
notion-cli comment list
--resolved # Include resolved discussions too
notion-cli comment list
--json # Output as JSON
notion-cli comment list "Meeting Notes" # Resolve the page by name
notion-cli comment create
--content "Comment text"
notion-cli comment create https://notion.so/... --content "Looks good"注释命令接受页面URL、ID或名称。 comment list 默认情况下,包括页面级和块级讨论,除非您通过,否则仅显示打开的讨论 --resolved.
其他
notion-cli tools # List available MCP tools
notion-cli tools --json # Output tools as JSON
notion-cli version # Show version
notion-cli --version # Alias for version
notion-cli -v # Short alias for version
notion-cli --help # Show help配置
CLI使用Notion的远程MCP服务器进行OAuth身份验证。在第一次运行时, notion-cli auth login 将打开浏览器,通过Notion工作区授权CLI。
注: 访问令牌将在1小时后过期。当令牌过期或即将过期时,CLI会自动刷新令牌,因此您通常不需要考虑这一点。使用 notion-cli auth refresh 如果需要,可以手动刷新。
环境变量
| 变量 | 描述 |
|---|---|
NOTION_ACCESS_TOKEN | 用于CI/无头使用的访问令牌(跳过OAuth) |
NOTION_API_TOKEN | 用于上传回退和验证的官方Notion API令牌 |
NOTION_API_BASE_URL | 覆盖官方的Notion API基础URL |
NOTION_API_NOTION_VERSION | 覆盖官方Notion API版本 |
运作原理
此CLI连接到 Notion的远程MCP服务器 在 https://mcp.notion.com/mcp 使用模型上下文协议。这提供了:
- OAuth身份验证 -没有要管理的API令牌
- Notion风格的Markdown -自然地创建/编辑内容
- 语义搜索 -也可以在连接的应用程序中搜索
- 针对CLI进行了优化 -高效响应
技能
cli概念包括一种帮助AI代理有效使用cli的技能。
安培/克劳德码
使用安装技能 技能s.sh:
npx skills add lox/notion-cli或者手动添加到Amp/Claude配置中:
# Amp
amp skill add https://github.com/lox/notion-cli/tree/main/skills/notion-cli
# Claude Code
claude plugin marketplace add lox/notion-cli
claude plugin install notion-cli@notion-cli在以下网址查看技能: 技能/概念/SKILL.md
链接
许可证
MIT许可证-请参阅 许可证 了解详情。
