Skip to content

Add Serena MCP duplicate code detector workflow with Docker container support#1293

Merged
pelikhan merged 9 commits intomainfrom
copilot/add-mcp-docker-workflow
Oct 7, 2025
Merged

Add Serena MCP duplicate code detector workflow with Docker container support#1293
pelikhan merged 9 commits intomainfrom
copilot/add-mcp-docker-workflow

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 7, 2025

This PR adds a new agentic workflow that uses the Serena MCP server running in a Docker container to analyze commits to the main branch and detect duplicated code patterns in Go files.

Overview

The workflow leverages Serena's semantic code analysis capabilities to identify various types of code duplication:

  • Exact duplication (identical code blocks)
  • Structural duplication (same logic with minor variations)
  • Functional duplication (different implementations of the same functionality)
  • Copy-paste programming patterns

When significant duplication is found, the workflow automatically creates a GitHub issue with detailed findings, including specific file locations, severity assessment, and refactoring recommendations.

Key Changes

1. New Duplicate Code Detection Workflow

Added .github/workflows/duplicate-code-detector.md which:

  • Triggers on pushes to the main branch when Go files (**.go) are modified
  • Supports manual execution via workflow_dispatch trigger
  • Uses Serena MCP server in a Docker container for semantic code analysis
  • Analyzes changed files for duplication patterns
  • Automatically creates GitHub issues via safe-outputs when duplication is detected
  • Provides comprehensive instructions to the AI agent on detection strategies and reporting

2. Enhanced Container Support

Fixed container image pattern in schema to support version tags:

  • Updated regex pattern from ^[a-zA-Z0-9][a-zA-Z0-9/_.-]*$ to ^[a-zA-Z0-9][a-zA-Z0-9/:_.-]*$
  • Now allows container images like ghcr.io/oraios/serena:latest (with colons)
  • Previously only docker.io/mcp/brave-search (without tags) worked

Added version field for container-based MCP servers:

  • MCP servers can now specify container version/tag separately using the version field
  • Provides cleaner separation between image name and version
  • Backward compatible - version tags can still be included in the container field directly

Added support for custom Docker arguments:

  • MCP servers using the container field can now specify custom args for advanced Docker configurations
  • Custom args are inserted into the docker run command after environment variables but before the container image
  • Enables volume mounts, working directory configuration, and other Docker run flags

Example:

mcp-servers:
  serena:
    container: "ghcr.io/oraios/serena"
    version: "latest"
    args:
      - "-v"
      - "${{ github.workspace }}:/workspace:ro"
      - "-w"
      - "/workspace"
    env:
      SERENA_DOCKER: "1"
    allowed: ["read_file", "find_symbol"]

Generates:

docker run --rm -i -e SERENA_DOCKER -v $WORKSPACE:/workspace:ro -w /workspace ghcr.io/oraios/serena:latest

3. Documentation and Tests

  • Added comprehensive documentation in docs/src/content/docs/guides/mcps.md explaining custom Docker args and the version field
  • Added unit tests in pkg/workflow/mcp_container_args_test.go to verify the new functionality including version field handling
  • All existing tests continue to pass, ensuring backward compatibility

Why These Changes?

The Serena MCP server is a powerful code analysis tool that requires access to the codebase when running in Docker. Previously, there was no way to mount the repository directory into the container, making it impossible to use containerized code analysis tools effectively. This PR enables that use case while maintaining the security and isolation benefits of Docker containers.

The addition of the version field provides a cleaner way to specify container versions separately from the image name, making configurations more maintainable and following best practices for container image management.

Testing

  • ✅ All 59 existing workflows compile successfully
  • ✅ Unit tests pass (including new tests for custom args and version field)
  • ✅ Schema validation passes
  • make agent-finish completes successfully
  • ✅ Code formatting and linting checks pass

Resolves the requirement to add an agentic workflow using Serena MCP Docker with the container feature.

Original prompt

Add agentic workflow that uses Serena MCP docker (using container feature) to analyze the changes in commits to main and detect duplicated code.

https://raw.githubusercontent.com/oraios/serena/main/DOCKER.md


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits October 7, 2025 05:22
… in schema

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
engine: copilot
mcp-servers:
serena:
container: "ghcr.io/oraios/serena:latest"
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 use version field to specify "latest" and make sure the docker container contains the image name and version.

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.

Updated in commit 1117412. The workflow now uses container: "ghcr.io/oraios/serena" with version: "latest" as a separate field. The compiler automatically appends the version to create the full image reference ghcr.io/oraios/serena:latest.

Copilot AI and others added 2 commits October 7, 2025 05:34
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
… support

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add agentic workflow to analyze commit changes Add Serena MCP duplicate code detector workflow with Docker container support Oct 7, 2025
Copilot AI requested a review from pelikhan October 7, 2025 05:37
Comment thread .github/workflows/duplicate-code-detector.md
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Comment thread .github/workflows/duplicate-code-detector.md
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI requested a review from pelikhan October 7, 2025 06:26
@pelikhan pelikhan marked this pull request as ready for review October 7, 2025 06:29
@pelikhan pelikhan merged commit c3c00d2 into main Oct 7, 2025
23 of 32 checks passed
@pelikhan pelikhan deleted the copilot/add-mcp-docker-workflow branch October 7, 2025 06:29
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