Skip to content

mcp: answer a request sent before initialize with Invalid Request - #1393

Merged
guglielmo-san merged 1 commit into
modelcontextprotocol:mainfrom
talhayme:fix/1367-pre-initialize-error-code
Oct 12, 2026
Merged

guglielmo-san merged 1 commit into
modelcontextprotocol:mainfrom
talhayme:fix/1367-pre-initialize-error-code

Conversation

@talhayme

Copy link
Copy Markdown
Contributor

A legacy server session that has not been initialized refuses a request other than initialize or ping. The refusal was a plain error, which reaches the wire as JSON-RPC error code 0. It is now -32600 (Invalid Request).

This is a behavioral change, so MCPGODEBUG=nopreinitinvalidrequest=1 restores the previous code. The option is documented in docs/mcpgodebug.md under 1.9.0, and TestServerHandle_LegacyCallBeforeInitialize checks both settings.

Fixes #1367

AI disclosure: written with Claude Code; I reviewed the change and ran go test ./... and the touched tests under -race.

🤖 Generated with Claude Code

A legacy server session that has not been initialized refuses a request
other than initialize or ping. The refusal was a plain error, which
reaches the wire as JSON-RPC error code 0. It is now -32600 (Invalid
Request).

This is a behavioral change, so MCPGODEBUG=nopreinitinvalidrequest=1
restores the previous code.

Fixes modelcontextprotocol#1367

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@guglielmo-san
guglielmo-san merged commit b5d319b into modelcontextprotocol:main Oct 12, 2026
10 checks passed
@guglielmo-san

Copy link
Copy Markdown
Contributor

@talhayme thank you for the contribution!

@Goldziher

Copy link
Copy Markdown

Confirmed downstream. Using the reproduction from #1367 (tools/list sent before initialize over IOTransport):

  • v1.8.0: {"error":{"code":0,"message":"method \"tools/list\" is invalid during session initialization"}}
  • b5d319b (this PR merged): same message, "code":-32600

We were rewriting the code to -32600 in a transport wrapper (Goldziher/ai-rulez#385) and will drop that for the authoring server once a release includes this. Thanks for the quick fix.

@talhayme

Copy link
Copy Markdown
Contributor Author

Thanks for confirming. The other places where a plain error reaches the wire as code 0 (prompt, resource and raw tool handlers, middleware) are collected in #1394, in case your wrapper was covering those too.

AI disclosure: drafted with Claude Code; I reviewed it.

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.

bug: a request sent before initialize is answered with JSON-RPC error code 0 instead of -32600

3 participants