api reference
CLI
命令行接口——init、build、doctor 和 mcp。
next-ai-ready 提供四个 CLI 命令,用于构建、验证和运行你的 AI 就绪站点。
命令
`next-ai-ready init`
在项目中脚手架化 handler 桩文件和配置。
npx next-ai-ready init创建:
ai-ready.config.mjs— 带占位值的站点配置。app/_ai-ready/— route handler 桩文件(一行 re-export)。app/api/actions/[name]/route.ts— action 执行端点。app/api/mcp/[transport]/route.ts— MCP 服务器端点。actions/index.mjs— 带ping健康检查的 starter action 文件。
使用 --force 覆盖已有文件。
`next-ai-ready build`
扫描内容、编译语义图谱并产出所有产物。
npx next-ai-ready build产出:
.next-ai-ready/graph.json— SemanticGraph。.next-ai-ready/actions.manifest.json— 带 JSON Schema 的 action 清单。public/llms.txt— 全站 LLM 索引。public/llms-full.txt— 完整内容(含正文;frontmatter 有questions时追加## FAQ)。public/openapi.json— OpenAPI 3.1 规范。public/tools.json— 工具定义。public/.well-known/ai-plugin.json— 插件清单。public/robots.txt— AI 爬虫策略。
使用 --silent 抑制控制台输出(CI 中有用)。
典型的 package.json 配置:
{
"scripts": {
"build": "next-ai-ready build && next build"
}
}`next-ai-ready doctor`
验证你的配置、action 暴露规则和路由接线。
npx next-ai-ready doctor
npx next-ai-ready doctor --score # 0–100 就绪分数 + 优先修复建议
npx next-ai-ready doctor --json # 机器可读报告(含 actionItems)检查项包括:
1. 配置 — ai-ready.config.mjs 及必填的 site.name、site.baseUrl、site.description。
2. Actions — 公开/私有统计;公开 action 缺少 whenToUse 时警告。
3. 构建产物 — graph、OpenAPI、package.json 是否含 prebuild。
4. 路由桩文件 — app/_ai-ready/* 与 next.config 中的 withAiReady()。
5. Robots — public/robots.txt 或 app/robots.ts(emit.robots: false 时不会因缺少静态文件误报)。
6. MCP — 生产环境未设置 NEXT_AI_READY_MCP_TOKEN 时警告。
7. 内容质量 — noai、JSON-LD helper、updatedAt / author 覆盖率。
发现错误时以代码 1 退出。警告不会导致非零退出。
使用 --score 时会打印 Top fixes(如添加 prebuild、配置 MCP token、补充 frontmatter)。
在 CI 中使用:
# .github/workflows/ci.yml
- run: npx next-ai-ready doctor --score`next-ai-ready mcp`
通过 stdio 启动 MCP 服务器,供本地桌面客户端使用。
npx next-ai-ready mcp选项:
| 标志 | 说明 |
|---|---|
--no-resources | 跳过页面资源注册(启动更快)。 |
配合 Claude Desktop 使用:
{
"mcpServers": {
"my-site": {
"command": "npx",
"args": ["next-ai-ready", "mcp"]
}
}
}退出码
| 代码 | 含义 |
|---|---|
0 | 成功。 |
1 | 错误(缺少配置、无效 action、构建失败)。 |
2 | 未知命令。 |