internal/mcp: pointerize all the things
Use pointers for the protocol's struct types, to future-proof against them getting large. Change-Id: I55b204080a41c8140539697ba264e502e912e613 Reviewed-on: https://go-review.googlesource.com/c/tools/+/672575 Reviewed-by: Robert Findley <rfindley@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
7b100d7b30
commit
02fa1b3ea6
1 changed files with 137 additions and 98 deletions
|
|
@ -20,7 +20,7 @@ type PromptHandler func(context.Context, *ServerConnection, map[string]string) (
|
|||
|
||||
// A Prompt is a prompt definition bound to a prompt handler.
|
||||
type ServerPrompt struct {
|
||||
Definition Prompt
|
||||
Definition *Prompt
|
||||
Handler PromptHandler
|
||||
}
|
||||
|
||||
|
|
@ -41,7 +41,7 @@ func NewPrompt[TReq any](name, description string, handler func(context.Context,
|
|||
panic(fmt.Sprintf("handler request type must be a struct"))
|
||||
}
|
||||
prompt := &ServerPrompt{
|
||||
Definition: Prompt{
|
||||
Definition: &Prompt{
|
||||
Name: name,
|
||||
Description: description,
|
||||
},
|
||||
|
|
@ -54,7 +54,7 @@ func NewPrompt[TReq any](name, description string, handler func(context.Context,
|
|||
if prop.Type != "string" {
|
||||
panic(fmt.Sprintf("handler type must consist only of string fields"))
|
||||
}
|
||||
prompt.Definition.Arguments = append(prompt.Definition.Arguments, PromptArgument{
|
||||
prompt.Definition.Arguments = append(prompt.Definition.Arguments, &PromptArgument{
|
||||
Name: name,
|
||||
Description: prop.Description,
|
||||
Required: required[name],
|
||||
|
|
@ -95,13 +95,13 @@ func (s promptSetter) set(p *ServerPrompt) { s(p) }
|
|||
// Required and Description, and panics when encountering any other option.
|
||||
func Argument(name string, opts ...SchemaOption) PromptOption {
|
||||
return promptSetter(func(p *ServerPrompt) {
|
||||
i := slices.IndexFunc(p.Definition.Arguments, func(arg PromptArgument) bool {
|
||||
i := slices.IndexFunc(p.Definition.Arguments, func(arg *PromptArgument) bool {
|
||||
return arg.Name == name
|
||||
})
|
||||
var arg PromptArgument
|
||||
var arg *PromptArgument
|
||||
if i < 0 {
|
||||
i = len(p.Definition.Arguments)
|
||||
arg = PromptArgument{Name: name}
|
||||
arg = &PromptArgument{Name: name}
|
||||
p.Definition.Arguments = append(p.Definition.Arguments, arg)
|
||||
} else {
|
||||
arg = p.Definition.Arguments[i]
|
||||
|
|
|
|||
Loading…
Reference in a new issue