@@ -67,6 +67,119 @@ func GetPullRequest(client *github.Client, t translations.TranslationHelperFunc)
67
67
}
68
68
}
69
69
70
+ // UpdatePullRequest creates a tool to update an existing pull request.
71
+ func UpdatePullRequest (client * github.Client , t translations.TranslationHelperFunc ) (tool mcp.Tool , handler server.ToolHandlerFunc ) {
72
+ return mcp .NewTool ("update_pull_request" ,
73
+ mcp .WithDescription (t ("TOOL_UPDATE_PULL_REQUEST_DESCRIPTION" , "Update an existing pull request in a GitHub repository" )),
74
+ mcp .WithString ("owner" ,
75
+ mcp .Required (),
76
+ mcp .Description ("Repository owner" ),
77
+ ),
78
+ mcp .WithString ("repo" ,
79
+ mcp .Required (),
80
+ mcp .Description ("Repository name" ),
81
+ ),
82
+ mcp .WithNumber ("pullNumber" ,
83
+ mcp .Required (),
84
+ mcp .Description ("Pull request number to update" ),
85
+ ),
86
+ mcp .WithString ("title" ,
87
+ mcp .Description ("New title" ),
88
+ ),
89
+ mcp .WithString ("body" ,
90
+ mcp .Description ("New description" ),
91
+ ),
92
+ mcp .WithString ("state" ,
93
+ mcp .Description ("New state ('open' or 'closed')" ),
94
+ mcp .Enum ("open" , "closed" ),
95
+ ),
96
+ mcp .WithString ("base" ,
97
+ mcp .Description ("New base branch name" ),
98
+ ),
99
+ mcp .WithBoolean ("maintainer_can_modify" ,
100
+ mcp .Description ("Allow maintainer edits" ),
101
+ ),
102
+ ),
103
+ func (ctx context.Context , request mcp.CallToolRequest ) (* mcp.CallToolResult , error ) {
104
+ owner , err := requiredParam [string ](request , "owner" )
105
+ if err != nil {
106
+ return mcp .NewToolResultError (err .Error ()), nil
107
+ }
108
+ repo , err := requiredParam [string ](request , "repo" )
109
+ if err != nil {
110
+ return mcp .NewToolResultError (err .Error ()), nil
111
+ }
112
+ pullNumber , err := RequiredInt (request , "pullNumber" )
113
+ if err != nil {
114
+ return mcp .NewToolResultError (err .Error ()), nil
115
+ }
116
+
117
+ // Build the update struct only with provided fields
118
+ update := & github.PullRequest {}
119
+ updateNeeded := false
120
+
121
+ if title , ok , err := OptionalParamOK [string ](request , "title" ); err != nil {
122
+ return mcp .NewToolResultError (err .Error ()), nil
123
+ } else if ok {
124
+ update .Title = github .Ptr (title )
125
+ updateNeeded = true
126
+ }
127
+
128
+ if body , ok , err := OptionalParamOK [string ](request , "body" ); err != nil {
129
+ return mcp .NewToolResultError (err .Error ()), nil
130
+ } else if ok {
131
+ update .Body = github .Ptr (body )
132
+ updateNeeded = true
133
+ }
134
+
135
+ if state , ok , err := OptionalParamOK [string ](request , "state" ); err != nil {
136
+ return mcp .NewToolResultError (err .Error ()), nil
137
+ } else if ok {
138
+ update .State = github .Ptr (state )
139
+ updateNeeded = true
140
+ }
141
+
142
+ if base , ok , err := OptionalParamOK [string ](request , "base" ); err != nil {
143
+ return mcp .NewToolResultError (err .Error ()), nil
144
+ } else if ok {
145
+ update .Base = & github.PullRequestBranch {Ref : github .Ptr (base )}
146
+ updateNeeded = true
147
+ }
148
+
149
+ if maintainerCanModify , ok , err := OptionalParamOK [bool ](request , "maintainer_can_modify" ); err != nil {
150
+ return mcp .NewToolResultError (err .Error ()), nil
151
+ } else if ok {
152
+ update .MaintainerCanModify = github .Ptr (maintainerCanModify )
153
+ updateNeeded = true
154
+ }
155
+
156
+ if ! updateNeeded {
157
+ return mcp .NewToolResultError ("No update parameters provided." ), nil
158
+ }
159
+
160
+ pr , resp , err := client .PullRequests .Edit (ctx , owner , repo , pullNumber , update )
161
+ if err != nil {
162
+ return nil , fmt .Errorf ("failed to update pull request: %w" , err )
163
+ }
164
+ defer func () { _ = resp .Body .Close () }()
165
+
166
+ if resp .StatusCode != http .StatusOK {
167
+ body , err := io .ReadAll (resp .Body )
168
+ if err != nil {
169
+ return nil , fmt .Errorf ("failed to read response body: %w" , err )
170
+ }
171
+ return mcp .NewToolResultError (fmt .Sprintf ("failed to update pull request: %s" , string (body ))), nil
172
+ }
173
+
174
+ r , err := json .Marshal (pr )
175
+ if err != nil {
176
+ return nil , fmt .Errorf ("failed to marshal response: %w" , err )
177
+ }
178
+
179
+ return mcp .NewToolResultText (string (r )), nil
180
+ }
181
+ }
182
+
70
183
// ListPullRequests creates a tool to list and filter repository pull requests.
71
184
func ListPullRequests (client * github.Client , t translations.TranslationHelperFunc ) (tool mcp.Tool , handler server.ToolHandlerFunc ) {
72
185
return mcp .NewTool ("list_pull_requests" ,
0 commit comments