mcp,design: revert 'content' back to an interface type (#29)
After some experience with the flattened version of Content, we see that it can easily lead to incorrect usage and is a harder API to read. Therefore, this CL changes back to a design similar to what we had prior to https://go.dev/cl/672415, though opting to promote content unmarshalling to the protocol types that use it, which leads to an overall simpler api.
This commit is contained in:
parent
d6ea827820
commit
204b59483b
2 changed files with 333 additions and 159 deletions
|
|
@ -40,7 +40,7 @@ func main() {
|
|||
log.Fatal("tool failed")
|
||||
}
|
||||
for _, c := range res.Content {
|
||||
log.Print(c.Text)
|
||||
log.Print(c.(*mcp.TextContent).Text)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ type HiParams struct {
|
|||
|
||||
func SayHi(ctx context.Context, cc *mcp.ServerSession, params *mcp.CallToolParamsFor[HiParams]) (*mcp.CallToolResultFor[any], error) {
|
||||
return &mcp.CallToolResultFor[any]{
|
||||
Content: []*mcp.ContentBlock{mcp.NewTextContent("Hi " + params.Name)},
|
||||
Content: []mcp.Content{&mcp.TextContent{Text: "Hi " + params.Name}},
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue