Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func init() {
rootCmd.PersistentFlags().StringVar(&mlConfig.BasePath, "base_path", mlConfig.BasePath, "MoLing Base Data Path, automatically set by the system, cannot be changed, display only.")
rootCmd.PersistentFlags().BoolVarP(&mlConfig.Debug, "debug", "d", false, "Debug mode, default is false.")
rootCmd.PersistentFlags().StringVarP(&mlConfig.ListenAddr, "listen_addr", "l", "", "listen address for SSE mode. default:'', not listen, used STDIO mode.")
rootCmd.PersistentFlags().StringVarP(&mlConfig.Module, "module", "m", "all", "module to load, default: all; others: browser, filesystem, command, etc. Multiple modules are separated by commas")
rootCmd.PersistentFlags().StringVarP(&mlConfig.Module, "module", "m", "all", "module to load, default: all; others: Browser,FileSystem,Command, etc. Multiple modules are separated by commas")
rootCmd.SilenceUsage = true
}

Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ module github.com/gojue/moling
go 1.24.1

require (
github.com/chromedp/cdproto v0.0.0-20250417220500-b38043e8e6c8
github.com/chromedp/chromedp v0.13.6
github.com/mark3labs/mcp-go v0.21.0
github.com/mark3labs/mcp-go v0.21.1
github.com/rs/zerolog v1.34.0
github.com/spf13/cobra v1.9.1
github.com/spf13/pflag v1.0.6
)

