Repository navigation
fix: report why nextjs_index cannot reach an explicit port - #162
Open
vishalhabib99 wants to merge 1 commit into
Open
vishalhabib99 wants to merge 1 commit into
vishalhabib99 wants to merge 1 commit into
Conversation
listNextJsTools catches every request error and returns [], so
nextjs_index {port} said "No MCP tools found ... may not be running
Next.js 16+" when nothing was listening on the port. The explicit-port
path now uses fetchNextJsTools, which rejects with the real reason
(e.g. "Cannot connect to Next.js dev server on port N"). Auto-discovery
keeps listNextJsTools, so one failing candidate still doesn't fail the
whole listing.
Auto-discovered servers also reported http://localhost:<port> even when
NEXT_DEVTOOLS_HOST was set; they now use MCP_HOST like the
explicit-port path.
Author
|
Hi @gaojude, just checking this one is still on your radar. It's still mergeable, and both new tests still fail on main: an explicit port with nothing listening reports |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's wrong
1.
nextjs_indexwith an explicit port hides "cannot connect". With nothing listening on port 4999:nextjs_index {"port": 4999}returnsNo MCP tools found on port 4999. The server may not be running Next.js 16+ or MCP may not be enabled.nextjs_call {"port": 4999, ...}on the same port correctly returnsCannot connect to Next.js dev server on port 4999. Make sure the dev server is running. ...So the agent is told to check the Next.js version when the dev server simply isn't running. A 404, an
MCP Error: ...or an invalid SSE response get the same "No MCP tools found" text.2. Auto-discovery ignores
NEXT_DEVTOOLS_HOSTin its output. WithNEXT_DEVTOOLS_HOST=127.0.0.1,nextjs_index {}reports"url": "http://localhost:3007"for a server on 3007, whilenextjs_index {"port": 4555}reports"url": "http://127.0.0.1:4555".Cause
listNextJsTools(src/_internal/nextjs-runtime-manager.ts:403-415) catches every error and returns[].probeAndListTools(src/tools/nextjs_index.ts:86-92) reads[]as "not Next.js 16+", so its owncatch("Failed to connect to port ...") never runs.src/tools/nextjs_index.ts:157hard-codeslocalhost. The explicit-port path (line 99) usesMCP_HOST.Fix
listNextJsToolsintofetchNextJsTools(rejects with the reason) andlistNextJsTools(same as before: logs and returns[]).probeAndListToolscallsfetchNextJsTools, so an explicit port now returnsFailed to connect to port 4999: Cannot connect to Next.js dev server on port 4999. .... Auto-discovery still useslistNextJsTools, so one failing candidate still drops out without failing the whole listing (fix: exclude servers without a valid MCP tool listing #154).MCP_HOSTin the auto-discovery URL.Includes a patch changeset.
Tests
test/unit/nextjs-index-errors.test.ts: callsnextjs_indexon a port with nothing listening and expects the "Cannot connect" reason. No mocks, no network beyond loopback.test/unit/nextjs-index-validation.test.ts: the module mock now setsMCP_HOSTto127.0.0.1and providesfetchNextJsTools. A new case checks that an auto-discovered server's URL uses that host and matches the explicit-port URL. The existing explicit-port case now mocksfetchNextJsTools.Both new tests fail on
main(Received: "No MCP tools found on port ..."andReceived: "http://localhost:3001") and pass with the fix.pnpm buildandpnpm typecheckpass.pnpm test: 50 passed, 1 skipped (main: 48 passed, 1 skipped). In both runstest/unit/nextjs-runtime-discovery.test.tsfails in setup locally because it shells out topnpm installfor its fixture app andpnpmisn't on my PATH. That's unrelated to this change. I didn't run the e2e tests.