From 3b7c7a08ff4fe9de26873973f8d0f214840ba49e Mon Sep 17 00:00:00 2001 From: Haitao Pan Date: Tue, 13 Jan 2026 23:34:56 +0800 Subject: [PATCH] Add Dev MCP setup --- .gitignore | 1 + .mcp.json | 16 +++++++++++++++ package.json | 2 +- scripts/Dev-MCP-Server.sh | 41 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 .mcp.json create mode 100755 scripts/Dev-MCP-Server.sh diff --git a/.gitignore b/.gitignore index 7fa7c06..ff4c015 100644 --- a/.gitignore +++ b/.gitignore @@ -48,6 +48,7 @@ coverage/ *.test-cache/ *.test-data/ .env.test +.env .env.local .env.*.local diff --git a/.mcp.json b/.mcp.json new file mode 100644 index 0000000..1ef3bca --- /dev/null +++ b/.mcp.json @@ -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" + } + } + } +} diff --git a/package.json b/package.json index 153039a..e318984 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "node": ">=18.17 <23" }, "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", "build": "next build", "build:static": "npm run prebuild && next build", diff --git a/scripts/Dev-MCP-Server.sh b/scripts/Dev-MCP-Server.sh new file mode 100755 index 0000000..5207eb9 --- /dev/null +++ b/scripts/Dev-MCP-Server.sh @@ -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"