mcp: check that UnmarshalJSON methods for Content don't panic on nil

Introduces a new test file content_nil_test.go which verifies that UnmarshalJSON methods for various Content types do not panic when unmarshaling onto nil pointers.
Adds a nil check in contentFromWire function to guard against a nil wire.Content parameter.
Tests cover different scenarios, including valid and invalid content types, as well as cases with empty or missing content fields.

For #205
This commit is contained in:
Tim Gossett 2025-08-14 14:27:25 -04:00 • committed by GitHub
commit cfa5c1d802
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -252,6 +252,9 @@ func contentsFromWire(wires []*wireContent, allow map[string]bool) ([]Content, e
}
func contentFromWire(wire *wireContent, allow map[string]bool) (Content, error) {
if wire == nil {
return nil, fmt.Errorf("content wire is nil")
}
if allow != nil && !allow[wire.Type] {
return nil, fmt.Errorf("invalid content type %q", wire.Type)
}