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 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(n MoLingServerType, f func(ctx context.Context) (Service, error))
- func ServiceList() map[MoLingServerType]func(ctx context.Context) (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) Config() string
- func (mls *MLService) Ctx() context.Context
- func (mls *MLService) LoadConfig(jsonData map[string]interface{}) error
- 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 MoLingServer
- type MoLingServerType
- 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
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") )
var (
ErrConfigNotLoaded = errors.New("config not loaded, please call LoadConfig() first")
)
Functions ¶
func ExecCommand ¶ added in v0.0.4
ExecCommand executes a command and returns its output.
func RegisterServ ¶ added in v0.0.2
func RegisterServ(n MoLingServerType, f func(ctx context.Context) (Service, error))
RegisterServ register service
func ServiceList ¶ added in v0.0.2
func ServiceList() map[MoLingServerType]func(ctx context.Context) (Service, error)
ServiceList get service lists
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"` // URLTimeout is the timeout for loading a URL. time.Second
SelectorQueryTimeout int `json:"selector_query_timeout"` // SelectorQueryTimeout is the timeout for CSS selector queries. time.Second
DataPath string `json:"data_path"` // DataPath is the path to the data directory.
BrowserDataPath string `json:"browser_data_path"` // BrowserDataPath is the path to the browser 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 (bs *BrowserServer) Config() string
Config returns the configuration of the service as a string.
func (*BrowserServer) Init ¶ added in v0.0.6
func (bs *BrowserServer) Init() error
Init initializes the browser server by creating a new context.
func (*BrowserServer) LoadConfig ¶ added in v0.0.6
func (bs *BrowserServer) LoadConfig(jsonData map[string]interface{}) error
LoadConfig loads the configuration from a JSON object.
func (*BrowserServer) Name ¶ added in v0.0.2
func (bs *BrowserServer) Name() MoLingServerType
type CommandConfig ¶
type CommandConfig struct {
AllowedCommand string `json:"allowed_command"` // AllowedCommand is a list of allowed command. split by comma. e.g. ls,cat,echo
// contains filtered or unexported fields
}
CommandConfig represents the configuration for allowed commands.
func NewCommandConfig ¶
func NewCommandConfig() *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 (cs *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) Init ¶ added in v0.0.6
func (cs *CommandServer) Init() error
func (*CommandServer) LoadConfig ¶ added in v0.0.6
func (cs *CommandServer) LoadConfig(jsonData map[string]interface{}) error
LoadConfig loads the configuration from a JSON object.
func (*CommandServer) Name ¶ added in v0.0.2
func (cs *CommandServer) Name() MoLingServerType
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 {
AllowedDir string `json:"allowed_dir"` // AllowedDirs is a list of allowed directories. split by comma. e.g. /tmp,/var/tmp
CachePath string `json:"cache_path"` // CachePath is the root path for the file system.
// contains filtered or unexported fields
}
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 (fs *FilesystemServer) Close() error
func (*FilesystemServer) Config ¶ added in v0.0.2
func (fs *FilesystemServer) Config() string
Config returns the configuration of the service as a string.
func (*FilesystemServer) Init ¶ added in v0.0.6
func (fs *FilesystemServer) Init() error
func (*FilesystemServer) LoadConfig ¶ added in v0.0.6
func (fs *FilesystemServer) LoadConfig(jsonData map[string]interface{}) error
LoadConfig loads the configuration from a JSON object.
func (*FilesystemServer) Name ¶ added in v0.0.2
func (fs *FilesystemServer) Name() MoLingServerType
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 NewMLService ¶ added in v0.0.6
NewMLService creates a new MLService with the given context and logger.
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) Config ¶ added in v0.0.4
Config returns the configuration of the service as a string.
func (*MLService) LoadConfig ¶ added in v0.0.6
LoadConfig loads the configuration for the service from a map.
func (*MLService) MlConfig ¶ added in v0.0.4
func (mls *MLService) MlConfig() *MoLingConfig
MlConfig returns the configuration of the MoLing service.
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.
Module string `json:"module"` // The module to load, default: all
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
// for MCP Server Config
Description string // Description of the MCP Server, default: CliDescription
Command string // Command to start the MCP Server, STDIO mode only, default: CliName
Args string // Arguments to pass to the command, STDIO mode only, default: empty
BaseUrl string // BaseUrl , SSE mode only.
ServerName string // ServerName MCP ServerName, add to the MCP Client config
// 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 MoLingServer ¶ added in v0.0.8
type MoLingServer struct {
// contains filtered or unexported fields
}
func NewMoLingServer ¶ added in v0.0.8
func NewMoLingServer(ctx context.Context, srvs []Service, mlConfig MoLingConfig) (*MoLingServer, error)
func (*MoLingServer) Serve ¶ added in v0.0.8
func (s *MoLingServer) Serve() error
type MoLingServerType ¶ added in v0.3.0
type MoLingServerType string // MoLingServerType is the type of the server
const ( BrowserDataPath = "browser" // Path to store browser data BrowserServerName MoLingServerType = "Browser" )
const (
CommandServerName MoLingServerType = "Command"
)
const (
FilesystemServerName MoLingServerType = "FileSystem"
)
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
// LoadConfig loads the configuration for the service from a map.
LoadConfig(jsonData map[string]interface{}) error
// Init initializes the service with the given context and configuration.
Init() error
MlConfig() *MoLingConfig
// Name returns the name of the service.
Name() MoLingServerType
// 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.