Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions pkgs/mcpx/internal/mcpserver/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
25 changes: 25 additions & 0 deletions pkgs/mcpx/internal/mcpserver/enum_downgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":{}}}`)
Expand Down
Loading