services

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

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

View Source
const (
	// MaxInlineSize Maximum size for inline content (5MB)
	MaxInlineSize = 1024 * 1024 * 5
	// MaxBase64Size Maximum size for base64 encoding (1MB)
	MaxBase64Size = 1024 * 1024 * 1
)
View Source
const (
	MoLingConfigKey contextKey = "moling_config"
	MoLingLoggerKey contextKey = "moling_logger"
)

MoLingConfigKey is a context key for storing the version of MoLing

View Source
const (
	BrowserDataPath = "browser" // Path to store browser data
)

Variables

View Source
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

func ExecCommand(command string) (string, error)

ExecCommand executes a command and returns its output.

func RegisterServ added in v0.0.2

func RegisterServ(f func(ctx context.Context, args []string) (Service, error))

RegisterServ register service

func ServiceList added in v0.0.2

func ServiceList() []func(ctx context.Context, args []string) (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"`
	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 FileInfo

type FileInfo struct {
	Size        int64     `json:"size"`
	Created     time.Time `json:"created"`
	Modified    time.Time `json:"modified"`
	Accessed    time.Time `json:"accessed"`
	IsDirectory bool      `json:"isDirectory"`
	IsFile      bool      `json:"isFile"`
	Permissions string    `json:"permissions"`
}

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

func (mls *MLService) Config() string

Config returns the configuration of the service as a string.

func (*MLService) Ctx

func (mls *MLService) Ctx() context.Context

Ctx returns the context of the MLService.

func (*MLService) MlConfig added in v0.0.4

func (mls *MLService) MlConfig() *MoLingConfig

func (*MLService) Name added in v0.0.4

func (mls *MLService) Name() string

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

func NewBrowserServer(ctx context.Context, args []string) (Service, error)

NewBrowserServer creates a new BrowserServer instance with the given context and configuration.

func NewCommandServer

func NewCommandServer(ctx context.Context, args []string) (Service, error)

NewCommandServer creates a new CommandServer with the given allowed commands.

func NewFilesystemServer

func NewFilesystemServer(ctx context.Context, args []string) (Service, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL