Skip to content

Commit 7edc2dd

Browse files
carogalvinCopilot
andauthored
Add list_code_quality_findings tool to code_quality toolset (#3564)
* Add list_code_quality_findings tool to code_quality toolset Add a read-only tool that lists code quality findings for a repository via GET /repos/{owner}/{repo}/code-quality/findings. It supports the endpoint's filters: state (open or dismissed, defaulting to open), direction (asc or desc), and cursor pagination (perPage, after). The tool follows the list_dependabot_alerts pattern: cursor pagination schema, defaults stripped from the validation schema, a typed output with findings and pageInfo, and the same scopes as get_code_quality_finding. Like get_code_quality_finding, it attaches no IFC label. Includes unit tests, the tool snapshot, and regenerated README docs. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Clarify direction description for list_code_quality_findings The endpoint sorts findings by creation date only, so describe the direction values in those terms. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Cover list_code_quality_findings in repository-health-review skill Every tool must be covered by a bundled skill or explicitly exempted. Add list_code_quality_findings as an optional tool of the repository-health-review skill, next to the code scanning and Dependabot alert tools, and mention it in the outstanding-risk step. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Attach IFC label to list_code_quality_findings results Label successful results with ifc.LabelSecurityAlert() (private, untrusted) when the ifc_labels feature flag is enabled, the same label the code scanning, Dependabot and secret scanning tools use. Findings embed file paths and messages derived from repository code, and without a label, clients that enforce IFC have no classification for this data. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: carogalvin <223556219+Copilot@users.noreply.github.com>
1 parent c6b6295 commit 7edc2dd

11 files changed

Lines changed: 665 additions & 17 deletions

File tree

‎README.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,15 @@ For negotiated supported protocol versions `2026-07-28` or newer, the consolidat
733733
- `owner`: The owner of the repository. (string, required)
734734
- `repo`: The name of the repository. (string, required)
735735

736+
- **list_code_quality_findings** - List code quality findings
737+
- **OAuth Challenge Scopes**: `repo`
738+
- `after`: Cursor for pagination. Use the cursor from the previous response. (string, optional)
739+
- `direction`: Sort by creation date: `desc` (newest first, default) or `asc` (oldest first). (string, optional)
740+
- `owner`: The owner of the repository. (string, required)
741+
- `perPage`: Results per page for pagination (min 1, max 100) (number, optional)
742+
- `repo`: The name of the repository. (string, required)
743+
- `state`: Filter code quality findings by state. Defaults to open (string, optional)
744+
736745
</details>
737746

738747
<details>
Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
{
2+
"annotations": {
3+
"idempotentHint": false,
4+
"readOnlyHint": true,
5+
"title": "List code quality findings"
6+
},
7+
"description": "List code quality findings in a GitHub repository.",
8+
"inputSchema": {
9+
"properties": {
10+
"after": {
11+
"description": "Cursor for pagination. Use the cursor from the previous response.",
12+
"type": "string"
13+
},
14+
"direction": {
15+
"description": "Sort by creation date: `desc` (newest first, default) or `asc` (oldest first).",
16+
"enum": [
17+
"asc",
18+
"desc"
19+
],
20+
"type": "string"
21+
},
22+
"owner": {
23+
"description": "The owner of the repository.",
24+
"type": "string"
25+
},
26+
"perPage": {
27+
"description": "Results per page for pagination (min 1, max 100)",
28+
"maximum": 100,
29+
"minimum": 1,
30+
"type": "number"
31+
},
32+
"repo": {
33+
"description": "The name of the repository.",
34+
"type": "string"
35+
},
36+
"state": {
37+
"default": "open",
38+
"description": "Filter code quality findings by state. Defaults to open",
39+
"enum": [
40+
"open",
41+
"dismissed"
42+
],
43+
"type": "string"
44+
}
45+
},
46+
"required": [
47+
"owner",
48+
"repo"
49+
],
50+
"type": "object"
51+
},
52+
"name": "list_code_quality_findings",
53+
"outputSchema": {
54+
"additionalProperties": false,
55+
"properties": {
56+
"findings": {
57+
"items": {
58+
"additionalProperties": false,
59+
"properties": {
60+
"created_at": {
61+
"description": "Finding creation time (RFC 3339).",
62+
"type": [
63+
"null",
64+
"string"
65+
]
66+
},
67+
"location": {
68+
"additionalProperties": false,
69+
"properties": {
70+
"end_column": {
71+
"type": [
72+
"null",
73+
"integer"
74+
]
75+
},
76+
"end_line": {
77+
"type": [
78+
"null",
79+
"integer"
80+
]
81+
},
82+
"path": {
83+
"type": [
84+
"null",
85+
"string"
86+
]
87+
},
88+
"start_column": {
89+
"type": [
90+
"null",
91+
"integer"
92+
]
93+
},
94+
"start_line": {
95+
"type": [
96+
"null",
97+
"integer"
98+
]
99+
}
100+
},
101+
"type": [
102+
"null",
103+
"object"
104+
]
105+
},
106+
"message": {
107+
"additionalProperties": false,
108+
"properties": {
109+
"markdown": {
110+
"type": "string"
111+
},
112+
"text": {
113+
"type": "string"
114+
}
115+
},
116+
"required": [
117+
"text",
118+
"markdown"
119+
],
120+
"type": [
121+
"null",
122+
"object"
123+
]
124+
},
125+
"number": {
126+
"type": [
127+
"null",
128+
"integer"
129+
]
130+
},
131+
"rule": {
132+
"additionalProperties": false,
133+
"properties": {
134+
"category": {
135+
"type": [
136+
"null",
137+
"string"
138+
]
139+
},
140+
"description": {
141+
"type": [
142+
"null",
143+
"string"
144+
]
145+
},
146+
"help": {
147+
"type": [
148+
"null",
149+
"string"
150+
]
151+
},
152+
"id": {
153+
"type": [
154+
"null",
155+
"string"
156+
]
157+
},
158+
"severity": {
159+
"type": [
160+
"null",
161+
"string"
162+
]
163+
},
164+
"title": {
165+
"type": [
166+
"null",
167+
"string"
168+
]
169+
}
170+
},
171+
"type": [
172+
"null",
173+
"object"
174+
]
175+
},
176+
"state": {
177+
"type": [
178+
"null",
179+
"string"
180+
]
181+
}
182+
},
183+
"type": [
184+
"null",
185+
"object"
186+
]
187+
},
188+
"type": [
189+
"null",
190+
"array"
191+
]
192+
},
193+
"pageInfo": {
194+
"additionalProperties": false,
195+
"properties": {
196+
"hasNextPage": {
197+
"type": "boolean"
198+
},
199+
"hasPreviousPage": {
200+
"type": "boolean"
201+
},
202+
"nextCursor": {
203+
"type": "string"
204+
},
205+
"prevCursor": {
206+
"type": "string"
207+
}
208+
},
209+
"required": [
210+
"hasNextPage",
211+
"hasPreviousPage"
212+
],
213+
"type": "object"
214+
}
215+
},
216+
"required": [
217+
"findings",
218+
"pageInfo"
219+
],
220+
"type": "object"
221+
}
222+
}

‎pkg/github/code_quality.go‎

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ import (
66
"fmt"
77
"io"
88
"net/http"
9+
"net/url"
10+
"strconv"
911

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

1315
ghErrors "github.com/github/github-mcp-server/v2/pkg/errors"
16+
"github.com/github/github-mcp-server/v2/pkg/ifc"
1417
"github.com/github/github-mcp-server/v2/pkg/inventory"
1518
"github.com/github/github-mcp-server/v2/pkg/scopes"
1619
"github.com/github/github-mcp-server/v2/pkg/translations"
@@ -99,6 +102,138 @@ func GetCodeQualityFinding(t translations.TranslationHelperFunc) inventory.Serve
99102
)
100103
}
101104

