Skip to content

Commit 713d4d3

Browse files
committed
fix rebase
1 parent a44b254 commit 713d4d3

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

client/elicitation_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,23 @@ func TestClient_Initialize_WithElicitationHandler(t *testing.T) {
144144
t.Fatalf("expected initialize method, got %s", request.Method)
145145
}
146146

147+
// Verify that elicitation capability is included in the request
148+
paramsBytes, err := json.Marshal(request.Params)
149+
if err != nil {
150+
t.Fatalf("failed to marshal params: %v", err)
151+
}
152+
153+
var initParams struct {
154+
Capabilities mcp.ClientCapabilities `json:"capabilities"`
155+
}
156+
if err := json.Unmarshal(paramsBytes, &initParams); err != nil {
157+
t.Fatalf("failed to unmarshal params: %v", err)
158+
}
159+
160+
if initParams.Capabilities.Elicitation == nil {
161+
t.Error("expected elicitation capability to be declared")
162+
}
163+
147164
// Return successful initialization response
148165
result := mcp.InitializeResult{
149166
ProtocolVersion: mcp.LATEST_PROTOCOL_VERSION,

examples/elicitation/main.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ func demoElicitationHandler(s *server.MCPServer) server.ToolHandlerFunc {
5858
return nil, fmt.Errorf("unexpected response format")
5959
}
6060

61-
projectName := data["projectName"].(string)
61+
projectName, ok := data["projectName"].(string)
62+
if !ok || projectName == "" {
63+
return nil, fmt.Errorf("invalid or missing 'projectName' in elicitation response")
64+
}
65+
6266
framework := "none"
6367
if fw, ok := data["framework"].(string); ok {
6468
framework = fw
@@ -123,8 +127,7 @@ func main() {
123127
mcp.WithString("data", mcp.Required(), mcp.Description("Data to process")),
124128
),
125129
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
126-
data := request.GetArguments()["data"].(string)
127-
130+
data := request.GetString("data", "")
128131
// Only request elicitation if data seems sensitive
129132
if len(data) > 100 {
130133
elicitationRequest := mcp.ElicitationRequest{
@@ -160,7 +163,11 @@ func main() {
160163
}, nil
161164
}
162165

163-
responseData := result.Response.Value.(map[string]interface{})
166+
responseData, ok := result.Response.Value.(map[string]interface{})
167+
if !ok {
168+
responseData = make(map[string]interface{})
169+
}
170+
164171
if proceed, ok := responseData["proceed"].(bool); !ok || !proceed {
165172
reason := "No reason provided"
166173
if r, ok := responseData["reason"].(string); ok && r != "" {

server/session.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,6 @@ type SessionWithElicitation interface {
5959
RequestElicitation(ctx context.Context, request mcp.ElicitationRequest) (*mcp.ElicitationResult, error)
6060
}
6161

62-
// SessionWithElicitation is an extension of ClientSession that can send elicitation requests
63-
type SessionWithElicitation interface {
64-
ClientSession
65-
// RequestElicitation sends an elicitation request to the client and waits for response
66-
RequestElicitation(ctx context.Context, request mcp.ElicitationRequest) (*mcp.ElicitationResult, error)
67-
}
68-
6962
// SessionWithStreamableHTTPConfig extends ClientSession to support streamable HTTP transport configurations
7063
type SessionWithStreamableHTTPConfig interface {
7164
ClientSession

0 commit comments

Comments
 (0)