@@ -27,6 +27,7 @@ import (
2727 "github.com/google/jsonschema-go/jsonschema"
2828 internaljson "github.com/modelcontextprotocol/go-sdk/internal/json"
2929 "github.com/modelcontextprotocol/go-sdk/internal/jsonrpc2"
30+ "github.com/modelcontextprotocol/go-sdk/internal/mcpgodebug"
3031 "github.com/modelcontextprotocol/go-sdk/internal/util"
3132 "github.com/modelcontextprotocol/go-sdk/jsonrpc"
3233 "github.com/yosida95/uritemplate/v3"
@@ -661,7 +662,23 @@ func (s *Server) capabilities() *ServerCapabilities {
661662 return caps
662663}
663664
665+ // disablecompleteparamsvalidation is a compatibility parameter that restores
666+ // the previous behavior of [Server.complete], where required fields on
667+ // [CompleteParams] were not validated before dispatching to the completion
668+ // handler. See the documentation for the mcpgodebug package for instructions
669+ // how to enable it.
670+ // The option will be removed in a future version of the SDK.
671+ var disablecompleteparamsvalidation = mcpgodebug .Value ("disablecompleteparamsvalidation" )
672+
664673func (s * Server ) complete (ctx context.Context , req * CompleteRequest ) (* CompleteResult , error ) {
674+ if disablecompleteparamsvalidation != "1" {
675+ if req .Params .Ref == nil {
676+ return nil , fmt .Errorf ("%w: missing required 'ref' field" , jsonrpc2 .ErrInvalidParams )
677+ }
678+ if req .Params .Argument .Name == "" {
679+ return nil , fmt .Errorf ("%w: missing required 'argument.name' field" , jsonrpc2 .ErrInvalidParams )
680+ }
681+ }
665682 if s .opts .CompletionHandler == nil {
666683 return nil , jsonrpc2 .ErrMethodNotFound
667684 }
0 commit comments