1- //go:build ignore
2-
31package github
42
53import (
@@ -11,49 +9,56 @@ import (
119
1210ghErrors"github.com/github/github-mcp-server/pkg/errors"
1311"github.com/github/github-mcp-server/pkg/translations"
12+ "github.com/github/github-mcp-server/pkg/utils"
1413"github.com/google/go-github/v79/github"
15- "github.com/mark3labs/mcp -go/mcp "
16- "github.com/mark3labs/mcp-go/server "
14+ "github.com/google/jsonschema -go/jsonschema "
15+ "github.com/modelcontextprotocol/go-sdk/mcp "
1716)
1817
19- func GetSecretScanningAlert (getClient GetClientFn ,t translations.TranslationHelperFunc ) (tool mcp.Tool ,handler server. ToolHandlerFunc ) {
20- return mcp .NewTool (
21- "get_secret_scanning_alert" ,
22- mcp . WithDescription ( t ("TOOL_GET_SECRET_SCANNING_ALERT_DESCRIPTION" ,"Get details of a specific secret scanning alert in a GitHub repository." ) ),
23- mcp .WithToolAnnotation (mcp. ToolAnnotation {
18+ func GetSecretScanningAlert (getClient GetClientFn ,t translations.TranslationHelperFunc ) (mcp.Tool ,mcp. ToolHandlerFor [ map [ string ] any , any ] ) {
19+ return mcp.Tool {
20+ Name : "get_secret_scanning_alert" ,
21+ Description : t ("TOOL_GET_SECRET_SCANNING_ALERT_DESCRIPTION" ,"Get details of a specific secret scanning alert in a GitHub repository." ),
22+ Annotations : & mcp.ToolAnnotations {
2423Title :t ("TOOL_GET_SECRET_SCANNING_ALERT_USER_TITLE" ,"Get secret scanning alert" ),
25- ReadOnlyHint :ToBoolPtr (true ),
26- }),
27- mcp .WithString ("owner" ,
28- mcp .Required (),
29- mcp .Description ("The owner of the repository." ),
30- ),
31- mcp .WithString ("repo" ,
32- mcp .Required (),
33- mcp .Description ("The name of the repository." ),
34- ),
35- mcp .WithNumber ("alertNumber" ,
36- mcp .Required (),
37- mcp .Description ("The number of the alert." ),
38- ),
39- ),
40- func (ctx context.Context ,request mcp.CallToolRequest ) (* mcp.CallToolResult ,error ) {
41- owner ,err := RequiredParam [string ](request ,"owner" )
24+ ReadOnlyHint :true ,
25+ },
26+ InputSchema :& jsonschema.Schema {
27+ Type :"object" ,
28+ Properties :map [string ]* jsonschema.Schema {
29+ "owner" : {
30+ Type :"string" ,
31+ Description :"The owner of the repository." ,
32+ },
33+ "repo" : {
34+ Type :"string" ,
35+ Description :"The name of the repository." ,
36+ },
37+ "alertNumber" : {
38+ Type :"number" ,
39+ Description :"The number of the alert." ,
40+ },
41+ },
42+ Required : []string {"owner" ,"repo" ,"alertNumber" },
43+ },
44+ },
45+ func (ctx context.Context ,_ * mcp.CallToolRequest ,args map [string ]any ) (* mcp.CallToolResult ,any ,error ) {
46+ owner ,err := RequiredParam [string ](args ,"owner" )
4247if err != nil {
43- return mcp .NewToolResultError (err .Error ()),nil
48+ return utils .NewToolResultError (err .Error ()), nil ,nil
4449}
45- repo ,err := RequiredParam [string ](request ,"repo" )
50+ repo ,err := RequiredParam [string ](args ,"repo" )
4651if err != nil {
47- return mcp .NewToolResultError (err .Error ()),nil
52+ return utils .NewToolResultError (err .Error ()), nil ,nil
4853}
49- alertNumber ,err := RequiredInt (request ,"alertNumber" )
54+ alertNumber ,err := RequiredInt (args ,"alertNumber" )
5055if err != nil {
51- return mcp .NewToolResultError (err .Error ()),nil
56+ return utils .NewToolResultError (err .Error ()), nil ,nil
5257}
5358
5459client ,err := getClient (ctx )
5560if err != nil {
56- return nil ,fmt .Errorf ("failed to get GitHub client: %w" ,err )
61+ return nil ,nil , fmt .Errorf ("failed to get GitHub client: %w" ,err )
5762}
5863
5964alert ,resp ,err := client .SecretScanning .GetAlert (ctx ,owner ,repo ,int64 (alertNumber ))
@@ -62,104 +67,113 @@ func GetSecretScanningAlert(getClient GetClientFn, t translations.TranslationHel
6267fmt .Sprintf ("failed to get alert with number '%d'" ,alertNumber ),
6368resp ,
6469err ,
65- ),nil
70+ ),nil , nil
6671}
6772defer func () {_ = resp .Body .Close () }()
6873
6974if resp .StatusCode != http .StatusOK {
7075body ,err := io .ReadAll (resp .Body )
7176if err != nil {
72- return nil ,fmt .Errorf ("failed to read response body: %w" ,err )
77+ return nil ,nil , fmt .Errorf ("failed to read response body: %w" ,err )
7378}
74- return mcp .NewToolResultError (fmt .Sprintf ("failed to get alert: %s" ,string (body ))),nil
79+ return utils .NewToolResultError (fmt .Sprintf ("failed to get alert: %s" ,string (body ))), nil ,nil
7580}
7681
7782r ,err := json .Marshal (alert )
7883if err != nil {
79- return nil ,fmt .Errorf ("failed to marshal alert: %w" ,err )
84+ return nil ,nil , fmt .Errorf ("failed to marshal alert: %w" ,err )
8085}
8186
82- return mcp .NewToolResultText (string (r )),nil
87+ return utils .NewToolResultText (string (r )), nil ,nil
8388}
8489}
8590
86- func ListSecretScanningAlerts (getClient GetClientFn ,t translations.TranslationHelperFunc ) (tool mcp.Tool ,handler server. ToolHandlerFunc ) {
87- return mcp .NewTool (
88- "list_secret_scanning_alerts" ,
89- mcp . WithDescription ( t ("TOOL_LIST_SECRET_SCANNING_ALERTS_DESCRIPTION" ,"List secret scanning alerts in a GitHub repository." ) ),
90- mcp .WithToolAnnotation (mcp. ToolAnnotation {
91+ func ListSecretScanningAlerts (getClient GetClientFn ,t translations.TranslationHelperFunc ) (mcp.Tool ,mcp. ToolHandlerFor [ map [ string ] any , any ] ) {
92+ return mcp.Tool {
93+ Name : "list_secret_scanning_alerts" ,
94+ Description : t ("TOOL_LIST_SECRET_SCANNING_ALERTS_DESCRIPTION" ,"List secret scanning alerts in a GitHub repository." ),
95+ Annotations : & mcp.ToolAnnotations {
9196Title :t ("TOOL_LIST_SECRET_SCANNING_ALERTS_USER_TITLE" ,"List secret scanning alerts" ),
92- ReadOnlyHint :ToBoolPtr (true ),
93- }),
94- mcp .WithString ("owner" ,
95- mcp .Required (),
96- mcp .Description ("The owner of the repository." ),
97- ),
98- mcp .WithString ("repo" ,
99- mcp .Required (),
100- mcp .Description ("The name of the repository." ),
101- ),
102- mcp .WithString ("state" ,
103- mcp .Description ("Filter by state" ),
104- mcp .Enum ("open" ,"resolved" ),
105- ),
106- mcp .WithString ("secret_type" ,
107- 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." ),
108- ),
109- mcp .WithString ("resolution" ,
110- mcp .Description ("Filter by resolution" ),
111- mcp .Enum ("false_positive" ,"wont_fix" ,"revoked" ,"pattern_edited" ,"pattern_deleted" ,"used_in_tests" ),
112- ),
113- ),
114- func (ctx context.Context ,request mcp.CallToolRequest ) (* mcp.CallToolResult ,error ) {
115- owner ,err := RequiredParam [string ](request ,"owner" )
97+ ReadOnlyHint :true ,
98+ },
99+ InputSchema :& jsonschema.Schema {
100+ Type :"object" ,
101+ Properties :map [string ]* jsonschema.Schema {
102+ "owner" : {
103+ Type :"string" ,
104+ Description :"The owner of the repository." ,
105+ },
106+ "repo" : {
107+ Type :"string" ,
108+ Description :"The name of the repository." ,
109+ },
110+ "state" : {
111+ Type :"string" ,
112+ Description :"Filter by state" ,
113+ Enum : []any {"open" ,"resolved" },
114+ },
115+ "secret_type" : {
116+ Type :"string" ,
117+ 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." ,
118+ },
119+ "resolution" : {
120+ Type :"string" ,
121+ Description :"Filter by resolution" ,
122+ Enum : []any {"false_positive" ,"wont_fix" ,"revoked" ,"pattern_edited" ,"pattern_deleted" ,"used_in_tests" },
123+ },
124+ },
125+ Required : []string {"owner" ,"repo" },
126+ },
127+ },
128+ func (ctx context.Context ,_ * mcp.CallToolRequest ,args map [string ]any ) (* mcp.CallToolResult ,any ,error ) {
129+ owner ,err := RequiredParam [string ](args ,"owner" )
116130if err != nil {
117- return mcp .NewToolResultError (err .Error ()),nil
131+ return utils .NewToolResultError (err .Error ()), nil ,nil
118132}
119- repo ,err := RequiredParam [string ](request ,"repo" )
133+ repo ,err := RequiredParam [string ](args ,"repo" )
120134if err != nil {
121- return mcp .NewToolResultError (err .Error ()),nil
135+ return utils .NewToolResultError (err .Error ()), nil ,nil
122136}
123- state ,err := OptionalParam [string ](request ,"state" )
137+ state ,err := OptionalParam [string ](args ,"state" )
124138if err != nil {
125- return mcp .NewToolResultError (err .Error ()),nil
139+ return utils .NewToolResultError (err .Error ()), nil ,nil
126140}
127- secretType ,err := OptionalParam [string ](request ,"secret_type" )
141+ secretType ,err := OptionalParam [string ](args ,"secret_type" )
128142if err != nil {
129- return mcp .NewToolResultError (err .Error ()),nil
143+ return utils .NewToolResultError (err .Error ()), nil ,nil
130144}
131- resolution ,err := OptionalParam [string ](request ,"resolution" )
145+ resolution ,err := OptionalParam [string ](args ,"resolution" )
132146if err != nil {
133- return mcp .NewToolResultError (err .Error ()),nil
147+ return utils .NewToolResultError (err .Error ()), nil ,nil
134148}
135149
136150client ,err := getClient (ctx )
137151if err != nil {
138- return nil ,fmt .Errorf ("failed to get GitHub client: %w" ,err )
152+ return nil ,nil , fmt .Errorf ("failed to get GitHub client: %w" ,err )
139153}
140154alerts ,resp ,err := client .SecretScanning .ListAlertsForRepo (ctx ,owner ,repo ,& github.SecretScanningAlertListOptions {State :state ,SecretType :secretType ,Resolution :resolution })
141155if err != nil {
142156return ghErrors .NewGitHubAPIErrorResponse (ctx ,
143157fmt .Sprintf ("failed to list alerts for repository '%s/%s'" ,owner ,repo ),
144158resp ,
145159err ,
146- ),nil
160+ ),nil , nil
147161}
148162defer func () {_ = resp .Body .Close () }()
149163
150164if resp .StatusCode != http .StatusOK {
151165body ,err := io .ReadAll (resp .Body )
152166if err != nil {
153- return nil ,fmt .Errorf ("failed to read response body: %w" ,err )
167+ return nil ,nil , fmt .Errorf ("failed to read response body: %w" ,err )
154168}
155- return mcp .NewToolResultError (fmt .Sprintf ("failed to list alerts: %s" ,string (body ))),nil
169+ return utils .NewToolResultError (fmt .Sprintf ("failed to list alerts: %s" ,string (body ))), nil ,nil
156170}
157171
158172r ,err := json .Marshal (alerts )
159173if err != nil {
160- return nil ,fmt .Errorf ("failed to marshal alerts: %w" ,err )
174+ return nil ,nil , fmt .Errorf ("failed to marshal alerts: %w" ,err )
161175}
162176
163- return mcp .NewToolResultText (string (r )),nil
177+ return utils .NewToolResultText (string (r )), nil ,nil
164178}
165179}