require (
github.com/chromedp/cdproto v0.0.0-20250416210000-d7e4d624041a // indirect
github.com/chromedp/sysutil v1.1.0 // indirect
github.com/go-json-experiment/json v0.0.0-20250223041408-d3c622f1b874 // indirect
github.com/go-json-experiment/json v0.0.0-20250417205406-170dfdcf87d1 // indirect
github.com/gobwas/httphead v0.1.0 // indirect
github.com/gobwas/pool v0.2.1 // indirect
github.com/gobwas/ws v1.4.0 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ github.com/chromedp/cdproto v0.0.0-20250403032234-65de8f5d025b h1:jJmiCljLNTaq/O
github.com/chromedp/cdproto v0.0.0-20250403032234-65de8f5d025b/go.mod h1:NItd7aLkcfOA/dcMXvl8p1u+lQqioRMq/SqDp71Pb/k=
github.com/chromedp/cdproto v0.0.0-20250416210000-d7e4d624041a h1:TVjyMfX22UgV/jP0A4UwrrCmI9zfvp6ZS5UBZMy3HDw=
github.com/chromedp/cdproto v0.0.0-20250416210000-d7e4d624041a/go.mod h1:NItd7aLkcfOA/dcMXvl8p1u+lQqioRMq/SqDp71Pb/k=
github.com/chromedp/cdproto v0.0.0-20250417220500-b38043e8e6c8 h1:j1b2XORm5Zh5jhTu8rH8AoRnrdT1V4x00OrBXU8Qzs4=
github.com/chromedp/cdproto v0.0.0-20250417220500-b38043e8e6c8/go.mod h1:NItd7aLkcfOA/dcMXvl8p1u+lQqioRMq/SqDp71Pb/k=
github.com/chromedp/chromedp v0.13.3 h1:c6nTn97XQBykzcXiGYL5LLebw3h3CEyrCihm4HquYh0=
github.com/chromedp/chromedp v0.13.3/go.mod h1:khsDP9OP20GrowpJfZ7N05iGCwcAYxk7qf9AZBzR3Qw=
github.com/chromedp/chromedp v0.13.6 h1:xlNunMyzS5bu3r/QKrb3fzX6ow3WBQ6oao+J65PGZxk=
Expand All @@ -18,6 +20,8 @@ github.com/go-json-experiment/json v0.0.0-20250211171154-1ae217ad3535 h1:yE7argO
github.com/go-json-experiment/json v0.0.0-20250211171154-1ae217ad3535/go.mod h1:BWmvoE1Xia34f3l/ibJweyhrT+aROb/FQ6d+37F0e2s=
github.com/go-json-experiment/json v0.0.0-20250223041408-d3c622f1b874 h1:F8d1AJ6M9UQCavhwmO6ZsrYLfG8zVFWfEfMS2MXPkSY=
github.com/go-json-experiment/json v0.0.0-20250223041408-d3c622f1b874/go.mod h1:TiCD2a1pcmjd7YnhGH0f/zKNcCD06B029pHhzV23c2M=
github.com/go-json-experiment/json v0.0.0-20250417205406-170dfdcf87d1 h1:+VexzzkMLb1tnvpuQdGT/DicIRW7MN8ozsXqBMgp0Hk=
github.com/go-json-experiment/json v0.0.0-20250417205406-170dfdcf87d1/go.mod h1:TiCD2a1pcmjd7YnhGH0f/zKNcCD06B029pHhzV23c2M=
github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU=
github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM=
github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og=
Expand All @@ -43,6 +47,8 @@ github.com/mark3labs/mcp-go v0.20.1 h1:E1Bbx9K8d8kQmDZ1QHblM38c7UU2evQ2LlkANk1U/
github.com/mark3labs/mcp-go v0.20.1/go.mod h1:KmJndYv7GIgcPVwEKJjNcbhVQ+hJGJhrCCB/9xITzpE=
github.com/mark3labs/mcp-go v0.21.0 h1:oyEtiXg8PnrVEFis9b1AwbiUWF2dTbyBP5yLo7SruXE=
github.com/mark3labs/mcp-go v0.21.0/go.mod h1:KmJndYv7GIgcPVwEKJjNcbhVQ+hJGJhrCCB/9xITzpE=
github.com/mark3labs/mcp-go v0.21.1 h1:7Ek6KPIIbMhEYHRiRIg6K6UAgNZCJaHKQp926MNr6V0=
github.com/mark3labs/mcp-go v0.21.1/go.mod h1:KmJndYv7GIgcPVwEKJjNcbhVQ+hJGJhrCCB/9xITzpE=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
Expand Down
40 changes: 4 additions & 36 deletions services/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,40 +289,7 @@ func (bs *BrowserServer) handlePrompt(ctx context.Context, request mcp.GetPrompt
Role: mcp.RoleUser,
Content: mcp.TextContent{
Type: "text",
Text: fmt.Sprintf(`
You are an AI-powered browser automation assistant capable of performing a wide range of web interactions and debugging tasks. Your capabilities include:

1. **Navigation**: Navigate to any specified URL to load web pages.

2. **Screenshot Capture**: Take full-page screenshots or capture specific elements using CSS selectors, with customizable dimensions (default: 1700x1100 pixels).

3. **Element Interaction**:
- Click on elements identified by CSS selectors
- Hover over specified elements
- Fill input fields with provided values
- Select options in dropdown menus

4. **JavaScript Execution**:
- Run arbitrary JavaScript code in the browser context
- Evaluate scripts and return results

5. **Debugging Tools**:
- Enable/disable JavaScript debugging mode
- Set breakpoints at specific script locations (URL + line number + optional column/condition)
- Remove existing breakpoints by ID
- Pause and resume script execution
- Retrieve current call stack when paused

For all actions requiring element selection, you must use precise CSS selectors. When capturing screenshots, you can specify either the entire page or target specific elements. For debugging operations, you can precisely control execution flow and inspect runtime behavior.

Please provide clear instructions including:
- The specific action you want performed
- Required parameters (URLs, selectors, values, etc.)
- Any optional parameters (dimensions, conditions, etc.)
- Expected outcomes where relevant

You should confirm actions before execution when dealing with sensitive operations or destructive commands. Report back with clear status updates, success/failure indicators, and any relevant output or captured data.
`),
Text: bs.config.prompt,
},
},
},
Expand Down Expand Up @@ -473,8 +440,9 @@ func (bs *BrowserServer) Close() error {
bs.cancelAlloc()
bs.cancelChrome()
// Cancel the context to stop the browser
//_ = chromedp.Cancel(bs.ctx)
return nil
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
return chromedp.Cancel(ctx)
}

