Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply Next.js best practices for RSC boundaries, async APIs, routing, metadata, and optimization.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
debug-tricks.md
1# Debug Tricks23Tricks to speed up debugging Next.js applications.45## MCP Endpoint (Dev Server)67Next.js exposes a `/_next/mcp` endpoint in development for AI-assisted debugging via MCP (Model Context Protocol).89- **Next.js 16+**: Enabled by default, use `next-devtools-mcp`10- **Next.js < 16**: Requires `experimental.mcpServer: true` in next.config.js1112Reference: https://nextjs.org/docs/app/guides/mcp1314**Important**: Find the actual port of the running Next.js dev server (check terminal output or `package.json` scripts). Don't assume port 3000.1516### Request Format1718The endpoint uses JSON-RPC 2.0 over HTTP POST:1920```bash21curl -X POST http://localhost:<port>/_next/mcp \22-H "Content-Type: application/json" \23-H "Accept: application/json, text/event-stream" \24-d '{25"jsonrpc": "2.0",26"id": "1",27"method": "tools/call",28"params": {29"name": "<tool-name>",30"arguments": {}31}32}'33```3435### Available Tools3637#### `get_errors`38Get current errors from dev server (build errors, runtime errors with source-mapped stacks):39```json40{ "name": "get_errors", "arguments": {} }41```4243#### `get_routes`44Discover all routes by scanning filesystem:45```json46{ "name": "get_routes", "arguments": {} }47// Optional: { "name": "get_routes", "arguments": { "routerType": "app" } }48```49Returns: `{ "appRouter": ["/", "/api/users/[id]", ...], "pagesRouter": [...] }`5051#### `get_project_metadata`52Get project path and dev server URL:53```json54{ "name": "get_project_metadata", "arguments": {} }55```56Returns: `{ "projectPath": "/path/to/project", "devServerUrl": "http://localhost:3000" }`5758#### `get_page_metadata`59Get runtime metadata about current page render (requires active browser session):60```json61{ "name": "get_page_metadata", "arguments": {} }62```63Returns segment trie data showing layouts, boundaries, and page components.6465#### `get_logs`66Get path to Next.js development log file:67```json68{ "name": "get_logs", "arguments": {} }69```70Returns path to `<distDir>/logs/next-development.log`7172#### `get_server_action_by_id`73Locate a Server Action by ID:74```json75{ "name": "get_server_action_by_id", "arguments": { "actionId": "<action-id>" } }76```7778### Example: Get Errors7980```bash81curl -X POST http://localhost:<port>/_next/mcp \82-H "Content-Type: application/json" \83-H "Accept: application/json, text/event-stream" \84-d '{"jsonrpc":"2.0","id":"1","method":"tools/call","params":{"name":"get_errors","arguments":{}}}'85```8687## Rebuild Specific Routes (Next.js 16+)8889Use `--debug-build-paths` to rebuild only specific routes instead of the entire app:9091```bash92# Rebuild a specific route93next build --debug-build-paths "/dashboard"9495# Rebuild routes matching a glob96next build --debug-build-paths "/api/*"9798# Dynamic routes99next build --debug-build-paths "/blog/[slug]"100```101102Use this to:103- Quickly verify a build fix without full rebuild104- Debug static generation issues for specific pages105- Iterate faster on build errors106