Skip to content

--tools alone exits with "Cannot use both --tools and --toolsets flags together" #379

@sebin

Description

@sebin

Summary

Passing only --tools (without --toolsets) on the command line causes the server to exit immediately with:

Cannot use both --tools and --toolsets flags together

Repro

$ go build -o ./terraform-mcp-server ./cmd/terraform-mcp-server/
$ ./terraform-mcp-server --tools=search_providers,get_provider_details
time="..." level=fatal msg="Cannot use both --tools and --toolsets flags together"
$ echo $?
1

The same Fatal fires whether the transport is stdio, the streamable-http subcommand, or the env-var-driven HTTP path (TRANSPORT_MODE=streamable-http ./terraform-mcp-server --tools=...).

Root cause

getToolsetsFromCmd in cmd/terraform-mcp-server/main.go reads the --toolsets value with GetString and rejects anything that is non-empty and not "default":

toolsetsFlag, _ := cmd.Flags().GetString("toolsets")
if toolsetsFlag == "" {
    toolsetsFlag, _ = cmd.Root().PersistentFlags().GetString("toolsets")
}
if toolsetsFlag != "" && toolsetsFlag != "default" {
    logger.Fatal("Cannot use both --tools and --toolsets flags together")
}

The --toolsets persistent flag is declared with default "all" in init.go. GetString returns the default when the user has not passed the flag, so the check fires whenever the operator passes only --tools.

Workaround: pass --toolsets="" explicitly along with --tools=....

Suggested fix

Use pflag.Flag.Changed, which is true only when the operator set the flag on the command line. That maps 1:1 to the intent of the check ("did the user pass --toolsets?") without coupling to the declared default.

I have a fix prepared in #380.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions