Skip to content

Add Tool Name property for List Code Scanning Alerts tool #272

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

Merged
merged 8 commits into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ export GITHUB_MCP_TOOL_ADD_ISSUE_COMMENT_DESCRIPTION="an alternative description
- `ref`: Git reference (string, optional)
- `state`: Alert state (string, optional)
- `severity`: Alert severity (string, optional)
- `tool_name`: The name of the tool used for code scanning (string, optional)

## Resources

Expand Down
9 changes: 8 additions & 1 deletion pkg/github/code_scanning.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@
mcp.WithString("severity",
mcp.Description("Only code scanning alerts with this severity will be returned. Possible values are: critical, high, medium, low, warning, note, error."),
),
mcp.WithString("tool_name",
mcp.Description("The name of the tool used for code scanning."),
),
),
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
owner, err := requiredParam[string](request, "owner")
Expand All @@ -114,12 +117,16 @@
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
tool_name, err := OptionalParam[string](request, "tool_name")

Check failure on line 120 in pkg/github/code_scanning.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: don't use underscores in Go names; var tool_name should be toolName (revive)

Check failure on line 120 in pkg/github/code_scanning.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: don't use underscores in Go names; var tool_name should be toolName (revive)
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}

client, err := getClient(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get GitHub client: %w", err)
}
alerts, resp, err := client.CodeScanning.ListAlertsForRepo(ctx, owner, repo, &github.AlertListOptions{Ref: ref, State: state, Severity: severity})
alerts, resp, err := client.CodeScanning.ListAlertsForRepo(ctx, owner, repo, &github.AlertListOptions{Ref: ref, State: state, Severity: severity, ToolName: tool_name})
if err != nil {
return nil, fmt.Errorf("failed to list alerts: %w", err)
}
Expand Down
19 changes: 11 additions & 8 deletions pkg/github/code_scanning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func Test_ListCodeScanningAlerts(t *testing.T) {
assert.Contains(t, tool.InputSchema.Properties, "ref")
assert.Contains(t, tool.InputSchema.Properties, "state")
assert.Contains(t, tool.InputSchema.Properties, "severity")
assert.Contains(t, tool.InputSchema.Properties, "tool_name")
assert.ElementsMatch(t, tool.InputSchema.Required, []string{"owner", "repo"})

// Setup mock alerts for success case
Expand Down Expand Up @@ -159,20 +160,22 @@ func Test_ListCodeScanningAlerts(t *testing.T) {
mock.WithRequestMatchHandler(
mock.GetReposCodeScanningAlertsByOwnerByRepo,
expectQueryParams(t, map[string]string{
"ref": "main",
"state": "open",
"severity": "high",
"ref": "main",
"state": "open",
"severity": "high",
"tool_name": "CodeQL",
}).andThen(
mockResponse(t, http.StatusOK, mockAlerts),
),
),
),
requestArgs: map[string]interface{}{
"owner": "owner",
"repo": "repo",
"ref": "main",
"state": "open",
"severity": "high",
"owner": "owner",
"repo": "repo",
"ref": "main",
"state": "open",
"severity": "high",
"tool_name": "CodeQL",
},
expectError: false,
expectedAlerts: mockAlerts,
Expand Down
Loading