Skip to content

[Bug] Auto-discovery fails on Windows - discover_servers returns 406 due to missing Accept header #90

@zoranbebic-ct

Description

@zoranbebic-ct

Environment

Operating System:

  • Windows 11 (MINGW64_NT-10.0-26200)

Versions:

  • next-devtools-mcp: 0.3.3 (latest)
  • Next.js: 16.0.3
  • Node.js: v24.9.0
  • Bun: 1.3.0 (used as package manager)
  • React: 19.2.0

MCP Configuration (.mcp.json):
{
"servers": {
"next-devtools": {
"type": "stdio",
"command": "bunx",
"args": ["next-devtools-mcp@latest"],
"env": {}
}
}
}

Next.js Configuration:
const nextConfig: NextConfig = {
reactCompiler: true,
cacheComponents: true,
};


Issue Description

The discover_servers action consistently fails to detect running Next.js dev servers on Windows, despite the server running correctly on port 3000 and the MCP
endpoint being fully functional.


Steps to Reproduce

  1. Start Next.js 16.0.3 dev server on Windows 11:
    bun run dev
  2. Verify server is running:
    netstat -ano | findstr :3000

Output shows: LISTENING on port 3000 (PID ****)

  1. Attempt MCP server discovery:
    nextjs_runtime({ action: "discover_servers" })
  2. Result: No servers found

Expected Behavior

Auto-discovery should detect the Next.js dev server running on port 3000 and return available MCP tools.


Actual Behavior

Discovery fails with zero servers detected. Manual testing reveals the root cause:

Test 1: Standard HTTP Request (Fails)

curl -v http://localhost:3000/_next/mcp
Result: HTTP/1.1 406 Not Acceptable

Test 2: JSON-RPC without proper headers (Fails)

curl -X POST http://localhost:3000/_next/mcp
-H "Content-Type: application/json"
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}'
Response:
{
"jsonrpc": "2.0",
"error": {
"code": -32000,
"message": "Not Acceptable: Client must accept both application/json and text/event-stream"
},
"id": null
}

Test 3: With correct Accept header (Success)

curl -X POST http://localhost:3000/_next/mcp
-H "Content-Type: application/json"
-H "Accept: application/json, text/event-stream"
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}'
Result: ✅ Success - Returns 6 tools with full metadata


Root Cause Analysis

The auto-discovery mechanism fails because it does not send the required Accept: application/json, text/event-stream header when probing ports. The Next.js MCP
endpoint strictly requires both content types in the Accept header, even for standard JSON-RPC requests (not SSE streams).

Windows-Specific Factors:

  • Windows resolves localhost to IPv6 (::1) before IPv4 (127.0.0.1)
  • Potential stricter header validation in Windows networking stack
  • This issue was partially addressed in v0.2.4 ("Fix Next.js runtime discovery on Windows"), but the header issue persists

Workaround

Manually specify the port instead of relying on auto-discovery:

nextjs_runtime({ action: "list_tools", port: "3000" })

This successfully connects and returns all 6 MCP tools:

  • get_project_metadata
  • get_errors
  • get_page_metadata
  • get_logs
  • get_server_action_by_id
  • get_routes

Proposed Solutions

Option 1: Fix Discovery Probe (Recommended)

Update the port scanning mechanism to include the required Accept header:
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json, text/event-stream'
}

Option 2: Add Configuration Support

Allow users to specify custom port in .mcp.json (assume default 3000 in absence of env variable):
{
"servers": {
"next-devtools": {
"command": "bunx",
"args": ["next-devtools-mcp@latest"],
"env": {
"NEXTJS_DEFAULT_PORT": "3000"
}
}
}
}

Option 3: Relax Header Requirements

Consider whether the text/event-stream requirement is necessary for standard JSON-RPC requests (vs SSE streams).


Additional Context

This appears to be related to a broader MCP protocol implementation pattern where HTTP endpoints require text/event-stream even for non-streaming requests.
Similar issues exist in other MCP implementations:


Impact

  • Users on Windows cannot use auto-discovery functionality
  • Requires manual port specification in every MCP tool call
  • Reduces developer experience and adds friction to Windows workflows

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions