internal/mcp: generic handling of CallToolParams
Make Tool APIs future-proof by pushing generics into CallToolParams, and using CallToolParams throughout. This has several advantages: - We no longer need the awkward CallToolOptions type, which is almost but not quite like CallToolParams. - NewTool no longer needs to define its own handler type: it accepts a ToolHandler[TArgs]. This also means its signature is future-proof. Additionally, provide a `CallTool` helper (the analog of NewTool) to serve as a more strongly typed variant of `ClientSession.CallTool`. + design, protocol generation Change-Id: I80172a25bc50734dae84a541aa4776ed9161694e Reviewed-on: https://go-review.googlesource.com/c/tools/+/676495 Reviewed-by: Jonathan Amsterdam <jba@google.com> Auto-Submit: Robert Findley <rfindley@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
bb2347385e
commit
04ca8ac03b
1 changed files with 170 additions and 108 deletions
|
|
@ -7,8 +7,6 @@
|
|||
package mcp
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/modelcontextprotocol/go-sdk/jsonschema"
|
||||
)
|
||||
|
||||
|
|
@ -28,15 +26,15 @@ type Annotations struct {
|
|||
Priority float64 `json:"priority,omitempty"`
|
||||
}
|
||||
|
||||
type CallToolParams struct {
|
||||
type CallToolParams[TArgs any] struct {
|
||||
// This property is reserved by the protocol to allow clients and servers to
|
||||
// attach additional metadata to their responses.
|
||||
Meta Meta `json:"_meta,omitempty"`
|
||||
Arguments json.RawMessage `json:"arguments,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Meta Meta `json:"_meta,omitempty"`
|
||||
Arguments TArgs `json:"arguments,omitempty"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
func (x *CallToolParams) GetMeta() *Meta { return &x.Meta }
|
||||
func (x *CallToolParams[TArgs]) GetMeta() *Meta { return &x.Meta }
|
||||
|
||||
// The server's response to a tool call.
|
||||
//
|
||||
|
|
|
|||
Loading…
Reference in a new issue