Documentation
¶
Overview ¶
Package services provides a set of services for the MoLing application.
Package services provides a set of services for the MoLing application.
Package services Description: This file contains the implementation of the CommandServer interface for macOS and Linux.
Package services provides the implementation of the FileSystemServer, which allows access to files and directories on the local file system.
Index ¶
- Constants
- Variables
- func ExecCommand(command string) (string, error)
- func RegisterServ(f func(ctx context.Context, args []string) (Service, error))
- func ServiceList() []func(ctx context.Context, args []string) (Service, error)
- type BrowserConfig
- type BrowserServer
- type CommandConfig
- type CommandServer
- type Config
- type FileInfo
- type FileSystemConfig
- type FilesystemServer
- type MLService
- func (mls *MLService) AddNotificationHandler(name string, handler server.NotificationHandlerFunc)
- func (mls *MLService) AddPrompt(pe PromptEntry)
- func (mls *MLService) AddResource(rs mcp.Resource, hr server.ResourceHandlerFunc)
- func (mls *MLService) AddResourceTemplate(rt mcp.ResourceTemplate, hr server.ResourceTemplateHandlerFunc)
- func (mls *MLService) AddTool(tool mcp.Tool, handler server.ToolHandlerFunc)
- func (mls *MLService) CallToolResult(msg string) *mcp.CallToolResult
- func (mls *MLService) CallToolResultErr(msg string) *mcp.CallToolResult
- func (mls *MLService) Config() string
- func (mls *MLService) Ctx() context.Context
- func (mls *MLService) MlConfig() *MoLingConfig
- func (mls *MLService) Name() string
- func (mls *MLService) NotificationHandlers() map[string]server.NotificationHandlerFunc
- func (mls *MLService) Prompts() []PromptEntry
- func (mls *MLService) ResourceTemplates() map[mcp.ResourceTemplate]server.ResourceTemplateHandlerFunc
- func (mls *MLService) Resources() map[mcp.Resource]server.ResourceHandlerFunc
- func (mls *MLService) Tools() []server.ServerTool
- type MoLingConfig
- type PromptEntry
- type Service
Constants ¶
const ( // MaxInlineSize Maximum size for inline content (5MB) MaxInlineSize = 1024 * 1024 * 5 // MaxBase64Size Maximum size for base64 encoding (1MB) MaxBase64Size = 1024 * 1024 * 1 )
const ( MoLingConfigKey contextKey = "moling_config" MoLingLoggerKey contextKey = "moling_logger" )
MoLingConfigKey is a context key for storing the version of MoLing
const (
BrowserDataPath = "browser" // Path to store browser data
)
Variables ¶
var ( // ErrCommandNotFound is returned when the command is not found. ErrCommandNotFound = fmt.Errorf("command not found") // ErrCommandNotAllowed is returned when the command is not allowed. ErrCommandNotAllowed = fmt.Errorf("command not allowed") )
Functions ¶
func ExecCommand ¶ added in v0.0.4
ExecCommand executes a command and returns its output.
func RegisterServ ¶ added in v0.0.2
RegisterServ register service
Types ¶
type BrowserConfig ¶ added in v0.0.2
type BrowserConfig struct {
Headless bool `json:"headless"`
Timeout int `json:"timeout"`
Proxy string `json:"proxy"`
UserAgent string `json:"user_agent"`
DefaultLanguage string `json:"default_language"`
URLTimeout int `json:"url_timeout"`
CSSTimeout int `json:"css_timeout"`
DataPath string `json:"data_path"` // DataPath is the path to the data directory.
}
func NewBrowserConfig ¶ added in v0.0.2
func NewBrowserConfig() *BrowserConfig
NewBrowserConfig creates a new BrowserConfig with default values.
func (*BrowserConfig) Check ¶ added in v0.0.2
func (cfg *BrowserConfig) Check() error
type BrowserServer ¶ added in v0.0.2
type BrowserServer struct {
MLService
// contains filtered or unexported fields
}
BrowserServer represents the configuration for the browser service.
func (*BrowserServer) Close ¶ added in v0.0.2
func (bs *BrowserServer) Close() error
func (*BrowserServer) Config ¶ added in v0.0.2
func (mls *BrowserServer) Config() string
Config returns the configuration of the service as a string.
func (*BrowserServer) Name ¶ added in v0.0.2
func (cs *BrowserServer) Name() string
type CommandConfig ¶
type CommandConfig struct {
// AllowedCommands is a list of allowed commands.
AllowedCommands []string `json:"allowed_commands"`
}
CommandConfig represents the configuration for allowed commands.
func NewCommandConfig ¶
func NewCommandConfig(commands []string) *CommandConfig
NewCommandConfig creates a new CommandConfig with the given allowed commands.
func (*CommandConfig) Check ¶
func (cc *CommandConfig) Check() error
Check validates the allowed commands in the CommandConfig.
type CommandServer ¶
type CommandServer struct {
MLService
// contains filtered or unexported fields
}
CommandServer implements the Service interface and provides methods to execute named commands.
func (*CommandServer) Close ¶ added in v0.0.2
func (bs *CommandServer) Close() error
func (*CommandServer) Config ¶ added in v0.0.2
func (cs *CommandServer) Config() string
Config returns the configuration of the service as a string.
func (*CommandServer) Name ¶ added in v0.0.2
func (cs *CommandServer) Name() string
type Config ¶
type Config interface {
// Check validates the configuration and returns an error if the configuration is invalid.
Check() error
}
Config is an interface that defines a method for checking configuration validity.
type FileSystemConfig ¶
type FileSystemConfig struct {
AllowedDirs []string `json:"allowed_dirs"` // AllowedDirs is a list of allowed directories.
CachePath string `json:"cache_path"` // CachePath is the root path for the file system.
}
FileSystemConfig represents the configuration for the file system.
func NewFileSystemConfig ¶
func NewFileSystemConfig(path []string) *FileSystemConfig
NewFileSystemConfig creates a new FileSystemConfig with the given allowed directories.
func (*FileSystemConfig) Check ¶
func (fc *FileSystemConfig) Check() error
Check validates the allowed directories in the FileSystemConfig.
type FilesystemServer ¶
type FilesystemServer struct {
MLService
// contains filtered or unexported fields
}
func (*FilesystemServer) Close ¶ added in v0.0.2
func (fss *FilesystemServer) Close() error
func (*FilesystemServer) Config ¶ added in v0.0.2
func (fss *FilesystemServer) Config() string
Config returns the configuration of the service as a string.
func (*FilesystemServer) Name ¶ added in v0.0.2
func (fss *FilesystemServer) Name() string
type MLService ¶
type MLService struct {
// contains filtered or unexported fields
}
MLService implements the Service interface and provides methods to manage resources, templates, prompts, tools, and notification handlers.
func (*MLService) AddNotificationHandler ¶
func (mls *MLService) AddNotificationHandler(name string, handler server.NotificationHandlerFunc)
AddNotificationHandler adds a notification handler to the service.
func (*MLService) AddPrompt ¶
func (mls *MLService) AddPrompt(pe PromptEntry)
AddPrompt adds a prompt and its handler function to the service.
func (*MLService) AddResource ¶
func (mls *MLService) AddResource(rs mcp.Resource, hr server.ResourceHandlerFunc)
AddResource adds a resource and its handler function to the service.
func (*MLService) AddResourceTemplate ¶
func (mls *MLService) AddResourceTemplate(rt mcp.ResourceTemplate, hr server.ResourceTemplateHandlerFunc)
AddResourceTemplate adds a resource template and its handler function to the service.
func (*MLService) AddTool ¶
func (mls *MLService) AddTool(tool mcp.Tool, handler server.ToolHandlerFunc)
AddTool adds a tool and its handler function to the service.
func (*MLService) CallToolResult ¶ added in v0.0.4
func (mls *MLService) CallToolResult(msg string) *mcp.CallToolResult
CallToolResult return a CallToolResult with the given message and success status.
func (*MLService) CallToolResultErr ¶ added in v0.0.5
func (mls *MLService) CallToolResultErr(msg string) *mcp.CallToolResult
CallToolResultErr return a CallToolResult with the given message and error status.
func (*MLService) Config ¶ added in v0.0.4
Config returns the configuration of the service as a string.
func (*MLService) MlConfig ¶ added in v0.0.4
func (mls *MLService) MlConfig() *MoLingConfig
func (*MLService) NotificationHandlers ¶
func (mls *MLService) NotificationHandlers() map[string]server.NotificationHandlerFunc
NotificationHandlers returns the map of notification handlers.
func (*MLService) Prompts ¶
func (mls *MLService) Prompts() []PromptEntry
Prompts returns the map of prompts and their handler functions.
func (*MLService) ResourceTemplates ¶
func (mls *MLService) ResourceTemplates() map[mcp.ResourceTemplate]server.ResourceTemplateHandlerFunc
ResourceTemplates returns the map of resource templates and their handler functions.
func (*MLService) Resources ¶
func (mls *MLService) Resources() map[mcp.Resource]server.ResourceHandlerFunc
Resources returns the map of resources and their handler functions.
func (*MLService) Tools ¶
func (mls *MLService) Tools() []server.ServerTool
Tools returns the slice of server tools.
type MoLingConfig ¶ added in v0.0.2
type MoLingConfig struct {
ConfigFile string `json:"config_file"` // The path to the configuration file.
BasePath string `json:"base_path"` // The base path for the server, used for storing files. automatically created if not exists. eg: /Users/user1/.moling
//AllowDir []string `json:"allow_dir"` // The directories that are allowed to be accessed by the server.
Version string `json:"version"` // The version of the MoLing server.
ListenAddr string `json:"listen_addr"` // The address to listen on for SSE mode.
Debug bool `json:"debug"` // Debug mode, if true, the server will run in debug mode.
Username string // The username of the user running the server.
HomeDir string // The home directory of the user running the server. macOS: /Users/user1, Linux: /home/user1
SystemInfo string // The system information of the user running the server. macOS: Darwin 15.3.3, Linux: Ubuntu 20.04.1 LTS
// contains filtered or unexported fields
}
MoLingConfig is a struct that holds the configuration for the MoLing server.
func (*MoLingConfig) Check ¶ added in v0.0.2
func (cfg *MoLingConfig) Check() error
func (*MoLingConfig) Logger ¶ added in v0.0.2
func (cfg *MoLingConfig) Logger() zerolog.Logger
func (*MoLingConfig) SetLogger ¶ added in v0.0.2
func (cfg *MoLingConfig) SetLogger(logger zerolog.Logger)
type PromptEntry ¶
type PromptEntry struct {
// contains filtered or unexported fields
}
func (*PromptEntry) Handler ¶
func (pe *PromptEntry) Handler() server.PromptHandlerFunc
func (*PromptEntry) Prompt ¶
func (pe *PromptEntry) Prompt() mcp.Prompt
type Service ¶
type Service interface {
Ctx() context.Context
// Resources returns a map of resources and their corresponding handler functions.
Resources() map[mcp.Resource]server.ResourceHandlerFunc
// ResourceTemplates returns a map of resource templates and their corresponding handler functions.
ResourceTemplates() map[mcp.ResourceTemplate]server.ResourceTemplateHandlerFunc
// Prompts returns a map of prompts and their corresponding handler functions.
Prompts() []PromptEntry
// Tools returns a slice of server tools.
Tools() []server.ServerTool
// NotificationHandlers returns a map of notification handlers.
NotificationHandlers() map[string]server.NotificationHandlerFunc
// Config returns the configuration of the service as a string.
Config() string
MlConfig() *MoLingConfig
// Name returns the name of the service.
Name() string
// Close closes the service and releases any resources it holds.
Close() error
}
Service defines the interface for a service with various handlers and tools.
func NewBrowserServer ¶ added in v0.0.2
NewBrowserServer creates a new BrowserServer instance with the given context and configuration.
func NewCommandServer ¶
NewCommandServer creates a new CommandServer with the given allowed commands.