Documentation
¶
Index ¶
- Constants
- func As[T any](ts ToolSet) (T, bool)
- func ConfigureHandlers(ts ToolSet, elicitHandler ElicitationHandler, oauthHandler func(), ...)
- func ConvertSchema(params, v any) error
- func DescribeToolSet(ts ToolSet) string
- func ExtractDescription(arguments string) string
- func GetInstructions(ts ToolSet) string
- func MustSchemaFor[T any]() any
- func SchemaFor[T any]() (any, error)
- func SchemaToMap(params any) (map[string]any, error)
- func ToolsetIdentifier(ts ToolSet) string
- type AudioContent
- type ChangeNotifier
- type Describer
- type Elicitable
- type ElicitationAction
- type ElicitationHandler
- type ElicitationResult
- type FunctionCall
- type ImageContent
- type Instructable
- type MediaContent
- type OAuthCapable
- type Startable
- type StartableToolSet
- func (s *StartableToolSet) ConsumeRecovery() bool
- func (s *StartableToolSet) IsStarted() bool
- func (s *StartableToolSet) ShouldReportFailure() bool
- func (s *StartableToolSet) Start(ctx context.Context) error
- func (s *StartableToolSet) Stop(ctx context.Context) error
- func (s *StartableToolSet) Unwrap() ToolSet
- type Tool
- type ToolAnnotations
- type ToolCall
- type ToolCallResult
- type ToolHandler
- type ToolSet
- type ToolType
- type ToolsetMetadata
- type Unwrapper
Constants ¶
const (
// DescriptionParam is the parameter name for the description
DescriptionParam = "description"
)
Variables ¶
This section is empty.
Functions ¶
func As ¶
As performs a type assertion on a ToolSet, walking the wrapper chain if needed. It checks the outermost toolset first, then recursively unwraps through any Unwrapper implementations (including StartableToolSet and decorator wrappers) until it finds a match or reaches the end of the chain.
Example:
if pp, ok := tools.As[tools.PromptProvider](toolset); ok {
prompts, _ := pp.ListPrompts(ctx)
}
func ConfigureHandlers ¶
func ConfigureHandlers(ts ToolSet, elicitHandler ElicitationHandler, oauthHandler func(), managedOAuth bool)
ConfigureHandlers sets all applicable handlers on a toolset. It checks for Elicitable and OAuthCapable interfaces and configures them. This is a convenience function that handles the capability checking internally.
func ConvertSchema ¶
func DescribeToolSet ¶
DescribeToolSet returns a short description for ts suitable for user-visible messages. It unwraps a StartableToolSet, then delegates to Describer if implemented. Falls back to the Go type name when not.
func ExtractDescription ¶
ExtractDescription extracts the description from tool call arguments.
func GetInstructions ¶
GetInstructions returns instructions if the toolset implements Instructable. Returns empty string if the toolset doesn't provide instructions.
func MustSchemaFor ¶
func ToolsetIdentifier ¶
ToolsetIdentifier returns a human-readable identifier for a toolset. It falls back to the toolset type when no metadata is available.
Types ¶
type AudioContent ¶
type AudioContent = MediaContent
AudioContent is an alias kept for readability at call sites.
type ChangeNotifier ¶
type ChangeNotifier interface {
SetToolsChangedHandler(handler func())
}
ChangeNotifier is implemented by toolsets that can notify when their tool list changes (e.g. after an MCP ToolListChanged notification).
type Describer ¶
type Describer interface {
Describe() string
}
Describer can be implemented by a ToolSet to provide a short, user-visible description that uniquely identifies the toolset instance (e.g. for use in error messages and warnings). The string must never contain secrets.
type Elicitable ¶
type Elicitable interface {
SetElicitationHandler(handler ElicitationHandler)
}
Elicitable is implemented by toolsets that support MCP elicitation.
type ElicitationAction ¶
type ElicitationAction string
const ( ElicitationActionAccept ElicitationAction = "accept" ElicitationActionDecline ElicitationAction = "decline" ElicitationActionCancel ElicitationAction = "cancel" )
type ElicitationHandler ¶
type ElicitationHandler func(ctx context.Context, req *mcp.ElicitParams) (ElicitationResult, error)
ElicitationHandler is a function type that handles elicitation requests from the MCP server This allows the runtime to handle elicitation requests and propagate them to its own client
type ElicitationResult ¶
type ElicitationResult struct {
Action ElicitationAction `json:"action"`
Content map[string]any `json:"content,omitempty"`
}
type FunctionCall ¶
type ImageContent ¶
type ImageContent = MediaContent
ImageContent is an alias kept for readability at call sites.
type Instructable ¶
type Instructable interface {
Instructions() string
}
Instructable is implemented by toolsets that provide custom instructions.
type MediaContent ¶
type MediaContent struct {
// Data is the base64-encoded payload.
Data string `json:"data"`
// MimeType identifies the content type (e.g. "image/png", "audio/wav").
MimeType string `json:"mimeType"`
}
MediaContent represents base64-encoded binary data (image, audio, etc.) returned by a tool.
type OAuthCapable ¶
type OAuthCapable interface {
SetOAuthSuccessHandler(handler func())
SetManagedOAuth(managed bool)
}
OAuthCapable is implemented by toolsets that support OAuth flows.
type Startable ¶
Startable is implemented by toolsets that require initialization before use. Toolsets that don't implement this interface are assumed to be ready immediately.
type StartableToolSet ¶
type StartableToolSet struct {
ToolSet
// contains filtered or unexported fields
}
StartableToolSet wraps a ToolSet with lazy, single-flight start semantics. This is the canonical way to manage toolset lifecycle.
Failure and recovery tracking:
- freshFailure is set to true on the first Start() failure in a streak (i.e. when hasEverFailed transitions false→true). It is consumed by ShouldReportFailure() which returns true exactly once per streak.
- hasEverFailed stays true for the duration of the failure streak.
- pendingRecovery is set to true on the first successful Start() after a failure streak. It is consumed by ConsumeRecovery().
- ConsumeRecovery() also resets hasEverFailed, so the next failure streak generates a fresh warning.
func NewStartable ¶
func NewStartable(ts ToolSet) *StartableToolSet
NewStartable wraps a ToolSet for lazy initialization.
func (*StartableToolSet) ConsumeRecovery ¶ added in v1.48.0
func (s *StartableToolSet) ConsumeRecovery() bool
ConsumeRecovery returns true exactly once after a Start() that succeeded following a previously-reported failure streak. Calling it also resets hasEverFailed and freshFailure so that a future failure generates a fresh warning.
func (*StartableToolSet) IsStarted ¶
func (s *StartableToolSet) IsStarted() bool
IsStarted returns whether the toolset has been successfully started. For toolsets that don't implement Startable, this always returns true.
func (*StartableToolSet) ShouldReportFailure ¶ added in v1.48.0
func (s *StartableToolSet) ShouldReportFailure() bool
ShouldReportFailure returns true the first time Start() fails in a new failure streak — i.e. when hasEverFailed transitions from false to true. It returns false for all subsequent failures in the same streak, preventing repeated "start failed" warnings from flooding the user. It is safe to call even when Start() did not return an error (it will return false).
func (*StartableToolSet) Start ¶
func (s *StartableToolSet) Start(ctx context.Context) error
Start starts the toolset with single-flight semantics. Concurrent callers block until the start attempt completes. If start fails, a future call will retry. If the underlying toolset doesn't implement Startable, this is a no-op.
func (*StartableToolSet) Stop ¶
func (s *StartableToolSet) Stop(ctx context.Context) error
Stop stops the toolset if it implements Startable and resets the started flag so that a subsequent Start will re-initialize.
func (*StartableToolSet) Unwrap ¶
func (s *StartableToolSet) Unwrap() ToolSet
Unwrap returns the underlying ToolSet.
type Tool ¶
type Tool struct {
Name string `json:"name"`
Category string `json:"category"`
Description string `json:"description,omitempty"`
Parameters any `json:"parameters"`
Annotations ToolAnnotations `json:"annotations"`
OutputSchema any `json:"outputSchema"`
Handler ToolHandler `json:"-"`
AddDescriptionParameter bool `json:"-"`
// ModelOverride is the per-toolset model for the LLM turn that processes
// this tool's results. Set automatically from the toolset "model" field.
ModelOverride string `json:"-"`
}
func AddDescriptionParameter ¶
AddDescriptionParameter adds a "description" parameter to tools that have AddDescriptionParameter set to true. This allows the LLM to provide context about what it's doing with each tool call.
func (*Tool) DisplayName ¶
type ToolAnnotations ¶
type ToolAnnotations mcp.ToolAnnotations
type ToolCall ¶
type ToolCall struct {
ID string `json:"id,omitempty"`
Type ToolType `json:"type"`
Function FunctionCall `json:"function"`
}
type ToolCallResult ¶
type ToolCallResult struct {
Output string `json:"output"`
IsError bool `json:"isError,omitempty"`
Meta any `json:"meta,omitempty"`
// Images contains optional image attachments returned by the tool.
Images []MediaContent `json:"images,omitempty"`
// Audios contains optional audio attachments returned by the tool.
Audios []MediaContent `json:"audios,omitempty"`
// StructuredContent holds optional structured output returned by an MCP
// tool whose definition includes an OutputSchema. When non-nil it is the
// JSON-decoded structured result from the server.
StructuredContent any `json:"structuredContent,omitempty"`
}
func ResultError ¶
func ResultError(output string) *ToolCallResult
func ResultJSON ¶ added in v1.30.1
func ResultJSON(v any) *ToolCallResult
ResultJSON marshals v as JSON and returns it as a successful tool result. If marshaling fails, it returns an error result.
func ResultSuccess ¶
func ResultSuccess(output string) *ToolCallResult
type ToolHandler ¶
type ToolHandler func(ctx context.Context, toolCall ToolCall) (*ToolCallResult, error)
func NewHandler ¶
func NewHandler[T any](fn func(context.Context, T) (*ToolCallResult, error)) ToolHandler
NewHandler creates a type-safe tool handler from a function that accepts typed parameters. It handles JSON unmarshaling of the tool call arguments into the specified type T.
type ToolsetMetadata ¶
type ToolsetMetadata interface {
ToolsetID() string
}
ToolsetMetadata exposes optional details for toolset identification. Implemented by toolsets that can provide additional context for warnings.