mcp: fix the type of the Complete handler

The Complete handler was returning an abstract Result type, rather than concrete CompleteResult type.

Fixes #375
This commit is contained in:
Huabing (Robin) Zhao 2025-08-29 22:06:23 +08:00 • committed by GitHub
commit f6118aaace
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 1 deletions

View file

@ -1725,3 +1725,36 @@ func TestPointerArgEquivalence(t *testing.T) {
func ptr[T any](v T) *T {
return &v
}
func TestComplete(t *testing.T) {
completionValues := []string{"python", "pytorch", "pyside"}
serverOpts := &ServerOptions{
CompletionHandler: func(_ context.Context, request *CompleteRequest) (*CompleteResult, error) {
return &CompleteResult{
Completion: CompletionResultDetails{
Values: completionValues,
},
}, nil
},
}
server := NewServer(testImpl, serverOpts)
cs, _ := basicClientServerConnection(t, nil, server, func(s *Server) {})
result, err := cs.Complete(context.Background(), &CompleteParams{
Argument: CompleteParamsArgument{
Name: "language",
Value: "py",
},
Ref: &CompleteReference{
Type: "ref/prompt",
Name: "code_review",
},
})
if err != nil {
t.Fatal(err)
}
if diff := cmp.Diff(completionValues, result.Completion.Values); diff != "" {
t.Errorf("Complete() mismatch (-want +got):\n%s", diff)
}
}

View file

@ -407,7 +407,7 @@ func (s *Server) capabilities() *ServerCapabilities {
return caps
}
func (s *Server) complete(ctx context.Context, req *CompleteRequest) (Result, error) {
func (s *Server) complete(ctx context.Context, req *CompleteRequest) (*CompleteResult, error) {
if s.opts.CompletionHandler == nil {
return nil, jsonrpc2.ErrMethodNotFound
}