diff --git a/pkgs/mcpx/internal/mcpserver/conn.go b/pkgs/mcpx/internal/mcpserver/conn.go index 782a12764a..231d54f12c 100644 --- a/pkgs/mcpx/internal/mcpserver/conn.go +++ b/pkgs/mcpx/internal/mcpserver/conn.go @@ -226,15 +226,28 @@ func (p Peer) Declared(name string) bool { // // Three gates, and all three are needed. The revision has to define // elicitation at all -- 2025-03-26 does not. The client has to have declared -// it. And url mode has to be separately declared, because it arrived in -// 2025-11-25 and a client that knows only form mode receives a request with -// no `requestedSchema` and no way to render it. +// it. And each mode has to be separately declared from 2025-11-25, when the +// declaration gained sub-keys: url mode because it arrived then and a client +// that knows only form mode receives a request with no `requestedSchema` and +// no way to render it, and form mode because a client that declared only +// url never agreed to a form -- {} remains the form-only declaration, and +// below 2025-11-25 presence of the capability is the form declaration. func (p Peer) CanElicit(mode string) bool { if !AtLeast(p.Version, "2025-06-18") || !p.Declared("elicitation") { return false } if mode != "url" { - return true + if !AtLeast(p.Version, "2025-11-25") { + return true + } + var e struct { + Form json.RawMessage `json:"form"` + URL json.RawMessage `json:"url"` + } + if json.Unmarshal(p.Caps["elicitation"], &e) != nil { + return false + } + return len(e.Form) > 0 || len(e.URL) == 0 } if !AtLeast(p.Version, "2025-11-25") { return false diff --git a/pkgs/mcpx/internal/mcpserver/proto_test.go b/pkgs/mcpx/internal/mcpserver/proto_test.go index 56bc6d8197..786bf9e0b6 100644 --- a/pkgs/mcpx/internal/mcpserver/proto_test.go +++ b/pkgs/mcpx/internal/mcpserver/proto_test.go @@ -129,6 +129,18 @@ func TestAClientIsNeverSentSomethingItDidNotDeclare(t *testing.T) { peer("2025-11-25", `{"elicitation":{"form":{}}}`), "url", false, false}, {"url mode declared on 2025-11-25", peer("2025-11-25", `{"elicitation":{"url":{}}}`), "url", true, false}, + {"url-only declaration refuses form on 2025-11-25", + peer("2025-11-25", `{"elicitation":{"url":{}}}`), "form", false, false}, + {"form declared on 2025-11-25", + peer("2025-11-25", `{"elicitation":{"form":{}}}`), "form", true, false}, + {"both modes declared on 2025-11-25, form allowed", + peer("2025-11-25", `{"elicitation":{"form":{},"url":{}}}`), "form", true, false}, + {"empty declaration on 2025-11-25 is form-only", + peer("2025-11-25", `{"elicitation":{}}`), "form", true, false}, + {"url-only on 2025-06-18 is still form -- sub-keys do not exist yet", + peer("2025-06-18", `{"elicitation":{"url":{}}}`), "form", true, false}, + {"malformed declaration on 2025-11-25 reads as undeclared", + peer("2025-11-25", `{"elicitation":"yes"}`), "form", false, false}, {"nothing declared", peer("2026-07-28", `{}`), "form", false, false}, {"sampling only",