@@ -214,3 +214,90 @@ func splitAndTrim(s, sep string) []string {
214
214
215
215
return result
216
216
}
217
+
218
+ // CreatePullRequestTool creates a tool for creating a new pull request
219
+ func CreatePullRequestTool (config * config.Config , client * client.Client ) (tool mcp.Tool , handler server.ToolHandlerFunc ) {
220
+ return mcp .NewTool ("create_pull_request" ,
221
+ mcp .WithDescription ("Create a new pull request in a Harness repository." ),
222
+ mcp .WithString ("repo_identifier" ,
223
+ mcp .Required (),
224
+ mcp .Description ("The identifier of the repository" ),
225
+ ),
226
+ mcp .WithString ("title" ,
227
+ mcp .Required (),
228
+ mcp .Description ("The title of the pull request" ),
229
+ ),
230
+ mcp .WithString ("description" ,
231
+ mcp .Description ("The description of the pull request" ),
232
+ ),
233
+ mcp .WithString ("source_branch" ,
234
+ mcp .Required (),
235
+ mcp .Description ("The source branch for the pull request" ),
236
+ ),
237
+ mcp .WithString ("target_branch" ,
238
+ mcp .Description ("The target branch for the pull request" ),
239
+ mcp .DefaultString ("main" ),
240
+ ),
241
+ mcp .WithBoolean ("is_draft" ,
242
+ mcp .Description ("Whether the pull request should be created as a draft" ),
243
+ mcp .DefaultBool (false ),
244
+ ),
245
+ WithScope (config , false ),
246
+ ),
247
+ func (ctx context.Context , request mcp.CallToolRequest ) (* mcp.CallToolResult , error ) {
248
+ repoIdentifier , err := requiredParam [string ](request , "repo_identifier" )
249
+ if err != nil {
250
+ return mcp .NewToolResultError (err .Error ()), nil
251
+ }
252
+
253
+ title , err := requiredParam [string ](request , "title" )
254
+ if err != nil {
255
+ return mcp .NewToolResultError (err .Error ()), nil
256
+ }
257
+
258
+ description , err := OptionalParam [string ](request , "description" )
259
+ if err != nil {
260
+ return mcp .NewToolResultError (err .Error ()), nil
261
+ }
262
+
263
+ sourceBranch , err := requiredParam [string ](request , "source_branch" )
264
+ if err != nil {
265
+ return mcp .NewToolResultError (err .Error ()), nil
266
+ }
267
+
268
+ isDraft , err := OptionalParam [bool ](request , "is_draft" )
269
+ if err != nil {
270
+ return mcp .NewToolResultError (err .Error ()), nil
271
+ }
272
+
273
+ targetBranch , err := OptionalParam [string ](request , "target_branch" )
274
+ if err != nil {
275
+ return mcp .NewToolResultError (err .Error ()), nil
276
+ }
277
+
278
+ scope , err := fetchScope (config , request , false )
279
+ if err != nil {
280
+ return mcp .NewToolResultError (err .Error ()), nil
281
+ }
282
+
283
+ createRequest := & dto.CreatePullRequest {
284
+ Title : title ,
285
+ SourceBranch : sourceBranch ,
286
+ TargetBranch : targetBranch ,
287
+ IsDraft : isDraft ,
288
+ Description : description ,
289
+ }
290
+
291
+ data , err := client .PullRequests .Create (ctx , scope , repoIdentifier , createRequest )
292
+ if err != nil {
293
+ return nil , fmt .Errorf ("failed to create pull request: %w" , err )
294
+ }
295
+
296
+ r , err := json .Marshal (data )
297
+ if err != nil {
298
+ return nil , fmt .Errorf ("failed to marshal pull request: %w" , err )
299
+ }
300
+
301
+ return mcp .NewToolResultText (string (r )), nil
302
+ }
303
+ }
0 commit comments