@@ -229,24 +229,24 @@ func ListWorkflowRuns(getClient GetClientFn, t translations.TranslationHelperFun
229229 }
230230}
231231
232- // RunWorkflow creates a tool to run an Actions workflow
232+ // RunWorkflow creates a tool to run an Actions workflow by workflow ID
233233func RunWorkflow (getClient GetClientFn , t translations.TranslationHelperFunc ) (tool mcp.Tool , handler server.ToolHandlerFunc ) {
234234 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 " )),
236236 mcp .WithToolAnnotation (mcp.ToolAnnotation {
237237 ReadOnlyHint : ToBoolPtr (false ),
238238 }),
239239 mcp .WithString ("owner" ,
240240 mcp .Required (),
241- mcp .Description ("The account owner of the repository. The name is not case sensitive. " ),
241+ mcp .Description ("Repository owner" ),
242242 ),
243243 mcp .WithString ("repo" ,
244244 mcp .Required (),
245245 mcp .Description ("Repository name" ),
246246 ),
247- mcp .WithString ( "workflow_file " ,
247+ mcp .WithNumber ( "workflow_id " ,
248248 mcp .Required (),
249- mcp .Description ("The workflow ID or workflow file name " ),
249+ mcp .Description ("The workflow ID (numeric identifier) " ),
250250 ),
251251 mcp .WithString ("ref" ,
252252 mcp .Required (),
@@ -265,10 +265,11 @@ func RunWorkflow(getClient GetClientFn, t translations.TranslationHelperFunc) (t
265265 if err != nil {
266266 return mcp .NewToolResultError (err .Error ()), nil
267267 }
268- workflowFile , err := RequiredParam [ string ] (request , "workflow_file " )
268+ workflowIDInt , err := RequiredInt (request , "workflow_id " )
269269 if err != nil {
270270 return mcp .NewToolResultError (err .Error ()), nil
271271 }
272+ workflowID := int64 (workflowIDInt )
272273 ref , err := RequiredParam [string ](request , "ref" )
273274 if err != nil {
274275 return mcp .NewToolResultError (err .Error ()), nil
@@ -292,15 +293,17 @@ func RunWorkflow(getClient GetClientFn, t translations.TranslationHelperFunc) (t
292293 Inputs : inputs ,
293294 }
294295
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 )
296299 if err != nil {
297300 return nil , fmt .Errorf ("failed to run workflow: %w" , err )
298301 }
299302 defer func () { _ = resp .Body .Close () }()
300303
301304 result := map [string ]any {
302305 "message" : "Workflow run has been queued" ,
303- "workflow " : workflowFile ,
306+ "workflow_id " : workflowID ,
304307 "ref" : ref ,
305308 "inputs" : inputs ,
306309 "status" : resp .Status ,
@@ -316,6 +319,93 @@ func RunWorkflow(getClient GetClientFn, t translations.TranslationHelperFunc) (t
316319 }
317320}
318321
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+
319409// GetWorkflowRun creates a tool to get details of a specific workflow run
320410func GetWorkflowRun (getClient GetClientFn , t translations.TranslationHelperFunc ) (tool mcp.Tool , handler server.ToolHandlerFunc ) {
321411 return mcp .NewTool ("get_workflow_run" ,
0 commit comments