名称: nextjs-devtools 描述: | Next.js 开发工具通过 MCP 实现。检查路由、组件、构建信息,并调试 Next.js 应用。 当您在处理 Next.js 应用程序、调试路由或检查应用结构时使用。 不适用于一般的 React 或非 Next.js 项目。
Next.js 开发工具
通过 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 <工具名称>
故障排除
| 问题 | 解决方案 |
|---|---|
| 服务器无法启动 | 手动检查 npx next-devtools-mcp@latest 是否正常工作 |
| 找不到路由 | 确保从 Next.js 项目根目录运行 |
| 构建信息为空 | 先运行 next build |