Content-Length: 626293 | pFad | http://github.com/github/github-mcp-server/commit/bb9f2b8e731e702640fee5515e2b729aabc36fcf

D2 Merge branch 'main' of ssh://github.com/github/github-mcp-server · github/github-mcp-server@bb9f2b8 · GitHub
Skip to content

Commit bb9f2b8

Browse files
committed
Merge branch 'main' of ssh://github.com/github/github-mcp-server
2 parents a2e662a + 6c4bbf0 commit bb9f2b8

File tree

6 files changed

+134
-3
lines changed

6 files changed

+134
-3
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,21 @@ and set it as the GITHUB_PERSONAL_ACCESS_TOKEN environment variable.
166166
- `page`: Page number (number, optional)
167167
- `per_page`: Results per page (number, optional)
168168

169+
### Code Scanning
170+
171+
- **get_code_scanning_alert** - Get a code scanning alert
172+
173+
- `owner`: Repository owner (string, required)
174+
- `repo`: Repository name (string, required)
175+
- `alert_number`: Alert number (number, required)
176+
177+
- **list_code_scanning_alerts** - List code scanning alerts for a repository
178+
- `owner`: Repository owner (string, required)
179+
- `repo`: Repository name (string, required)
180+
- `ref`: Git reference (string, optional)
181+
- `state`: Alert state (string, optional)
182+
- `severity`: Alert severity (string, optional)
183+
169184
## Standard input/output server
170185

