-
Notifications
You must be signed in to change notification settings - Fork 43
Add Semgrep MCP shared workflow and daily security scan #11454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
| ## Semgrep MCP Server | ||
|
|
||
| Semgrep is a fast, open-source static analysis tool for finding bugs, detecting security vulnerabilities, and enforcing code standards. It supports multiple languages and custom rules. | ||
|
|
||
| ### Available Tools | ||
|
|
||
| The Semgrep MCP server provides the following tools for code analysis: | ||
|
|
||
| - **semgrep_rule_schema**: Retrieves the schema required to write a Semgrep rule, lists available fields, and verifies rule syntax | ||
| - **get_supported_languages**: Lists all programming languages supported by Semgrep | ||
| - **semgrep_scan**: Scans code files for security vulnerabilities, bugs, and code quality issues using default rules | ||
| - **semgrep_scan_local**: Performs scans on local files and returns results in JSON format | ||
| - **semgrep_scan_with_custom_rule**: Runs a scan using a custom rule on provided code and returns findings | ||
| - **semgrep_findings**: Fetches findings from the Semgrep AppSec Platform API (requires Semgrep Cloud authentication) | ||
|
|
||
| ### Basic Usage | ||
|
|
||
| To use Semgrep in your workflow, simply import this shared configuration: | ||
|
|
||
| ```yaml | ||
| imports: | ||
| - shared/mcp/semgrep.md | ||
| ``` | ||
|
|
||
| The MCP server will enable the agent to perform static analysis on code, including: | ||
| - Security vulnerability detection | ||
| - Bug finding | ||
| - Code quality checks | ||
| - Custom rule validation | ||
| - Language-specific pattern matching | ||
|
|
||
| ### Example Patterns | ||
|
|
||
| **Security Scanning:** | ||
| ``` | ||
| Use semgrep to scan the repository for SQL injection vulnerabilities | ||
| ``` | ||
|
|
||
| **Custom Rule Testing:** | ||
| ``` | ||
| Test this custom Semgrep rule against the code in src/auth.go | ||
| ``` | ||
|
|
||
| **Language Support:** | ||
| ``` | ||
| Check which languages are supported by Semgrep for our multi-language repository | ||
| ``` | ||
|
|
||
| ### More Information | ||
|
|
||
| - Official Documentation: https://semgrep.dev/docs/ | ||
| - Rule Examples: https://semgrep.dev/explore | ||
| - Writing Rules: https://semgrep.dev/docs/writing-rules/overview | ||
| - Supported Languages: https://semgrep.dev/docs/supported-languages | ||
| - Docker Image: https://hub.docker.com/r/semgrep/semgrep |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot this is a help manual for a editing agent but not the prompt. Make it a xml comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Converted the documentation section to XML comment block (similar to arxiv.md pattern). The help manual is now wrapped in <!-- --> and won't be visible to agents. Fixed in commit f233069.
Address PR feedback - wrap help manual in XML comment block Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
@copilot review agentic workflows and import semgrep where appropriate |
Import shared/mcp/semgrep.md in 6 workflows: - static-analysis-report.md: Enhance static analysis with semgrep - daily-malicious-code-scan.md: Add semgrep for malicious pattern detection - code-scanning-fixer.md: Enable semgrep for automated security fixes - security-fix-pr.md: Add semgrep for security vulnerability analysis - code-simplifier.md: Use semgrep for code quality improvements - go-fan.md: Add semgrep for Go code analysis Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Reviewed and added semgrep import to 6 security and code quality workflows:
All workflows compile successfully with the semgrep MCP server configured. Fixed in commit 1cc4977. |
| reviewers: [copilot] | ||
| timeout-minutes: 20 | ||
| imports: | ||
| - shared/mcp/semgrep.md |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Revert changes to this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted. Removed semgrep import from code-scanning-fixer.md in commit 2f43e27.
.github/workflows/go-fan.md
Outdated
| - go | ||
|
|
||
| imports: | ||
| - shared/mcp/semgrep.md |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Revert changes to this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted. Removed semgrep import from go-fan.md in commit 2f43e27.
.github/workflows/security-fix-pr.md
Outdated
| autofix-code-scanning-alert: | ||
| max: 5 | ||
| timeout-minutes: 20 | ||
| imports: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Revert changes to this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted. Removed semgrep import from security-fix-pr.md in commit 2f43e27.
| strict: true | ||
| imports: | ||
| - shared/mcp/gh-aw.md | ||
| - shared/mcp/semgrep.md |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Revert changes to this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted. Removed semgrep import from static-analysis-report.md in commit 2f43e27.
Remove shared/mcp/semgrep.md import from: - code-scanning-fixer.md - go-fan.md - security-fix-pr.md - static-analysis-report.md As requested in PR review feedback. Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
pelikhan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add daily semgrep workflow
imports:
- shared/mcp/semgrep.md
on: daily !
workflow_dispatch:
Scan the repository for SQL injection vulnerabilities using Semgrep.
.github/workflows/code-simplifier.md
Outdated
| tracker-id: code-simplifier | ||
|
|
||
| imports: | ||
| - shared/mcp/semgrep.md |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot revert file changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted. Removed semgrep import from code-simplifier.md in commit 7dc9b70.
| timeout-minutes: 15 | ||
| strict: true | ||
| imports: | ||
| - shared/mcp/semgrep.md |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot revert file changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted. Removed semgrep import from daily-malicious-code-scan.md in commit 7dc9b70.
- Removed semgrep import from code-simplifier.md - Removed semgrep import from daily-malicious-code-scan.md - Created new daily-semgrep-scan.md workflow for SQL injection scanning As requested in PR feedback. Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Created daily-semgrep-scan.md workflow with daily schedule and workflow_dispatch trigger. The workflow scans for SQL injection vulnerabilities using Semgrep. Fixed in commit 7dc9b70. |
| schedule: daily | ||
| workflow_dispatch: | ||
| permissions: | ||
| contents: read |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot use crate code scanning alert safe output to publish results
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added code scanning alert safe output configuration to daily-semgrep-scan.md:
- Added
security-events: readpermission - Configured
create-code-scanning-alertwith driver "Semgrep Security Scanner"
Semgrep findings will now be published as code scanning alerts. Fixed in commit 0b9228f.
Configure daily-semgrep-scan.md to publish results as code scanning alerts: - Added security-events: read permission - Added safe-outputs with create-code-scanning-alert configuration - Set driver name to "Semgrep Security Scanner" As requested in PR feedback. Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Plan: Add Semgrep MCP Shared Workflow
.github/workflows/shared/mcp/semgrep.mdsemgrep/semgrepimageentrypointArgswith["semgrep", "mcp", "-t", "stdio"]for MCP interfaceChanges
Created Shared MCP Configuration
.github/workflows/shared/mcp/semgrep.mdsemgrep/semgrep:latestsemgrep mcp -t stdioviaentrypointArgssemgrep_scan,semgrep_scan_local,semgrep_scan_with_custom_rule,get_supported_languages,semgrep_rule_schema,semgrep_findingsCreated Daily Semgrep Workflow
.github/workflows/daily-semgrep-scan.mdUsage
Workflows can now use Semgrep for static analysis by importing the shared configuration:
The MCP gateway spawns the Semgrep container with stdio transport, making all security scanning capabilities available to agents through the Model Context Protocol. Results are published as code scanning alerts for easy tracking and remediation in GitHub's Security tab.
Original prompt
💡 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.