Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,15 @@ For negotiated supported protocol versions `2026-07-28` or newer, the consolidat
- `owner`: The owner of the repository. (string, required)
- `repo`: The name of the repository. (string, required)

- **list_code_quality_findings** - List code quality findings
- **OAuth Challenge Scopes**: `repo`
- `after`: Cursor for pagination. Use the cursor from the previous response. (string, optional)
- `direction`: Sort by creation date: `desc` (newest first, default) or `asc` (oldest first). (string, optional)
- `owner`: The owner of the repository. (string, required)
- `perPage`: Results per page for pagination (min 1, max 100) (number, optional)
- `repo`: The name of the repository. (string, required)
- `state`: Filter code quality findings by state. Defaults to open (string, optional)

</details>

<details>
Expand Down
222 changes: 222 additions & 0 deletions pkg/github/__toolsnaps__/list_code_quality_findings.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
{
"annotations": {
"idempotentHint": false,
"readOnlyHint": true,
"title": "List code quality findings"
},
"description": "List code quality findings in a GitHub repository.",
"inputSchema": {
"properties": {
"after": {
"description": "Cursor for pagination. Use the cursor from the previous response.",
"type": "string"
},
"direction": {
"description": "Sort by creation date: `desc` (newest first, default) or `asc` (oldest first).",
"enum": [
"asc",
"desc"
],
"type": "string"
},
"owner": {
"description": "The owner of the repository.",
"type": "string"
},
"perPage": {
"description": "Results per page for pagination (min 1, max 100)",
"maximum": 100,
"minimum": 1,
"type": "number"
},
"repo": {
"description": "The name of the repository.",
"type": "string"
},
"state": {
"default": "open",
"description": "Filter code quality findings by state. Defaults to open",
"enum": [
"open",
"dismissed"
],
"type": "string"
}
},
"required": [
"owner",
"repo"
],
"type": "object"
},
"name": "list_code_quality_findings",
"outputSchema": {
"additionalProperties": false,
"properties": {
"findings": {
"items": {
"additionalProperties": false,
"properties": {
"created_at": {
"description": "Finding creation time (RFC 3339).",
"type": [
"null",
"string"
]
},
"location": {
"additionalProperties": false,
"properties": {
"end_column": {
"type": [
"null",
"integer"
]
},
"end_line": {
"type": [
"null",
"integer"
]
},
"path": {
"type": [
"null",
"string"
]
},
"start_column": {
"type": [
"null",
"integer"
]
},
"start_line": {
"type": [
"null",
"integer"
]
}
},
"type": [
"null",
"object"
]
},
"message": {
"additionalProperties": false,
"properties": {
"markdown": {
"type": "string"
},
"text": {
"type": "string"
}
},
"required": [
"text",
"markdown"
],
"type": [
"null",
"object"
]
},
"number": {
"type": [
"null",
"integer"
]
},
"rule": {
"additionalProperties": false,
"properties": {
"category": {
"type": [
"null",
"string"
]
},
"description": {
"type": [
"null",
"string"
]
},
"help": {
"type": [
"null",
"string"
]
},
"id": {
"type": [
"null",
"string"
]
},
"severity": {
"type": [
"null",
"string"
]
},
"title": {
"type": [
"null",
"string"
]
}
},
"type": [
"null",
"object"
]
},
"state": {
"type": [
"null",
"string"
]
}
},
"type": [
"null",
"object"
]
},
"type": [
"null",
"array"
]
},
"pageInfo": {
"additionalProperties": false,
"properties": {
"hasNextPage": {
"type": "boolean"
},
"hasPreviousPage": {
"type": "boolean"
},
"nextCursor": {
"type": "string"
},
"prevCursor": {
"type": "string"
}
},
"required": [
"hasNextPage",
"hasPreviousPage"
],
"type": "object"
}
},
"required": [
"findings",
"pageInfo"
],
"type": "object"
}
}
135 changes: 135 additions & 0 deletions pkg/github/code_quality.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import (
"fmt"
"io"
"net/http"
"net/url"
"strconv"

"github.com/google/jsonschema-go/jsonschema"
"github.com/modelcontextprotocol/go-sdk/mcp"

ghErrors "github.com/github/github-mcp-server/v2/pkg/errors"
"github.com/github/github-mcp-server/v2/pkg/ifc"
"github.com/github/github-mcp-server/v2/pkg/inventory"
"github.com/github/github-mcp-server/v2/pkg/scopes"
"github.com/github/github-mcp-server/v2/pkg/translations"
Expand Down Expand Up @@ -99,6 +102,138 @@ func GetCodeQualityFinding(t translations.TranslationHelperFunc) inventory.Serve
)
}

