Next.js DevTools 是做什么的?
通过 MCP 服务器检查并调试 Next.js 应用。
快速开始
# 启动服务器(按需启动)
bash scripts/start-server.sh
# 或通过 mcp-client 直接使用
python3 scripts/mcp-client.py call \
-s "npx next-devtools-mcp@latest" \
-t list-routes
可用工具
| 工具 | 描述 |
|---|---|
list-routes | 获取所有应用路由 |
get-route-info | 特定路由的详细信息 |
list-components | 应用中的 React 组件 |
get-build-info | 构建配置 |
get-config | next.config.js 设置 |
工作流程模式
模式 1:路由检查
# 列出所有路由
python3 scripts/mcp-client.py call \
-s "npx next-devtools-mcp@latest" \
-t list-routes
# 获取特定路由详情
python3 scripts/mcp-client.py call \
-s "npx next-devtools-mcp@latest" \
-t get-route-info \
-p '{"route": "/api/auth"}'
模式 2:调试构建问题
# 检查构建配置
python3 scripts/mcp-client.py call \
-s "npx next-devtools-mcp@latest" \
-t get-build-info
# 检查 next.config.js
python3 scripts/mcp-client.py call \
-s "npx next-devtools-mcp@latest" \
-t get-config
模式 3:组件发现
python3 scripts/mcp-client.py call \
-s "npx next-devtools-mcp@latest" \
-t list-components
脚本
start-server.sh
用于持久化服务器(多次调用):
bash scripts/start-server.sh
# 服务器在默认端口运行
# 使用 mcp-client.py 时加上 -u 标志代替 -s
按需模式(推荐)
对于单次调用,使用 -s 标志,每次调用都会启动一个服务器:
python3 scripts/mcp-client.py call \
-s "npx next-devtools-mcp@latest" \
-t <tool-name>
故障排查
| 问题 | 解决方案 |
|---|---|
| 服务器无法启动 | 手动检查 npx next-devtools-mcp@latest 是否可用 |
| 未找到路由 | 确保在 Next.js 项目根目录中运行 |
| 构建信息为空 | 先运行 next build |