@@ -109,11 +109,51 @@ func Example_prompts() {
109109
110110## Utilities
111111
112- <!-- TODO -->
113-
114112### Completion
115113
116- <!-- TODO -->
114+ To support the
115+ [ completion] ( https://modelcontextprotocol.io/specification/2025-06-18/server/utilities/completion )
116+ capability, the server needs a completion handler.
117+
118+ ** Client-side** : completion is called using the
119+ [ ` ClientSession.Complete ` ] ( https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ClientSession.Complete )
120+ method.
121+
122+ ** Server-side** : completion is enabled by setting
123+ [ ` ServerOptions.CompletionHandler ` ] ( https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ServerOptions.CompletionHandler ) .
124+ If this field is set to a non-nil value, the server will advertise the
125+ ` completions ` server capability, and use this handler to respond to completion
126+ requests.
127+
128+ ``` go
129+ myCompletionHandler := func (_ context.Context , req *mcp.CompleteRequest ) (*mcp.CompleteResult , error ) {
130+ // In a real application, you'd implement actual completion logic here.
131+ // For this example, we return a fixed set of suggestions.
132+ var suggestions []string
133+ switch req.Params .Ref .Type {
134+ case " ref/prompt" :
135+ suggestions = []string {" suggestion1" , " suggestion2" , " suggestion3" }
136+ case " ref/resource" :
137+ suggestions = []string {" suggestion4" , " suggestion5" , " suggestion6" }
138+ default :
139+ return nil , fmt.Errorf (" unrecognized content type %s " , req.Params .Ref .Type )
140+ }
141+
142+ return &mcp.CompleteResult {
143+ Completion: mcp.CompletionResultDetails {
144+ HasMore: false ,
145+ Total: len (suggestions),
146+ Values: suggestions,
147+ },
148+ }, nil
149+ }
150+
151+ // Create the MCP Server instance and assign the handler.
152+ // No server running, just showing the configuration.
153+ _ = mcp.NewServer (&mcp.Implementation {Name: " server" }, &mcp.ServerOptions {
154+ CompletionHandler : myCompletionHandler,
155+ })
156+ ```
117157
118158### Logging
119159
0 commit comments