@@ -3,7 +3,9 @@ package github
33import (
44 "context"
55 "encoding/json"
6+ "fmt"
67 "maps"
8+ "slices"
79 "strings"
810
911 ghErrors "github.com/github/github-mcp-server/pkg/errors"
@@ -61,7 +63,7 @@ var issueCommentVisibilityTarget = commentVisibilityTarget{
6163 },
6264 required : []string {"comment_id" },
6365 resolveNodeID : func (ctx context.Context , client * github.Client , owner , repo string , args map [string ]any ) (string , * mcp.CallToolResult ) {
64- commentID , err := RequiredBigInt (args , "comment_id" )
66+ commentID , err := requiredPositiveBigInt (args , "comment_id" )
6567 if err != nil {
6668 return "" , utils .NewToolResultError (err .Error ())
6769 }
@@ -88,7 +90,7 @@ var pullRequestReviewCommentVisibilityTarget = commentVisibilityTarget{
8890 },
8991 required : []string {"comment_id" },
9092 resolveNodeID : func (ctx context.Context , client * github.Client , owner , repo string , args map [string ]any ) (string , * mcp.CallToolResult ) {
91- commentID , err := RequiredBigInt (args , "comment_id" )
93+ commentID , err := requiredPositiveBigInt (args , "comment_id" )
9294 if err != nil {
9395 return "" , utils .NewToolResultError (err .Error ())
9496 }
@@ -124,7 +126,10 @@ var pullRequestReviewVisibilityTarget = commentVisibilityTarget{
124126 if err != nil {
125127 return "" , utils .NewToolResultError (err .Error ())
126128 }
127- reviewID , err := RequiredBigInt (args , "review_id" )
129+ if pullNumber < 1 {
130+ return "" , utils .NewToolResultError ("pullNumber must be greater than 0" )
131+ }
132+ reviewID , err := requiredPositiveBigInt (args , "review_id" )
128133 if err != nil {
129134 return "" , utils .NewToolResultError (err .Error ())
130135 }
@@ -204,6 +209,10 @@ func setCommentVisibility(ctx context.Context, deps ToolDependencies, target com
204209 if err != nil {
205210 return utils .NewToolResultError (err .Error ())
206211 }
212+ classifier = strings .ToUpper (classifier )
213+ if ! slices .Contains (commentClassifiers , any (classifier )) {
214+ return utils .NewToolResultError (fmt .Sprintf ("invalid classifier %q: must be one of %v" , classifier , commentClassifiers ))
215+ }
207216 }
208217
209218 client , err := deps .GetClient (ctx )
@@ -223,7 +232,7 @@ func setCommentVisibility(ctx context.Context, deps ToolDependencies, target com
223232
224233 var result MinimizeCommentResult
225234 if hide {
226- result , errResult = minimizeComment (ctx , gqlClient , nodeID , strings . ToUpper ( classifier ) )
235+ result , errResult = minimizeComment (ctx , gqlClient , nodeID , classifier )
227236 } else {
228237 result , errResult = unminimizeComment (ctx , gqlClient , nodeID )
229238 }
@@ -238,6 +247,19 @@ func setCommentVisibility(ctx context.Context, deps ToolDependencies, target com
238247 return utils .NewToolResultText (string (r ))
239248}
240249
250+ // requiredPositiveBigInt reads a required ID argument. The schema's minimum is not enforced
251+ // when arguments are unmarshalled, so negative values are rejected here before any API call.
252+ func requiredPositiveBigInt (args map [string ]any , p string ) (int64 , error ) {
253+ v , err := RequiredBigInt (args , p )
254+ if err != nil {
255+ return 0 , err
256+ }
257+ if v < 1 {
258+ return 0 , fmt .Errorf ("%s must be greater than 0" , p )
259+ }
260+ return v , nil
261+ }
262+
241263// nodeIDFromResponse turns the result of a REST lookup into a GraphQL node ID, since the
242264// minimize mutations only accept node IDs.
243265func nodeIDFromResponse (ctx context.Context , errMessage , nodeID string , resp * github.Response , err error ) (string , * mcp.CallToolResult ) {
0 commit comments