mcp: fix multi-select enum elicitation

This commit is contained in:
Maciek Kisiel 2026-02-16 10:55:54 +00:00 • committed by Maciej Kisiel
commit 40475813dd

View file

@ -1095,7 +1095,7 @@ func TestElicitationSchemaValidation(t *testing.T) {
},
},
{
name: "string enum",
name: "single select untitled enum",
schema: &jsonschema.Schema{
Type: "object",
Properties: map[string]*jsonschema.Schema{
@ -1111,7 +1111,7 @@ func TestElicitationSchemaValidation(t *testing.T) {
},
},
{
name: "enum with matching enumNames",
name: "legacy titled enum",
schema: &jsonschema.Schema{
Type: "object",
Properties: map[string]*jsonschema.Schema{
@ -1130,7 +1130,7 @@ func TestElicitationSchemaValidation(t *testing.T) {
},
},
{
name: "enum with enum schema",
name: "single select titled enum",
schema: &jsonschema.Schema{
Type: "object",
Properties: map[string]*jsonschema.Schema{
@ -1138,22 +1138,62 @@ func TestElicitationSchemaValidation(t *testing.T) {
Type: "string",
OneOf: []*jsonschema.Schema{
{
Const: anyPtr(map[string]string{
"const": "high",
"title": "High Priority",
}),
Const: anyPtr("high"),
Title: "High Priority",
},
{
Const: anyPtr(map[string]string{
"const": "medium",
"title": "Medium Priority",
}),
Const: anyPtr("medium"),
Title: "Medium Priority",
},
{
Const: anyPtr(map[string]string{
"const": "low",
"title": "Low Priority",
}),
Const: anyPtr("low"),
Title: "Low Priority",
},
},
},
},
},
},
{
name: "multi select untitled enum",
schema: &jsonschema.Schema{
Type: "object",
Properties: map[string]*jsonschema.Schema{
"status": {
Type: "array",
Items: &jsonschema.Schema{
Type: "string",
Enum: []any{
"active",
"inactive",
"pending",
},
},
},
},
},
},
{
name: "multi select titled enum",
schema: &jsonschema.Schema{
Type: "object",
Properties: map[string]*jsonschema.Schema{
"priority": {
Type: "array",
Items: &jsonschema.Schema{
AnyOf: []*jsonschema.Schema{
{
Const: anyPtr("high"),
Title: "High Priority",
},
{
Const: anyPtr("medium"),
Title: "Medium Priority",
},
{
Const: anyPtr("low"),
Title: "Low Priority",
},
},
},
},
@ -1210,17 +1250,7 @@ func TestElicitationSchemaValidation(t *testing.T) {
"config": {Type: "object"},
},
},
expectedError: "elicit schema property \"config\" has unsupported type \"object\", only string, number, integer, and boolean are allowed",
},
{
name: "array property",
schema: &jsonschema.Schema{
Type: "object",
Properties: map[string]*jsonschema.Schema{
"tags": {Type: "array", Items: &jsonschema.Schema{Type: "string"}},
},
},
expectedError: "elicit schema property \"tags\" has unsupported type \"array\", only string, number, integer, and boolean are allowed",
expectedError: "elicit schema property \"config\" has unsupported type \"object\", only string, number, integer, boolean, and array are allowed",
},
{
name: "array without items",
@ -1230,7 +1260,27 @@ func TestElicitationSchemaValidation(t *testing.T) {
"items": {Type: "array"},
},
},
expectedError: "elicit schema property \"items\" has unsupported type \"array\", only string, number, integer, and boolean are allowed",
expectedError: "elicit schema property \"items\" is array but missing 'items' definition",
},
{
name: "array with integer items",
schema: &jsonschema.Schema{
Type: "object",
Properties: map[string]*jsonschema.Schema{
"items": {Type: "array", Items: &jsonschema.Schema{Type: "integer"}},
},
},
expectedError: "elicit schema property \"items\" items have unsupported type \"integer\"",
},
{
name: "array of generic strings",
schema: &jsonschema.Schema{
Type: "object",
Properties: map[string]*jsonschema.Schema{
"items": {Type: "array", Items: &jsonschema.Schema{Type: "string"}},
},
},
expectedError: "elicit schema property \"items\" items must specify enum for untitled enums",
},
{
name: "unsupported string format",
@ -1385,7 +1435,29 @@ func TestElicitationSchemaValidation(t *testing.T) {
},
},
},
expectedError: "elicit schema property \"priority\" has unsupported type \"\", only string, number, integer, and boolean are allowed",
expectedError: "elicit schema property \"priority\" has unsupported type \"\", only string, number, integer, boolean, and array are allowed",
},
{
name: "titled enum without const",
schema: &jsonschema.Schema{
Type: "object",
Properties: map[string]*jsonschema.Schema{
"priority": {
Type: "string",
OneOf: []*jsonschema.Schema{
{
Const: anyPtr("high"),
Title: "High Priority",
},
{
Type: "string",
Title: "Other Priority",
},
},
},
},
},
expectedError: "elicit schema property \"priority\" oneOf has invalid entry: const is required for titled enum entries",
},
{
name: "untyped property",
@ -1395,7 +1467,7 @@ func TestElicitationSchemaValidation(t *testing.T) {
"data": {},
},
},
expectedError: "elicit schema property \"data\" has unsupported type \"\", only string, number, integer, and boolean are allowed",
expectedError: "elicit schema property \"data\" has unsupported type \"\", only string, number, integer, boolean, and array are allowed",
},
}
@ -1458,10 +1530,8 @@ func TestElicitContentValidation(t *testing.T) {
Type: "string",
OneOf: []*jsonschema.Schema{
{
Const: anyPtr(map[string]string{
"const": "high",
"title": "High Priority",
}),
Const: anyPtr("high"),
Title: "High Priority",
},
},
},
@ -1478,10 +1548,8 @@ func TestElicitContentValidation(t *testing.T) {
Type: "string",
OneOf: []*jsonschema.Schema{
{
Const: anyPtr(map[string]string{
"const": "potato",
"title": "Potato Priority",
}),
Const: anyPtr("potato"),
Title: "Potato Priority",
},
},
},