internal/mcp: add tool and schema options
Implement variadic options for building tools and schemas, to allow easier customization of tool input schemas. Also, make fields required, unless they are marked as "omitempty". Change-Id: I7a29258fae3ec5e7ea4906ed30ed6750979de962 Reviewed-on: https://go-review.googlesource.com/c/tools/+/668955 Reviewed-by: Jonathan Amsterdam <jba@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
ffa7599a10
commit
e082a340be
1 changed files with 236 additions and 14 deletions
|
|
@ -17,7 +17,7 @@ import (
|
|||
var httpAddr = flag.String("http", "", "if set, use SSE HTTP at this address, instead of stdin/stdout")
|
||||
|
||||
type SayHiParams struct {
|
||||
Name string `json:"name" mcp:"the name to say hi to"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
func SayHi(ctx context.Context, cc *mcp.ClientConnection, params *SayHiParams) ([]mcp.Content, error) {
|
||||
|
|
@ -30,7 +30,9 @@ func main() {
|
|||
flag.Parse()
|
||||
|
||||
server := mcp.NewServer("greeter", "v0.0.1", nil)
|
||||
server.AddTools(mcp.MakeTool("greet", "say hi", SayHi))
|
||||
server.AddTools(mcp.MakeTool("greet", "say hi", SayHi, mcp.Input(
|
||||
mcp.Property("name", mcp.Description("the name to say hi to")),
|
||||
)))
|
||||
|
||||
if *httpAddr != "" {
|
||||
handler := mcp.NewSSEHandler(func(*http.Request) *mcp.Server {
|
||||
|
|
|
|||
Loading…
Reference in a new issue