mcp: infer elicit mode from ElicitParams (#1078)

Fixes #1072
This commit is contained in:
Guglielmo Colombo 2026-07-13 11:49:15 +02:00 • committed by GitHub
commit 40f034322f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -63,6 +63,9 @@ func (m InputRequestMap) MarshalJSON() ([]byte, error) {
if err != nil {
return nil, err
}
if ep, ok := v.(*ElicitParams); ok {
v = ep.inferElicitMode()
}
converted[k] = &wire{Method: method, Params: v}
}
return json.Marshal(converted)
@ -2126,6 +2129,21 @@ func (x *ElicitParams) isNil() bool { return x == nil }
func (x *ElicitParams) GetProgressToken() any { return getProgressToken(x) }
func (x *ElicitParams) SetProgressToken(t any) { setProgressToken(x, t) }
// inferElicitMode returns x with Mode populated by inference if it was empty.
// Mode is inferred as "url" when URL or ElicitationID is set, otherwise "form".
func (x *ElicitParams) inferElicitMode() *ElicitParams {
if x == nil || x.Mode != "" {
return x
}
x2 := *x
if x.URL != "" || x.ElicitationID != "" {
x2.Mode = "url"
} else {
x2.Mode = "form"
}
return &x2
}
// The client's response to an elicitation/create request from the server.
type ElicitResult struct {
// This property is reserved by the protocol to allow clients and servers to