Skip to content

Commit

Permalink
✨ Add config file support
Browse files Browse the repository at this point in the history
  • Loading branch information
wesen committed Feb 11, 2025
1 parent 2b7ae23 commit 03ac5da
Show file tree
Hide file tree
Showing 20 changed files with 1,371 additions and 1,285 deletions.
137 changes: 46 additions & 91 deletions cmd/go-go-mcp/cmds/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,15 @@ import (
"syscall"
"time"

cmds2 "github.com/go-go-golems/go-go-mcp/pkg/cmds"
"github.com/go-go-golems/go-go-mcp/pkg/tools/examples"

"github.com/go-go-golems/clay/pkg/repositories"
"github.com/go-go-golems/glazed/pkg/cmds"
"github.com/go-go-golems/glazed/pkg/cmds/layers"
"github.com/go-go-golems/glazed/pkg/cmds/parameters"
"github.com/go-go-golems/glazed/pkg/help"
"github.com/go-go-golems/go-go-mcp/pkg/prompts"
"github.com/go-go-golems/go-go-mcp/pkg/protocol"
"github.com/go-go-golems/go-go-mcp/pkg/resources"
"github.com/go-go-golems/go-go-mcp/pkg/server"
"github.com/go-go-golems/go-go-mcp/pkg/tools"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"

"github.com/go-go-golems/go-go-mcp/pkg/config"
)

