@@ -229,24 +229,24 @@ func ListWorkflowRuns(getClient GetClientFn, t translations.TranslationHelperFun
229
229
}
230
230
}
231
231
232
- // RunWorkflow creates a tool to run an Actions workflow
232
+ // RunWorkflow creates a tool to run an Actions workflow by workflow ID
233
233
func RunWorkflow (getClient GetClientFn , t translations.TranslationHelperFunc ) (tool mcp.Tool , handler server.ToolHandlerFunc ) {
234
234
return mcp .NewTool ("run_workflow" ,
235
- mcp .WithDescription (t ("TOOL_RUN_WORKFLOW_DESCRIPTION" , "Run an Actions workflow" )),
235
+ mcp .WithDescription (t ("TOOL_RUN_WORKFLOW_DESCRIPTION" , "Run an Actions workflow by workflow ID " )),
236
236
mcp .WithToolAnnotation (mcp.ToolAnnotation {
237
237
ReadOnlyHint : ToBoolPtr (false ),
238
238
}),
239
239
mcp .WithString ("owner" ,
240
240
mcp .Required (),
241
- mcp .Description ("The account owner of the repository. The name is not case sensitive. " ),
241
+ mcp .Description ("Repository owner" ),
242
242
),
243
243
mcp .WithString ("repo" ,
244
244
mcp .Required (),
245
245
mcp .Description ("Repository name" ),
246
246
),
247
- mcp .WithString ( "workflow_file " ,
247
+ mcp .WithNumber ( "workflow_id " ,
248
248
mcp .Required (),
249
- mcp .Description ("The workflow ID or workflow file name " ),
249
+ mcp .Description ("The workflow ID (numeric identifier) " ),
250
250
),
251
251
mcp .WithString ("ref" ,
252
252
mcp .Required (),
@@ -265,10 +265,11 @@ func RunWorkflow(getClient GetClientFn, t translations.TranslationHelperFunc) (t
265
265
if err != nil {
266
266
return mcp .NewToolResultError (err .Error ()), nil
267
267
}
268
- workflowFile , err := RequiredParam [ string ] (request , "workflow_file " )
268
+ workflowIDInt , err := RequiredInt (request , "workflow_id " )
269
269
if err != nil {
270
270
return mcp .NewToolResultError (err .Error ()), nil
271
271
}
272
+ workflowID := int64 (workflowIDInt )
272
273
ref , err := RequiredParam [string ](request , "ref" )
273
274
if err != nil {
274
275
return mcp .NewToolResultError (err .Error ()), nil
@@ -292,15 +293,17 @@ func RunWorkflow(getClient GetClientFn, t translations.TranslationHelperFunc) (t
292
293
Inputs : inputs ,
293
294
}
294
295
295
- resp , err := client .Actions .CreateWorkflowDispatchEventByFileName (ctx , owner , repo , workflowFile , event )
296
+ // Convert workflow ID to string format for the API call
297
+ workflowIDStr := fmt .Sprintf ("%d" , workflowID )
298
+ resp , err := client .Actions .CreateWorkflowDispatchEventByFileName (ctx , owner , repo , workflowIDStr , event )
296
299
if err != nil {
297
300
return nil , fmt .Errorf ("failed to run workflow: %w" , err )
298
301
}
299
302
defer func () { _ = resp .Body .Close () }()
300
303
301
304
result := map [string ]any {
302
305
"message" : "Workflow run has been queued" ,
303
- "workflow " : workflowFile ,
306
+ "workflow_id " : workflowID ,
304
307
"ref" : ref ,
305
308
"inputs" : inputs ,
306
309
"status" : resp .Status ,
@@ -316,6 +319,93 @@ func RunWorkflow(getClient GetClientFn, t translations.TranslationHelperFunc) (t
316
319
}
317
320
}
318
321
322
+ // RunWorkflowByFileName creates a tool to run an Actions workflow by filename
323
+ func RunWorkflowByFileName (getClient GetClientFn , t translations.TranslationHelperFunc ) (tool mcp.Tool , handler server.ToolHandlerFunc ) {
324
+ return mcp .NewTool ("run_workflow_by_filename" ,
325
+ mcp .WithDescription (t ("TOOL_RUN_WORKFLOW_BY_FILENAME_DESCRIPTION" , "Run an Actions workflow by workflow filename" )),
326
+ mcp .WithToolAnnotation (mcp.ToolAnnotation {
327
+ ReadOnlyHint : ToBoolPtr (false ),
328
+ }),
329
+ mcp .WithString ("owner" ,
330
+ mcp .Required (),
331
+ mcp .Description ("Repository owner" ),
332
+ ),
333
+ mcp .WithString ("repo" ,
334
+ mcp .Required (),
335
+ mcp .Description ("Repository name" ),
336
+ ),
337
+ mcp .WithString ("workflow_file" ,
338
+ mcp .Required (),
339
+ mcp .Description ("The workflow file name (e.g., main.yml, ci.yaml)" ),
340
+ ),
341
+ mcp .WithString ("ref" ,
342
+ mcp .Required (),
343
+ mcp .Description ("The git reference for the workflow. The reference can be a branch or tag name." ),
344
+ ),
345
+ mcp .WithObject ("inputs" ,
346
+ mcp .Description ("Inputs the workflow accepts" ),
347
+ ),
348
+ ),
349
+ func (ctx context.Context , request mcp.CallToolRequest ) (* mcp.CallToolResult , error ) {
350
+ owner , err := RequiredParam [string ](request , "owner" )
351
+ if err != nil {
352
+ return mcp .NewToolResultError (err .Error ()), nil
353
+ }
354
+ repo , err := RequiredParam [string ](request , "repo" )
355
+ if err != nil {
356
+ return mcp .NewToolResultError (err .Error ()), nil
357
+ }
358
+ workflowFile , err := RequiredParam [string ](request , "workflow_file" )
359
+ if err != nil {
360
+ return mcp .NewToolResultError (err .Error ()), nil
361
+ }
362
+ ref , err := RequiredParam [string ](request , "ref" )
363
+ if err != nil {
364
+ return mcp .NewToolResultError (err .Error ()), nil
365
+ }
366
+
367
+ // Get optional inputs parameter
368
+ var inputs map [string ]interface {}
369
+ if requestInputs , ok := request .GetArguments ()["inputs" ]; ok {
370
+ if inputsMap , ok := requestInputs .(map [string ]interface {}); ok {
371
+ inputs = inputsMap
372
+ }
373
+ }
374
+
375
+ client , err := getClient (ctx )
376
+ if err != nil {
377
+ return nil , fmt .Errorf ("failed to get GitHub client: %w" , err )
378
+ }
379
+
380
+ event := github.CreateWorkflowDispatchEventRequest {
381
+ Ref : ref ,
382
+ Inputs : inputs ,
383
+ }
384
+
385
+ resp , err := client .Actions .CreateWorkflowDispatchEventByFileName (ctx , owner , repo , workflowFile , event )
386
+ if err != nil {
387
+ return nil , fmt .Errorf ("failed to run workflow: %w" , err )
388
+ }
389
+ defer func () { _ = resp .Body .Close () }()
390
+
391
+ result := map [string ]any {
392
+ "message" : "Workflow run has been queued" ,
393
+ "workflow_file" : workflowFile ,
394
+ "ref" : ref ,
395
+ "inputs" : inputs ,
396
+ "status" : resp .Status ,
397
+ "status_code" : resp .StatusCode ,
398
+ }
399
+
400
+ r , err := json .Marshal (result )
401
+ if err != nil {
402
+ return nil , fmt .Errorf ("failed to marshal response: %w" , err )
403
+ }
404
+
405
+ return mcp .NewToolResultText (string (r )), nil
406
+ }
407
+ }
408
+
319
409
// GetWorkflowRun creates a tool to get details of a specific workflow run
320
410
func GetWorkflowRun (getClient GetClientFn , t translations.TranslationHelperFunc ) (tool mcp.Tool , handler server.ToolHandlerFunc ) {
321
411
return mcp .NewTool ("get_workflow_run" ,
0 commit comments