Skip to content

Fix: --tools alone falsely flagged as conflicting with --toolsets#380

Open
sebin wants to merge 2 commits into
hashicorp:mainfrom
sebin:fix/toolsets-default-conflict
Open

Fix: --tools alone falsely flagged as conflicting with --toolsets#380
sebin wants to merge 2 commits into
hashicorp:mainfrom
sebin:fix/toolsets-default-conflict

Conversation

@sebin

@sebin sebin commented Jun 2, 2026

Copy link
Copy Markdown

Fixes #379.

Summary

getToolsetsFromCmd guards against passing both --tools and --toolsets at the same time. It does so by reading the --toolsets value with GetString and rejecting any value 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")
}

--toolsets is declared with default "all" in init.go. GetString returns the default when the operator has not passed the flag, so the check fires every time someone passes only --tools:

$ ./terraform-mcp-server --tools=search_providers
time="..." level=fatal msg="Cannot use both --tools and --toolsets flags together"

Change

Replace the value-based check with a pflag.Flag.Changed check. Changed is true only when the operator set the flag on the command line, which is precisely the condition the original check was reaching for. The intent (forbid passing both flags) is preserved; the false positive on the declared default goes away.

Diff is +8 / -5 in main.go and a new test file.

Verification

$ go build -o ./terraform-mcp-server ./cmd/terraform-mcp-server/

# Before
$ ./terraform-mcp-server stdio --tools=search_providers
level=fatal msg="Cannot use both --tools and --toolsets flags together"
# exit 1

# After
$ ./terraform-mcp-server stdio --tools=search_providers,get_provider_details
level=info msg="Enabled individual tools: [search_providers get_provider_details]"
Terraform MCP Server running on stdio

go test ./... passes (578/578).

Test plan

  • TestToolsFlagAloneDoesNotConflictWithDefaultToolsets — passes only --tools, asserts the Fatal is not triggered (uses a logrus ExitFunc override so a Fatal call would be observable without exiting the test binary).
  • TestToolsAndToolsetsTogetherTriggersFatal — locks the negative behavior down: passing both flags explicitly must still Fatal.
  • go test ./... — 578 pass.
  • Manual repro: ./terraform-mcp-server stdio --tools=search_providers now starts cleanly.

getToolsetsFromCmd guarded against passing both --tools and --toolsets at
the same time by reading the --toolsets value and rejecting any value
that was non-empty and not "default". The persistent flag is declared
with default "all", so GetString returns "all" even when the operator
did not pass --toolsets, and the check fires unconditionally:

    $ terraform-mcp-server --tools=search_providers
    Cannot use both --tools and --toolsets flags together

pflag exposes Changed, which is true only when the operator set the flag
on the command line. Switching the check to Changed tests the intended
condition ("did the user supply --toolsets?") without coupling to the
declared default.

Adds two tests: one for the bug scenario (only --tools), one locking the
intended negative behavior (both flags explicitly set still triggers
the Fatal). Both use a logrus ExitFunc override so Fatal does not
terminate the test binary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant