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
1 changed files with 333 additions and 159 deletions
|
|
@ -24,8 +24,8 @@ type HiArgs struct {
|
|||
|
||||
func SayHi(ctx context.Context, ss *mcp.ServerSession, params *mcp.CallToolParamsFor[HiArgs]) (*mcp.CallToolResultFor[struct{}], error) {
|
||||
return &mcp.CallToolResultFor[struct{}]{
|
||||
Content: []*mcp.ContentBlock{
|
||||
mcp.NewTextContent("Hi " + params.Name),
|
||||
Content: []mcp.Content{
|
||||
&mcp.TextContent{Text: "Hi " + params.Name},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
|
@ -36,7 +36,7 @@ func PromptHi(ctx context.Context, ss *mcp.ServerSession, params *mcp.GetPromptP
|
|||
return &mcp.GetPromptResult{
|
||||
Description: "Code review prompt",
|
||||
Messages: []*mcp.PromptMessage{
|
||||
{Role: "user", Content: mcp.NewTextContent("Say hi to " + params.Arguments["name"])},
|
||||
{Role: "user", Content: &mcp.TextContent{Text: "Say hi to " + params.Arguments["name"]}},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
|
@ -93,6 +93,8 @@ func handleEmbeddedResource(_ context.Context, _ *mcp.ServerSession, params *mcp
|
|||
return nil, fmt.Errorf("no embedded resource named %q", key)
|
||||
}
|
||||
return &mcp.ReadResourceResult{
|
||||
Contents: []*mcp.ResourceContents{mcp.NewTextResourceContents(params.URI, "text/plain", text)},
|
||||
Contents: []*mcp.ResourceContents{
|
||||
{URI: params.URI, MIMEType: "text/plain", Text: text},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue