Skip to content

Add five new analysis tools to drain3 shared agentic workflow and PR diagnostic reporting - #1963

Merged
pelikhan merged 6 commits into
mainfrom
copilot/add-tools-to-drain3-workflow
Oct 19, 2025
Merged

pelikhan merged 6 commits into
mainfrom
copilot/add-tools-to-drain3-workflow

Conversation

Copilot AI commented Oct 19, 2025 •

Copy link
Copy Markdown
Contributor
  • Explore repository structure and understand drain3 shared workflow
  • Review drain3_server.py implementation and test files
  • Build and test the project successfully
  • Add five new tools to drain3_server.py:
    • list_clusters - Enumerate all discovered log pattern clusters
    • cluster_stats - Retrieve metrics for a specific cluster (count, frequency, template)
    • find_anomalies - Detect outlier clusters or rare patterns (configurable threshold)
    • compare_runs - Compare two log files to identify added, removed, and changed clusters
    • search_pattern - Search logs for specific text/regex patterns, returning matching clusters
  • Update drain3.md shared workflow to include new tools in allowed list
  • Update dev.md to import mcp-debug.md for testing
  • Update test_drain3_server.py to validate new tools
  • Test the implementation (syntax validation, structure validation, compilation)
  • Run final validation (agent-finish) - all checks pass
  • Remove Jupyter import from dev.md per feedback and recompile
  • Add report_diagnostics_to_pull_request safe-output job to mcp-debug.md
  • Update dev.md to analyze Go source files using drain3
  • Rewrite mcp-debug.md as AI agent prompt

Implementation Complete ✅

Successfully added 5 new tools to the drain3 MCP server and configured dev.md to demonstrate Go source code pattern analysis using drain3.

MCP Debug Enhancement

Added custom safe-output job report_diagnostics_to_pull_request to mcp-debug.md and rewrote the documentation as an AI agent prompt:

  • Safe-Output Job: Enables AI agents to post MCP diagnostic findings directly to pull requests

    • Takes a message string parameter containing the diagnostic report
    • Automatically resolves the PR associated with the triggering branch using GitHub REST API
    • Posts the diagnostic message as a comment on the resolved PR
    • Configured with contents: read and pull-requests: write permissions
    • Supports staged mode for preview without posting
    • Gracefully handles cases where no PR is found
  • Prompt-Oriented Documentation: Rewrote mcp-debug.md from user manual to AI agent instructions

    • Changed from documentation style to direct agent prompt ("You are an expert MCP server debugger...")
    • Removed "Integration with Workflows" section
    • Emphasized CRITICAL requirement to use report_diagnostics_to_pull_request safe-output for all diagnostic findings
    • Streamlined from 407 to ~280 lines, focusing on actionable debugging workflow
    • Provides structured JSON template for diagnostic reports with required sections (Issue, Root Cause, Evidence, Impact, Fix, Workaround)

Dev Workflow Enhancement

Updated dev.md to demonstrate drain3 capabilities with Go source code analysis:

  • Purpose: Changed from file size distribution analysis to Go code pattern analysis
  • Drain3 Integration: Imports both mcp-debug.md and drain3.md
  • Analysis Tasks: Uses drain3 tools to:
    • Extract code patterns from .go files using index_file
    • Enumerate discovered patterns with list_clusters
    • Detect anomalous patterns with find_anomalies
    • Search for specific patterns like error handling and logging with search_pattern
  • Output: Creates GitHub discussion with insights about code structure, consistency, and recommendations

This workflow serves as a practical demonstration of using drain3 for code pattern analysis and anomaly detection in software projects.

Original prompt

Add the following tools to the drain3 shared agentic workflow and configure dev.md for testing using mcp-debug.

Tool Description
list_clusters Enumerate all discovered log pattern clusters
cluster_stats Retrieve metrics for a specific cluster (count, frequency, timestamps, examples)
find_anomalies Detect outlier clusters or rare patterns that may indicate new issues
compare_runs Compare two log files or runs to identify added, removed, or changed clusters
search_pattern Search logs for specific text or regex patterns, returning matching clusters

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add tools for log pattern analysis to drain3 workflow Add five new analysis tools to drain3 shared agentic workflow Oct 19, 2025
Copilot AI requested a review from pelikhan October 19, 2025 00:51
Comment thread .github/workflows/dev.md Outdated
@@ -23,6 +23,7 @@ safe-outputs:

