From 3d4a82e16cbdb469a74424cbbe670f148b89a6cc Mon Sep 17 00:00:00 2001 From: jyotir-aditya Date: Sun, 25 Oct 2026 01:22:45 +0530 Subject: [PATCH] mcp: reject null titled enum entries in elicitation schemas validateTitledEnumEntry dereferenced entry.Const without checking entry for nil. A JSON null inside oneOf (single-select) or anyOf (multi-select) unmarshals to a nil *jsonschema.Schema, so the client panicked while validating an elicitation/create request. ServerSession.Elicit runs the same validateElicitSchema on the schema it sent once the client accepts, so a server passing a nil entry could panic there too. Return an invalid-params error instead, as for other invalid schemas, and add oneOf and anyOf regression cases to TestElicitationSchemaValidation. --- mcp/client.go | 3 +++ mcp/mcp_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/mcp/client.go b/mcp/client.go index 3b24b2e9d..38c9d6afd 100644 --- a/mcp/client.go +++ b/mcp/client.go @@ -1119,6 +1119,9 @@ func validateElicitArrayProperty(propName string, propSchema *jsonschema.Schema) } func validateTitledEnumEntry(entry *jsonschema.Schema) error { + if entry == nil { + return fmt.Errorf("titled enum entries must be objects") + } if entry.Const == nil { return fmt.Errorf("const is required for titled enum entries") } diff --git a/mcp/mcp_test.go b/mcp/mcp_test.go index c53e6d571..b15cd7fb0 100644 --- a/mcp/mcp_test.go +++ b/mcp/mcp_test.go @@ -1650,6 +1650,34 @@ func TestElicitationSchemaValidation(t *testing.T) { }, expectedError: "elicit schema property \"priority\" oneOf has invalid entry: const is required for titled enum entries", }, + { + name: "titled enum with null oneOf entry", + schema: &jsonschema.Schema{ + Type: "object", + Properties: map[string]*jsonschema.Schema{ + "priority": { + Type: "string", + OneOf: []*jsonschema.Schema{nil}, + }, + }, + }, + expectedError: "elicit schema property \"priority\" oneOf has invalid entry: titled enum entries must be objects", + }, + { + name: "multi select titled enum with null anyOf entry", + schema: &jsonschema.Schema{ + Type: "object", + Properties: map[string]*jsonschema.Schema{ + "priorities": { + Type: "array", + Items: &jsonschema.Schema{ + AnyOf: []*jsonschema.Schema{nil}, + }, + }, + }, + }, + expectedError: "elicit schema property \"priorities\" items has invalid entry: titled enum entries must be objects", + }, { name: "untyped property", schema: &jsonschema.Schema{