examples: add a 'listeverything' client example, and reorganize
Add a client example that lists all features on a stdio server. Since this is our first client example, organize examples by client / server -- otherwise it is too difficult to find client examples. For #33
This commit is contained in:
parent
c132621eb0
commit
e00c485969
1 changed files with 65 additions and 0 deletions
49
examples/server/completion/main.go
Normal file
49
examples/server/completion/main.go
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
// Copyright 2025 The Go MCP SDK Authors. All rights reserved.
|
||||
// Use of this source code is governed by an MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/modelcontextprotocol/go-sdk/mcp"
|
||||
)
|
||||
|
||||
// This example demonstrates the minimal code to declare and assign
|
||||
// a CompletionHandler to an MCP Server's options.
|
||||
func main() {
|
||||
// Define your custom CompletionHandler logic.
|
||||
myCompletionHandler := func(_ context.Context, _ *mcp.ServerSession, params *mcp.CompleteParams) (*mcp.CompleteResult, error) {
|
||||
// In a real application, you'd implement actual completion logic here.
|
||||
// For this example, we return a fixed set of suggestions.
|
||||
var suggestions []string
|
||||
switch params.Ref.Type {
|
||||
case "ref/prompt":
|
||||
suggestions = []string{"suggestion1", "suggestion2", "suggestion3"}
|
||||
case "ref/resource":
|
||||
suggestions = []string{"suggestion4", "suggestion5", "suggestion6"}
|
||||
default:
|
||||
return nil, fmt.Errorf("unrecognized content type %s", params.Ref.Type)
|
||||
}
|
||||
|
||||
return &mcp.CompleteResult{
|
||||
Completion: mcp.CompletionResultDetails{
|
||||
HasMore: false,
|
||||
Total: len(suggestions),
|
||||
Values: suggestions,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Create the MCP Server instance and assign the handler.
|
||||
// No server running, just showing the configuration.
|
||||
_ = mcp.NewServer(&mcp.Implementation{Name: "server"}, &mcp.ServerOptions{
|
||||
CompletionHandler: myCompletionHandler,
|
||||
})
|
||||
|
||||
log.Println("MCP Server instance created with a CompletionHandler assigned (but not running).")
|
||||
log.Println("This example demonstrates configuration, not live interaction.")
|
||||
}
|
||||
Loading…
Reference in a new issue