Neon CLI
$ neonctl 官方出品 中风险Neon CLI 用于管理 Neon Serverless Postgres 项目、写时复制分支、计算端点与角色。全命令支持 --output json 与非交互式 NEON_API_KEY 鉴权,其秒级分支工作流非常适合 AI 编程 Agent 进行隔离测试。
brew install neonctl 确定性的分支生命周期、CI 脚本和连接串获取适合使用 neonctl;如需自然语言交互式 SQL 探索,可搭配 Neon MCP 服务。
Agent 友好度体检单
当前为静态评估(本机尚未安装或尚未运行探针)。可在本地运行 npm run data:probe 并提交 data/probes/ 升级为实测证据。
FCRS-1.0 六维评分拆解
原生支持 --output json / yaml / table、非交互式 NEON_API_KEY 鉴权与清晰的子命令结构。
- Supports
--output jsonacross resource commands andNEON_API_KEYenv auth
写时复制分支机制天然支持隔离测试,但 branches delete 与 projects delete 仍需护栏约束。
- Isolated branch creation protects production
main; delete commands have remote impact
提供 brew、npm、npx 及多平台独立二进制,跨 macOS、Linux、Windows 开箱即用。
- Multi-channel distribution via Homebrew and npm
Agent 可在数秒内创建临时 Postgres 分支并拿到连接 URI。
- Instant copy-on-write Postgres branching in a single command
由 Neon 官方在 neondatabase/neonctl 仓库以 Apache-2.0 协议维护。
- Official
neondatabase/neonctlrepo
官方 CLI 参考文档详尽,包含各命令参数表与示例。
- Official reference at neon.tech/docs/reference/neon-cli
安全边界、鉴权与放权指南
OAuth 凭证保存在 ~/.config/neonctl/credentials.json,也可通过 NEON_API_KEY 环境变量或 --api-key 传入。
CLI 以 Apache-2.0 开源;Neon 提供免费额度,付费方案按计算与存储用量计费。
# Neon CLI Agent Rules - Always pass `--output json` and set `NEON_API_KEY` for headless runs. - Create an isolated branch with `neonctl branches create` before running schema migrations. - NEVER run `neonctl projects delete` or `neonctl branches delete main` autonomously.
Agent 高频安全命令配方
只读查询(安全推荐)
neonctl projects list --output json
获取结构化 JSON 格式的项目 ID、区域和 Postgres 版本信息。
neonctl connection-string main --project-id <project-id> --output json
返回指定分支的 PostgreSQL URI 供下游迁移或查询工具使用。
受控写入与预演
neonctl branches create --name agent-test --project-id <project-id> --output json
拉起写时复制的 Postgres 分支,确保 Agent 不会直接修改 main 主分支。
核心优势
- + 一致的
--output json输出让项目与分支自动化极易解析。 - + 写时复制
branches create让 Agent 能在独立分支安全验证迁移。 - +
NEON_API_KEY便于无头 CI 与 Agent 环境免交互运行。
注意事项与踩坑点
- !
connection-string会向 stdout 输出数据库密码,注意在共享日志中脱敏。 - ! 删除类破坏性操作缺少原生
--dry-run预演开关。