// Config returns the configuration of the service as a string.
Expand Down
45 changes: 45 additions & 0 deletions services/browser_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,44 @@ import (
"path/filepath"
)

const BrowserPromptDefault = `
You are an AI-powered browser automation assistant capable of performing a wide range of web interactions and debugging tasks. Your capabilities include:

1. **Navigation**: Navigate to any specified URL to load web pages.

2. **Screenshot Capture**: Take full-page screenshots or capture specific elements using CSS selectors, with customizable dimensions (default: 1700x1100 pixels).

3. **Element Interaction**:
- Click on elements identified by CSS selectors
- Hover over specified elements
- Fill input fields with provided values
- Select options in dropdown menus

4. **JavaScript Execution**:
- Run arbitrary JavaScript code in the browser context
- Evaluate scripts and return results

5. **Debugging Tools**:
- Enable/disable JavaScript debugging mode
- Set breakpoints at specific script locations (URL + line number + optional column/condition)
- Remove existing breakpoints by ID
- Pause and resume script execution
- Retrieve current call stack when paused

For all actions requiring element selection, you must use precise CSS selectors. When capturing screenshots, you can specify either the entire page or target specific elements. For debugging operations, you can precisely control execution flow and inspect runtime behavior.

Please provide clear instructions including:
- The specific action you want performed
- Required parameters (URLs, selectors, values, etc.)
- Any optional parameters (dimensions, conditions, etc.)
- Expected outcomes where relevant

You should confirm actions before execution when dealing with sensitive operations or destructive commands. Report back with clear status updates, success/failure indicators, and any relevant output or captured data.
`

