Skip to content

Commit 489920c

Browse files
authored
simplify server discovery (#96)
1 parent 62ba9b2 commit 489920c

13 files changed

+292
-309
lines changed

CLAUDE.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ All tools, prompts, and resources are explicitly imported and registered in `src
6262
- Tools are manually imported and registered in `src/index.ts`
6363
- `nextjs_docs`: Search Next.js documentation and knowledge base
6464
- `browser_eval`: Playwright browser automation (via `playwright-mcp` server)
65-
- `nextjs_runtime`: Connect to Next.js dev server MCP endpoint for runtime diagnostics
65+
- `nextjs_index`: Discover all running Next.js dev servers and list their available MCP tools
66+
- `nextjs_call`: Execute specific MCP tools on a running Next.js dev server
6667
- `upgrade_nextjs_16`: Automated Next.js 16 upgrade guidance
6768
- `enable_cache_components`: Complete Cache Components setup with error detection
6869

6970
**MCP Client Library** (`src/_internal/mcp-client.ts`):
7071
- Connects to external MCP servers via stdio transport
7172
- Used by `browser_eval` to communicate with `playwright-mcp`
72-
- Used by `nextjs_runtime` to communicate with Next.js dev server MCP endpoint
7373

7474
**Runtime Managers** (`src/_internal/`):
7575
- `browser-eval-manager.ts`: Manages Playwright MCP server lifecycle
@@ -127,7 +127,7 @@ This server can:
127127
- Command: `npx @playwright/mcp@latest` (with optional `--browser` and `--headless` flags)
128128
- Used for browser automation and testing
129129

130-
**Next.js Runtime MCP** (`nextjs_runtime` tool):
130+
**Next.js Runtime MCP** (`nextjs_index` and `nextjs_call` tools):
131131
- Built into Next.js 16+ (enabled by default)
132132
- Endpoint: `http://localhost:<port>/_next/mcp`
133133
- Provides runtime diagnostics, errors, routes, and build status

README.md

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ Next Devtools, show me the structure of my routes
182182
Next Devtools, what's in the development server logs?
183183
```
184184

185-
Your coding agent will use the `nextjs_runtime` tool to query your running application's actual state.
185+
Your coding agent will use the `nextjs_index` and `nextjs_call` tools to query your running application's actual state.
186186

187187
### For All Next.js Projects
188188

@@ -355,7 +355,7 @@ Automate and test web applications using Playwright browser automation.
355355
- Detecting runtime errors, hydration issues, and client-side problems
356356
- Capturing browser console errors and warnings
357357

358-
**Important:** For Next.js projects, prioritize using the `nextjs_runtime` tool instead of browser console log forwarding. Only use browser_eval's `console_messages` action as a fallback when `nextjs_runtime` tools are not available.
358+
**Important:** For Next.js projects, prioritize using the `nextjs_index` and `nextjs_call` tools instead of browser console log forwarding. Only use browser_eval's `console_messages` action as a fallback when these tools are not available.
359359

360360
**Available actions:**
361361
- `start` - Start browser automation (automatically installs if needed)
@@ -383,21 +383,17 @@ Automate and test web applications using Playwright browser automation.
383383
</details>
384384

385385
<details>
386-
<summary><code>nextjs_runtime</code></summary>
386+
<summary><code>nextjs_index</code></summary>
387387

388-
Connect to your running Next.js dev server's built-in MCP endpoint to access live application state, runtime diagnostics, and internal information.
388+
Discover all running Next.js dev servers and list their available MCP tools.
389389

390390
**What this tool does:**
391391

392-
This tool acts as a bridge between your coding agent and Next.js 16's built-in MCP endpoint at `/_next/mcp`. It provides three key actions:
392+
Automatically discovers all running Next.js 16+ dev servers on your machine and lists the runtime diagnostic tools available from each server's built-in MCP endpoint at `/_next/mcp`.
393393

394-
1. **`discover_servers`**: Find all running Next.js dev servers on your machine
395-
2. **`list_tools`**: See what runtime diagnostic tools are available from Next.js
396-
3. **`call_tool`**: Execute a specific Next.js runtime tool (e.g., get errors, query routes, fetch logs)
394+
**No parameters required** - Just call the tool and it will scan for servers.
397395

398-
**Available Next.js Runtime Tools** (accessed via `call_tool`):
399-
400-
Once connected to a Next.js 16+ dev server, you can access these built-in tools:
396+
**Available Next.js Runtime Tools** (varies by Next.js version):
401397
- `get_errors` - Get current build, runtime, and type errors
402398
- `get_logs` - Get path to development log file (browser console + server output)
403399
- `get_page_metadata` - Query application routes, pages, and component metadata
@@ -408,38 +404,52 @@ Once connected to a Next.js 16+ dev server, you can access these built-in tools:
408404
- Next.js 16+ (MCP enabled by default)
409405
- Running dev server (`npm run dev`)
410406

407+
**Output:**
408+
- JSON with list of discovered servers, each containing:
409+
- Port, PID, URL
410+
- Available tools with descriptions and input schemas
411+
412+
**Example prompts:**
413+
- "Next Devtools, what servers are running?"
414+
- "Next Devtools, show me available diagnostic tools"
415+
416+
</details>
417+
418+
<details>
419+
<summary><code>nextjs_call</code></summary>
420+
421+
Execute a specific MCP tool on a running Next.js dev server.
422+
423+
**What this tool does:**
424+
425+
Calls a specific runtime diagnostic tool on a Next.js 16+ dev server's built-in MCP endpoint at `/_next/mcp`.
426+
427+
**Input Parameters:**
428+
- `port` (required) - Dev server port (use `nextjs_index` first to discover)
429+
- `toolName` (required) - Name of the Next.js tool to invoke
430+
- `args` (optional) - Arguments object for the tool (only if required by that tool)
431+
432+
**Requirements:**
433+
- Next.js 16+ (MCP enabled by default)
434+
- Running dev server (`npm run dev`)
435+
- Use `nextjs_index` first to discover available servers and tools
436+
411437
**Typical workflow:**
412438

413439
```javascript
414-
// Step 1: Discover running servers (optional - auto-discovery works in most cases)
415-
{
416-
"action": "discover_servers"
417-
}
440+
// Step 1: Discover servers and tools
441+
// (call nextjs_index first)
418442

419-
// Step 2: List available runtime tools
443+
// Step 2: Call a specific tool
420444
{
421-
"action": "list_tools",
422-
"port": 3000 // optional if only one server is running
423-
}
424-
425-
// Step 3: Call a specific tool
426-
{
427-
"action": "call_tool",
428445
"port": 3000,
429446
"toolName": "get_errors"
430447
// args is optional and only needed if the tool requires parameters
431448
}
432449
```
433450

434-
**Input Parameters:**
435-
- `action` (required) - `discover_servers`, `list_tools`, or `call_tool`
436-
- `port` (optional) - Dev server port (auto-discovers if not provided)
437-
- `toolName` (required for `call_tool`) - Name of the Next.js tool to invoke
438-
- `args` (optional) - Arguments object for the tool (only if required by that tool)
439-
- `includeUnverified` (optional) - For `discover_servers`: include servers even if MCP verification fails
440-
441451
**Output:**
442-
- JSON with discovered servers, available tools list, or tool execution results
452+
- JSON with tool execution results
443453

444454
**Example prompts that use this tool:**
445455
- "Next Devtools, what errors are in my Next.js app?"
@@ -515,7 +525,7 @@ With other agents or programmatically:
515525

516526
`next-devtools-mcp` collects anonymous usage telemetry to help improve the tool. The following data is collected:
517527

518-
- **Tool usage**: Which MCP tools are invoked (e.g., `nextjs_runtime`, `browser_eval`, `upgrade_nextjs_16`)
528+
- **Tool usage**: Which MCP tools are invoked (e.g., `nextjs_index`, `nextjs_call`, `browser_eval`, `upgrade_nextjs_16`)
519529
- **Error events**: Anonymous error messages when tools fail
520530
- **Session metadata**: Session ID, timestamps, and basic environment info (OS, Node.js version)
521531

@@ -616,7 +626,7 @@ Coding Agent
616626

617627
2. **For all Next.js projects**: Provides development automation tools (upgrades, Cache Components setup), documentation access, and browser testing capabilities that work independently of the runtime connection.
618628

619-
3. **Auto-discovery**: The `nextjs_runtime` tool scans common ports (3000, 3001, etc.) to find running Next.js servers, so you don't need to manually specify ports in most cases.
629+
3. **Simple workflow**: Call `nextjs_index` to see all servers and available tools, then call `nextjs_call` with the specific port and tool name you want to execute.
620630

621631

622632
## License

src/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ import * as browserEval from "./tools/browser-eval.js"
2525
import * as enableCacheComponents from "./tools/enable-cache-components.js"
2626
import * as init from "./tools/init.js"
2727
import * as nextjsDocs from "./tools/nextjs-docs.js"
28-
import * as nextjsRuntime from "./tools/nextjs-runtime.js"
28+
import * as nextjsIndex from "./tools/nextjs_index.js"
29+
import * as nextjsCall from "./tools/nextjs_call.js"
2930
import * as upgradeNextjs16 from "./tools/upgrade-nextjs-16.js"
3031

3132
import * as upgradeNextjs16Prompt from "./prompts/upgrade-nextjs-16.js"
@@ -48,14 +49,15 @@ import * as nextjs16BetaToStable from "./resources/(nextjs16)/migration/beta-to-
4849
import * as nextjs16Examples from "./resources/(nextjs16)/migration/examples.js"
4950
import * as nextjsDocsLlmsIndex from "./resources/(nextjs-docs)/llms-index.js"
5051

51-
const tools = [browserEval, enableCacheComponents, init, nextjsDocs, nextjsRuntime, upgradeNextjs16]
52+
const tools = [browserEval, enableCacheComponents, init, nextjsDocs, nextjsIndex, nextjsCall, upgradeNextjs16]
5253

5354
const toolNameToTelemetryName: Record<string, McpToolName> = {
5455
browser_eval: "mcp/browser_eval",
5556
enable_cache_components: "mcp/enable_cache_components",
5657
init: "mcp/init",
5758
nextjs_docs: "mcp/nextjs_docs",
58-
nextjs_runtime: "mcp/nextjs_runtime",
59+
nextjs_index: "mcp/nextjs_index",
60+
nextjs_call: "mcp/nextjs_call",
5961
upgrade_nextjs_16: "mcp/upgrade_nextjs_16",
6062
}
6163

src/telemetry/mcp-telemetry-tracker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ export type McpToolName =
33
| "mcp/enable_cache_components"
44
| "mcp/init"
55
| "mcp/nextjs_docs"
6-
| "mcp/nextjs_runtime"
6+
| "mcp/nextjs_index"
7+
| "mcp/nextjs_call"
78
| "mcp/upgrade_nextjs_16"
89

910
export interface McpToolUsage {

src/tools/browser-eval.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ in a real browser instead of curl or simple HTTP requests. This is because:
9393
- Captures browser console errors and warnings via console_messages action
9494
9595
IMPORTANT FOR NEXT.JS PROJECTS:
96-
If working with a Next.js application, PRIORITIZE using the 'nextjs_runtime' tool instead of browser console log forwarding.
96+
If working with a Next.js application, PRIORITIZE using the 'nextjs_index' and 'nextjs_call' tools instead of browser console log forwarding.
9797
Next.js has built-in MCP integration that provides superior error reporting, build diagnostics, and runtime information
98-
directly from the Next.js dev server. Only use browser_eval's console_messages action as a fallback when nextjs_runtime
99-
tools are not available or when you specifically need to test client-side browser behavior that Next.js runtime cannot capture.
98+
directly from the Next.js dev server. Only use browser_eval's console_messages action as a fallback when these Next.js tools
99+
are not available or when you specifically need to test client-side browser behavior that Next.js runtime cannot capture.
100100
101101
Available actions:
102102
- start: Start browser automation (automatically installs if needed). Verbose logging is always enabled.
@@ -106,7 +106,7 @@ Available actions:
106106
- fill_form: Fill multiple form fields at once
107107
- evaluate: Execute JavaScript in browser context
108108
- screenshot: Take a screenshot of the page
109-
- console_messages: Get browser console messages (for Next.js, prefer nextjs_runtime tool instead)
109+
- console_messages: Get browser console messages (for Next.js, prefer nextjs_index/nextjs_call tools instead)
110110
- close: Close the browser
111111
- drag: Perform drag and drop
112112
- upload_file: Upload files

src/tools/init.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Key Points:
2020
- Fetches latest Next.js LLM documentation from nextjs.org
2121
- Establishes MANDATORY requirement to use nextjs_docs for ALL Next.js concepts
2222
- Instructs AI to forget any prior Next.js knowledge and always query docs
23-
- Documents all available MCP tools (nextjs_docs, nextjs_runtime, browser_eval, upgrade_nextjs_16, enable_cache_components)
23+
- Documents all available MCP tools (nextjs_docs, nextjs_index, nextjs_call, browser_eval, upgrade_nextjs_16, enable_cache_components)
2424
2525
Use this tool at the beginning of a Next.js session to:
2626
- Reset AI's Next.js knowledge baseline
@@ -165,12 +165,19 @@ You MUST still use the \`nextjs_docs\` tool with GET to retrieve the full detail
165165
- **REQUIRED** for ALL Next.js-related questions
166166
- **OPTIMIZATION:** For batch operations, fetch the \`nextjs-docs://llms-index\` resource to look up multiple paths
167167
168-
### 2. **nextjs_runtime** - Live Next.js Dev Server Integration
169-
- Get real-time errors and logs from running dev server
170-
- Inspect routes, components, and runtime diagnostics
171-
- Requires Next.js 16+ (or experimental.mcpServer in older versions)
168+
### 2. **nextjs_index** - Discover Running Next.js Servers
169+
- Lists all running Next.js dev servers with MCP enabled
170+
- Shows available runtime tools for each server
171+
- Takes no parameters - automatically discovers servers
172+
- Requires Next.js 16+
172173
173-
### 3. **browser_eval** - Browser Automation
174+
### 3. **nextjs_call** - Execute Next.js Runtime Tools
175+
- Calls specific MCP tools on a running Next.js dev server
176+
- Get real-time errors, logs, routes, and diagnostics
177+
- Requires port and toolName (use nextjs_index first to discover)
178+
- Requires Next.js 16+
179+
180+
### 4. **browser_eval** - Browser Automation
174181
- Test Next.js pages with Playwright
175182
- Verify functionality and capture runtime errors
176183
- Use after implementing features to verify behavior
@@ -191,7 +198,7 @@ You MUST still use the \`nextjs_docs\` tool with GET to retrieve the full detail
191198
2. **ALWAYS** use \`nextjs_docs\` for ANY Next.js concept (even if you think you know it)
192199
- Start with search action for most queries: \`{ action: "search", query: "..." }\`
193200
- For batch operations or multiple lookups, fetch \`nextjs-docs://llms-index\` resource to find paths directly
194-
3. Use \`nextjs_runtime\` for debugging running applications
201+
3. Use \`nextjs_index\` to discover servers, then \`nextjs_call\` to debug running applications
195202
4. Use \`browser_eval\` to verify implementations
196203
5. Use specialized tools (\`upgrade_nextjs_16\`, \`enable_cache_components\`) as needed
197204

0 commit comments

Comments
 (0)