Skip to content

Fix invalid initialize request handling#1709

Open
lntutor wants to merge 1 commit into
modelcontextprotocol:mainfrom
lntutor:fix/invalid-initialize-params-788
Open

Fix invalid initialize request handling#1709
lntutor wants to merge 1 commit into
modelcontextprotocol:mainfrom
lntutor:fix/invalid-initialize-params-788

Conversation

@lntutor

@lntutor lntutor commented Jul 19, 2026

Copy link
Copy Markdown

Summary

  • validate initialize request parameters before creating an HTTP session
  • return HTTP 400 with JSON-RPC InvalidParams and the original request ID
  • cover a missing clientInfo.version payload

Testing

  • dotnet build
  • ASP.NET Core test suite on net8.0, net9.0, and net10.0

Fixes #788

{
try
{
JsonSerializer.Deserialize(initializeRequest.Params, s_initializeRequestParamsTypeInfo);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing params or "params": null can deserialize to null without throwing, so this still proceeds to GetOrCreateSessionAsync, creates a session, and leaves the original observable side effect in place. Could we treat a null result as InvalidParams too and add test coverage for both missing and explicit-null params?

Note

GitHub Copilot helped create this comment.

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.

Passing a malformed body throws a 500 error instead of 400. Very hard to figure out what is incorrect in the request being issued by the caller

2 participants