From 955afec19e7078d3d2196db8fbe76d3e9d818bf0 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Thu, 29 Oct 2026 01:58:34 -0500 Subject: [PATCH] fix(mcpx): gate form elicitation on the declaration sub-keys (#1757) CanElicit("form") returned true for any elicitation declaration, so a 2025-11-25+ host that declared only url mode was offered form elicitations with a requestedSchema it never agreed to. From 2025-11-25 the form branch now parses the declaration: form is sendable iff a form key is present or the declaration is empty ({} is the form-only declaration); url-only is not form-capable and a malformed declaration reads as undeclared. Below 2025-11-25 presence of the capability remains the form declaration, unchanged. Phase 3a of #1753 (form portion of #1757), per triage task 1980. Lands on top of merged PR #2003 (Phase 1 sampling gate, same file). Tests: declaration matrix extended in proto_test.go (url-only refused at 2025-11-25+, form-only, both keys, {}, legacy, malformed). --- pkgs/mcpx/internal/mcpserver/conn.go | 21 +++++++++++++++++---- pkgs/mcpx/internal/mcpserver/proto_test.go | 12 ++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) 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",