type StartCommandSettings struct {
Expand All @@ -31,6 +26,8 @@ type StartCommandSettings struct {
Repositories []string `glazed.parameter:"repositories"`
Debug bool `glazed.parameter:"debug"`
TracingDir string `glazed.parameter:"tracing-dir"`
ConfigFile string `glazed.parameter:"config-file" help:"Path to the configuration file"`
Profile string `glazed.parameter:"profile" help:"Profile to use from the configuration file"`
}

type StartCommand struct {
Expand Down Expand Up @@ -78,8 +75,19 @@ Available transports:
parameters.WithHelp("Directory to store tool call traces"),
parameters.WithDefault(""),
),
parameters.NewParameterDefinition(
"config-file",
parameters.ParameterTypeString,
parameters.WithHelp("Path to the configuration file"),
parameters.WithDefault(""),
),
parameters.NewParameterDefinition(
"profile",
parameters.ParameterTypeString,
parameters.WithHelp("Profile to use from the configuration file"),
parameters.WithDefault(""),
),
),
cmds.WithLayersList(),
),
}, nil
}
Expand All @@ -95,68 +103,34 @@ func (c *StartCommand) Run(

// Create server
srv := server.NewServer(log.Logger)
promptRegistry := prompts.NewRegistry()
resourceRegistry := resources.NewRegistry()
toolRegistry := tools.NewRegistry()

// Register a simple prompt directly
promptRegistry.RegisterPrompt(protocol.Prompt{
Name: "simple",
Description: "A simple prompt that can take optional context and topic arguments",
Arguments: []protocol.PromptArgument{
{
Name: "context",
Description: "Additional context to consider",
Required: false,
},
{
Name: "topic",
Description: "Specific topic to focus on",
Required: false,
},
},
})

// Register registries with the server
srv.GetRegistry().RegisterPromptProvider(promptRegistry)
srv.GetRegistry().RegisterResourceProvider(resourceRegistry)
srv.GetRegistry().RegisterToolProvider(toolRegistry)

// Register tools (DON'T DELETE)
if err := examples.RegisterEchoTool(toolRegistry); err != nil {
log.Error().Err(err).Msg("Error registering echo tool")
return err
}
if err := examples.RegisterFetchTool(toolRegistry); err != nil {
log.Error().Err(err).Msg("Error registering fetch tool")
return err
// Create tool provider options
toolProviderOptions := []config.ConfigToolProviderOption{
config.WithDebug(s.Debug),
}
if err := examples.RegisterSQLiteTool(toolRegistry); err != nil {
log.Error().Err(err).Msg("Error registering sqlite tool")
return err
if s.TracingDir != "" {
toolProviderOptions = append(toolProviderOptions, config.WithTracingDir(s.TracingDir))
}
// if err := cursor.RegisterCursorTools(toolRegistry); err != nil {
// log.Error().Err(err).Msg("Error registering cursor tools")
// return err
// }

// Register the weather tool (DO NOT DELETE)
// weatherTool, err := tools.NewReflectTool(
// "getWeather",
// "Get weather information for a city",
// getWeather,
// )
// if err != nil {
// log.Error().Err(err).Msg("Error creating weather tool")
// return err
// }
// toolRegistry.RegisterTool(weatherTool)
// Handle configuration file if provided
if s.ConfigFile != "" {
cfg, err := config.LoadFromFile(s.ConfigFile)
if err != nil {
return errors.Wrap(err, "failed to load configuration file")
}

// Determine profile
profile := s.Profile
if profile == "" {
profile = cfg.DefaultProfile
}

toolProviderOptions = append(toolProviderOptions, config.WithConfig(cfg, profile))
}

// Load shell commands from repositories
// Handle repository directories
if len(s.Repositories) > 0 {
loader := &cmds2.ShellCommandLoader{}
directories := []repositories.Directory{}

for _, repoPath := range s.Repositories {
dir := os.ExpandEnv(repoPath)
// check if dir exists
Expand All @@ -175,36 +149,17 @@ func (c *StartCommand) Run(
}

if len(directories) > 0 {
repo := repositories.NewRepository(
repositories.WithDirectories(directories...),
repositories.WithCommandLoader(loader),
)

helpSystem := help.NewHelpSystem()
err := repo.LoadCommands(helpSystem)
if err != nil {
log.Error().Err(err).Msg("Error loading shell commands from repositories")
return err
}

commands := repo.CollectCommands([]string{}, true)
log.Info().Int("count", len(commands)).Msg("Loaded shell commands from repositories")
for _, cmd := range commands {
log.Debug().Str("name", cmd.Description().Name).Msg("Loaded shell command")
}

toolProvider, err := cmds2.NewShellToolProvider(commands,
cmds2.WithDebug(s.Debug),
cmds2.WithTracingDir(s.TracingDir),
)
if err != nil {
log.Error().Err(err).Msg("Error creating shell tool provider")
return err
}
srv.GetRegistry().RegisterToolProvider(toolProvider)
toolProviderOptions = append(toolProviderOptions, config.WithDirectories(directories))
}
}

// Create and register tool provider
toolProvider, err := config.NewConfigToolProvider(toolProviderOptions...)
if err != nil {
return errors.Wrap(err, "failed to create tool provider")
}
srv.GetRegistry().RegisterToolProvider(toolProvider)

// Create root context with cancellation
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down
4 changes: 2 additions & 2 deletions cmd/go-go-mcp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ func initRootCmd() (*help.HelpSystem, error) {
// Create and add start command
startCmd, err := server_cmds.NewStartCommand()
cobra.CheckErr(err)
cobraStartCmd, err := cli.BuildCobraCommandFromBareCommand(startCmd)
cobraStartCmd, err := cli.BuildCobraCommandFromBareCommand(startCmd, cli.WithSkipGlazedCommandLayer())
cobra.CheckErr(err)
rootCmd.AddCommand(cobraStartCmd)

// Create and add schema command
schemaCmd, err := server_cmds.NewSchemaCommand()
cobra.CheckErr(err)
cobraSchemaCmd, err := cli.BuildCobraCommandFromWriterCommand(schemaCmd)
cobraSchemaCmd, err := cli.BuildCobraCommandFromWriterCommand(schemaCmd, cli.WithSkipGlazedCommandLayer())
cobra.CheckErr(err)
rootCmd.AddCommand(cobraSchemaCmd)

Expand Down
114 changes: 114 additions & 0 deletions examples/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
version: "1"
defaultProfile: default

profiles:
default:
description: "Default profile with basic tools"
tools:
directories:
- path: ./examples/shell-commands
defaults:
default:
debug: false
verbose: false
files:
- path: ./examples/smart-connect/read.yaml

productivity:
description: "Tools for productivity and note-taking"
tools:
directories:
- path: ./examples/smart-connect
defaults:
default:
verbose: true
blacklist:
default:
- api_key
files:
- path: ./examples/smart-connect/read.yaml
overrides:
default:
verbose: true

research:
description: "Tools for research and data extraction"
tools:
directories:
- path: ./examples/html-extract
defaults:
default:
timeout: 30s
max_retries: 3
- path: ./examples/bio-stuff
defaults:
default:
cache_results: true
files:
- path: ./examples/html-extract/pubmed.yaml
overrides:
default:
max_results: 100

google-integration:
description: "Google and GitHub integration tools"
tools:
directories:
- path: ./examples/google
defaults:
default:
cache_credentials: true
blacklist:
default:
- client_secret
- refresh_token
whitelist:
default:
- query
- max_results
- start_date
- end_date

rag:
description: "RAG and knowledge management tools"
tools:
directories:
- path: ./examples/rag
defaults:
ai-chat:
model: gpt-4-turbo
max_tokens: 2000
overrides:
ai-chat:
temperature: 0.7
- path: ./examples/prompts/rag.yaml
defaults:
default:
verbose: true

devops:
description: "Development and operations tools"
tools:
directories:
- path: ./examples/shell-commands
defaults:
default:
debug: true
verbose: true
whitelist:
default:
- command
- args
- working_dir
- timeout
blacklist:
default:
- env
files:
- path: ./examples/shell-commands/docker-comp.yaml
- path: ./examples/shell-commands/git-sync.yaml
- path: ./examples/shell-commands/backup-db.yaml
overrides:
default:
timeout: 300s
max_retries: 5
23 changes: 23 additions & 0 deletions examples/html-extract/pubmed.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: pubmed-search
short: Search PubMed and extract structured data
long: |
Search PubMed using a search term and extract structured data from the results page.
Uses html-selector to parse the HTML and extract relevant information.
flags:
- name: search_term
type: string
help: PubMed search term
required: true
- name: max_pages
type: int
help: Maximum number of pages to scrape
default: 1

command:
- html-selector
- select
- --urls
- "https://pubmed.ncbi.nlm.nih.gov/?term={{ .Args.search_term }}"
- --config
- "/tmp/html-extraction-2025-01-26-19-54-54.yaml"
15 changes: 15 additions & 0 deletions examples/prompto/prompto-get.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: prompto-get
short: Get a specific prompto entry
long: |
Retrieves a specific prompto entry by its name.
This command wraps the 'prompto get' command.
flags:
- name: entry_name
type: string
help: Name of the prompto entry to retrieve
required: true
command:
- prompto
- get
- "{{ .Args.entry_name }}"
capture-stderr: true
9 changes: 9 additions & 0 deletions examples/prompto/prompto-list.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: prompto-list
short: List all prompto entries
long: |
Lists all available prompto entries in a formatted output.
This command wraps the 'prompto list' command.
command:
- prompto
- list
capture-stderr: true
Loading

0 comments on commit 03ac5da

Please sign in to comment.