Skip to content

Commit eda7280

Browse files
authored
Guard list_code_scanning_alerts workflow usage to prevent MCP context overflow (#27657)
1 parent a835285 commit eda7280

3 files changed

Lines changed: 12 additions & 5 deletions

File tree

.github/workflows/code-scanning-fixer.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ You are a security-focused code analysis agent that automatically fixes code sca
6060

6161
Your goal is to:
6262
1. **Check cache for previously fixed alerts**: Avoid fixing the same alert multiple times
63-
2. **List all open alerts**: Find all open code scanning alerts (prioritizing by severity: critical, high, medium, low, warning, note, error)
63+
2. **List open high-risk alerts**: Find open critical/high code scanning alerts (prioritizing critical over high)
6464
3. **Select an unfixed alert**: Pick the highest severity unfixed alert that hasn't been fixed recently
6565
4. **Analyze the vulnerability**: Understand the security issue and its context
6666
5. **Generate a fix**: Create code changes that address the security issue
@@ -84,15 +84,18 @@ Use the GitHub MCP server to list all open code scanning alerts:
8484
- `owner`: "githubnext" (the repository owner)
8585
- `repo`: "gh-aw" (the repository name)
8686
- `state`: "open"
87-
- Do NOT filter by severity - get all alerts
87+
- `severity`: "critical,high" (required to prevent oversized MCP responses)
88+
- Medium/low/warning/note/error are intentionally excluded in this workflow so each run stays within MCP context limits
89+
- Do NOT send `head_limit` to the default GitHub MCP tool (`list_code_scanning_alerts` does not support it)
90+
- If using a custom wrapper that explicitly documents `head_limit`, you may use `head_limit: 20`
8891
- Sort the results by severity (prioritize: critical > high > medium > low > warning > note > error)
8992
- If no open alerts are found, log "No unfixed security alerts found. All alerts have been addressed!" and exit gracefully
9093
- If you encounter tool errors, report them clearly and exit gracefully rather than trying workarounds
9194
- Create a list of alert numbers from the results, sorted by severity (highest first)
9295

9396
### 3. Select an Unfixed Alert
9497

95-
From the list of all open alerts (sorted by severity):
98+
From the list of open high-risk alerts (sorted by severity):
9699
- Exclude any alert numbers that are in the cache (already fixed)
97100
- Select the first alert from the filtered list (highest severity unfixed alert)
98101
- If no unfixed alerts remain, exit gracefully with message: "No unfixed security alerts found. All alerts have been addressed!"
@@ -189,7 +192,7 @@ After successfully creating the pull request:
189192

190193
## Security Guidelines
191194

192-
- **All Severity Levels**: Fix security alerts of all severities (prioritizing critical, high, medium, low, warning, note, error in that order)
195+
- **High-Risk Only**: This workflow only processes critical/high alerts to keep MCP responses bounded and actionable
193196
- **Minimal Changes**: Make only the changes necessary to fix the security issue
194197
- **No Breaking Changes**: Ensure the fix doesn't break existing functionality
195198
- **Best Practices**: Follow security best practices for the specific vulnerability type

.github/workflows/github-mcp-structural-analysis.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ Test ONE representative tool from each toolset with minimal parameters:
7575
3. **issues**: `list_issues` - List issues with perPage=1
7676
4. **pull_requests**: `list_pull_requests` - List PRs with perPage=1
7777
5. **actions**: `list_workflows` - List workflows with perPage=1
78-
6. **code_security**: `list_code_scanning_alerts` - List alerts with minimal params
78+
6. **code_security**: `list_code_scanning_alerts`
79+
- Required guard params: `state: open`, `severity: critical,high`
80+
- `head_limit` note: the GitHub MCP server's `list_code_scanning_alerts` tool does not support `head_limit`; use `head_limit: 20` only with custom wrappers that explicitly document support
7981
7. **discussions**: `list_discussions` (if available)
8082
8. **labels**: `get_label` - Get a single label
8183
9. **users**: `get_user` (if available)

AGENTS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ network:
166166
- **Never use `mode: remote`** — it does not work with the GitHub Actions token (`GITHUB_TOKEN`) and requires a special PAT or GitHub App token
167167
- Never rely on direct `api.github.com` access in Copilot workflows
168168
- **Never use direct GitHub CLI API reads in agent prompts** (for example: `gh api`, `gh repo view`, `gh pr list`) — use MCP `github` tools instead
169+
- **Guard `list_code_scanning_alerts` calls in workflow prompts**: always include `state: open` and `severity: critical,high` to avoid oversized MCP responses
170+
- **`head_limit` compatibility**: do **not** send `head_limit` to the default GitHub MCP tool; use `head_limit: 20` only with custom wrappers after verifying support in wrapper docs or wrapper-specific tests
169171

170172
See [GitHub MCP Server Documentation](skills/github-mcp-server/SKILL.md) for complete configuration details.
171173

0 commit comments

Comments
 (0)