171186
```sh

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/github/github-mcp-server
33
go 1.23.7
44

55
require (
6+
github.com/aws/smithy-go v1.22.3
67
github.com/google/go-github/v69 v69.2.0
78
github.com/mark3labs/mcp-go v0.11.2
89
github.com/sirupsen/logrus v1.9.3

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/aws/smithy-go v1.22.3 h1:Z//5NuZCSW6R4PhQ93hShNbyBbn8BWCmCVCt+Q8Io5k=
2+
github.com/aws/smithy-go v1.22.3/go.mod h1:t1ufH5HMublsJYulve2RKmHDC15xu1f26kHCp/HgceI=
13
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
24
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
35
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

pkg/github/code_scanning.go

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package github
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"fmt"
7+
"io"
8+
9+
"github.com/google/go-github/v69/github"
10+
"github.com/mark3labs/mcp-go/mcp"
11+
"github.com/mark3labs/mcp-go/server"
12+
)
13+
14+
func getCodeScanningAlert(client *github.Client) (tool mcp.Tool, handler server.ToolHandlerFunc) {
15+
return mcp.NewTool("get_code_scanning_alert",
16+
mcp.WithDescription("Get details of a specific code scanning alert in a GitHub repository."),
17+
mcp.WithString("owner",
18+
mcp.Required(),
19+
mcp.Description("The owner of the repository."),
20+
),
21+
mcp.WithString("repo",
22+
mcp.Required(),
23+
mcp.Description("The name of the repository."),
24+
),
25+
mcp.WithNumber("alert_number",
26+
mcp.Required(),
27+
mcp.Description("The number of the alert."),
28+
),
29+
),
30+
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
31+
owner, _ := request.Params.Arguments["owner"].(string)
32+
repo, _ := request.Params.Arguments["repo"].(string)
33+
alertNumber, _ := request.Params.Arguments["alert_number"].(float64)
34+
35+
alert, resp, err := client.CodeScanning.GetAlert(ctx, owner, repo, int64(alertNumber))
36+
if err != nil {
37+
return nil, fmt.Errorf("failed to get alert: %w", err)
38+
}
39+
defer func() { _ = resp.Body.Close() }()
40+
41+
if resp.StatusCode != 200 {
42+
body, err := io.ReadAll(resp.Body)
43+
if err != nil {
44+
return nil, fmt.Errorf("failed to read response body: %w", err)
45+
}
46+
return mcp.NewToolResultError(fmt.Sprintf("failed to get alert: %s", string(body))), nil
47+
}
48+
49+
r, err := json.Marshal(alert)
50+
if err != nil {
51+
return nil, fmt.Errorf("failed to marshal alert: %w", err)
52+
}
53+
54+
return mcp.NewToolResultText(string(r)), nil
55+
}
56+
}
57+
58+
func listCodeScanningAlerts(client *github.Client) (tool mcp.Tool, handler server.ToolHandlerFunc) {
59+
return mcp.NewTool("list_code_scanning_alerts",
60+
mcp.WithDescription("List code scanning alerts in a GitHub repository."),
61+
mcp.WithString("owner",
62+
mcp.Required(),
63+
mcp.Description("The owner of the repository."),
64+
),
65+
mcp.WithString("repo",
66+
mcp.Required(),
67+
mcp.Description("The name of the repository."),
68+
),
69+
mcp.WithString("ref",
70+
mcp.Description("The Git reference for the results you want to list."),
71+
),
72+
mcp.WithString("state",
73+
mcp.Description("State of the code scanning alerts to list. Set to closed to list only closed code scanning alerts. Default: open"),
74+
mcp.DefaultString("open"),
75+
),
76+
mcp.WithString("severity",
77+
mcp.Description("Only code scanning alerts with this severity will be returned. Possible values are: critical, high, medium, low, warning, note, error."),
78+
),
79+
),
80+
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
81+
owner, _ := request.Params.Arguments["owner"].(string)
82+
repo, _ := request.Params.Arguments["repo"].(string)
83+
ref, _ := request.Params.Arguments["ref"].(string)
84+
state, _ := request.Params.Arguments["state"].(string)
85+
severity, _ := request.Params.Arguments["severity"].(string)
86+
87+
alerts, resp, err := client.CodeScanning.ListAlertsForRepo(ctx, owner, repo, &github.AlertListOptions{Ref: ref, State: state, Severity: severity})
88+
if err != nil {
89+
return nil, fmt.Errorf("failed to list alerts: %w", err)
90+
}
91+
defer func() { _ = resp.Body.Close() }()
92+
93+
if resp.StatusCode != 200 {
94+
body, err := io.ReadAll(resp.Body)
95+
if err != nil {
96+
return nil, fmt.Errorf("failed to read response body: %w", err)
97+
}
98+
return mcp.NewToolResultError(fmt.Sprintf("failed to list alerts: %s", string(body))), nil
99+
}
100+
101+
r, err := json.Marshal(alerts)
102+
if err != nil {
103+
return nil, fmt.Errorf("failed to marshal alerts: %w", err)
104+
}
105+
106+
return mcp.NewToolResultText(string(r)), nil
107+
}
108+
}

pkg/github/repositories.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"io"
88

9+
"github.com/aws/smithy-go/ptr"
910
"github.com/google/go-github/v69/github"
1011
"github.com/mark3labs/mcp-go/mcp"
1112
"github.com/mark3labs/mcp-go/server"
@@ -125,14 +126,14 @@ func createOrUpdateFile(client *github.Client) (tool mcp.Tool, handler server.To
125126

126127
// Create the file options
127128
opts := &github.RepositoryContentFileOptions{
128-
Message: github.String(message),
129+
Message: ptr.String(message),
129130
Content: contentBytes,
130-
Branch: github.String(branch),
131+
Branch: ptr.String(branch),
131132
}
132133

133134
// If SHA is provided, set it (for updates)
134135
if sha, ok := request.Params.Arguments["sha"].(string); ok && sha != "" {
135-
opts.SHA = github.String(sha)
136+
opts.SHA = ptr.String(sha)
136137
}
137138

138139
// Create or update the file

pkg/github/server.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ func NewServer(client *github.Client) *server.MCPServer {
5151
// Add GitHub tools - Users
5252
s.AddTool(getMe(client))
5353

54+
// Add GitHub tools - Code Scanning
55+
s.AddTool(getCodeScanningAlert(client))
56+
s.AddTool(listCodeScanningAlerts(client))
57+
5458
return s
5559
}
5660

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/github/github-mcp-server/commit/bb9f2b8e731e702640fee5515e2b729aabc36fcf

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy