Skip to content

Commit

Permalink
✨ Add shell command
Browse files Browse the repository at this point in the history
  • Loading branch information
wesen committed Jan 24, 2025
1 parent c53e70c commit 6135ea9
Show file tree
Hide file tree
Showing 11 changed files with 1,537 additions and 173 deletions.
67 changes: 21 additions & 46 deletions cmd/mcp-client/main.go
Original file line number Diff line number Diff line change
@@ -1,48 +1,36 @@
package main

import (
"fmt"
"os"

clay "github.com/go-go-golems/clay/pkg"
"github.com/go-go-golems/glazed/pkg/help"
"github.com/spf13/cobra"

// Import the cmds package
"github.com/go-go-golems/go-go-mcp/cmd/mcp-client/cmds"
"github.com/spf13/cobra"
)

var (
// Version information
Version = "dev"
BuildTime = "unknown"
GitCommit = "none"

// Command flags
debug bool
logLevel string
withCaller bool

// Operation flags
promptArgs string
toolArgs string
)

var rootCmd = &cobra.Command{
Use: "mcp-client",
Short: "MCP client implementation in Go",
}

func main() {
rootCmd := &cobra.Command{
Use: "mcp-client",
Short: "MCP client CLI",
Long: `A Model Context Protocol (MCP) client CLI implementation.
Supports both stdio and SSE transports for client-server communication.`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
// reinitialize the logger because we can now parse --log-level and co
// from the command line flag
err := clay.InitLogger()
cobra.CheckErr(err)
helpSystem, err := initRootCmd()
cobra.CheckErr(err)

},
}
err = initAllCommands(helpSystem)
cobra.CheckErr(err)

err = rootCmd.Execute()
cobra.CheckErr(err)
}

func initRootCmd() (*help.HelpSystem, error) {
helpSystem := help.NewHelpSystem()
helpSystem.SetupCobraRootCommand(rootCmd)

Expand All @@ -51,27 +39,14 @@ Supports both stdio and SSE transports for client-server communication.`,
err = clay.InitLogger()
cobra.CheckErr(err)

// Add persistent flags
rootCmd.PersistentFlags().StringP("transport", "t", "command", "Transport type (command or sse)")
rootCmd.PersistentFlags().StringP("server", "s", "http://localhost:3001", "Server URL for SSE transport")
rootCmd.PersistentFlags().StringSliceP("command", "c", []string{"mcp-server", "start", "--transport", "stdio"}, "Command and arguments for command transport (first argument is the command)")

// Add all command groups to root command
// Remove existing subcommand additions
// rootCmd.AddCommand(promptsCmd)
// rootCmd.AddCommand(toolsCmd)
// rootCmd.AddCommand(resourcesCmd)
// rootCmd.AddCommand(versionCmd)
return helpSystem, nil
}

// Add subcommands from cmds package
rootCmd.AddCommand(cmds.PromptsCmd)
func initAllCommands(_ *help.HelpSystem) error {
// Add existing commands
rootCmd.AddCommand(cmds.ToolsCmd)
rootCmd.AddCommand(cmds.ResourcesCmd)
rootCmd.AddCommand(cmds.VersionCmd)
rootCmd.AddCommand(cmds.PromptsCmd)

// Execute
if err := rootCmd.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
return nil
}
Loading

0 comments on commit 6135ea9

Please sign in to comment.