- Notifications
You must be signed in to change notification settings - Fork937
Adding SecretScanning Toolset#280
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
9 commits Select commitHold shift + click to select a range
f14f0b3
Adding GetSecretScanningAlert and ListSecretScanningAlerts
tonytrg5dbfaa8
adding wip for tests
tonytrg47fdf2e
fix tests
tonytrg6d3954d
Merge branch 'main' into tonytrg/add-secret-scanning-tools
tonytrg6c01bf9
add readme section
tonytrgbab315f
Update README.md
tonytrg5e2fa39
Update .gitignore
tonytrg7a4b0e9
fix product name
tonytrg037bbaf
Merge branch 'tonytrg/add-secret-scanning-tools' of github.com:github…
tonytrgFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
.idea | ||
cmd/github-mcp-server/github-mcp-server | ||
# VSCode | ||
.vscode/mcp.json | ||
# Added by goreleaser init: | ||
dist/ | ||
__debug_bin* | ||
# Go | ||
vendor |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
package github | ||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"github.com/github/github-mcp-server/pkg/translations" | ||
"github.com/google/go-github/v69/github" | ||
"github.com/mark3labs/mcp-go/mcp" | ||
"github.com/mark3labs/mcp-go/server" | ||
) | ||
func GetSecretScanningAlert(getClient GetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { | ||
return mcp.NewTool( | ||
"get_secret_scanning_alert", | ||
mcp.WithDescription(t("TOOL_GET_SECRET_SCANNING_ALERT_DESCRIPTION", "Get details of a specific secret scanning alert in a GitHub repository.")), | ||
mcp.WithString("owner", | ||
mcp.Required(), | ||
mcp.Description("The owner of the repository."), | ||
), | ||
mcp.WithString("repo", | ||
mcp.Required(), | ||
mcp.Description("The name of the repository."), | ||
), | ||
mcp.WithNumber("alertNumber", | ||
mcp.Required(), | ||
mcp.Description("The number of the alert."), | ||
), | ||
), | ||
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { | ||
owner, err := requiredParam[string](request, "owner") | ||
if err != nil { | ||
return mcp.NewToolResultError(err.Error()), nil | ||
} | ||
repo, err := requiredParam[string](request, "repo") | ||
if err != nil { | ||
return mcp.NewToolResultError(err.Error()), nil | ||
} | ||
alertNumber, err := RequiredInt(request, "alertNumber") | ||
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) | ||
} | ||
alert, resp, err := client.SecretScanning.GetAlert(ctx, owner, repo, int64(alertNumber)) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get alert: %w", err) | ||
} | ||
defer func() { _ = resp.Body.Close() }() | ||
if resp.StatusCode != http.StatusOK { | ||
body, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to read response body: %w", err) | ||
} | ||
return mcp.NewToolResultError(fmt.Sprintf("failed to get alert: %s", string(body))), nil | ||
} | ||
r, err := json.Marshal(alert) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to marshal alert: %w", err) | ||
} | ||
return mcp.NewToolResultText(string(r)), nil | ||
} | ||
} | ||
func ListSecretScanningAlerts(getClient GetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { | ||
return mcp.NewTool( | ||
"list_secret_scanning_alerts", | ||
mcp.WithDescription(t("TOOL_LIST_SECRET_SCANNING_ALERTS_DESCRIPTION", "List secret scanning alerts in a GitHub repository.")), | ||
mcp.WithString("owner", | ||
mcp.Required(), | ||
mcp.Description("The owner of the repository."), | ||
), | ||
mcp.WithString("repo", | ||
mcp.Required(), | ||
mcp.Description("The name of the repository."), | ||
), | ||
mcp.WithString("state", | ||
mcp.Description("Filter by state"), | ||
mcp.Enum("open", "resolved"), | ||
), | ||
mcp.WithString("secret_type", | ||
mcp.Description("A comma-separated list of secret types to return. All default secret patterns are returned. To return generic patterns, pass the token name(s) in the parameter."), | ||
), | ||
mcp.WithString("resolution", | ||
mcp.Description("Filter by resolution"), | ||
mcp.Enum("false_positive", "wont_fix", "revoked", "pattern_edited", "pattern_deleted", "used_in_tests"), | ||
), | ||
), | ||
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { | ||
owner, err := requiredParam[string](request, "owner") | ||
if err != nil { | ||
return mcp.NewToolResultError(err.Error()), nil | ||
} | ||
repo, err := requiredParam[string](request, "repo") | ||
if err != nil { | ||
return mcp.NewToolResultError(err.Error()), nil | ||
} | ||
state, err := OptionalParam[string](request, "state") | ||
if err != nil { | ||
return mcp.NewToolResultError(err.Error()), nil | ||
} | ||
secretType, err := OptionalParam[string](request, "secret_type") | ||
if err != nil { | ||
return mcp.NewToolResultError(err.Error()), nil | ||
} | ||
resolution, err := OptionalParam[string](request, "resolution") | ||
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.SecretScanning.ListAlertsForRepo(ctx, owner, repo, &github.SecretScanningAlertListOptions{State: state, SecretType: secretType, Resolution: resolution}) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to list alerts: %w", err) | ||
} | ||
defer func() { _ = resp.Body.Close() }() | ||
if resp.StatusCode != http.StatusOK { | ||
body, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to read response body: %w", err) | ||
} | ||
return mcp.NewToolResultError(fmt.Sprintf("failed to list alerts: %s", string(body))), nil | ||
} | ||
r, err := json.Marshal(alerts) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to marshal alerts: %w", err) | ||
} | ||
return mcp.NewToolResultText(string(r)), nil | ||
} | ||
} |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.