Skip to content

mcp: return nil params for missing optional requests#1056

Open
ychampion wants to merge 2 commits into
modelcontextprotocol:mainfrom
ychampion:fix-optional-request-params
Open

mcp: return nil params for missing optional requests#1056
ychampion wants to merge 2 commits into
modelcontextprotocol:mainfrom
ychampion:fix-optional-request-params

Conversation

@ychampion

Copy link
Copy Markdown

Requests with missing optional params could store a typed nil pointer in the typed request. Middleware calling GetParams then received a non-nil Params interface, so a normal nil check did not prevent calls like GetMeta from panicking.

This normalizes typed nil params in GetParams for both client and server requests, while leaving non-nil generated and custom params unchanged.

Fixes #1052

Tested:

  • go test ./mcp -run 'Test(ServerRequestGetParamsMissingOptionalParams|RequestGetParamsTypedNilCustomParams)' -count=1\n- go test ./mcp\n- go test ./...\n- git diff --check

Requests with missing optional params could store a typed nil pointer in the typed request. When middleware called GetParams, that pointer was returned as a non-nil Params interface, so standard nil checks did not protect later method calls.

Normalize typed nil params in GetParams for client and server requests, and cover missing optional server params plus custom params that embed ParamsBase.

Fixes modelcontextprotocol#1052
Copilot AI review requested due to automatic review settings July 8, 2026 10:19

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Comment thread mcp/shared.go
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.

GetParams() returns typed nil pointer wrapped in Params interface, causing nil check bypass and panic

3 participants