Skip to content

Commit

Permalink
Merge pull request #6 from wesen/task/add-repository-watcher
Browse files Browse the repository at this point in the history
Add direct tool access and repository watching
  • Loading branch information
wesen authored Feb 12, 2025
2 parents a060679 + 793f5c3 commit 7b9790d
Show file tree
Hide file tree
Showing 18 changed files with 729 additions and 207 deletions.
11 changes: 10 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/go-go-mcp",
"args": ["start", "--transport", "sse", "--profile", "all", "--log-level", "debug", "--port", "3000"],
"args": ["start", "--transport", "sse", "--profile", "html-extraction", "--log-level", "debug", "--port", "3000"],
"cwd": "${workspaceFolder}"
},
{
"name": "Add HTML Extraction Tool",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/go-go-mcp",
"args": ["config", "add-tool", "html-extraction", "--dir", "~/code/wesen/corporate-headquarters/go-go-mcp/examples/html-extract"],
"cwd": "${workspaceFolder}"
}
]
Expand Down
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,50 @@ go-go-mcp start --transport stdio
go-go-mcp start --transport sse --port 3001
```

The server automatically watches configured repositories and files for changes, reloading tools when:
- Files are added or removed from watched directories
- Tool configuration files are modified
- Repository structure changes

This allows for dynamic tool updates without server restarts.

#### Server Tools

You can interact with tools directly without starting a server using the `server tools` commands:

```bash
# List available tools using the 'all' profile
go-go-mcp server tools list --profile all

# List only system monitoring tools
go-go-mcp server tools list --profile system

# Call a tool directly
go-go-mcp server tools call system-monitor --args format=json,metrics=cpu,memory

# Call a tool with JSON arguments
go-go-mcp server tools call calendar-event --json '{
"title": "Team Meeting",
"start_time": "2024-02-01 10:00",
"duration": 60
}'
```

The available tools depend on the selected profile:
```bash
# System monitoring profile
go-go-mcp server tools list --profile system
# Shows: system-monitor, disk-usage, etc.

# Calendar profile
go-go-mcp server tools list --profile calendar
# Shows: calendar-event, calendar-availability, etc.

# Data analysis profile
go-go-mcp server tools list --profile data
# Shows: data-analyzer, data-visualizer, etc.
```

#### Client Mode

Use the client subcommand to interact with an MCP server:
Expand Down
27 changes: 26 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -1022,4 +1022,29 @@ Enhanced parameter validation to return cast values along with validation errors
- Modified `CheckValueValidity` to return both the cast value and any validation errors
- Added `setReflectValue` method to handle setting reflect values with proper type casting
- Updated tests to verify cast values
- Improved error messages for invalid choices
- Improved error messages for invalid choices

# 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

Improved code organization by moving tool provider creation to server layer package.

- 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

## Server Tools Commands

Added server-side tool management commands for direct interaction with tool providers.

- 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
25 changes: 0 additions & 25 deletions cmd/go-go-mcp/cmds/client/version.go

This file was deleted.

5 changes: 1 addition & 4 deletions cmd/go-go-mcp/cmds/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,7 @@ func NewConfigAddToolCommand() *cobra.Command {
}

if dir != "" {
err = editor.AddToolDirectory(args[0], dir, map[string]interface{}{
"debug": false,
"verbose": false,
})
err = editor.AddToolDirectory(args[0], dir, map[string]interface{}{})
if err != nil {
return fmt.Errorf("could not add tool directory: %w", err)
}
Expand Down
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 7b9790d

Please sign in to comment.