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:
parent
a76bae3a11
commit
f6118aaace
2 changed files with 34 additions and 1 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue