MCPcopy Create free account
hub / github.com/github/gh-aw / validateMCPServerConfiguration

Function validateMCPServerConfiguration

pkg/cli/mcp_validation.go:173–225  ·  view source on GitHub ↗

validateMCPServerConfiguration validates that the CLI is properly configured by running the status command as a test. Diagnostics are emitted through the debug logger only.

(ctx context.Context, cmdPath string, env []string)

Source from the content-addressed store, hash-verified

171// by running the status command as a test.
172// Diagnostics are emitted through the debug logger only.
173func validateMCPServerConfiguration(ctx context.Context, cmdPath string, env []string) error {
174 mcpValidationLog.Printf("Validating MCP server configuration: cmdPath=%s", cmdPath)
175
176 // Determine, log, and validate the binary path only if --cmd flag is not provided
177 // When --cmd is provided, the user explicitly specified the binary path to use
178 if cmdPath == "" {
179 // Attempt to detect the binary path and assign it to cmdPath
180 // This ensures the validation uses the actual binary path instead of falling back to "gh aw"
181 detectedPath, err := logAndValidateBinaryPath()
182 if err == nil && detectedPath != "" {
183 cmdPath = detectedPath
184 }
185 }
186
187 // Try to run the status command to verify CLI is working
188 ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
189 defer cancel()
190
191 var cmd *exec.Cmd
192 if cmdPath != "" {
193 mcpValidationLog.Printf("Using custom command path: %s", cmdPath)
194 // Use custom command path
195 cmd = exec.CommandContext(ctx, cmdPath, "status")
196 } else {
197 mcpValidationLog.Print("Using default gh aw command with proper token handling")
198 // Use default gh aw command with proper token handling
199 cmd = workflow.ExecGHContext(ctx, "aw", "status")
200 }
201 if env != nil {
202 cmd.Env = append([]string(nil), env...)
203 }
204 output, err := runMCPSubprocessCombinedOutput(ctx, cmd)
205
206 if err != nil {
207 // Check for common error cases
208 if errors.Is(ctx.Err(), context.DeadlineExceeded) {
209 mcpValidationLog.Print("Status command timed out")
210 return errors.New("status command timed out - this may indicate a configuration issue")
211 }
212
213 mcpValidationLog.Printf("Status command failed: %v", err)
214
215 // If the command failed, provide helpful error message
216 if cmdPath != "" {
217 return fmt.Errorf("failed to run status command with custom command '%s': %w\nOutput: %s\n\nPlease ensure:\n - The command path is correct and executable\n - You are in a git repository with .github/workflows directory", cmdPath, err, string(output))
218 }
219 return fmt.Errorf("failed to run status command: %w\nOutput: %s\n\nPlease ensure:\n - gh CLI is installed and in PATH\n - gh aw extension is installed (run: gh extension install github/gh-aw)\n - You are in a git repository with .github/workflows directory", err, string(output))
220 }
221
222 // Status command succeeded - configuration is valid
223 mcpValidationLog.Print("MCP server configuration validated successfully")
224 return nil
225}
226
227// validateMCPWorkflowName validates that a workflow name exists in the repository.
228// Returns nil if the workflow exists, or an error with suggestions if not.

Callers 1

runMCPServerFunction · 0.85

Calls 6

ExecGHContextFunction · 0.92
logAndValidateBinaryPathFunction · 0.85
PrintMethod · 0.80
PrintfMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected