Skip to content

Commit f6118aa

Browse files
authored
mcp: fix the type of the Complete handler
The Complete handler was returning an abstract Result type, rather than concrete CompleteResult type. Fixes #375
1 parent a76bae3 commit f6118aa

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

mcp/mcp_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,3 +1725,36 @@ func TestPointerArgEquivalence(t *testing.T) {
17251725
func ptr[T any](v T) *T {
17261726
return &v
17271727
}
1728+
1729+
func TestComplete(t *testing.T) {
1730+
completionValues := []string{"python", "pytorch", "pyside"}
1731+
1732+
serverOpts := &ServerOptions{
1733+
CompletionHandler: func(_ context.Context, request *CompleteRequest) (*CompleteResult, error) {
1734+
return &CompleteResult{
1735+
Completion: CompletionResultDetails{
1736+
Values: completionValues,
1737+
},
1738+
}, nil
1739+
},
1740+
}
1741+
server := NewServer(testImpl, serverOpts)
1742+
cs, _ := basicClientServerConnection(t, nil, server, func(s *Server) {})
1743+
result, err := cs.Complete(context.Background(), &CompleteParams{
1744+
Argument: CompleteParamsArgument{
1745+
Name: "language",
1746+
Value: "py",
1747+
},
1748+
Ref: &CompleteReference{
1749+
Type: "ref/prompt",
1750+
Name: "code_review",
1751+
},
1752+
})
1753+
if err != nil {
1754+
t.Fatal(err)
1755+
}
1756+
1757+
if diff := cmp.Diff(completionValues, result.Completion.Values); diff != "" {
1758+
t.Errorf("Complete() mismatch (-want +got):\n%s", diff)
1759+
}
1760+
}

mcp/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ func (s *Server) capabilities() *ServerCapabilities {
407407
return caps
408408
}
409409

410-
func (s *Server) complete(ctx context.Context, req *CompleteRequest) (Result, error) {
410+
func (s *Server) complete(ctx context.Context, req *CompleteRequest) (*CompleteResult, error) {
411411
if s.opts.CompletionHandler == nil {
412412
return nil, jsonrpc2.ErrMethodNotFound
413413
}

0 commit comments

Comments
 (0)