From 6a362d2f5e356d65d443ddd9ce21bae2f3c17a04 Mon Sep 17 00:00:00 2001 From: Ed Zynda Date: Tue, 10 Jun 2025 15:18:06 +0300 Subject: [PATCH] string based system prompts --- cmd/root.go | 2 +- internal/config/config.go | 33 ++++++++++++++++++++------------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 9ec79aa2..be270dc1 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -79,7 +79,7 @@ func init() { rootCmd.PersistentFlags(). StringVar(&configFile, "config", "", "config file (default is $HOME/.mcp.json)") rootCmd.PersistentFlags(). - StringVar(&systemPromptFile, "system-prompt", "", "system prompt json file") + StringVar(&systemPromptFile, "system-prompt", "", "system prompt text or path to system prompt json file") rootCmd.PersistentFlags(). IntVar(&messageWindow, "message-window", 40, "number of messages to keep in context") rootCmd.PersistentFlags(). diff --git a/internal/config/config.go b/internal/config/config.go index 768fdb82..290c9dc8 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -121,25 +121,32 @@ func LoadMCPConfig(configFile string) (*Config, error) { return &config, nil } -// LoadSystemPrompt loads system prompt from file -func LoadSystemPrompt(filePath string) (string, error) { - if filePath == "" { +// LoadSystemPrompt loads system prompt from file or returns the string directly +func LoadSystemPrompt(input string) (string, error) { + if input == "" { return "", nil } - v := viper.New() - v.SetConfigFile(filePath) + // Check if input is a file that exists + if _, err := os.Stat(input); err == nil { + // Treat as file path + v := viper.New() + v.SetConfigFile(input) - if err := v.ReadInConfig(); err != nil { - return "", fmt.Errorf("error reading system prompt file: %v", err) + if err := v.ReadInConfig(); err != nil { + return "", fmt.Errorf("error reading system prompt file: %v", err) + } + + systemPrompt := v.GetString("systemPrompt") + if systemPrompt == "" { + return "", fmt.Errorf("systemPrompt field not found in config file") + } + + return systemPrompt, nil } - systemPrompt := v.GetString("systemPrompt") - if systemPrompt == "" { - return "", fmt.Errorf("systemPrompt field not found in config file") - } - - return systemPrompt, nil + // Treat as direct string + return input, nil } // createDefaultConfig creates a default .mcphost.yml file in the user's home directory