ScanWorkflowsForMCP scans workflow files for MCP configurations Returns metadata for workflows that contain MCP servers
(workflowsDir string, serverFilter string, verbose bool)
| 24 | // ScanWorkflowsForMCP scans workflow files for MCP configurations |
| 25 | // Returns metadata for workflows that contain MCP servers |
| 26 | func 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 | } |