-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.go
More file actions
45 lines (38 loc) · 1.03 KB
/
start.go
File metadata and controls
45 lines (38 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package cobrax
import (
"log/slog"
"github.com/spf13/cobra"
)
// startCommandFlags holds flags for the start command.
type startCommandFlags struct {
logLevel string
}
// startCommand creates the 'mcp start' command.
func startCommand(config *Config) *cobra.Command {
f := &startCommandFlags{}
cmd := &cobra.Command{
Use: "start",
Short: "Start the MCP server",
Long: `Start stdio server to expose CLI commands to AI assistants`,
RunE: func(cmd *cobra.Command, _ []string) error {
if config == nil {
config = &Config{}
}
if f.logLevel != "" {
level := parseLogLevel(f.logLevel)
// Ensure SloggerOptions is initialized
if config.SloggerOptions == nil {
config.SloggerOptions = &slog.HandlerOptions{}
}
// Set the log level based on the flag
config.SloggerOptions.Level = level
}
// Create and start the server
return config.serveStdio(cmd)
},
}
// Add flags
flags := cmd.Flags()
flags.StringVar(&f.logLevel, "log-level", "", "Log level (debug, info, warn, error)")
return cmd
}