105+
func ListCodeQualityFindings(t translations.TranslationHelperFunc) inventory.ServerTool {
106+
schema := &jsonschema.Schema{
107+
Type: "object",
108+
Properties: map[string]*jsonschema.Schema{
109+
"owner": {
110+
Type: "string",
111+
Description: "The owner of the repository.",
112+
},
113+
"repo": {
114+
Type: "string",
115+
Description: "The name of the repository.",
116+
},
117+
"state": {
118+
Type: "string",
119+
Description: "Filter code quality findings by state. Defaults to open",
120+
Enum: []any{"open", "dismissed"},
121+
Default: json.RawMessage(`"open"`),
122+
},
123+
"direction": {
124+
Type: "string",
125+
Description: "Sort by creation date: `desc` (newest first, default) or `asc` (oldest first).",
126+
Enum: []any{"asc", "desc"},
127+
},
128+
},
129+
Required: []string{"owner", "repo"},
130+
}
131+
WithCursorPagination(schema)
132+
133+
return NewToolWithSchemaOptions[ListCodeQualityFindingsInput, CodeQualityFindingsOutput](
134+
ToolsetMetadataCodeQuality,
135+
mcp.Tool{
136+
Name: "list_code_quality_findings",
137+
Description: t("TOOL_LIST_CODE_QUALITY_FINDINGS_DESCRIPTION", "List code quality findings in a GitHub repository."),
138+
Annotations: &mcp.ToolAnnotations{
139+
Title: t("TOOL_LIST_CODE_QUALITY_FINDINGS_USER_TITLE", "List code quality findings"),
140+
ReadOnlyHint: true,
141+
},
142+
InputSchema: schema,
143+
},
144+
scopes.PublicRead(scopes.Repo),
145+
inventory.TypedSchemaOptions{
146+
ValidationInputSchema: inventory.CloneSchemaWithoutDefaults(schema),
147+
},
148+
func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, args ListCodeQualityFindingsInput) (*mcp.CallToolResult, CodeQualityFindingsOutput, error) {
149+
if args.Owner == "" {
150+
return utils.NewToolResultError("missing required parameter: owner"), CodeQualityFindingsOutput{}, nil
151+
}
152+
if args.Repo == "" {
153+
return utils.NewToolResultError("missing required parameter: repo"), CodeQualityFindingsOutput{}, nil
154+
}
155+
156+
pagination := securityCursorPagination(args.PerPage, args.After)
157+
client, err := deps.GetClient(ctx)
158+
if err != nil {
159+
return utils.NewToolResultErrorFromErr("failed to get GitHub client", err), CodeQualityFindingsOutput{}, nil
160+
}
161+
162+
query := url.Values{}
163+
if args.State != "" {
164+
query.Set("state", args.State)
165+
}
166+
if args.Direction != "" {
167+
query.Set("direction", args.Direction)
168+
}
169+
query.Set("per_page", strconv.Itoa(pagination.PerPage))
170+
if pagination.After != "" {
171+
query.Set("after", pagination.After)
172+
}
173+
apiURL := fmt.Sprintf("repos/%s/%s/code-quality/findings?%s", url.PathEscape(args.Owner), url.PathEscape(args.Repo), query.Encode())
174+
req, err := client.NewRequest(ctx, http.MethodGet, apiURL, nil)
175+
if err != nil {
176+
return utils.NewToolResultErrorFromErr("failed to create request", err), CodeQualityFindingsOutput{}, nil
177+
}
178+
179+
var rawFindings json.RawMessage
180+
resp, err := client.Do(req, &rawFindings)
181+
if resp != nil {
182+
defer func() { _ = resp.Body.Close() }()
183+
}
184+
if err != nil {
185+
return ghErrors.NewGitHubAPIErrorResponse(ctx,
186+
fmt.Sprintf("failed to list findings for repository '%s/%s'", args.Owner, args.Repo),
187+
resp,
188+
err,
189+
), CodeQualityFindingsOutput{}, nil
190+
}
191+
192+
if resp.StatusCode != http.StatusOK {
193+
body, err := io.ReadAll(resp.Body)
194+
if err != nil {
195+
return utils.NewToolResultErrorFromErr("failed to read response body", err), CodeQualityFindingsOutput{}, nil
196+
}
197+
return ghErrors.NewGitHubAPIStatusErrorResponse(ctx, "failed to list findings", resp, body), CodeQualityFindingsOutput{}, nil
198+
}
199+
200+
if len(rawFindings) == 0 {
201+
rawFindings = json.RawMessage("null")
202+
}
203+
var findings []*CodeQualityFindingOutput
204+
if err := json.Unmarshal(rawFindings, &findings); err != nil {
205+
return utils.NewToolResultErrorFromErr("failed to decode findings", err), CodeQualityFindingsOutput{}, nil
206+
}
207+
208+
apiPageInfo := buildPageInfo(resp)
209+
output := CodeQualityFindingsOutput{
210+
Findings: findings,
211+
PageInfo: SecurityPageInfo(apiPageInfo),
212+
}
213+
214+
response := struct {
215+
Findings json.RawMessage `json:"findings"`
216+
PageInfo pageInfo `json:"pageInfo"`
217+
}{
218+
Findings: rawFindings,
219+
PageInfo: apiPageInfo,
220+
}
221+
r, err := json.Marshal(response)
222+
if err != nil {
223+
return utils.NewToolResultErrorFromErr("failed to marshal findings", err), CodeQualityFindingsOutput{}, nil
224+
}
225+
226+
result := utils.NewToolResultText(string(r))
227+
// Like code scanning alerts, findings embed text derived from
228+
// repository code (file paths and messages), so they share the
229+
// private-untrusted security alert label.
230+
result = attachStaticIFCLabel(ctx, deps, result, ifc.LabelSecurityAlert())
231+
return result, output, nil
232+
},
233+
normalizeTypedReadArguments(nil, false),
234+
)
235+
}
236+
102237
func marshalLegacyCodeQualityFinding(rawFinding json.RawMessage) ([]byte, error) {
103238
// Match main's map-based formatting, including key ordering and number encoding.
104239
var finding map[string]any

0 commit comments

Comments
 (0)