Skip to content

mcp: handle nil elicitation content with defaults#1068

Open
ychampion wants to merge 1 commit into
modelcontextprotocol:mainfrom
ychampion:fix-elicit-nil-content-defaults
Open

mcp: handle nil elicitation content with defaults#1068
ychampion wants to merge 1 commit into
modelcontextprotocol:mainfrom
ychampion:fix-elicit-nil-content-defaults

Conversation

@ychampion

Copy link
Copy Markdown

Summary

  • Treat accepted elicitation responses with omitted content as an empty object before validation.
  • Apply that normalization on both client and server elicitation paths.
  • Add a regression test for schema defaults with nil content.

Why

Fixes #1062. jsonschema-go can panic when applying defaults into a nil map, so a loose client response could crash the server during ServerSession.Elicit.

Validation

  • go test ./mcp -run TestElicitationAcceptNilContentAppliesDefaults -count=1 — failed before the fix with panic: assignment to entry in nil map; passed after
  • go test ./mcp -run 'TestElicitation|TestClientElicitation|TestServerRequestElicit|TestInputRequired' -count=1 — passed\n- go test ./mcp -count=1 — passed\n- go test ./... — passed\n- go vet ./... — passed\n- gofmt — passed\n- git diff --check — passed

Constraint: accepted elicitation responses may omit content while schemas still define defaults.

Rejected: recover from jsonschema panic | Normalizing content before validation is simpler.

Confidence: high

Scope-risk: narrow

Directive: Keep accepted form elicitation content non-nil before applying defaults.

Tested: go test ./mcp -run TestElicitationAcceptNilContentAppliesDefaults -count=1

Tested: go test ./mcp -run 'TestElicitation|TestClientElicitation|TestServerRequestElicit|TestInputRequired' -count=1

Tested: go test ./mcp -count=1

Tested: go test ./...

Tested: go vet ./...

Tested: gofmt; git diff --check

Not-tested: external non-SDK clients
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.

ServerSession.Elicit: accept response without content panics the server ("assignment to entry in nil map")

1 participant