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 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)
- type Elicitable
- type ElicitationAction
- type ElicitationHandler
- type ElicitationResult
- type FunctionCall
- type Instructable
- type OAuthCapable
- type Startable
- type StartableToolSet
- type Tool
- type ToolAnnotations
- type ToolCall
- type ToolCallResult
- type ToolHandler
- type ToolSet
- type ToolType
Constants ¶
const (
// DescriptionParam is the parameter name for the description
DescriptionParam = "description"
)
Variables ¶
This section is empty.
Functions ¶
func As ¶ added in v1.20.2
As performs a type assertion on a ToolSet, unwrapping StartableToolSet if needed. Returns the typed toolset and true if the assertion succeeds.
Example:
if pp, ok := tools.As[tools.PromptProvider](toolset); ok {
prompts, _ := pp.ListPrompts(ctx)
}
func ConfigureHandlers ¶ added in v1.20.2
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 ¶ added in v1.7.1
func ExtractDescription ¶ added in v1.19.4
ExtractDescription extracts the description from tool call arguments.
func GetInstructions ¶ added in v1.20.2
GetInstructions returns instructions if the toolset implements Instructable. Returns empty string if the toolset doesn't provide instructions.
func MustSchemaFor ¶ added in v1.7.1
Types ¶
type Elicitable ¶ added in v1.20.2
type Elicitable interface {
SetElicitationHandler(handler ElicitationHandler)
}
Elicitable is implemented by toolsets that support MCP elicitation.
type ElicitationAction ¶ added in v1.8.2
type ElicitationAction string
const ( ElicitationActionAccept ElicitationAction = "accept" ElicitationActionDecline ElicitationAction = "decline" ElicitationActionCancel ElicitationAction = "cancel" )
type ElicitationHandler ¶ added in v1.7.0
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 ¶ added in v1.7.0
type ElicitationResult struct {
Action ElicitationAction `json:"action"`
Content map[string]any `json:"content,omitempty"`
}
type FunctionCall ¶
type Instructable ¶ added in v1.20.2
type Instructable interface {
Instructions() string
}
Instructable is implemented by toolsets that provide custom instructions.
type OAuthCapable ¶ added in v1.20.2
type OAuthCapable interface {
SetOAuthSuccessHandler(handler func())
SetManagedOAuth(managed bool)
}
OAuthCapable is implemented by toolsets that support OAuth flows.
type Startable ¶ added in v1.20.2
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 ¶ added in v1.20.2
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.
func NewStartable ¶ added in v1.20.2
func NewStartable(ts ToolSet) *StartableToolSet
NewStartable wraps a ToolSet for lazy initialization.
func (*StartableToolSet) IsStarted ¶ added in v1.20.2
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) Start ¶ added in v1.20.2
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 ¶ added in v1.20.2
func (s *StartableToolSet) Stop(ctx context.Context) error
Stop stops the toolset if it implements Startable.
func (*StartableToolSet) Unwrap ¶ added in v1.20.2
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:"-"`
}
func AddDescriptionParameter ¶ added in v1.20.2
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 ¶ added in v0.7.0
type ToolAnnotations ¶ added in v1.7.0
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"`
}
func ResultError ¶ added in v1.8.2
func ResultError(output string) *ToolCallResult
func ResultSuccess ¶ added in v1.8.2
func ResultSuccess(output string) *ToolCallResult
type ToolHandler ¶
type ToolHandler func(ctx context.Context, toolCall ToolCall) (*ToolCallResult, error)
func NewHandler ¶ added in v1.19.1
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.