Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/metrics-collector.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion pkg/cli/mcp_list_tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,12 @@ The command will:

return ListToolsForMCP(workflowFile, serverFilter, verbose)
},
ValidArgsFunction: CompleteWorkflowNames,
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) > 0 {
return nil, cobra.ShellCompDirectiveNoFileComp
}
return CompleteWorkflowNames(cmd, args, toComplete)
},
Comment on lines +206 to +211
}

cmd.Flags().StringVar(&serverFilter, "server", "", "MCP server name to list tools for")
Expand Down
41 changes: 41 additions & 0 deletions pkg/cli/mcp_list_tools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/github/gh-aw/pkg/constants"
"github.com/github/gh-aw/pkg/parser"
"github.com/modelcontextprotocol/go-sdk/mcp"
"github.com/spf13/cobra"
)

func TestListToolsForMCP(t *testing.T) {
Expand Down Expand Up @@ -336,3 +337,43 @@ func TestNewMCPListToolsSubcommand(t *testing.T) {
t.Error("Expected 'server' flag to be marked as required")
}
}

func TestMCPListToolsValidArgsFunction(t *testing.T) {
cmd := NewMCPListToolsSubcommand()

t.Run("no_completions_when_first_arg_already_provided", func(t *testing.T) {
completions, directive := cmd.ValidArgsFunction(cmd, []string{"my-workflow"}, "")
if len(completions) != 0 {
t.Errorf("Expected no completions when first arg is already provided, got: %v", completions)
}
if directive != cobra.ShellCompDirectiveNoFileComp {
t.Errorf("Expected ShellCompDirectiveNoFileComp, got: %v", directive)
}
})

t.Run("completions_offered_for_first_arg", func(t *testing.T) {
// Set up a temporary workflow directory so CompleteWorkflowNames finds files.
tmpDir := testutil.TempDir(t, "test-*")
workflowsDir := filepath.Join(tmpDir, constants.GetWorkflowDir())
if err := os.MkdirAll(workflowsDir, 0755); err != nil {
t.Fatalf("Failed to create workflows dir: %v", err)
}
content := "---\nengine: copilot\n---\n# Workflow\n"
if err := os.WriteFile(filepath.Join(workflowsDir, "my-workflow.md"), []byte(content), 0644); err != nil {
t.Fatalf("Failed to write workflow file: %v", err)
}
origDir, err := os.Getwd()
if err != nil {
t.Fatalf("Failed to get current directory: %v", err)
}
defer os.Chdir(origDir)
if err := os.Chdir(tmpDir); err != nil {
t.Fatalf("Failed to change to temp directory: %v", err)
}

completions, _ := cmd.ValidArgsFunction(cmd, []string{}, "")
if len(completions) == 0 {
t.Error("Expected at least one completion for first positional arg when workflows exist")
}
})
}