string based system prompts

This commit is contained in:
Ed Zynda
2025-06-10 15:18:06 +03:00
parent cff5c2deda
commit 6a362d2f5e
2 changed files with 21 additions and 14 deletions
+1 -1
View File
@@ -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().
+20 -13
View File
@@ -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