Skip to content

Commit 876d852

Browse files
committed
Added the ability to test crd equivalence call from the CLI.
Fixes from feeedback. Added Compatible CLI command as well.
1 parent 3dca4db commit 876d852

File tree

4 files changed

+118
-0
lines changed

4 files changed

+118
-0
lines changed

.gemini/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"crd": {
1111
"command": "dev/mcp/crd-mcp-server",
1212
"args": [
13+
"stdio"
1314
]
1415
}
1516
}

dev/tools/crd-mcp-server/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ require (
3131
github.com/go-logr/logr v1.4.2 // indirect
3232
github.com/gogo/protobuf v1.3.2 // indirect
3333
github.com/google/uuid v1.6.0 // indirect
34+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
3435
github.com/invopop/jsonschema v0.13.0 // indirect
3536
github.com/json-iterator/go v1.1.12 // indirect
3637
github.com/mailru/easyjson v0.7.7 // indirect
@@ -39,6 +40,8 @@ require (
3940
github.com/modern-go/reflect2 v1.0.2 // indirect
4041
github.com/pkg/errors v0.9.1 // indirect
4142
github.com/spf13/cast v1.7.1 // indirect
43+
github.com/spf13/cobra v1.10.2 // indirect
44+
github.com/spf13/pflag v1.0.9 // indirect
4245
github.com/tidwall/gjson v1.18.0 // indirect
4346
github.com/tidwall/match v1.1.1 // indirect
4447
github.com/tidwall/pretty v1.2.1 // indirect

dev/tools/crd-mcp-server/go.sum

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/tools/crd-mcp-server/main.go

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
package main
1717

1818
import (
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

2729
const (
@@ -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+
5874
func 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

76181
func handleCheckEquivalence(arguments EquivalenceArguments) (*mcp_golang.ToolResponse, error) {

0 commit comments

Comments
 (0)