Documentation
¶
Index ¶
- func AddMCPCommand(rootCmd *cobra.Command, opts ...ServerOption) error
- func GetCommandFlags(ctx context.Context) (map[string]interface{}, bool)
- func NewMCPCommand(opts ...ServerOption) *cobra.Command
- func RegisterFunctionTool(config *ServerConfig, name string, fn interface{}) error
- func RegisterSimpleTools(config *ServerConfig, tools map[string]ToolHandler) error
- func RegisterStructTool(config *ServerConfig, name string, obj interface{}, methodName string) error
- type Arguments
- func (a Arguments) BindArguments(target interface{}) error
- func (a Arguments) GetBool(key string, defaultValue bool) bool
- func (a Arguments) GetFloat(key string, defaultValue float64) float64
- func (a Arguments) GetInt(key string, defaultValue int) int
- func (a Arguments) GetIntSlice(key string, defaultValue []int) []int
- func (a Arguments) GetString(key string, defaultValue string) string
- func (a Arguments) GetStringSlice(key string, defaultValue []string) []string
- func (a Arguments) Has(key string) bool
- func (a Arguments) Keys() []string
- func (a Arguments) Raw() map[string]interface{}
- func (a Arguments) RequireBool(key string) (bool, error)
- func (a Arguments) RequireFloat(key string) (float64, error)
- func (a Arguments) RequireInt(key string) (int, error)
- func (a Arguments) RequireIntSlice(key string) ([]int, error)
- func (a Arguments) RequireString(key string) (string, error)
- func (a Arguments) RequireStringSlice(key string) ([]string, error)
- type Backend
- type CommandCustomizer
- type ContextKey
- type EnhancedToolConfig
- type EnhancedToolHandler
- type EnhancedToolOption
- func WithAnnotations(annotations ToolAnnotations) EnhancedToolOption
- func WithArrayProperty(name string, opts ...PropertyOption) EnhancedToolOption
- func WithBooleanProperty(name string, opts ...PropertyOption) EnhancedToolOption
- func WithDestructiveHint(destructive bool) EnhancedToolOption
- func WithEnhancedDescription(desc string) EnhancedToolOption
- func WithIdempotentHint(idempotent bool) EnhancedToolOption
- func WithIntProperty(name string, opts ...PropertyOption) EnhancedToolOption
- func WithNumberProperty(name string, opts ...PropertyOption) EnhancedToolOption
- func WithObjectProperty(name string, opts ...PropertyOption) EnhancedToolOption
- func WithOpenWorldHint(openWorld bool) EnhancedToolOption
- func WithReadOnlyHint(readOnly bool) EnhancedToolOption
- func WithStringProperty(name string, opts ...PropertyOption) EnhancedToolOption
- type Hooks
- type JSONSchema
- type PropertyOption
- func ArrayItems(itemSchema map[string]interface{}) PropertyOption
- func DefaultBool(value bool) PropertyOption
- func DefaultNumber(value float64) PropertyOption
- func DefaultString(value string) PropertyOption
- func MaxItems(maxItems int) PropertyOption
- func MaxLength(maxLen int) PropertyOption
- func Maximum(maxVal float64) PropertyOption
- func MinItems(minItems int) PropertyOption
- func MinLength(minLen int) PropertyOption
- func Minimum(minVal float64) PropertyOption
- func MultipleOf(value float64) PropertyOption
- func PropertyDescription(desc string) PropertyOption
- func PropertyRequired() PropertyOption
- func PropertyTitle(title string) PropertyOption
- func StringEnum(values ...string) PropertyOption
- func StringPattern(pattern string) PropertyOption
- func UniqueItems(unique bool) PropertyOption
- type PropertySchema
- type ServerConfig
- type ServerOption
- func WithCommandCustomizer(customizer CommandCustomizer) ServerOption
- func WithConfigEnabled(enabled bool) ServerOption
- func WithConfigFile(file string) ServerOption
- func WithDefaultPort(port int) ServerOption
- func WithDefaultTransport(transport string) ServerOption
- func WithEnhancedTool(name string, handler EnhancedToolHandler, opts ...EnhancedToolOption) ServerOption
- func WithHooks(hooks *Hooks) ServerOption
- func WithInternalServers(servers ...string) ServerOption
- func WithMiddleware(middleware ...ToolMiddleware) ServerOption
- func WithName(name string) ServerOption
- func WithServerDescription(description string) ServerOption
- func WithSessionStore(store session.SessionStore) ServerOption
- func WithTool(name string, handler ToolHandler, opts ...ToolOption) ServerOption
- func WithToolRegistry(registry *tool_registry.Registry) ServerOption
- func WithVersion(version string) ServerOption
- type ToolAnnotations
- type ToolConfig
- type ToolExample
- type ToolHandler
- type ToolMiddleware
- type ToolOption
- func WithBoolArg(name, description string, required bool) ToolOption
- func WithDescription(desc string) ToolOption
- func WithExample(name, description string, args map[string]interface{}) ToolOption
- func WithFileArg(name, description string, required bool) ToolOption
- func WithIntArg(name, description string, required bool) ToolOption
- func WithSchema(schema interface{}) ToolOption
- func WithStringArg(name, description string, required bool) ToolOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddMCPCommand ¶
func AddMCPCommand(rootCmd *cobra.Command, opts ...ServerOption) error
AddMCPCommand adds a standard 'mcp' subcommand to an existing cobra application
func GetCommandFlags ¶ added in v0.0.11
GetCommandFlags retrieves command flags from context
func NewMCPCommand ¶
func NewMCPCommand(opts ...ServerOption) *cobra.Command
NewMCPCommand creates a new 'mcp' command with the given options
func RegisterFunctionTool ¶
func RegisterFunctionTool(config *ServerConfig, name string, fn interface{}) error
RegisterFunctionTool creates a tool from a function using reflection
func RegisterSimpleTools ¶
func RegisterSimpleTools(config *ServerConfig, tools map[string]ToolHandler) error
RegisterSimpleTools provides a very easy way to register multiple tools
func RegisterStructTool ¶
func RegisterStructTool(config *ServerConfig, name string, obj interface{}, methodName string) error
RegisterStructTool automatically creates a tool from a struct and method
Types ¶
type Arguments ¶
type Arguments map[string]interface{}
Arguments provides convenient methods for accessing tool arguments with type conversion and validation, inspired by mark3labs/mcp-go
func NewArguments ¶
NewArguments creates an Arguments instance from a map
func (Arguments) BindArguments ¶
BindArguments unmarshals the arguments into the provided struct
func (Arguments) GetIntSlice ¶
Int slice argument access
func (Arguments) GetStringSlice ¶
String slice argument access
type Backend ¶ added in v0.0.14
Backend represents a runnable server backend that starts the selected transport using an mcp-go MCPServer.
func NewBackend ¶ added in v0.0.14
func NewBackend(cfg *ServerConfig) (Backend, error)
NewBackend constructs an mcp-go based backend from the provided ServerConfig. It builds an MCP server, registers tools via existing configuration, and returns a transport-specific backend that can Start(ctx).
type CommandCustomizer ¶ added in v0.0.11
CommandCustomizer is a function that can customize a cobra.Command
type ContextKey ¶ added in v0.0.11
type ContextKey string
ContextKey is used for storing values in context
const ( // CommandFlagsKey is the context key for storing command flags CommandFlagsKey ContextKey = "command_flags" )
type EnhancedToolConfig ¶
type EnhancedToolConfig struct { Description string Schema map[string]interface{} Annotations ToolAnnotations Examples []ToolExample }
EnhancedToolConfig holds configuration for enhanced tools
type EnhancedToolHandler ¶
EnhancedToolHandler is an enhanced function signature for tool handlers It provides an Arguments wrapper with convenient accessor methods
type EnhancedToolOption ¶
type EnhancedToolOption func(*EnhancedToolConfig) error
EnhancedToolOption configures enhanced tools
func WithAnnotations ¶
func WithAnnotations(annotations ToolAnnotations) EnhancedToolOption
func WithArrayProperty ¶
func WithArrayProperty(name string, opts ...PropertyOption) EnhancedToolOption
func WithBooleanProperty ¶
func WithBooleanProperty(name string, opts ...PropertyOption) EnhancedToolOption
func WithDestructiveHint ¶
func WithDestructiveHint(destructive bool) EnhancedToolOption
func WithEnhancedDescription ¶
func WithEnhancedDescription(desc string) EnhancedToolOption
Enhanced tool configuration options
func WithIdempotentHint ¶
func WithIdempotentHint(idempotent bool) EnhancedToolOption
func WithIntProperty ¶
func WithIntProperty(name string, opts ...PropertyOption) EnhancedToolOption
func WithNumberProperty ¶
func WithNumberProperty(name string, opts ...PropertyOption) EnhancedToolOption
func WithObjectProperty ¶
func WithObjectProperty(name string, opts ...PropertyOption) EnhancedToolOption
func WithOpenWorldHint ¶
func WithOpenWorldHint(openWorld bool) EnhancedToolOption
func WithReadOnlyHint ¶
func WithReadOnlyHint(readOnly bool) EnhancedToolOption
func WithStringProperty ¶
func WithStringProperty(name string, opts ...PropertyOption) EnhancedToolOption
Enhanced property configuration
type Hooks ¶
type Hooks struct { OnServerStart func(ctx context.Context) error BeforeToolCall func(ctx context.Context, toolName string, args map[string]interface{}) error AfterToolCall func(ctx context.Context, toolName string, result *protocol.ToolResult, err error) }
Hooks allows customization of server behavior
type JSONSchema ¶ added in v0.0.12
type JSONSchema struct { Type string `json:"type"` Properties map[string]PropertySchema `json:"properties"` Required []string `json:"required"` Description string `json:"description"` }
JSONSchema represents a JSON Schema structure
type PropertyOption ¶
type PropertyOption func(map[string]interface{})
PropertyOption configures a property in a tool's input schema
func ArrayItems ¶
func ArrayItems(itemSchema map[string]interface{}) PropertyOption
Array property options
func MaxItems ¶
func MaxItems(maxItems int) PropertyOption
func MaxLength ¶
func MaxLength(maxLen int) PropertyOption
func Maximum ¶
func Maximum(maxVal float64) PropertyOption
func MinItems ¶
func MinItems(minItems int) PropertyOption
func MinLength ¶
func MinLength(minLen int) PropertyOption
func Minimum ¶
func Minimum(minVal float64) PropertyOption
func MultipleOf ¶
func MultipleOf(value float64) PropertyOption
func PropertyDescription ¶
func PropertyDescription(desc string) PropertyOption
Property configuration options
func PropertyRequired ¶
func PropertyRequired() PropertyOption
func PropertyTitle ¶
func PropertyTitle(title string) PropertyOption
func StringEnum ¶
func StringEnum(values ...string) PropertyOption
func StringPattern ¶
func StringPattern(pattern string) PropertyOption
func UniqueItems ¶
func UniqueItems(unique bool) PropertyOption
type PropertySchema ¶ added in v0.0.12
type PropertySchema struct { Type string `json:"type"` Description string `json:"description"` Enum []string `json:"enum"` Default interface{} `json:"default"` }
PropertySchema represents a property in JSON Schema
type ServerConfig ¶
type ServerConfig struct { Name string Version string Description string // contains filtered or unexported fields }
ServerConfig holds the configuration for the embeddable server
func NewServerConfig ¶
func NewServerConfig() *ServerConfig
NewServerConfig creates a new server configuration with defaults
func (*ServerConfig) GetToolProvider ¶
func (c *ServerConfig) GetToolProvider() pkg.ToolProvider
GetToolProvider returns the tool provider for the server config
type ServerOption ¶
type ServerOption func(*ServerConfig) error
ServerOption configures the embeddable MCP server
func WithCommandCustomizer ¶ added in v0.0.11
func WithCommandCustomizer(customizer CommandCustomizer) ServerOption
func WithConfigEnabled ¶
func WithConfigEnabled(enabled bool) ServerOption
func WithConfigFile ¶
func WithConfigFile(file string) ServerOption
func WithDefaultPort ¶
func WithDefaultPort(port int) ServerOption
func WithDefaultTransport ¶
func WithDefaultTransport(transport string) ServerOption
Transport options
func WithEnhancedTool ¶
func WithEnhancedTool(name string, handler EnhancedToolHandler, opts ...EnhancedToolOption) ServerOption
Enhanced tool registration with mark3labs/mcp-go inspired API
func WithHooks ¶
func WithHooks(hooks *Hooks) ServerOption
func WithInternalServers ¶
func WithInternalServers(servers ...string) ServerOption
func WithMiddleware ¶
func WithMiddleware(middleware ...ToolMiddleware) ServerOption
func WithServerDescription ¶
func WithServerDescription(description string) ServerOption
func WithSessionStore ¶
func WithSessionStore(store session.SessionStore) ServerOption
Advanced options
func WithTool ¶
func WithTool(name string, handler ToolHandler, opts ...ToolOption) ServerOption
Tool registration options
func WithToolRegistry ¶
func WithToolRegistry(registry *tool_registry.Registry) ServerOption
func WithVersion ¶
func WithVersion(version string) ServerOption
type ToolAnnotations ¶
type ToolAnnotations struct { Title string `json:"title,omitempty"` ReadOnlyHint *bool `json:"readOnlyHint,omitempty"` DestructiveHint *bool `json:"destructiveHint,omitempty"` IdempotentHint *bool `json:"idempotentHint,omitempty"` OpenWorldHint *bool `json:"openWorldHint,omitempty"` }
ToolAnnotations provides metadata about tool behavior
type ToolConfig ¶
type ToolConfig struct { Description string Schema interface{} // Can be a struct, JSON schema string, or json.RawMessage Examples []ToolExample }
ToolConfig holds configuration for a tool
type ToolExample ¶
type ToolExample struct { Name string `json:"name"` Description string `json:"description"` Arguments map[string]interface{} `json:"arguments"` }
ToolExample represents an example usage of a tool
type ToolHandler ¶
type ToolHandler func(ctx context.Context, args map[string]interface{}) (*protocol.ToolResult, error)
ToolHandler is a simplified function signature for tool handlers Session information is available via session.GetSessionFromContext(ctx)
type ToolMiddleware ¶
type ToolMiddleware func(next ToolHandler) ToolHandler
ToolMiddleware is a function that wraps a ToolHandler
type ToolOption ¶
type ToolOption func(*ToolConfig) error
ToolOption configures individual tools
func WithBoolArg ¶
func WithBoolArg(name, description string, required bool) ToolOption
func WithExample ¶
func WithExample(name, description string, args map[string]interface{}) ToolOption
func WithFileArg ¶
func WithFileArg(name, description string, required bool) ToolOption
func WithIntArg ¶
func WithIntArg(name, description string, required bool) ToolOption
func WithSchema ¶
func WithSchema(schema interface{}) ToolOption
func WithStringArg ¶
func WithStringArg(name, description string, required bool) ToolOption
Convenience functions for common tool patterns