Skip to content

Commit 93978e1

Browse files
authored
Fix command processing (#172)
Signed-off-by: Juan Antonio Osorio <ozz@stacklok.com>
1 parent 627e87d commit 93978e1

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

cmd/thv/app/run.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ If not found, it will treat the argument as a Docker image and run it directly.
2727
The container will be started with minimal permissions and the specified transport mode.`,
2828
Args: cobra.MinimumNArgs(1),
2929
RunE: runCmdFunc,
30+
// Ignore unknown flags to allow passing flags to the MCP server
31+
FParseErrWhitelist: cobra.FParseErrWhitelist{
32+
UnknownFlags: true,
33+
},
3034
}
3135

3236
var (
@@ -92,9 +96,14 @@ func init() {
9296
}
9397

9498
func runCmdFunc(cmd *cobra.Command, args []string) error {
95-
// Get the server name or image and command arguments
99+
// Get the server name or image
96100
serverOrImage := args[0]
97-
cmdArgs := args[1:]
101+
102+
// Process command arguments using os.Args to find everything after --
103+
cmdArgs := parseCommandArguments(os.Args)
104+
105+
// Print the processed command arguments for debugging
106+
logger.Log.Info(fmt.Sprintf("Processed cmdArgs: %v", cmdArgs))
98107

99108
// Create context
100109
ctx, cancel := context.WithCancel(context.Background())
@@ -354,3 +363,17 @@ func logDebug(debugMode bool, format string, args ...interface{}) {
354363
logger.Log.Info(fmt.Sprintf(format+"", args...))
355364
}
356365
}
366+
367+
// parseCommandArguments processes command-line arguments to find everything after the -- separator
368+
// which are the arguments to be passed to the MCP server
369+
func parseCommandArguments(args []string) []string {
370+
var cmdArgs []string
371+
for i, arg := range args {
372+
if arg == "--" && i < len(args)-1 {
373+
// Found the separator, take everything after it
374+
cmdArgs = args[i+1:]
375+
break
376+
}
377+
}
378+
return cmdArgs
379+
}

cmd/thv/app/run_common.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ func detachProcess(cmd *cobra.Command, options *runner.RunConfig) error {
133133
// Add the image and any arguments
134134
detachedArgs = append(detachedArgs, options.Image)
135135
if len(options.CmdArgs) > 0 {
136+
detachedArgs = append(detachedArgs, "--")
136137
detachedArgs = append(detachedArgs, options.CmdArgs...)
137138
}
138139

0 commit comments

Comments
 (0)