1616package main
1717
1818import (
19+ "context"
1920 "fmt"
2021 "os"
2122 "strings"
2223
2324 "github.com/metoro-io/mcp-golang"
2425 "github.com/metoro-io/mcp-golang/transport/stdio"
26+ "github.com/spf13/cobra"
2527)
2628
2729const (
@@ -55,7 +57,88 @@ type BackwardCompatArguments struct {
5557 Ref string `json:"ref" jsonschema:"description=Git ref for the old version (default: HEAD)."`
5658}
5759
60+ type StdioOptions struct {
61+ }
62+
63+ type EquivalentOptions struct {
64+ File string
65+ Ref string
66+ }
67+
68+ type CompatibleOptions struct {
69+ File string
70+ Ref string
71+ }
72+
73+
5874func main () {
75+ rootCmd := & cobra.Command {
76+ Use : "crd-mcp-server subcommand" ,
77+ Short : "crd-mcp-server is a MCP server for KCC handling of CRDs." ,
78+ }
79+
80+ rootCmd .AddCommand (BuildStdioCmd ())
81+ rootCmd .AddCommand (BuildEquivalentCmd ())
82+ rootCmd .AddCommand (BuildCompatibleCmd ())
83+
84+ if err := rootCmd .Execute (); err != nil {
85+ fmt .Fprintf (os .Stderr , "%v\n " , err )
86+ os .Exit (1 )
87+ }
88+ }
89+
90+ func BuildStdioCmd () * cobra.Command {
91+ var opts StdioOptions
92+ cmd := & cobra.Command {
93+ Use : "stdio" ,
94+ Short : "stdio" ,
95+ Example : `crd-mcp-server stdio` ,
96+ RunE : func (cmd * cobra.Command , args []string ) error {
97+ return RunStdio (cmd .Context (), & opts )
98+ },
99+ Args : cobra .ExactArgs (0 ),
100+ }
101+
102+ return cmd
103+ }
104+
105+ func BuildEquivalentCmd () * cobra.Command {
106+ var opts EquivalentOptions
107+ cmd := & cobra.Command {
108+ Use : "equivalent" ,
109+ Short : "CLI version of the equivalent MCP. Is the CRD equivalent to the older form?" ,
110+ Example : `crd-mcp-server equivalent` ,
111+ RunE : func (cmd * cobra.Command , args []string ) error {
112+ return RunEquivalent (cmd .Context (), & opts )
113+ },
114+ Args : cobra .ExactArgs (0 ),
115+ }
116+ cmd .Flags ().StringVarP (& opts .File , "file" , "" , opts .File , "Path to the CRD YAML file to check." )
117+ cmd .MarkFlagRequired ("file" )
118+ cmd .Flags ().StringVarP (& opts .Ref , "ref" , "" , "HEAD" , "Git ref for the old version (default: HEAD)." )
119+
120+ return cmd
121+ }
122+
123+ func BuildCompatibleCmd () * cobra.Command {
124+ var opts CompatibleOptions
125+ cmd := & cobra.Command {
126+ Use : "compatible" ,
127+ Short : "CLI version of the compatible MCP. Is the CRD backward compatible with the older form?" ,
128+ Example : `crd-mcp-server compatible` ,
129+ RunE : func (cmd * cobra.Command , args []string ) error {
130+ return RunCompatible (cmd .Context (), & opts )
131+ },
132+ Args : cobra .ExactArgs (0 ),
133+ }
134+ cmd .Flags ().StringVarP (& opts .File , "file" , "" , opts .File , "Path to the CRD YAML file to check." )
135+ cmd .MarkFlagRequired ("file" )
136+ cmd .Flags ().StringVarP (& opts .Ref , "ref" , "" , "HEAD" , "Git ref for the old version (default: HEAD)." )
137+
138+ return cmd
139+ }
140+
141+ func RunStdio (ctx context.Context , opts * StdioOptions ) error {
59142 done := make (chan struct {})
60143 server := mcp_golang .NewServer (stdio .NewStdioServerTransport ())
61144
@@ -71,6 +154,28 @@ func main() {
71154 }
72155
73156 <- done
157+
158+ return nil
159+ }
160+
161+ func RunEquivalent (ctx context.Context , opts * EquivalentOptions ) error {
162+ result , err := runEquivalenceCheck (opts .File , opts .Ref )
163+ if err != nil {
164+ fmt .Fprintf (os .Stderr , "Error: %v" , err )
165+ return err
166+ }
167+ fmt .Fprint (os .Stdout , result )
168+ return nil
169+ }
170+
171+ func RunCompatible (ctx context.Context , opts * CompatibleOptions ) error {
172+ result , err := runBackwardCompatCheck (opts .File , opts .Ref )
173+ if err != nil {
174+ fmt .Fprintf (os .Stderr , "Error: %v" , err )
175+ return err
176+ }
177+ fmt .Fprint (os .Stdout , result )
178+ return nil
74179}
75180
76181func handleCheckEquivalence (arguments EquivalenceArguments ) (* mcp_golang.ToolResponse , error ) {
0 commit comments