type BrowserConfig struct {
PromptFile string `json:"prompt_file"` // PromptFile is the prompt file for the browser.
prompt string
Headless bool `json:"headless"`
Timeout int `json:"timeout"`
Proxy string `json:"proxy"`
Expand All @@ -36,6 +73,7 @@ type BrowserConfig struct {
}

func (cfg *BrowserConfig) Check() error {
cfg.prompt = BrowserPromptDefault
if cfg.Timeout <= 0 {
return fmt.Errorf("timeout must be greater than 0")
}
Expand All @@ -45,6 +83,13 @@ func (cfg *BrowserConfig) Check() error {
if cfg.SelectorQueryTimeout <= 0 {
return fmt.Errorf("selector Query timeout must be greater than 0")
}
if cfg.PromptFile != "" {
read, err := os.ReadFile(cfg.PromptFile)
if err != nil {
return fmt.Errorf("failed to read prompt file:%s, error: %v", cfg.PromptFile, err)
}
cfg.prompt = string(read)
}
return nil
}

Expand Down
40 changes: 1 addition & 39 deletions services/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,45 +107,7 @@ func (cs *CommandServer) handlePrompt(ctx context.Context, request mcp.GetPrompt
Role: mcp.RoleUser,
Content: mcp.TextContent{
Type: "text",
Text: fmt.Sprintf(`
You are a powerful terminal command assistant capable of executing various command-line on %s operations and management tasks. Your capabilities include:

1. **File and Directory Management**:
- List files and subdirectories in a directory
- Create new files or directories
- Delete specified files or directories
- Copy and move files and directories
- Rename files or directories

2. **File Content Operations**:
- View the contents of text files
- Edit file contents
- Redirect output to a file
- Search file contents

3. **System Information Retrieval**:
- Retrieve system information (e.g., CPU usage, memory usage, etc.)
- View the current user and their permissions
- Check the current working directory

4. **Network Operations**:
- Check network connection status (e.g., using the ping command)
- Query domain information (e.g., using the whois command)
- Manage network services (e.g., start, stop, and restart services)

5. **Process Management**:
- List currently running processes
- Terminate specified processes
- Adjust process priorities

Before executing any actions, please provide clear instructions, including:
- The specific command you want to execute
- Required parameters (file paths, directory names, etc.)
- Any optional parameters (e.g., modification options, output formats, etc.)
- Relevant expected results or output

When dealing with sensitive operations or destructive commands, please confirm before execution. Report back with clear status updates, success/failure indicators, and any relevant output or results.
`, cs.MlConfig().SystemInfo),
Text: fmt.Sprintf(cs.config.prompt, cs.MlConfig().SystemInfo),
},
},
},
Expand Down
54 changes: 53 additions & 1 deletion services/command_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,56 @@ package services

import (
"fmt"
"os"
"strings"
)

const (
CommandPromptDefault = `
You are a powerful terminal command assistant capable of executing various command-line on %s operations and management tasks. Your capabilities include:

1. **File and Directory Management**:
- List files and subdirectories in a directory
- Create new files or directories
- Delete specified files or directories
- Copy and move files and directories
- Rename files or directories

2. **File Content Operations**:
- View the contents of text files
- Edit file contents
- Redirect output to a file
- Search file contents

3. **System Information Retrieval**:
- Retrieve system information (e.g., CPU usage, memory usage, etc.)
- View the current user and their permissions
- Check the current working directory

4. **Network Operations**:
- Check network connection status (e.g., using the ping command)
- Query domain information (e.g., using the whois command)
- Manage network services (e.g., start, stop, and restart services)

5. **Process Management**:
- List currently running processes
- Terminate specified processes
- Adjust process priorities

Before executing any actions, please provide clear instructions, including:
- The specific command you want to execute
- Required parameters (file paths, directory names, etc.)
- Any optional parameters (e.g., modification options, output formats, etc.)
- Relevant expected results or output

When dealing with sensitive operations or destructive commands, please confirm before execution. Report back with clear status updates, success/failure indicators, and any relevant output or results.
`
)

// CommandConfig represents the configuration for allowed commands.
type CommandConfig struct {
PromptFile string `json:"prompt_file"` // PromptFile is the prompt file for the command.
prompt string
AllowedCommand string `json:"allowed_command"` // AllowedCommand is a list of allowed command. split by comma. e.g. ls,cat,echo
allowedCommands []string
}
Expand All @@ -49,6 +94,7 @@ func NewCommandConfig() *CommandConfig {

// Check validates the allowed commands in the CommandConfig.
func (cc *CommandConfig) Check() error {
cc.prompt = CommandPromptDefault
var cnt int
cnt = len(cc.allowedCommands)

Expand All @@ -62,6 +108,12 @@ func (cc *CommandConfig) Check() error {
if cnt <= 0 {
return fmt.Errorf("no allowed commands specified")
}

if cc.PromptFile != "" {
read, err := os.ReadFile(cc.PromptFile)
if err != nil {
return fmt.Errorf("failed to read prompt file:%s, error: %v", cc.PromptFile, err)
}
cc.prompt = string(read)
}
return nil
}
33 changes: 1 addition & 32 deletions services/file_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,38 +192,7 @@ func (fs *FilesystemServer) handlePrompt(ctx context.Context, request mcp.GetPro
Role: mcp.RoleUser,
Content: mcp.TextContent{
Type: "text",
Text: fmt.Sprintf(`
You are a powerful local filesystem management assistant capable of performing various file operations and management tasks. Your capabilities include:

1. **File Browsing**: Navigate to specified directories to load lists of files and folders.

2. **File Operations**:
- Create new files or folders
- Delete specified files or folders
- Copy and move files and folders
- Rename files or folders

3. **File Content Operations**:
- Read the contents of text files and return them
- Write text to specified files
- Append content to existing files

4. **File Information Retrieval**:
- Retrieve properties of files or folders (e.g., size, creation date, modification date)
- Check if files or folders exist

5. **Search Functionality**:
- Search for files in specified directories, supporting wildcard matching
- Filter search results by file type or modification date

For all actions, please provide clear instructions, including:
- The specific action you want to perform
- Required parameters (directory paths, filenames, content, etc.)
- Any optional parameters (e.g., new filenames, search patterns, etc.)
- Relevant expected outcomes

You should confirm actions before execution when dealing with sensitive operations or destructive commands. Report back with clear status updates, success/failure indicators, and any relevant output or results.
`),
Text: fs.config.prompt,
},
},
},
Expand Down
Loading
Loading