package cmd import ( "context" "fmt" "os" "github.com/spf13/cobra" "github.com/spf13/viper" "gmgauthier.com/grokkit/internal/logger" "gmgauthier.com/grokkit/internal/mcp" ) var mcpCmd = &cobra.Command{ Use: "mcp", Short: "Start Grokkit as an MCP (Model Context Protocol) server", Long: `Starts Grokkit in MCP server mode over stdio. This allows MCP-compatible clients (such as Claude Code, Cursor, or other AI coding agents) to call Grokkit tools like lint_code, analyze_code, generate_docs, etc. directly. The server runs until the client closes the connection.`, Run: runMCP, } func init() { rootCmd.AddCommand(mcpCmd) } func runMCP(cmd *cobra.Command, args []string) { logger.Info("mcp command started") // Check if MCP is enabled in config if !viper.GetBool("mcp.enabled") { fmt.Println("MCP is disabled in configuration.") os.Exit(0) } srv, err := mcp.NewServer() if err != nil { fmt.Fprintf(os.Stderr, "Failed to create MCP server: %v\n", err) os.Exit(1) } ctx := context.Background() if err := srv.Run(ctx); err != nil { fmt.Fprintf(os.Stderr, "MCP server error: %v\n", err) os.Exit(1) } }