Skip to content

Commit

Permalink
✨ Add tools list to call server side commands immediately
Browse files Browse the repository at this point in the history
  • Loading branch information
wesen committed Feb 12, 2025
1 parent 50073e1 commit bf9b8c8
Show file tree
Hide file tree
Showing 9 changed files with 410 additions and 153 deletions.
71 changes: 10 additions & 61 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -1027,75 +1027,24 @@ Enhanced parameter validation to return cast values along with validation errors
# Improved YAML Editor Value Node Creation

Refactored YAML editor to have a more maintainable and recursive value node creation system:

- Extracted value node creation logic into a dedicated CreateValueNode method
- Made value creation process recursive for nested structures
- Improved error handling with more specific error messages
- Centralized value node creation logic for better maintainability

# Refactor Tool Provider Creation

Extracted tool provider creation logic from start command to config package for better code organization and reusability.

- Moved tool provider creation logic to pkg/tools/providers/config/
- Added CreateToolProviderFromConfig and CreateToolProviderFromDirectories functions
- Simplified start command by using the new functions

# Move Tool Provider to Dedicated Package

Moved the configuration-based tool provider to a dedicated package for better code organization.

- Moved tool provider code to pkg/tools/providers/config/
- Updated imports and type references
- Improved package documentation

# Documentation: Repository System Guide

Added comprehensive documentation for the repository system, including:
- Basic usage guide
- File system watching
- Command organization
- Advanced features and best practices
- Common patterns and examples

# File Watching Support for ConfigToolProvider

Added file watching support to automatically reload commands when files change in watched directories.

- Added Watch method to ConfigToolProvider for monitoring file changes
- Added WithWatch option to enable/disable file watching
- Automatically reload commands when files are changed or removed
- Support for watching multiple directories simultaneously

# Simplified File Watching Implementation

Refactored file watching to use Clay repository's built-in functionality:

- Removed custom file watching implementation in favor of repository's built-in watching
- Simplified ConfigToolProvider by removing watch-specific fields
- Improved code maintainability by reducing duplication
- Maintained thread safety with mutex protection

# Consistent Path Processing in Repository Watcher

Refactored path processing in repository watcher to use a shared helper function, ensuring consistent path handling across all operations.

- Extracted path processing logic into getProcessedPaths helper method
- Reused path processing in both write and remove callbacks
- Improved code maintainability by reducing duplication
- Maintained consistent path handling for command operations

## Add support for individual files in Repository
Improved code organization by moving tool provider creation to server layer package.

Added ability to load commands from individual files in Repository, alongside directories. This allows for more flexible command loading configurations.
- Moved tool provider creation to server layer package for better organization
- Made CreateToolProvider a public function for reuse
- Updated start command to use the new package function

- Added Files field to Repository struct
- Added WithFiles repository option
- Updated LoadCommands to handle individual files
- Updated LoadCommandsFromInputs to use file support
## Server Tools Commands

## Use Repository File Support in ConfigToolProvider
Added server-side tool management commands for direct interaction with tool providers.

Updated ConfigToolProvider to use the Repository's built-in file support instead of handling files manually:
- Removed manual file loading in ConfigToolProvider
- Use WithFiles repository option for individual files
- Simplified code by leveraging Repository functionality
- Added `server tools list` command to list available tools directly from tool provider
- Added `server tools call` command to call tools directly without starting the server
- Reused server layer for configuration consistency
108 changes: 108 additions & 0 deletions cmd/go-go-mcp/cmds/server/layers/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package layers

import (
"fmt"
"os"

"github.com/go-go-golems/glazed/pkg/cmds/layers"
"github.com/go-go-golems/glazed/pkg/cmds/parameters"
"github.com/go-go-golems/go-go-mcp/pkg/config"
config_provider "github.com/go-go-golems/go-go-mcp/pkg/tools/providers/config-provider"
"github.com/pkg/errors"
)

