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 |