Skip to content

fix: accept null for optional nextjs_index port and nextjs_call args - #164

Open
tlq5l wants to merge 5 commits into
vercel:mainfrom
tlq5l:fix/null-optional-arguments
Open

tlq5l wants to merge 5 commits into
vercel:mainfrom
tlq5l:fix/null-optional-arguments

Conversation

@tlq5l

@tlq5l tlq5l commented Oct 29, 2026

Copy link
Copy Markdown

Fixes #161

Problem

nextjs_index (port) and nextjs_call (args) reject an explicit null with Invalid argument '...', even though both are optional. The cause is zod: ZodOptional._parse returns undefined unchanged and passes every other value, null included, to its inner type, which then fails (node_modules/zod/v3/types.js:3310-3317, zod 3.25.76).

Fix

Both fields use .nullish(), which is .nullable().optional() (node_modules/zod/v3/types.js:295-297); ZodNullable accepts null (types.js:3329-3336), so null and a missing value both mean unset. A null port runs auto-discovery, as an omitted one does. A null args becomes {}, as a missing one does. The nextjs_index port and nextjs_call args descriptions and the README say so.

The advertised JSON Schema now allows null, matching the server. Treating null as omitted in parseToolArgs (src/index.ts:107) would leave the schema rejecting it.

Callers checked: src/index.ts (a null port reaches nextjs_index); src/tools/nextjs_call.ts (does not call it); browser-eval.ts and nextjs-docs.ts (own handlers, unchanged).

Tests: null cases in test/unit/tool-input-schema.test.ts, a mocked null-port case in test/unit/nextjs-index-validation.test.ts, and an end-to-end nextjs_call case in test/e2e/mcp-registration.test.ts (fake endpoint, isolated home directory).

Ran live: JSON-RPC over stdio into node dist/index.js built at 0181404, sending nextjs_index {"port": null} and nextjs_call {"port": 4555, "toolName": "get_errors", "args": null}. Both return tool results with no JSON-RPC error: No running Next.js dev servers with MCP enabled found and Cannot connect to Next.js dev server on port 4555. Pre-fix commit 1e8dcfa returned Invalid argument 'port' and Invalid argument 'args'.

AI disclosure: written and checked with AI assistance, including the tests and the live run; I take responsibility for it.

tlq5l added 5 commits October 28, 2026 16:33
Optional tool arguments used zod .optional(), which accepts undefined but
rejects null. Some MCP clients send null for arguments they leave unset,
so nextjs_index and nextjs_call failed with "Invalid argument". Make those
two fields .nullish(), treat a null port as omitted in nextjs_index, and
keep the advertised JSON schema in sync with what the server accepts.

Agent: claude
Replace the real-port nextjs_index null e2e case with a nextjs_call case
against a loopback fake /_next/mcp endpoint, so no real dev server can
change the result. Describe null args as treated like omitted in both
nextjs_call descriptions, and add a mocked nextjs_index null-port case.

Agent: claude
Cite the sources for the null handling and SIGKILL comments.

Agent: claude
@tlq5l

tlq5l commented Nov 13, 2026

Copy link
Copy Markdown
Author

Checking in on this one. Is there anything I should change to get it ready to merge? Happy to rebase or adjust.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Explicit null for an optional argument (port, args) is rejected

1 participant