@@ -1226,18 +1226,26 @@ func UpdateIssue(getClient GetClientFn, getGQLClient GetGQLClientFn, t translati
12261226 return mcp .NewToolResultError (err .Error ()), nil
12271227 }
12281228
1229- // If closing as duplicate, use GraphQL API, otherwise use REST API for state changes
1230- if stateReason == "duplicate" {
1229+ // Validate state_reason usage
1230+ if stateReason != "" && state == "" {
1231+ return mcp .NewToolResultError ("state_reason can only be used when state is also provided" ), nil
1232+ }
1233+ if state == "open" && stateReason != "" && stateReason != "reopened" {
1234+ return mcp .NewToolResultError ("when state is 'open', state_reason can only be 'reopened'" ), nil
1235+ }
1236+ if state == "closed" && stateReason != "" && stateReason != "completed" && stateReason != "not_planned" && stateReason != "duplicate" {
1237+ return mcp .NewToolResultError ("when state is 'closed', state_reason can only be 'completed', 'not_planned', or 'duplicate'" ), nil
1238+ }
1239+
1240+ // Use GraphQL for duplicate closure, REST for everything else
1241+ if state == "closed" && stateReason == "duplicate" {
12311242 gqlUpdateNeeded = true
1232- } else {
1233- if state != "" {
1234- issueRequest .State = github .Ptr (state )
1235- restUpdateNeeded = true
1236- }
1243+ } else if state != "" {
1244+ issueRequest .State = github .Ptr (state )
12371245 if stateReason != "" {
12381246 issueRequest .StateReason = github .Ptr (stateReason )
1239- restUpdateNeeded = true
12401247 }
1248+ restUpdateNeeded = true
12411249 }
12421250
12431251 duplicateOf , err := OptionalIntParam (request , "duplicate_of" )
0 commit comments