Documentation
¶
Index ¶
- func FormatMCPServersForDisplay(servers []string) []string
- func GetMCPDisplayName(serverSpec string) string
- func LoadMCPConfigFile(jsonFile string) (map[string]MCPConfig, error)
- func ParseServerSpec(spec string) (jsonFile string, serverName string)
- type ContextualTool
- type LoadResult
- type Logger
- type LoggerTool
- type MCPClient
- type MCPConfig
- type MCPServersConfig
- type MCPTool
- type NamespacedTool
- type ServerResult
- type ShellTool
- type Tool
- type ToolCall
- type ToolLoaderInfo
- type ToolRegistry
- func (r *ToolRegistry) All() []Tool
- func (r *ToolRegistry) Close() error
- func (r *ToolRegistry) Get(name string) (Tool, bool)
- func (r *ToolRegistry) GetActiveToolLoaders() []ToolLoaderInfo
- func (r *ToolRegistry) GetLoadedMCPServers() []string
- func (r *ToolRegistry) GetSchemas() []*jsonschema.Schema
- func (r *ToolRegistry) LoadMCPServer(serverSpec string) (LoadResult, error)
- func (r *ToolRegistry) LoadMCPServerWithFilter(serverSpec string, allowedTools []string) error
- func (r *ToolRegistry) LoadMCPServers(serverSpecs []string) error
- func (r *ToolRegistry) LoadShellTool(path string) (LoadResult, error)
- func (r *ToolRegistry) LoadToolAuto(pathOrServer string) (LoadResult, error)
- func (r *ToolRegistry) Register(tool Tool)
- func (r *ToolRegistry) RegisterNative(name string, factory func() Tool)
- func (r *ToolRegistry) Remove(namespacedName string)
- func (r *ToolRegistry) UnloadMCPServer(serverSpec string) error
- type UpperCaseTool
- type WordCountTool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatMCPServersForDisplay ¶
FormatMCPServersForDisplay formats a list of MCP server specs for display
func GetMCPDisplayName ¶
GetMCPDisplayName returns a display-friendly name for an MCP server spec Formats: "file.json → command args" or "file.json#server → command args"
func LoadMCPConfigFile ¶
LoadMCPConfigFile parses a config file and returns server configs Requires mcpServers format: {"mcpServers": {"name": {...}}}
func ParseServerSpec ¶
ParseServerSpec splits a server spec into file path and server name Format: "path/to/config.json" or "path/to/config.json#servername"
Types ¶
type ContextualTool ¶
ContextualTool is a tool that needs external context to execute
type LoadResult ¶
type LoadResult struct {
Type string // "native", "shell", "mcp"
Servers []ServerResult // For MCP, one per server loaded; for shell/native, single entry
}
LoadResult contains information about tools that were loaded
type Logger ¶
type Logger interface {
Log(message string)
}
Logger interface for dependency injection
type LoggerTool ¶
type LoggerTool struct {
// contains filtered or unexported fields
}
LoggerTool is an example tool that needs context to be injected
func (*LoggerTool) GetSchema ¶
func (t *LoggerTool) GetSchema() *jsonschema.Schema
func (*LoggerTool) GetSource ¶
func (t *LoggerTool) GetSource() string
GetSource returns "builtin" for native tools
func (*LoggerTool) GetType ¶
func (t *LoggerTool) GetType() string
GetType returns "native" for built-in tools
func (*LoggerTool) SetContext ¶
func (t *LoggerTool) SetContext(ctx any)
type MCPClient ¶
type MCPClient struct {
// contains filtered or unexported fields
}
MCPClient manages connection to an MCP server
func NewMCPClient ¶
NewMCPClient creates a new MCP client from a server spec Format: "path/to/config.json" or "path/to/config.json#servername"
func NewMCPClientFromConfig ¶
NewMCPClientFromConfig creates a new MCP client from a JSON configuration
type MCPConfig ¶
type MCPConfig struct {
// Local/stdio transport fields
Command string `json:"command,omitempty"`
Args []string `json:"args,omitempty"`
Env map[string]string `json:"env,omitempty"`
// Remote transport fields
URL string `json:"url,omitempty"` // Remote server URL
Transport string `json:"transport,omitempty"` // "stdio" | "sse" | "streamable"
Headers map[string]string `json:"headers,omitempty"` // Auth headers, API keys
Timeout string `json:"timeout,omitempty"` // Connection timeout (e.g., "30s")
}
MCPConfig represents the JSON configuration for an MCP server
type MCPServersConfig ¶
MCPServersConfig represents the Claude Desktop format with multiple servers
type MCPTool ¶
type MCPTool struct {
Source string // Server spec that provided this tool
// contains filtered or unexported fields
}
MCPTool wraps an MCP tool to implement the Tool interface
func NewMCPTool ¶
func NewMCPTool(session *mcp.ClientSession, tool *mcp.Tool) *MCPTool
NewMCPTool creates a new MCP tool wrapper
func (*MCPTool) GetSchema ¶
func (m *MCPTool) GetSchema() *jsonschema.Schema
GetSchema returns the tool's schema (cached after first call)
type NamespacedTool ¶
type NamespacedTool struct {
Tool
// contains filtered or unexported fields
}
NamespacedTool wraps a tool to provide a namespaced schema
func (*NamespacedTool) GetName ¶
func (n *NamespacedTool) GetName() string
GetName returns the namespaced name
func (*NamespacedTool) GetSchema ¶
func (n *NamespacedTool) GetSchema() *jsonschema.Schema
GetSchema returns a schema with the namespaced title
type ServerResult ¶
type ServerResult struct {
Name string // Server/tool name (e.g., "git", "filesystem", "datetime")
ToolNames []string // Fully namespaced tool names loaded
}
ServerResult contains information about tools loaded from a single source
type ShellTool ¶
type ShellTool struct {
Command string
// contains filtered or unexported fields
}
ShellTool wraps external commands/scripts as tools
func NewShellTool ¶
NewShellTool creates a new shell tool from a command
func (*ShellTool) GetSchema ¶
func (s *ShellTool) GetSchema() *jsonschema.Schema
GetSchema returns the tool's schema with namespaced title
type Tool ¶
type Tool interface {
// Execution methods
GetSchema() *jsonschema.Schema
Execute(ctx context.Context, args map[string]any) (string, error)
// Metadata methods
GetName() string // Returns the namespaced name (e.g., "script__toolname")
GetType() string // Returns the tool type: "shell", "mcp", or "native"
GetSource() string // Returns the source path/spec (e.g., "/path/to/script.sh")
}
Tool is the generic interface for all tools
func LoadShellTools ¶
LoadShellTools loads shell tools from the given file paths
type ToolCall ¶
type ToolCall struct {
ID string // Provider-specific ID (if any)
Name string // Tool name
Args map[string]any // Parsed arguments
}
ToolCall represents a request to execute a tool
type ToolLoaderInfo ¶
type ToolLoaderInfo struct {
Name string `json:"name"` // Full namespaced tool name
Type string `json:"type"` // "shell", "mcp", or "native"
Source string `json:"source"` // Path for shell, server spec for MCP, "builtin" for native
}
ToolLoaderInfo stores information needed to reload a specific tool
type ToolRegistry ¶
type ToolRegistry struct {
// contains filtered or unexported fields
}
ToolRegistry manages available tools
func NewToolRegistry ¶
func NewToolRegistry(tools []Tool) *ToolRegistry
NewToolRegistry creates a new tool registry from a list of tools
func (*ToolRegistry) All ¶
func (r *ToolRegistry) All() []Tool
All returns all tools in the registry
func (*ToolRegistry) Get ¶
func (r *ToolRegistry) Get(name string) (Tool, bool)
Get retrieves a tool by name
func (*ToolRegistry) GetActiveToolLoaders ¶
func (r *ToolRegistry) GetActiveToolLoaders() []ToolLoaderInfo
GetActiveToolLoaders returns loader information for all tools This returns one entry per tool to allow selective loading
func (*ToolRegistry) GetLoadedMCPServers ¶
func (r *ToolRegistry) GetLoadedMCPServers() []string
GetLoadedMCPServers returns list of loaded server specs
func (*ToolRegistry) GetSchemas ¶
func (r *ToolRegistry) GetSchemas() []*jsonschema.Schema
GetSchemas returns all tool schemas
func (*ToolRegistry) LoadMCPServer ¶
func (r *ToolRegistry) LoadMCPServer(serverSpec string) (LoadResult, error)
LoadMCPServer connects to an MCP server and registers its tools with namespace For multi-server configs (mcpServers format), loads ALL servers
func (*ToolRegistry) LoadMCPServerWithFilter ¶
func (r *ToolRegistry) LoadMCPServerWithFilter(serverSpec string, allowedTools []string) error
LoadMCPServerWithFilter connects to an MCP server and only registers specified tools serverSpec format: "path/to/config.json#servername"
func (*ToolRegistry) LoadMCPServers ¶
func (r *ToolRegistry) LoadMCPServers(serverSpecs []string) error
LoadMCPServers batch loads multiple servers
func (*ToolRegistry) LoadShellTool ¶
func (r *ToolRegistry) LoadShellTool(path string) (LoadResult, error)
LoadShellTool loads a single shell tool from a file path with namespace
func (*ToolRegistry) LoadToolAuto ¶
func (r *ToolRegistry) LoadToolAuto(pathOrServer string) (LoadResult, error)
LoadToolAuto attempts to load a tool, auto-detecting if it's native, shell tool, or MCP server
func (*ToolRegistry) Register ¶
func (r *ToolRegistry) Register(tool Tool)
Register adds a tool to the registry
func (*ToolRegistry) RegisterNative ¶
func (r *ToolRegistry) RegisterNative(name string, factory func() Tool)
RegisterNative registers a native tool factory
func (*ToolRegistry) Remove ¶
func (r *ToolRegistry) Remove(namespacedName string)
Remove removes a tool by namespaced name from the registry
func (*ToolRegistry) UnloadMCPServer ¶
func (r *ToolRegistry) UnloadMCPServer(serverSpec string) error
UnloadMCPServer removes all tools from a server and closes it
type UpperCaseTool ¶
type UpperCaseTool struct{}
UpperCaseTool is a simple example of a native Go tool
func (*UpperCaseTool) GetName ¶
func (t *UpperCaseTool) GetName() string
GetName returns the tool name
func (*UpperCaseTool) GetSchema ¶
func (t *UpperCaseTool) GetSchema() *jsonschema.Schema
func (*UpperCaseTool) GetSource ¶
func (t *UpperCaseTool) GetSource() string
GetSource returns "builtin" for native tools
func (*UpperCaseTool) GetType ¶
func (t *UpperCaseTool) GetType() string
GetType returns "native" for built-in tools
type WordCountTool ¶
type WordCountTool struct{}
WordCountTool counts words in text
func (*WordCountTool) GetName ¶
func (t *WordCountTool) GetName() string
GetName returns the tool name
func (*WordCountTool) GetSchema ¶
func (t *WordCountTool) GetSchema() *jsonschema.Schema
func (*WordCountTool) GetSource ¶
func (t *WordCountTool) GetSource() string
GetSource returns "builtin" for native tools
func (*WordCountTool) GetType ¶
func (t *WordCountTool) GetType() string
GetType returns "native" for built-in tools