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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if ep, ok := v.(*ElicitParams); ok {
|
||||||
|
v = ep.inferElicitMode()
|
||||||
|
}
|
||||||
converted[k] = &wire{Method: method, Params: v}
|
converted[k] = &wire{Method: method, Params: v}
|
||||||
}
|
}
|
||||||
return json.Marshal(converted)
|
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) GetProgressToken() any { return getProgressToken(x) }
|
||||||
func (x *ElicitParams) SetProgressToken(t any) { setProgressToken(x, t) }
|
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.
|
// The client's response to an elicitation/create request from the server.
|
||||||
type ElicitResult struct {
|
type ElicitResult struct {
|
||||||
// This property is reserved by the protocol to allow clients and servers to
|
// 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)
|
return nil, fmt.Errorf("%w: params cannot be nil", jsonrpc2.ErrInvalidParams)
|
||||||
}
|
}
|
||||||
|
|
||||||
if params.Mode == "" {
|
params = params.inferElicitMode()
|
||||||
params2 := *params
|
|
||||||
if params.URL != "" || params.ElicitationID != "" {
|
|
||||||
params2.Mode = "url"
|
|
||||||
} else {
|
|
||||||
params2.Mode = "form"
|
|
||||||
}
|
|
||||||
params = ¶ms2
|
|
||||||
}
|
|
||||||
|
|
||||||
if iparams := ss.InitializeParams(); iparams == nil || iparams.Capabilities == nil || iparams.Capabilities.Elicitation == nil {
|
if iparams := ss.InitializeParams(); iparams == nil || iparams.Capabilities == nil || iparams.Capabilities.Elicitation == nil {
|
||||||
return nil, fmt.Errorf("client does not support elicitation")
|
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": {
|
"who": {
|
||||||
"method": "elicitation/create",
|
"method": "elicitation/create",
|
||||||
"params": {
|
"params": {
|
||||||
"mode": "",
|
"mode": "form",
|
||||||
"message": "What is your name?",
|
"message": "What is your name?",
|
||||||
"requestedSchema": {
|
"requestedSchema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue