You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: enhance GetJobLogs functionality for improved job log retrieval
- Added new tests for GetJobLogs, including scenarios for retrieving logs for both single jobs and failed jobs.
- Updated GetJobLogs tool description to clarify its capabilities for fetching logs efficiently.
- Implemented error handling for missing required parameters and optimized responses for failed job logs.
- Introduced functionality to return actual log content instead of just URLs when requested.
@@ -336,7 +339,7 @@ func GetWorkflowRun(getClient GetClientFn, t translations.TranslationHelperFunc)
336
339
// GetWorkflowRunLogs creates a tool to download logs for a specific workflow run
337
340
funcGetWorkflowRunLogs(getClientGetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
338
341
returnmcp.NewTool("get_workflow_run_logs",
339
-
mcp.WithDescription(t("TOOL_GET_WORKFLOW_RUN_LOGS_DESCRIPTION", "Download logs for a specific workflow run")),
342
+
mcp.WithDescription(t("TOOL_GET_WORKFLOW_RUN_LOGS_DESCRIPTION", "Download logs for a specific workflow run (EXPENSIVE: downloads ALL logs as ZIP. Consider using get_job_logs with failed_only=true for debugging failed jobs)")),
340
343
mcp.WithToolAnnotation(mcp.ToolAnnotation{
341
344
ReadOnlyHint: toBoolPtr(true),
342
345
}),
@@ -382,9 +385,11 @@ func GetWorkflowRunLogs(getClient GetClientFn, t translations.TranslationHelperF
382
385
383
386
// Create response with the logs URL and information
384
387
result:=map[string]any{
385
-
"logs_url": url.String(),
386
-
"message": "Workflow run logs are available for download",
387
-
"note": "The logs_url provides a download link for the complete workflow run logs as a ZIP archive. You can download this archive to extract and examine individual job logs.",
388
+
"logs_url": url.String(),
389
+
"message": "Workflow run logs are available for download",
390
+
"note": "The logs_url provides a download link for the complete workflow run logs as a ZIP archive. You can download this archive to extract and examine individual job logs.",
391
+
"warning": "This downloads ALL logs as a ZIP file which can be large and expensive. For debugging failed jobs, consider using get_job_logs with failed_only=true and run_id instead.",
392
+
"optimization_tip": "Use: get_job_logs with parameters {run_id: "+fmt.Sprintf("%d", runID) +", failed_only: true} for more efficient failed job debugging",
388
393
}
389
394
390
395
r, err:=json.Marshal(result)
@@ -476,7 +481,13 @@ func ListWorkflowJobs(getClient GetClientFn, t translations.TranslationHelperFun
476
481
}
477
482
deferfunc() { _=resp.Body.Close() }()
478
483
479
-
r, err:=json.Marshal(jobs)
484
+
// Add optimization tip for failed job debugging
485
+
response:=map[string]any{
486
+
"jobs": jobs,
487
+
"optimization_tip": "For debugging failed jobs, consider using get_job_logs with failed_only=true and run_id="+fmt.Sprintf("%d", runID) +" to get logs directly without needing to list jobs first",
488
+
}
489
+
490
+
r, err:=json.Marshal(response)
480
491
iferr!=nil {
481
492
returnnil, fmt.Errorf("failed to marshal response: %w", err)
482
493
}
@@ -485,10 +496,10 @@ func ListWorkflowJobs(getClient GetClientFn, t translations.TranslationHelperFun
485
496
}
486
497
}
487
498
488
-
// GetJobLogs creates a tool to download logs for a specific workflow job
499
+
// GetJobLogs creates a tool to download logs for a specific workflow job or get failed job logs efficiently
489
500
funcGetJobLogs(getClientGetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
490
501
returnmcp.NewTool("get_job_logs",
491
-
mcp.WithDescription(t("TOOL_GET_JOB_LOGS_DESCRIPTION", "Download logs for a specific workflow job")),
502
+
mcp.WithDescription(t("TOOL_GET_JOB_LOGS_DESCRIPTION", "Download logs for a specific workflow job or efficiently get all failed job logs for a workflow run")),
492
503
mcp.WithToolAnnotation(mcp.ToolAnnotation{
493
504
ReadOnlyHint: toBoolPtr(true),
494
505
}),
@@ -501,8 +512,16 @@ func GetJobLogs(getClient GetClientFn, t translations.TranslationHelperFunc) (to
501
512
mcp.Description("Repository name"),
502
513
),
503
514
mcp.WithNumber("job_id",
504
-
mcp.Required(),
505
-
mcp.Description("The unique identifier of the workflow job"),
515
+
mcp.Description("The unique identifier of the workflow job (required for single job logs)"),
516
+
),
517
+
mcp.WithNumber("run_id",
518
+
mcp.Description("Workflow run ID (required when using failed_only)"),
519
+
),
520
+
mcp.WithBoolean("failed_only",
521
+
mcp.Description("When true, gets logs for all failed jobs in run_id"),
522
+
),
523
+
mcp.WithBoolean("return_content",
524
+
mcp.Description("Returns actual log content instead of URLs"),
returnnil, fmt.Errorf("failed to get job logs: %w", err)
560
+
// Validate parameters
561
+
iffailedOnly&&runID==0 {
562
+
returnmcp.NewToolResultError("run_id is required when failed_only is true"), nil
563
+
}
564
+
if!failedOnly&&jobID==0 {
565
+
returnmcp.NewToolResultError("job_id is required when failed_only is false"), nil
532
566
}
533
-
deferfunc() { _=resp.Body.Close() }()
534
567
535
-
// Create response with the logs URL and information
536
-
result:=map[string]any{
537
-
"logs_url": url.String(),
538
-
"message": "Job logs are available for download",
539
-
"note": "The logs_url provides a download link for the individual job logs in plain text format. This is more targeted than workflow run logs and easier to read for debugging specific failed steps.",
568
+
iffailedOnly&&runID>0 {
569
+
// Handle failed-only mode: get logs for all failed jobs in the workflow run
result["message"] ="Job logs are available for download"
685
+
result["note"] ="The logs_url provides a download link for the individual job logs in plain text format. Use return_content=true to get the actual log content."
686
+
}
687
+
688
+
returnresult, nil
689
+
}
690
+
691
+
// downloadLogContent downloads the actual log content from a GitHub logs URL
0 commit comments