imports:
- shared/mcp/jupyter.md

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot remove Jupyter and recompile

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed Jupyter import from dev.md and recompiled the workflow successfully. The workflow now only imports mcp-debug.md for testing drain3 tools.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI requested a review from pelikhan October 19, 2025 01:16
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot add a custom safe output job to mcp-debug.md called "report_diagnostics_to_pull_request"

This tool/job takes a input message: string that will be posted as a comment on the pull request associated with the triggering branch.

The job should checkout sources, and use JavaScript actions/github-script to resolve the PR and post the comment. Setup permissions accordingly.

The purpose of the tool is to allow the mcp-debug findings to be posted on the pull request being worked on.

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot update dev.md to analyze .go source files using drain3.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Oct 19, 2025

Copy link
Copy Markdown
Contributor Author

@copilot add a custom safe output job to mcp-debug.md called "report_diagnostics_to_pull_request"

This tool/job takes a input message: string that will be posted as a comment on the pull request asso...

Added the report_diagnostics_to_pull_request safe-output job to mcp-debug.md in commit fd84e0a.

The job:

  • Takes a message input (string) for the diagnostic report
  • Checks out the repository using actions/checkout@v4
  • Uses actions/github-script@v8 to resolve the PR associated with the triggering branch
  • Posts the message as a comment on that PR
  • Has permissions: contents: read, pull-requests: write
  • Supports staged mode for preview
  • Handles cases where no PR is found (logs warning, continues without error)

Agent output format:

{
  "items": [{
    "type": "report_diagnostics_to_pull_request",
    "message": "## Diagnostic Report\n\n..."
  }]
}

Copilot AI changed the title Add five new analysis tools to drain3 shared agentic workflow Add five new analysis tools to drain3 shared agentic workflow and PR diagnostic reporting Oct 19, 2025
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Oct 19, 2025

Copy link
Copy Markdown
Contributor Author

@copilot update dev.md to analyze .go source files using drain3.

Updated dev.md to analyze Go source files using drain3 in commit 6b9ed91.

Changes:

  • Added shared/mcp/drain3.md to imports
  • Changed task from file size analysis to Go code pattern analysis
  • Workflow now uses drain3 tools (index_file, list_clusters, find_anomalies, search_pattern) to:
    • Extract code patterns from .go files
    • Identify common structures and idioms
    • Detect anomalous patterns
    • Search for specific patterns (error handling, logging, etc.)
  • Results posted to GitHub discussion with insights and recommendations

Comment thread .github/workflows/shared/mcp-debug.md Outdated
- Access to mcp-inspect tool for MCP server diagnostics
- Documentation for MCP debugging procedures
- Reference for common issues and solutions
- Safe-output job for posting diagnostic reports to pull requests

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot

  • remove integration with workflows
  • rewrite the markdown as prompt, not a user manual.

Insist on using the safe output with any diagnostics results.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewrote mcp-debug.md as an AI agent prompt in commit 7c5a8e7.

Changes:

  • Removed "Integration with Workflows" section
  • Rewritten as prompt: Changed from user manual to direct AI agent instructions ("You are an expert MCP server debugger...")
  • Emphasized safe-output: Added "CRITICAL" requirement stating agent MUST use report_diagnostics_to_pull_request for diagnostic findings
  • Streamlined: Reduced from 407 to ~280 lines, focusing on actionable debugging workflow
  • Structured output template: Provides clear JSON format for diagnostic reports with required sections (Issue, Root Cause, Evidence, Impact, Fix, Workaround)

… safe-output

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI requested a review from pelikhan October 19, 2025 03:23
@pelikhan
pelikhan marked this pull request as ready for review October 19, 2025 03:43
@github-actions

Copy link
Copy Markdown
Contributor

Agentic Changeset Generator triggered by this pull request.

@pelikhan
pelikhan merged commit 6369da1 into main Oct 19, 2025
16 checks passed
@pelikhan
pelikhan deleted the copilot/add-tools-to-drain3-workflow branch October 19, 2025 03:45
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.

2 participants