From a125acba355492da5843432445c5d0711b10861b Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Sat, 31 Oct 2026 11:03:51 -0500 Subject: [PATCH] fix(mcpx): detect multi-select with tolerant schema parsing --- pkgs/mcpx/internal/mcpserver/conn.go | 32 ++++++++++++++----- .../internal/mcpserver/enum_downgrade_test.go | 25 +++++++++++++++ 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/pkgs/mcpx/internal/mcpserver/conn.go b/pkgs/mcpx/internal/mcpserver/conn.go index 63761a15d1..37d6d1881b 100644 --- a/pkgs/mcpx/internal/mcpserver/conn.go +++ b/pkgs/mcpx/internal/mcpserver/conn.go @@ -343,22 +343,38 @@ func (q Question) carriesMultiSelect() bool { return false } var schema struct { - Properties map[string]struct { - Type string `json:"type"` - Items map[string]json.RawMessage `json:"items"` - } `json:"properties"` + Properties map[string]json.RawMessage `json:"properties"` } if json.Unmarshal(m["requestedSchema"], &schema) != nil { return false } - for _, prop := range schema.Properties { - if prop.Type != "array" { + for _, raw := range schema.Properties { + var prop map[string]json.RawMessage + if json.Unmarshal(raw, &prop) != nil { continue } - if _, ok := prop.Items["enum"]; ok { + var typ string + var types []string + array := json.Unmarshal(prop["type"], &typ) == nil && typ == "array" + if !array && json.Unmarshal(prop["type"], &types) == nil { + for _, t := range types { + if t == "array" { + array = true + break + } + } + } + if !array { + continue + } + var items map[string]json.RawMessage + if json.Unmarshal(prop["items"], &items) != nil { + continue + } + if _, ok := items["enum"]; ok { return true } - if _, ok := prop.Items["anyOf"]; ok { + if _, ok := items["anyOf"]; ok { return true } } diff --git a/pkgs/mcpx/internal/mcpserver/enum_downgrade_test.go b/pkgs/mcpx/internal/mcpserver/enum_downgrade_test.go index 0fd42dece4..42a4ee46a9 100644 --- a/pkgs/mcpx/internal/mcpserver/enum_downgrade_test.go +++ b/pkgs/mcpx/internal/mcpserver/enum_downgrade_test.go @@ -99,6 +99,31 @@ func TestMultiSelectWithheldFromPre20251125Host(t *testing.T) { } } +func TestMultiSelectToleratesOtherPropertyShapes(t *testing.T) { + old := peer("2025-06-18", `{"elicitation":{}}`) + newer := peer("2025-11-25", `{"elicitation":{"form":{}}}`) + cases := map[string]string{ + "single control": `{"choice":{"type":"string","enum":["a"]}}`, + "multi control": `{"choice":{"type":"array","items":{"enum":["a"]}}}`, + "union sibling": `{"choice":{"type":"array","items":{"enum":["a"]}},"other":{"type":["string","null"]}}`, + "boolean items sibling": `{"choice":{"type":"array","items":{"anyOf":[]}},"other":{"type":"array","items":true}}`, + "union multi": `{"choice":{"type":["array","null"],"items":{"enum":["a"]}}}`, + "non-array union": `{"choice":{"type":["string","null"],"items":{"enum":["a"]}}}`, + } + for name, schema := range cases { + t.Run(name, func(t *testing.T) { + q := enumQuestion(schema) + want := name == "single control" || name == "non-array union" + if got := q.Sendable(old); got != want { + t.Errorf("old host Sendable = %v, want %v", got, want) + } + if !q.Sendable(newer) { + t.Error("new host must receive question") + } + }) + } +} + func TestNonBooleanDefaultsStrippedForPre20251125Host(t *testing.T) { old := peer("2025-06-18", `{"elicitation":{}}`) newer := peer("2025-11-25", `{"elicitation":{"form":{}}}`)