parent
ce393acb95
commit
40f034322f
3 changed files with 20 additions and 10 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1639,15 +1639,7 @@ func (ss *ServerSession) Elicit(ctx context.Context, params *ElicitParams) (*Eli
|
|||
return nil, fmt.Errorf("%w: params cannot be nil", jsonrpc2.ErrInvalidParams)
|
||||
}
|
||||
|
||||
if params.Mode == "" {
|
||||
params2 := *params
|
||||
if params.URL != "" || params.ElicitationID != "" {
|
||||
params2.Mode = "url"
|
||||
} else {
|
||||
params2.Mode = "form"
|
||||
}
|
||||
params = ¶ms2
|
||||
}
|
||||
params = params.inferElicitMode()
|
||||
|
||||
if iparams := ss.InitializeParams(); iparams == nil || iparams.Capabilities == nil || iparams.Capabilities.Elicitation == nil {
|
||||
return nil, fmt.Errorf("client does not support elicitation")
|
||||
|
|
|
|||
2
mcp/testdata/conformance/server/mrtr.txtar
vendored
2
mcp/testdata/conformance/server/mrtr.txtar
vendored
|
|
@ -52,7 +52,7 @@ confirmThenGreet
|
|||
"who": {
|
||||
"method": "elicitation/create",
|
||||
"params": {
|
||||
"mode": "",
|
||||
"mode": "form",
|
||||
"message": "What is your name?",
|
||||
"requestedSchema": {
|
||||
"type": "object",
|
||||
|
|
|
|||
Loading…
Reference in a new issue