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

Function ScanWorkflowsForMCP

pkg/cli/mcp_workflow_scanner.go:26–87  ·  view source on GitHub ↗

ScanWorkflowsForMCP scans workflow files for MCP configurations Returns metadata for workflows that contain MCP servers

(workflowsDir string, serverFilter string, verbose bool)

Source from the content-addressed store, hash-verified

24// ScanWorkflowsForMCP scans workflow files for MCP configurations
25// Returns metadata for workflows that contain MCP servers
26func ScanWorkflowsForMCP(workflowsDir string, serverFilter string, verbose bool) ([]WorkflowMCPMetadata, error) {
27 mcpWorkflowScannerLog.Printf("Scanning workflows for MCP configurations: dir=%s, filter=%s", workflowsDir, serverFilter)
28 // Check if the workflows directory exists
29 if _, err := os.Stat(workflowsDir); os.IsNotExist(err) {
30 mcpWorkflowScannerLog.Printf("Workflows directory not found: %s", workflowsDir)
31 return nil, fmt.Errorf("workflows directory not found: %s", workflowsDir)
32 }
33
34 // Find all .md files in the workflows directory
35 files, err := filepath.Glob(filepath.Join(workflowsDir, "*.md"))
36 if err != nil {
37 mcpWorkflowScannerLog.Printf("Failed to search for workflow files: %v", err)
38 return nil, fmt.Errorf("failed to search for workflow files: %w", err)
39 }
40
41 // Filter out README.md files
42 files = filterWorkflowFiles(files)
43
44 mcpWorkflowScannerLog.Printf("Found %d workflow files to scan", len(files))
45 var results []WorkflowMCPMetadata
46
47 for _, file := range files {
48 content, err := os.ReadFile(file)
49 if err != nil {
50 if verbose {
51 fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Skipping %s: %v", filepath.Base(file), err)))
52 }
53 continue
54 }
55
56 frontmatterData, err := parser.ExtractFrontmatterFromContent(string(content))
57 if err != nil {
58 if verbose {
59 fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Skipping %s: %v", filepath.Base(file), err)))
60 }
61 continue
62 }
63
64 mcpConfigs, err := parser.ExtractMCPConfigurations(frontmatterData.Frontmatter, serverFilter)
65 if err != nil {
66 if verbose {
67 fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Error extracting MCP from %s: %v", filepath.Base(file), err)))
68 }
69 continue
70 }
71
72 if len(mcpConfigs) > 0 {
73 baseName := normalizeWorkflowID(file)
74 mcpWorkflowScannerLog.Printf("Found MCP configuration in %s: %d servers", filepath.Base(file), len(mcpConfigs))
75 results = append(results, WorkflowMCPMetadata{
76 FilePath: file,
77 FileName: filepath.Base(file),
78 BaseName: baseName,
79 MCPConfigs: mcpConfigs,
80 Frontmatter: frontmatterData.Frontmatter,
81 })
82 }
83 }

Callers 4

listWorkflowsWithMCPFunction · 0.85
TestScanWorkflowsForMCPFunction · 0.85

Calls 7

FormatWarningMessageFunction · 0.92
ExtractMCPConfigurationsFunction · 0.92
filterWorkflowFilesFunction · 0.85
normalizeWorkflowIDFunction · 0.85
PrintfMethod · 0.45
ErrorfMethod · 0.45

Tested by 1

TestScanWorkflowsForMCPFunction · 0.68