mcp: new API for features (#88)
BREAKING CHANGE Change the API for adding tools, prompts, resources and resource templates to a server. The ServerXXX types are gone along with the plural Add methods (AddTools, AddPrompts etc.) Instead there are single Add methods (AddTool, AddPrompt). In addition, instead of NewServerTool, there is AddTool[In, Out]. Fixes #73.
This commit is contained in:
parent
328a25d503
commit
aebd244981
1 changed files with 366 additions and 612 deletions
24
README.md
24
README.md
|
|
@ -1,6 +1,21 @@
|
|||
<!-- Autogenerated by weave; DO NOT EDIT -->
|
||||
# MCP Go SDK
|
||||
|
||||
***BREAKING CHANGES***
|
||||
|
||||
The latest version contains breaking changes:
|
||||
|
||||
- Server.AddTools is replaced by Server.AddTool.
|
||||
|
||||
- NewServerTool is replaced by AddTool. AddTool takes a Tool rather than a name and description, so you can
|
||||
set any field on the Tool that you want before associating it with a handler.
|
||||
|
||||
- Tool options have been removed. If you don't want AddTool to infer a JSON Schema for you, you can construct one
|
||||
as a struct literal, or using any other code that suits you.
|
||||
|
||||
- AddPrompts, AddResources and AddResourceTemplates are similarly replaced by singular methods which pair the
|
||||
feature with a handler. The ServerXXX types have been removed.
|
||||
|
||||
[](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk)
|
||||
|
||||
This repository contains an unreleased implementation of the official Go
|
||||
|
|
@ -99,7 +114,7 @@ import (
|
|||
)
|
||||
|
||||
type HiParams struct {
|
||||
Name string `json:"name"`
|
||||
Name string `json:"name", mcp:"the name of the person to greet"`
|
||||
}
|
||||
|
||||
func SayHi(ctx context.Context, cc *mcp.ServerSession, params *mcp.CallToolParamsFor[HiParams]) (*mcp.CallToolResultFor[any], error) {
|
||||
|
|
@ -111,11 +126,8 @@ func SayHi(ctx context.Context, cc *mcp.ServerSession, params *mcp.CallToolParam
|
|||
func main() {
|
||||
// Create a server with a single tool.
|
||||
server := mcp.NewServer("greeter", "v1.0.0", nil)
|
||||
server.AddTools(
|
||||
mcp.NewServerTool("greet", "say hi", SayHi, mcp.Input(
|
||||
mcp.Property("name", mcp.Description("the name of the person to greet")),
|
||||
)),
|
||||
)
|
||||
|
||||
mcp.AddTool(server, &mcp.Tool{Name: "greet", Description: "say hi"}, SayHi)
|
||||
// Run the server over stdin/stdout, until the client disconnects
|
||||
if err := server.Run(context.Background(), mcp.NewStdioTransport()); err != nil {
|
||||
log.Fatal(err)
|
||||
|
|
|
|||
Loading…
Reference in a new issue