Skip to content

Commit 69e1989

Browse files
authored
docs: simplify MCP guide to focus on next-devtools-mcp (#85353)
1 parent d0d9466 commit 69e1989

File tree

1 file changed

+65
-62
lines changed

1 file changed

+65
-62
lines changed

docs/01-app/02-guides/mcp.mdx

Lines changed: 65 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,18 @@
11
---
22
title: Enabling Next.js MCP Server for Coding Agents
33
nav_title: Next.js MCP Server
4-
description: Learn how to enable the experimental Next.js MCP server to allow agents access to your application state
4+
description: Learn how to use Next.js MCP support to allow coding agents access to your application state
55
---
66

77
The [Model Context Protocol (MCP)](https://modelcontextprotocol.io) is an open standard that allows AI agents and coding assistants to interact with your applications through a standardized interface.
88

9-
Next.js provides two MCP servers, we recommend using both together for the best agent experience:
10-
11-
### 1. Next.js MCP Server (Built-in)
12-
13-
**Available in Next.js 16 and above**
14-
15-
The Next.js MCP server exposes your application's internals, allowing agents to:
16-
17-
- Access real-time application state and runtime information
18-
- Query page metadata, routes, and rendering details
19-
- Retrieve build errors, runtime errors, and development logs
20-
- Inspect Server Actions and component hierarchies
21-
22-
This server runs within your Next.js dev server and provides direct access to your application's internal state.
23-
24-
### 2. Next DevTools MCP (External Package)
25-
26-
[`next-devtools-mcp`](https://www.npmjs.com/package/next-devtools-mcp) is a separate package that provides high-level development tools and guidance:
27-
28-
- **Next.js Knowledge Base**: Query comprehensive Next.js documentation and best practices
29-
- **Migration and Upgrade Tools**: Automated helpers for upgrading to Next.js 16 with codemods
30-
- **Cache Components Guide**: Setup and configuration assistance for Cache Components
31-
- **Browser Testing**: [Playwright MCP](https://github.com/microsoft/playwright-mcp) integration for verifying pages in the browser
32-
33-
Additionally, `next-devtools-mcp` can automatically discover and communicate directly with running Next.js dev servers to access their MCP tools (`get_errors`, `get_logs`, `get_page_metadata`, etc.).
34-
35-
Together, these two MCP servers give agents both low-level application internals and high-level development guidance.
9+
Next.js 16+ includes MCP support that enables coding agents to access your application's internals in real-time. To use this functionality, install the [`next-devtools-mcp`](https://www.npmjs.com/package/next-devtools-mcp) package.
3610

3711
## Getting started
3812

39-
The built-in Next.js MCP server is enabled by default in development in Next.js 16 or above.
13+
**Requirements:** Next.js 16 or above
4014

41-
### Configuring Next DevTools MCP
42-
43-
To use the Next DevTools MCP, add [`next-devtools-mcp`](https://www.npmjs.com/package/next-devtools-mcp) to the `.mcp.json` file at the root of your project
15+
Add `next-devtools-mcp` to the `.mcp.json` file at the root of your project:
4416

4517
```json filename=".mcp.json"
4618
{
@@ -53,20 +25,30 @@ To use the Next DevTools MCP, add [`next-devtools-mcp`](https://www.npmjs.com/pa
5325
}
5426
```
5527

56-
For more devtools functionalities and configuration options, check out the [next-devtools-mcp repository](https://github.com/vercel/next-devtools-mcp).
28+
That's it! When you start your development server, `next-devtools-mcp` will automatically discover and connect to your running Next.js instance.
5729

58-
## Using with agents
30+
For more configuration options, see the [next-devtools-mcp repository](https://github.com/vercel/next-devtools-mcp).
5931

60-
MCP-compatible Coding Agents can automatically discover and connect to your Next.js development server. This provides agents with rich context about your project.
32+
## Capabilities
6133

62-
### Benefits for agent-assisted development
34+
`next-devtools-mcp` provides coding agents with a growing set of capabilities:
6335

64-
Agents can:
36+
### Application Runtime Access
6537

66-
- **Make context-aware suggestions**: Recommend the right place to add new features based on your existing structure
67-
- **Query live application state**: Check current configuration, routes, and middleware during development
68-
- **Understand your app router pages layout**: Know exactly which page and layout are rendered in the page
69-
- **Provide accurate implementations**: Generate code that follows your project's patterns and conventions
38+
- **Error Detection**: Retrieve current build errors, runtime errors, and type errors from your dev server
39+
- **Live State Queries**: Access real-time application state and runtime information
40+
- **Page Metadata**: Query page routes, components, and rendering details
41+
- **Server Actions**: Inspect Server Actions and component hierarchies
42+
- **Development Logs**: Access development server logs and console output
43+
44+
### Development Tools
45+
46+
- **Next.js Knowledge Base**: Query comprehensive Next.js documentation and best practices
47+
- **Migration and Upgrade Tools**: Automated helpers for upgrading to Next.js 16 with codemods
48+
- **Cache Components Guide**: Setup and configuration assistance for Cache Components
49+
- **Browser Testing**: [Playwright MCP](https://github.com/microsoft/playwright-mcp) integration for verifying pages in the browser
50+
51+
> **Note:** The Next.js team is actively expanding these capabilities. New tools and features are added regularly to improve the agent development experience.
7052
7153
## Development workflow
7254

@@ -76,37 +58,50 @@ Agents can:
7658
npm run dev
7759
```
7860

79-
2. Connect your Coding Agent to the running Next.js instance
61+
2. Your Coding Agent will automatically connect to the running Next.js instance via `next-devtools-mcp`
8062

81-
3. Open your application in the browser to view the page.
63+
3. Open your application in the browser to view pages
8264

8365
4. Query your agent for insights and diagnostics (see examples below)
8466

85-
### Available Next.js MCP Tools
67+
### Available tools
8668

87-
The experimental Next.js MCP server provides the following tools:
69+
Through `next-devtools-mcp`, agents can use the following tools:
8870

8971
- **`get_errors`**: Retrieve current build errors, runtime errors, and type errors from your dev server
90-
- **`get_logs`**: Access development server logs and console output
72+
- **`get_logs`**: Get the path to the development log file containing browser console logs and server output
9173
- **`get_page_metadata`**: Get metadata about specific pages including routes, components, and rendering information
92-
- **`get_project_metadata`**: Retrieve project structure, configuration, and overall metadata
93-
- **`get_server_action_by_id`**: Look up Server Actions by their ID for debugging and inspection
74+
- **`get_project_metadata`**: Retrieve project structure, configuration, and dev server URL
75+
- **`get_server_action_by_id`**: Look up Server Actions by their ID to find the source file and function name
76+
77+
## Using with agents
78+
79+
MCP-compatible Coding Agents can automatically discover and connect to your Next.js development server, providing them with rich context about your project.
80+
81+
### Benefits for agent-assisted development
82+
83+
Agents can:
84+
85+
- **Make context-aware suggestions**: Recommend the right place to add new features based on your existing structure
86+
- **Query live application state**: Check current configuration, routes, and middleware during development
87+
- **Understand your app router pages layout**: Know exactly which page and layout are rendered
88+
- **Provide accurate implementations**: Generate code that follows your project's patterns and conventions
9489

9590
## Examples
9691

9792
### Error detection and diagnosis
9893

99-
The agent can query your running Next.js application for real-time error information:
94+
Ask your agent about errors in real-time:
10095

10196
```bash
10297
User: "What errors are currently in my application?"
10398
```
10499

105-
Agent action:
100+
The agent will:
106101

107-
- Calls the `get_errors` tool provided by the Next.js MCP server
108-
- Retrieves current build errors, runtime errors, and type errors from the dev server
109-
- Analyzes the errors and provides actionable fixes
102+
- Query your running Next.js application via `next-devtools-mcp`
103+
- Retrieve current build errors, runtime errors, and type errors
104+
- Analyze the errors and provide actionable fixes
110105

111106
<details>
112107
<summary>Agent response (click to expand)</summary>
@@ -141,32 +136,40 @@ Agent action:
141136
142137
</details>
143138
144-
This demonstrates the power of having both MCP servers enabled: the Next.js MCP server provides real-time diagnostics directly from your application, while next-devtools-mcp can provide guidance on best practices and migration paths.
145-
146139
### Upgrading and best practices
147140
148-
You can also ask for help with Next.js concepts and migrations:
141+
Get help with Next.js concepts and migrations:
149142
150143
```bash
151144
User: "Help me upgrade my Next.js app to version 16"
152145
```
153146
154-
The agent will use next-devtools-mcp to analyze your current version, guide you through automated migrations with codemods, and provide step-by-step instructions for handling breaking changes like async Request APIs, dynamic route segments, and route handler return types.
147+
The agent will analyze your current version, guide you through automated migrations with codemods, and provide step-by-step instructions for handling breaking changes.
155148
156-
You can also ask conceptual questions:
149+
Ask conceptual questions:
157150
158151
```bash
159152
User: "When should I use 'use client' in App Router?"
160153
```
161154
162-
The agent will query the Next.js knowledge base via next-devtools-mcp and provide documentation-backed explanations with examples from your codebase.
155+
The agent will query the Next.js knowledge base and provide documentation-backed explanations with examples from your codebase.
156+
157+
## How it works
158+
159+
Next.js 16+ includes a built-in MCP endpoint at `/_next/mcp` that runs within your development server. The `next-devtools-mcp` package automatically discovers and communicates with these endpoints, allowing it to:
160+
161+
- Connect to multiple Next.js instances running on different ports
162+
- Forward tool calls to the appropriate Next.js dev server
163+
- Provide a unified interface for coding agents
164+
165+
This architecture decouples the agent interface from the internal implementation, enabling `next-devtools-mcp` to work seamlessly across different Next.js projects.
163166
164167
## Troubleshooting
165168
166169
### MCP server not connecting
167170
168171
- Ensure you're using Next.js v16 or above
172+
- Verify `next-devtools-mcp` is configured in your `.mcp.json`
169173
- Start your development server: `npm run dev`
170-
- Restart your development server
171-
- Check that your MCP client is configured with the correct path
172-
- Add MCP server to your agent's settings
174+
- Restart your development server if it was already running
175+
- Check that your coding agent has loaded the MCP server configuration

0 commit comments

Comments
 (0)