Draft
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new MCP tool to let users report a security vulnerability for a repository by creating a private security advisory in “triage” state, integrating it into the existing Security Advisories toolset and documentation.
Changes:
- Registers a new
report_security_vulnerabilitytool in the global tool inventory. - Implements the tool handler and input schema in
security_advisories.go. - Adds unit tests, toolsnap snapshot, and README tool documentation for the new tool.
Show a summary per file
| File | Description |
|---|---|
| pkg/github/tools.go | Registers the new tool in AllTools. |
| pkg/github/security_advisories.go | Implements ReportSecurityVulnerability tool schema + handler logic. |
| pkg/github/security_advisories_test.go | Adds tests for tool schema snapshot + handler behavior. |
| pkg/github/toolsnaps/report_security_vulnerability.snap | Adds schema snapshot for the new tool. |
| README.md | Documents the new tool and its parameters/scopes. |
Copilot's findings
Comments suppressed due to low confidence (1)
pkg/github/security_advisories.go:707
- API failures from
client.Doare returned as a Go error (fmt.Errorf("failed to report security vulnerability: %w", err)), while most tools return an MCP error result viaghErrors.NewGitHubAPIErrorResponse(...)to preserve error details in-context and keep handler errors (errreturn) reserved for unexpected/internal failures. Also note that withgithub.Client.Do, non-2xx responses typically come back aserr != nil, so theresp.StatusCode != http.StatusCreatedbranch is effectively dead for 4xx/5xx and may not capture the response body as intended.
var advisory github.SecurityAdvisory
resp, err := client.Do(ctx, req, &advisory)
if err != nil {
return nil, nil, fmt.Errorf("failed to report security vulnerability: %w", err)
}
defer func() { _ = resp.Body.Close() }()
if resp.StatusCode != http.StatusCreated {
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, nil, fmt.Errorf("failed to read response body: %w", err)
}
return ghErrors.NewGitHubAPIStatusErrorResponse(ctx, "failed to report security vulnerability", resp, body), nil, nil
}
- Files reviewed: 5/5 changed files
- Comments generated: 3
Comment on lines
+722
to
+730
| // For validation errors, err is nil but result.IsError is true | ||
| // For API errors, err is not nil | ||
| if err != nil { | ||
| assert.Contains(t, err.Error(), tc.expectedErrMsg) | ||
| } else { | ||
| require.True(t, result.IsError) | ||
| text := getTextResult(t, result).Text | ||
| assert.Contains(t, text, tc.expectedErrMsg) | ||
| } |
|
|
||
| client, err := deps.GetClient(ctx) | ||
| if err != nil { | ||
| return nil, nil, fmt.Errorf("failed to get GitHub client: %w", err) |
Comment on lines
+636
to
+680
| // Handle vulnerabilities array | ||
| if vulnsData, ok := args["vulnerabilities"]; ok { | ||
| if vulnsArray, ok := vulnsData.([]any); ok { | ||
| var vulnerabilities []*github.AdvisoryVulnerability | ||
| for _, v := range vulnsArray { | ||
| if vulnMap, ok := v.(map[string]any); ok { | ||
| vuln := &github.AdvisoryVulnerability{} | ||
|
|
||
| // Parse package | ||
| if pkgData, ok := vulnMap["package"].(map[string]any); ok { | ||
| pkg := &github.VulnerabilityPackage{} | ||
| if ecosystem, ok := pkgData["ecosystem"].(string); ok { | ||
| pkg.Ecosystem = &ecosystem | ||
| } | ||
| if name, ok := pkgData["name"].(string); ok { | ||
| pkg.Name = &name | ||
| } | ||
| vuln.Package = pkg | ||
| } | ||
|
|
||
| // Parse other fields | ||
| if versionRange, ok := vulnMap["vulnerable_version_range"].(string); ok { | ||
| vuln.VulnerableVersionRange = &versionRange | ||
| } | ||
| if patchedVersions, ok := vulnMap["patched_versions"].(string); ok { | ||
| vuln.PatchedVersions = &patchedVersions | ||
| } | ||
| if vulnFuncs, ok := vulnMap["vulnerable_functions"].([]any); ok { | ||
| var functions []string | ||
| for _, f := range vulnFuncs { | ||
| if funcStr, ok := f.(string); ok { | ||
| functions = append(functions, funcStr) | ||
| } | ||
| } | ||
| if len(functions) > 0 { | ||
| vuln.VulnerableFunctions = functions | ||
| } | ||
| } | ||
|
|
||
| vulnerabilities = append(vulnerabilities, vuln) | ||
| } | ||
| } | ||
| report.Vulnerabilities = &vulnerabilities | ||
| } | ||
| } |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
A
Why
Fixes #
What changed
MCP impact
Prompts tested (tool changes only)
Security / limits
Tool renaming
deprecated_tool_aliases.goNote: if you're renaming tools, you must add the tool aliases. For more information on how to do so, please refer to the official docs.
Lint & tests
./script/lint./script/testDocs