Add Dev MCP setup

This commit is contained in:
Haitao Pan 2026-01-13 23:34:56 +08:00
parent 3f16702d08
commit 3b7c7a08ff
4 changed files with 59 additions and 1 deletions

1
.gitignore vendored
View File

@ -48,6 +48,7 @@ coverage/
*.test-cache/ *.test-cache/
*.test-data/ *.test-data/
.env.test .env.test
.env
.env.local .env.local
.env.*.local .env.*.local

16
.mcp.json Normal file
View File

@ -0,0 +1,16 @@
{
"mcpServers": {
"next-devtools": {
"command": "npx",
"args": ["-y", "next-devtools-mcp@latest"]
},
"chrome-devtools": {
"command": "npx",
"args": ["-y", "chrome-devtools-mcp@latest"],
"env": {
"CHROME_DEBUGGING_HOST": "127.0.0.1",
"CHROME_DEBUGGING_PORT": "9222"
}
}
}
}

View File

@ -6,7 +6,7 @@
"node": ">=18.17 <23" "node": ">=18.17 <23"
}, },
"scripts": { "scripts": {
"dev": "next dev --turbo", "dev": "bash scripts/Dev-MCP-Server.sh && next dev --turbo",
"prebuild": "tsx scripts/generate-content.ts && node scripts/build-contentlayer.mjs", "prebuild": "tsx scripts/generate-content.ts && node scripts/build-contentlayer.mjs",
"build": "next build", "build": "next build",
"build:static": "npm run prebuild && next build", "build:static": "npm run prebuild && next build",

41
scripts/Dev-MCP-Server.sh Executable file
View File

@ -0,0 +1,41 @@
#!/usr/bin/env bash
set -euo pipefail
MCP_PROFILE="/tmp/chrome-mcp-profile"
CHROME_PORT=9222
LOG_DIR=".dev-logs"
mkdir -p "$LOG_DIR"
if curl -sf "http://127.0.0.1:$CHROME_PORT/json/version" >/dev/null; then
echo "[MCP] Chrome DevTools already running on port $CHROME_PORT, skipping launch."
else
echo "[MCP] Cleaning stale Chrome processes..."
pkill -f "$MCP_PROFILE" || true
echo "[MCP] Starting Chrome (remote debugging)..."
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \
--remote-debugging-port=$CHROME_PORT \
--user-data-dir=$MCP_PROFILE \
--disable-extensions \
--disable-background-networking \
> "$LOG_DIR/chrome.log" 2>&1 &
echo "[MCP] Waiting for Chrome DevTools endpoint..."
for i in {1..20}; do
if curl -sf "http://127.0.0.1:$CHROME_PORT/json/version" >/dev/null; then
echo "[MCP] Chrome is ready."
break
fi
sleep 0.5
done
fi
echo "[MCP] Chrome DevTools ready on port $CHROME_PORT"
echo "[MCP] (Optional) Pre-warming chrome-devtools-mcp..."
npx -y chrome-devtools-mcp@latest \
--browser-url="http://127.0.0.1:$CHROME_PORT" \
> "$LOG_DIR/chrome-mcp.log" 2>&1 &
echo "[MCP] Done. You can now run: npm run dev"