Documentation
¶
Overview ¶
Package toolsets provides a framework for managing collections of tools. This was heavily inspired by GitHub's MCP server implementation:
https://github.com/github/github-mcp-server/blob/3341e6bc461b461f0789518879f97bbd86ef7ee9/pkg/toolsets/toolsets.go
Index ¶
- func RegisterMethod(method Method)
- type Method
- type ServerPrompt
- type ServerResourceTemplate
- type Toolset
- func (t *Toolset) AddPrompts(prompts ...ServerPrompt) *Toolset
- func (t *Toolset) AddReadTools(tools ...server.ServerTool) *Toolset
- func (t *Toolset) AddResourceTemplates(templates ...ServerResourceTemplate) *Toolset
- func (t *Toolset) AddWriteTools(tools ...server.ServerTool) *Toolset
- func (t *Toolset) GetActiveResourceTemplates() []ServerResourceTemplate
- func (t *Toolset) GetActiveTools() []server.ServerTool
- func (t *Toolset) GetAvailableResourceTemplates() []ServerResourceTemplate
- func (t *Toolset) GetAvailableTools() []server.ServerTool
- func (t *Toolset) RegisterPrompts(s *server.MCPServer)
- func (t *Toolset) RegisterResourcesTemplates(s *server.MCPServer)
- func (t *Toolset) RegisterTools(s *server.MCPServer)
- func (t *Toolset) SetReadOnly()
- type ToolsetDoesNotExistError
- type ToolsetGroup
- func (tg *ToolsetGroup) AddToolset(ts *Toolset)
- func (tg *ToolsetGroup) EnableToolset(method Method) error
- func (tg *ToolsetGroup) EnableToolsets(methods ...Method) error
- func (tg *ToolsetGroup) GetToolset(method Method) (*Toolset, error)
- func (tg *ToolsetGroup) HasTools() bool
- func (tg *ToolsetGroup) IsEnabled(method Method) bool
- func (tg *ToolsetGroup) RegisterAll(s *server.MCPServer)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterMethod ¶
func RegisterMethod(method Method)
RegisterMethod registers a method. This is used to validate that only known methods are used when enabling Toolsets.
Types ¶
type Method ¶
type Method string
Method identifies the name of a logical unit of operation or action that can be executed as part of a pipeline step or invoked via tool calling from an LLM.
const MethodAll Method = "all"
MethodAll is a special method that can be used to indicate that all Toolsets should be enabled. It is not a valid method for any specific Toolset, but rather a convenience to enable all Toolsets in a ToolsetGroup at once.
func (Method) IsRegistered ¶
IsRegistered checks if the method is registered.
type ServerPrompt ¶
type ServerPrompt struct { Prompt mcp.Prompt Handler server.PromptHandlerFunc }
ServerPrompt represents a prompt that can be registered with the MCP server.
func NewServerPrompt ¶
func NewServerPrompt(prompt mcp.Prompt, handler server.PromptHandlerFunc) ServerPrompt
NewServerPrompt creates a new ServerPrompt with the given prompt and handler function.
type ServerResourceTemplate ¶
type ServerResourceTemplate struct {
// contains filtered or unexported fields
}
ServerResourceTemplate represents a resource template that can be registered with the MCP server.
func NewServerResourceTemplate ¶
func NewServerResourceTemplate( resourceTemplate mcp.ResourceTemplate, handler server.ResourceTemplateHandlerFunc, ) ServerResourceTemplate
NewServerResourceTemplate creates a new ServerResourceTemplate with the given resource template and handler function.
type Toolset ¶
type Toolset struct { Method Method Description string Enabled bool // contains filtered or unexported fields }
Toolset represents a collection of MCP functionality that can be enabled or disabled as a group.
func NewToolset ¶
NewToolset creates a new Toolset with the given method and description. The Toolset is initially disabled and not in read-only mode.
func (*Toolset) AddPrompts ¶
func (t *Toolset) AddPrompts(prompts ...ServerPrompt) *Toolset
AddPrompts adds prompts to the Toolset. These prompts can be used to define interactions that the MCP server can handle.
func (*Toolset) AddReadTools ¶
func (t *Toolset) AddReadTools(tools ...server.ServerTool) *Toolset
AddReadTools adds read tools to the Toolset. It will panic if any tool is not annotated as read-only.
func (*Toolset) AddResourceTemplates ¶
func (t *Toolset) AddResourceTemplates(templates ...ServerResourceTemplate) *Toolset
AddResourceTemplates adds resource templates to the Toolset. These templates can be used to define resources that the MCP server can manage.
func (*Toolset) AddWriteTools ¶
func (t *Toolset) AddWriteTools(tools ...server.ServerTool) *Toolset
AddWriteTools adds write tools to the Toolset. If the Toolset is read-only, this method will silently ignore the tools to avoid breaching the read-only contract. If a tool is incorrectly annotated as read-only, it will panic.
func (*Toolset) GetActiveResourceTemplates ¶
func (t *Toolset) GetActiveResourceTemplates() []ServerResourceTemplate
GetActiveResourceTemplates returns the resource templates that are currently active in the Toolset. If the Toolset is enabled, it returns all resource templates.
func (*Toolset) GetActiveTools ¶
func (t *Toolset) GetActiveTools() []server.ServerTool
GetActiveTools returns the tools that are currently active in the Toolset. If the Toolset is enabled, it returns both read and write tools. If the Toolset is not enabled, it returns nil.
func (*Toolset) GetAvailableResourceTemplates ¶
func (t *Toolset) GetAvailableResourceTemplates() []ServerResourceTemplate
GetAvailableResourceTemplates returns the resource templates that are available in the Toolset. This includes all resource templates regardless of whether the Toolset is enabled or not.
func (*Toolset) GetAvailableTools ¶
func (t *Toolset) GetAvailableTools() []server.ServerTool
GetAvailableTools returns the tools that are available in the Toolset.
func (*Toolset) RegisterPrompts ¶
RegisterPrompts registers the prompts in the Toolset with the MCP server.
func (*Toolset) RegisterResourcesTemplates ¶
RegisterResourcesTemplates registers the resource templates in the Toolset with the MCP server.
func (*Toolset) RegisterTools ¶
RegisterTools registers the tools in the Toolset with the MCP server.
func (*Toolset) SetReadOnly ¶
func (t *Toolset) SetReadOnly()
SetReadOnly sets the Toolset to read-only mode. In this mode, only read tools can be added, and write tools will be ignored if attempted to be added.
type ToolsetDoesNotExistError ¶
type ToolsetDoesNotExistError struct {
Method Method
}
ToolsetDoesNotExistError is an error type that indicates a requested toolset does not exist in the toolset group.
func NewToolsetDoesNotExistError ¶
func NewToolsetDoesNotExistError(method Method) *ToolsetDoesNotExistError
NewToolsetDoesNotExistError creates a new ToolsetDoesNotExistError with the given method.
func (*ToolsetDoesNotExistError) Error ¶
func (e *ToolsetDoesNotExistError) Error() string
Error implements the error interface for ToolsetDoesNotExistError.
func (*ToolsetDoesNotExistError) Is ¶
func (e *ToolsetDoesNotExistError) Is(target error) bool
Is checks if the error is of type ToolsetDoesNotExistError.
type ToolsetGroup ¶
ToolsetGroup is a collection of Toolsets that can be enabled or disabled as a group. It allows for managing multiple Toolsets and their states collectively.
func NewToolsetGroup ¶
func NewToolsetGroup(readOnly bool) *ToolsetGroup
NewToolsetGroup creates a new ToolsetGroup. If readOnly is true, all Toolsets added to this group will be set to read-only mode, meaning they can only have read tools added to them, and write tools will be ignored.
func (*ToolsetGroup) AddToolset ¶
func (tg *ToolsetGroup) AddToolset(ts *Toolset)
AddToolset adds a Toolset to the ToolsetGroup. If the ToolsetGroup is in read-only mode, the Toolset will also be set to read-only.
func (*ToolsetGroup) EnableToolset ¶
func (tg *ToolsetGroup) EnableToolset(method Method) error
EnableToolset enables a Toolset by its method. If the Toolset does not exist, it returns a ToolsetDoesNotExistError.
func (*ToolsetGroup) EnableToolsets ¶
func (tg *ToolsetGroup) EnableToolsets(methods ...Method) error
EnableToolsets enables multiple Toolsets by their methods. If "all" is included in the methods, it will enable all Toolsets in the group.
func (*ToolsetGroup) GetToolset ¶
func (tg *ToolsetGroup) GetToolset(method Method) (*Toolset, error)
GetToolset retrieves a Toolset by its method from the ToolsetGroup. If the Toolset does not exist, it returns a ToolsetDoesNotExistError.
func (*ToolsetGroup) HasTools ¶
func (tg *ToolsetGroup) HasTools() bool
HasTools checks if the ToolsetGroup has any enabled Toolsets with available tools. It returns true if at least one Toolset is enabled and has tools, otherwise it returns false.
func (*ToolsetGroup) IsEnabled ¶
func (tg *ToolsetGroup) IsEnabled(method Method) bool
IsEnabled checks if a Toolset with the given method is enabled in the ToolsetGroup.
func (*ToolsetGroup) RegisterAll ¶
func (tg *ToolsetGroup) RegisterAll(s *server.MCPServer)
RegisterAll registers all Toolsets in the ToolsetGroup with the MCP server.