Skip to content

Commit 28753c9

Browse files
authored
docs: document completion support (#495)
1 parent ff81f2f commit 28753c9

File tree

3 files changed

+60
-6
lines changed

3 files changed

+60
-6
lines changed

docs/server.md

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

examples/server/completion/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
// a CompletionHandler to an MCP Server's options.
1717
func main() {
1818
// Define your custom CompletionHandler logic.
19+
// !+completionhandler
1920
myCompletionHandler := func(_ context.Context, req *mcp.CompleteRequest) (*mcp.CompleteResult, error) {
2021
// In a real application, you'd implement actual completion logic here.
2122
// For this example, we return a fixed set of suggestions.
@@ -43,6 +44,7 @@ func main() {
4344
_ = mcp.NewServer(&mcp.Implementation{Name: "server"}, &mcp.ServerOptions{
4445
CompletionHandler: myCompletionHandler,
4546
})
47+
// !-completionhandler
4648

4749
log.Println("MCP Server instance created with a CompletionHandler assigned (but not running).")
4850
log.Println("This example demonstrates configuration, not live interaction.")

internal/docs/server.src.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,23 @@ Set [`ClientOptions.PromptListChangedHandler`](https://pkg.go.dev/github.com/mod
3636

3737
## Utilities
3838

39-
<!-- TODO -->
40-
4139
### Completion
4240

43-
<!-- TODO -->
41+
To support the
42+
[completion](https://modelcontextprotocol.io/specification/2025-06-18/server/utilities/completion)
43+
capability, the server needs a completion handler.
44+
45+
**Client-side**: completion is called using the
46+
[`ClientSession.Complete`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ClientSession.Complete)
47+
method.
48+
49+
**Server-side**: completion is enabled by setting
50+
[`ServerOptions.CompletionHandler`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ServerOptions.CompletionHandler).
51+
If this field is set to a non-nil value, the server will advertise the
52+
`completions` server capability, and use this handler to respond to completion
53+
requests.
54+
55+
%include ../../examples/server/completion/main.go completionhandler -
4456

4557
### Logging
4658

0 commit comments

Comments
 (0)