Skip to content

Commit aef7c8d

Browse files
miguelb-gkJBUinfo
authored andcommitted
Update elicitation response to match spec
Updating elicitation response to match MCP spec document https://modelcontextprotocol.io/specification/draft/client/elicitation
1 parent 6cd58d8 commit aef7c8d

File tree

5 files changed

+54
-58
lines changed

5 files changed

+54
-58
lines changed

client/elicitation_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ func TestClient_HandleElicitationRequest(t *testing.T) {
3838
name: "successful elicitation - accept",
3939
handler: &mockElicitationHandler{
4040
result: &mcp.ElicitationResult{
41-
Response: mcp.ElicitationResponse{
42-
Type: mcp.ElicitationResponseTypeAccept,
43-
Value: map[string]any{
41+
ElicitationResponse: mcp.ElicitationResponse{
42+
Action: mcp.ElicitationResponseActionAccept,
43+
Content: map[string]any{
4444
"name": "test-project",
4545
"framework": "react",
4646
},
@@ -52,8 +52,8 @@ func TestClient_HandleElicitationRequest(t *testing.T) {
5252
name: "successful elicitation - decline",
5353
handler: &mockElicitationHandler{
5454
result: &mcp.ElicitationResult{
55-
Response: mcp.ElicitationResponse{
56-
Type: mcp.ElicitationResponseTypeDecline,
55+
ElicitationResponse: mcp.ElicitationResponse{
56+
Action: mcp.ElicitationResponseActionDecline,
5757
},
5858
},
5959
},
@@ -62,8 +62,8 @@ func TestClient_HandleElicitationRequest(t *testing.T) {
6262
name: "successful elicitation - cancel",
6363
handler: &mockElicitationHandler{
6464
result: &mcp.ElicitationResult{
65-
Response: mcp.ElicitationResponse{
66-
Type: mcp.ElicitationResponseTypeCancel,
65+
ElicitationResponse: mcp.ElicitationResponse{
66+
Action: mcp.ElicitationResponseActionCancel,
6767
},
6868
},
6969
},

client/inprocess_elicitation_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ func (h *MockElicitationHandler) Elicit(ctx context.Context, request mcp.Elicita
2222

2323
// Simulate user accepting and providing data
2424
return &mcp.ElicitationResult{
25-
Response: mcp.ElicitationResponse{
26-
Type: mcp.ElicitationResponseTypeAccept,
27-
Value: map[string]any{
25+
ElicitationResponse: mcp.ElicitationResponse{
26+
Action: mcp.ElicitationResponseActionAccept,
27+
Content: map[string]any{
2828
"confirm": true,
2929
"details": "User provided additional details",
3030
},
@@ -84,12 +84,12 @@ func TestInProcessElicitation(t *testing.T) {
8484

8585
// Handle the response
8686
var responseText string
87-
switch result.Response.Type {
88-
case mcp.ElicitationResponseTypeAccept:
87+
switch result.Action {
88+
case mcp.ElicitationResponseActionAccept:
8989
responseText = "User accepted and provided data"
90-
case mcp.ElicitationResponseTypeDecline:
90+
case mcp.ElicitationResponseActionDecline:
9191
responseText = "User declined to provide information"
92-
case mcp.ElicitationResponseTypeCancel:
92+
case mcp.ElicitationResponseActionCancel:
9393
responseText = "User cancelled the request"
9494
}
9595

examples/elicitation/main.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ func demoElicitationHandler(s *server.MCPServer) server.ToolHandlerFunc {
5050
}
5151

5252
// Handle the user's response
53-
switch result.Response.Type {
54-
case mcp.ElicitationResponseTypeAccept:
53+
switch result.Action {
54+
case mcp.ElicitationResponseActionAccept:
5555
// User provided the information
56-
data, ok := result.Response.Value.(map[string]any)
56+
data, ok := result.Content.(map[string]any)
5757
if !ok {
58-
return nil, fmt.Errorf("unexpected response format: expected map[string]any, got %T", result.Response.Value)
58+
return nil, fmt.Errorf("unexpected response format: expected map[string]any, got %T", result.Content)
5959
}
6060

6161
// Safely extract projectName (required field)
@@ -103,18 +103,18 @@ func demoElicitationHandler(s *server.MCPServer) server.ToolHandlerFunc {
103103
},
104104
}, nil
105105

106-
case mcp.ElicitationResponseTypeDecline:
106+
case mcp.ElicitationResponseActionDecline:
107107
return &mcp.CallToolResult{
108108
Content: []mcp.Content{
109109
mcp.NewTextContent("Project creation cancelled - user declined to provide information"),
110110
},
111111
}, nil
112112

113-
case mcp.ElicitationResponseTypeCancel:
113+
case mcp.ElicitationResponseActionCancel:
114114
return nil, fmt.Errorf("project creation cancelled by user")
115115

116116
default:
117-
return nil, fmt.Errorf("unexpected response type: %s", result.Response.Type)
117+
return nil, fmt.Errorf("unexpected response action: %s", result.Action)
118118
}
119119
}
120120
}
@@ -183,7 +183,7 @@ func main() {
183183
return nil, fmt.Errorf("failed to get confirmation: %w", err)
184184
}
185185

186-
if result.Response.Type != mcp.ElicitationResponseTypeAccept {
186+
if result.Action != mcp.ElicitationResponseActionAccept {
187187
return &mcp.CallToolResult{
188188
Content: []mcp.Content{
189189
mcp.NewTextContent("Processing cancelled by user"),
@@ -192,9 +192,9 @@ func main() {
192192
}
193193

194194
// Safely extract response data
195-
responseData, ok := result.Response.Value.(map[string]any)
195+
responseData, ok := result.Content.(map[string]any)
196196
if !ok {
197-
return nil, fmt.Errorf("unexpected response format: expected map[string]any, got %T", result.Response.Value)
197+
return nil, fmt.Errorf("unexpected response format: expected map[string]any, got %T", result.Content)
198198
}
199199

200200
// Safely extract proceed field

mcp/types.go

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -842,32 +842,28 @@ type ElicitationParams struct {
842842
// ElicitationResult represents the result of an elicitation request.
843843
type ElicitationResult struct {
844844
Result
845-
// The user's response, which could be:
846-
// - The requested information (if user accepted)
847-
// - A decline indicator (if user declined)
848-
// - A cancel indicator (if user cancelled)
849-
Response ElicitationResponse `json:"response"`
845+
ElicitationResponse
850846
}
851847

852848
// ElicitationResponse represents the user's response to an elicitation request.
853849
type ElicitationResponse struct {
854-
// Type indicates whether the user accepted, declined, or cancelled.
855-
Type ElicitationResponseType `json:"type"`
856-
// Value contains the user's response data if they accepted.
850+
// Action indicates whether the user accepted, declined, or cancelled.
851+
Action ElicitationResponseAction `json:"action"`
852+
// Content contains the user's response data if they accepted.
857853
// Should conform to the requestedSchema from the ElicitationRequest.
858-
Value any `json:"value,omitempty"`
854+
Content any `json:"content,omitempty"`
859855
}
860856

861-
// ElicitationResponseType indicates how the user responded to an elicitation request.
862-
type ElicitationResponseType string
857+
// ElicitationResponseAction indicates how the user responded to an elicitation request.
858+
type ElicitationResponseAction string
863859

864860
const (
865-
// ElicitationResponseTypeAccept indicates the user provided the requested information.
866-
ElicitationResponseTypeAccept ElicitationResponseType = "accept"
867-
// ElicitationResponseTypeDecline indicates the user explicitly declined to provide information.
868-
ElicitationResponseTypeDecline ElicitationResponseType = "decline"
869-
// ElicitationResponseTypeCancel indicates the user cancelled without making a choice.
870-
ElicitationResponseTypeCancel ElicitationResponseType = "cancel"
861+
// ElicitationResponseActionAccept indicates the user provided the requested information.
862+
ElicitationResponseActionAccept ElicitationResponseAction = "accept"
863+
// ElicitationResponseActionDecline indicates the user explicitly declined to provide information.
864+
ElicitationResponseActionDecline ElicitationResponseAction = "decline"
865+
// ElicitationResponseActionCancel indicates the user cancelled without making a choice.
866+
ElicitationResponseActionCancel ElicitationResponseAction = "cancel"
871867
)
872868

873869
/* Sampling */

server/elicitation_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ func TestMCPServer_RequestElicitation_Success(t *testing.T) {
117117
mockSession := &mockElicitationSession{
118118
sessionID: "test-session",
119119
result: &mcp.ElicitationResult{
120-
Response: mcp.ElicitationResponse{
121-
Type: mcp.ElicitationResponseTypeAccept,
122-
Value: map[string]any{
120+
ElicitationResponse: mcp.ElicitationResponse{
121+
Action: mcp.ElicitationResponseActionAccept,
122+
Content: map[string]any{
123123
"projectName": "my-project",
124124
"framework": "react",
125125
},
@@ -155,11 +155,11 @@ func TestMCPServer_RequestElicitation_Success(t *testing.T) {
155155
return
156156
}
157157

158-
if result.Response.Type != mcp.ElicitationResponseTypeAccept {
159-
t.Errorf("expected response type %q, got %q", mcp.ElicitationResponseTypeAccept, result.Response.Type)
158+
if result.Action != mcp.ElicitationResponseActionAccept {
159+
t.Errorf("expected response type %q, got %q", mcp.ElicitationResponseActionAccept, result.Action)
160160
}
161161

162-
value, ok := result.Response.Value.(map[string]any)
162+
value, ok := result.Content.(map[string]any)
163163
if !ok {
164164
t.Error("expected value to be a map")
165165
return
@@ -176,16 +176,16 @@ func TestRequestElicitation(t *testing.T) {
176176
session ClientSession
177177
request mcp.ElicitationRequest
178178
expectedError error
179-
expectedType mcp.ElicitationResponseType
179+
expectedType mcp.ElicitationResponseAction
180180
}{
181181
{
182182
name: "successful elicitation with accept",
183183
session: &mockElicitationSession{
184184
sessionID: "test-1",
185185
result: &mcp.ElicitationResult{
186-
Response: mcp.ElicitationResponse{
187-
Type: mcp.ElicitationResponseTypeAccept,
188-
Value: map[string]any{
186+
ElicitationResponse: mcp.ElicitationResponse{
187+
Action: mcp.ElicitationResponseActionAccept,
188+
Content: map[string]any{
189189
"name": "test-project",
190190
"framework": "react",
191191
},
@@ -204,15 +204,15 @@ func TestRequestElicitation(t *testing.T) {
204204
},
205205
},
206206
},
207-
expectedType: mcp.ElicitationResponseTypeAccept,
207+
expectedType: mcp.ElicitationResponseActionAccept,
208208
},
209209
{
210210
name: "elicitation declined by user",
211211
session: &mockElicitationSession{
212212
sessionID: "test-2",
213213
result: &mcp.ElicitationResult{
214-
Response: mcp.ElicitationResponse{
215-
Type: mcp.ElicitationResponseTypeDecline,
214+
ElicitationResponse: mcp.ElicitationResponse{
215+
Action: mcp.ElicitationResponseActionDecline,
216216
},
217217
},
218218
},
@@ -222,7 +222,7 @@ func TestRequestElicitation(t *testing.T) {
222222
RequestedSchema: map[string]any{"type": "object"},
223223
},
224224
},
225-
expectedType: mcp.ElicitationResponseTypeDecline,
225+
expectedType: mcp.ElicitationResponseActionDecline,
226226
},
227227
{
228228
name: "session does not support elicitation",
@@ -252,10 +252,10 @@ func TestRequestElicitation(t *testing.T) {
252252

253253
require.NoError(t, err)
254254
require.NotNil(t, result)
255-
assert.Equal(t, tt.expectedType, result.Response.Type)
255+
assert.Equal(t, tt.expectedType, result.Action)
256256

257-
if tt.expectedType == mcp.ElicitationResponseTypeAccept {
258-
assert.NotNil(t, result.Response.Value)
257+
if tt.expectedType == mcp.ElicitationResponseActionAccept {
258+
assert.NotNil(t, result.Action)
259259
}
260260
})
261261
}

0 commit comments

Comments
 (0)