type ServerSettings struct {
Repositories []string `glazed.parameter:"repositories"`
ConfigFile string `glazed.parameter:"config-file"`
Profile string `glazed.parameter:"profile"`
Debug bool `glazed.parameter:"debug"`
TracingDir string `glazed.parameter:"tracing-dir"`
}

const ServerLayerSlug = "mcp-server"

func NewServerParameterLayer() (layers.ParameterLayer, error) {
defaultConfigFile, err := config.GetDefaultProfilesPath()
if err != nil {
return nil, errors.Wrap(err, "failed to get default profiles path")
}

return layers.NewParameterLayer(ServerLayerSlug, "MCP Server Settings",
layers.WithParameterDefinitions(
parameters.NewParameterDefinition(
"repositories",
parameters.ParameterTypeStringList,
parameters.WithHelp("List of directories containing shell command repositories"),
parameters.WithDefault([]string{}),
),
parameters.NewParameterDefinition(
"config-file",
parameters.ParameterTypeString,
parameters.WithHelp("Path to the configuration file"),
parameters.WithDefault(defaultConfigFile),
),
parameters.NewParameterDefinition(
"profile",
parameters.ParameterTypeString,
parameters.WithHelp("Profile to use from the configuration file"),
parameters.WithDefault(""),
),
parameters.NewParameterDefinition(
"debug",
parameters.ParameterTypeBool,
parameters.WithHelp("Enable debug mode for shell tool provider"),
parameters.WithDefault(false),
),
parameters.NewParameterDefinition(
"tracing-dir",
parameters.ParameterTypeString,
parameters.WithHelp("Directory to store tool call traces"),
parameters.WithDefault(""),
),
),
)
}

// CreateToolProvider creates a tool provider from the given server settings
func CreateToolProvider(serverSettings *ServerSettings) (*config_provider.ConfigToolProvider, error) {
// Create tool provider options
toolProviderOptions := []config_provider.ConfigToolProviderOption{
config_provider.WithDebug(serverSettings.Debug),
config_provider.WithWatch(true),
}
if serverSettings.TracingDir != "" {
toolProviderOptions = append(toolProviderOptions, config_provider.WithTracingDir(serverSettings.TracingDir))
}

var toolProvider *config_provider.ConfigToolProvider
var err error

// Try to create tool provider from config file first
if serverSettings.ConfigFile != "" {
toolProvider, err = config_provider.CreateToolProviderFromConfig(
serverSettings.ConfigFile,
serverSettings.Profile,
toolProviderOptions...)
if err != nil {
if !os.IsNotExist(err) || len(serverSettings.Repositories) == 0 {
fmt.Fprintf(os.Stderr, "Run 'go-go-mcp config init' to create a starting configuration file, and further edit it with 'go-go-mcp config edit'\n")
return nil, errors.Wrap(err, "failed to create tool provider from config")
}
// Config file doesn't exist but we have repositories, continue with directories
}
}

// If no tool provider yet and we have repositories, create from directories
if toolProvider == nil && len(serverSettings.Repositories) > 0 {
toolProvider, err = config_provider.CreateToolProviderFromDirectories(serverSettings.Repositories, toolProviderOptions...)
if err != nil {
return nil, errors.Wrap(err, "failed to create tool provider from directories")
}
}

if toolProvider == nil {
return nil, fmt.Errorf("no valid configuration source found (neither config file nor repositories)")
}

return toolProvider, nil
}
16 changes: 16 additions & 0 deletions cmd/go-go-mcp/cmds/server/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package server

import (
"github.com/spf13/cobra"
)

// ServerCmd is the root command for server-related operations
var ServerCmd = &cobra.Command{
Use: "server",
Short: "Server management commands",
Long: `Commands for managing the MCP server, including starting the server and managing tools.`,
}

func init() {
ServerCmd.AddCommand(ToolsCmd)
}
Loading

0 comments on commit bf9b8c8

Please sign in to comment.