func ListCodeQualityFindings(t translations.TranslationHelperFunc) inventory.ServerTool {
schema := &jsonschema.Schema{
Type: "object",
Properties: map[string]*jsonschema.Schema{
"owner": {
Type: "string",
Description: "The owner of the repository.",
},
"repo": {
Type: "string",
Description: "The name of the repository.",
},
"state": {
Type: "string",
Description: "Filter code quality findings by state. Defaults to open",
Enum: []any{"open", "dismissed"},
Default: json.RawMessage(`"open"`),
},
"direction": {
Type: "string",
Description: "Sort by creation date: `desc` (newest first, default) or `asc` (oldest first).",
Enum: []any{"asc", "desc"},
},
},
Required: []string{"owner", "repo"},
}
WithCursorPagination(schema)

return NewToolWithSchemaOptions[ListCodeQualityFindingsInput, CodeQualityFindingsOutput](
ToolsetMetadataCodeQuality,
mcp.Tool{
Name: "list_code_quality_findings",
Description: t("TOOL_LIST_CODE_QUALITY_FINDINGS_DESCRIPTION", "List code quality findings in a GitHub repository."),
Annotations: &mcp.ToolAnnotations{
Title: t("TOOL_LIST_CODE_QUALITY_FINDINGS_USER_TITLE", "List code quality findings"),
ReadOnlyHint: true,
},
InputSchema: schema,
},
scopes.PublicRead(scopes.Repo),
inventory.TypedSchemaOptions{
ValidationInputSchema: inventory.CloneSchemaWithoutDefaults(schema),
},
func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, args ListCodeQualityFindingsInput) (*mcp.CallToolResult, CodeQualityFindingsOutput, error) {
if args.Owner == "" {
return utils.NewToolResultError("missing required parameter: owner"), CodeQualityFindingsOutput{}, nil
}
if args.Repo == "" {
return utils.NewToolResultError("missing required parameter: repo"), CodeQualityFindingsOutput{}, nil
}

pagination := securityCursorPagination(args.PerPage, args.After)
client, err := deps.GetClient(ctx)
if err != nil {
return utils.NewToolResultErrorFromErr("failed to get GitHub client", err), CodeQualityFindingsOutput{}, nil
}

query := url.Values{}
if args.State != "" {
query.Set("state", args.State)
}
if args.Direction != "" {
query.Set("direction", args.Direction)
}
query.Set("per_page", strconv.Itoa(pagination.PerPage))
if pagination.After != "" {
query.Set("after", pagination.After)
}
apiURL := fmt.Sprintf("repos/%s/%s/code-quality/findings?%s", url.PathEscape(args.Owner), url.PathEscape(args.Repo), query.Encode())
req, err := client.NewRequest(ctx, http.MethodGet, apiURL, nil)
if err != nil {
return utils.NewToolResultErrorFromErr("failed to create request", err), CodeQualityFindingsOutput{}, nil
}

var rawFindings json.RawMessage
resp, err := client.Do(req, &rawFindings)
if resp != nil {
defer func() { _ = resp.Body.Close() }()
}
if err != nil {
return ghErrors.NewGitHubAPIErrorResponse(ctx,
fmt.Sprintf("failed to list findings for repository '%s/%s'", args.Owner, args.Repo),
resp,
err,
), CodeQualityFindingsOutput{}, nil
}

if resp.StatusCode != http.StatusOK {
body, err := io.ReadAll(resp.Body)
if err != nil {
return utils.NewToolResultErrorFromErr("failed to read response body", err), CodeQualityFindingsOutput{}, nil
}
return ghErrors.NewGitHubAPIStatusErrorResponse(ctx, "failed to list findings", resp, body), CodeQualityFindingsOutput{}, nil
}

if len(rawFindings) == 0 {
rawFindings = json.RawMessage("null")
}
var findings []*CodeQualityFindingOutput
if err := json.Unmarshal(rawFindings, &findings); err != nil {
return utils.NewToolResultErrorFromErr("failed to decode findings", err), CodeQualityFindingsOutput{}, nil
}

apiPageInfo := buildPageInfo(resp)
output := CodeQualityFindingsOutput{
Findings: findings,
PageInfo: SecurityPageInfo(apiPageInfo),
}

response := struct {
Findings json.RawMessage `json:"findings"`

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a known potential issue, but from what I can see in other tools we have there's no perfect fix for it. It looks like the metadata wrapping this autofix is suggesting was rejected in other PRs. Notably this tool will only return findings from the default branch of the repository at this time, so any malicious instructions would have to be placed by folks with permission to write code to the repo.

PageInfo pageInfo `json:"pageInfo"`
}{
Findings: rawFindings,
PageInfo: apiPageInfo,
}
r, err := json.Marshal(response)
if err != nil {
return utils.NewToolResultErrorFromErr("failed to marshal findings", err), CodeQualityFindingsOutput{}, nil
}

result := utils.NewToolResultText(string(r))

@carogalvin carogalvin Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a known potential issue, but from what I can see in other tools we have there's no perfect fix for it. The suggested fix drops the findings from the text output, which breaks clients that read text instead of structured content; the same change was declined in #3719. Notably this tool will only return findings from the default branch of the repository at this time, so any malicious instructions would have to be in code that someone with write access has merged into the default branch.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, Copilot is being a bit extra here. Don't worry about that.

// Like code scanning alerts, findings embed text derived from
// repository code (file paths and messages), so they share the
// private-untrusted security alert label.
result = attachStaticIFCLabel(ctx, deps, result, ifc.LabelSecurityAlert())
return result, output, nil
},
normalizeTypedReadArguments(nil, false),
)
}

func marshalLegacyCodeQualityFinding(rawFinding json.RawMessage) ([]byte, error) {
// Match main's map-based formatting, including key ordering and number encoding.
var finding map[string]any
Expand Down
Loading
Loading