Skip to content

Commit 7313191

Browse files
committed
Add the list_workflows option to the actions_read tool
1 parent cdcbe4b commit 7313191

File tree

1 file changed

+26
-60
lines changed

1 file changed

+26
-60
lines changed

pkg/github/actions.go

Lines changed: 26 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type actionsActionType int
2626

2727
const (
2828
actionsActionTypeUnknown actionsActionType = iota
29+
actionsActionTypeListWorkflows
2930
actionsActionTypeGetWorkflow
3031
actionsActionTypeGetWorkflowRun
3132
actionsActionTypeListWorkflowRuns
@@ -37,13 +38,14 @@ const (
3738
)
3839

3940
var actionsResourceTypes = map[actionsActionType]string{
41+
actionsActionTypeListWorkflows: "list_workflows",
4042
actionsActionTypeGetWorkflow: "get_workflow",
4143
actionsActionTypeGetWorkflowRun: "get_workflow_run",
4244
actionsActionTypeListWorkflowRuns: "list_workflow_runs",
4345
actionsActionTypeGetWorkflowJob: "get_workflow_job",
4446
actionsActionTypeListWorkflowJobs: "list_workflow_jobs",
45-
actionsActionTypeDownloadWorkflowArtifact: "download_workflow_artifact",
46-
actionsActionTypeListWorkflowArtifacts: "list_workflow_artifacts",
47+
actionsActionTypeDownloadWorkflowArtifact: "download_workflow_run_artifact",
48+
actionsActionTypeListWorkflowArtifacts: "list_workflow_run_artifacts",
4749
actionsActionTypeGetWorkflowRunUsage: "get_workflow_run_usage",
4850
}
4951

@@ -94,10 +96,10 @@ func ActionsRead(getClient GetClientFn, t translations.TranslationHelperFunc) (t
9496
mcp.Description(DescriptionRepositoryName),
9597
),
9698
mcp.WithNumber("resource_id",
97-
mcp.Required(),
9899
mcp.Description(`The unique identifier of the resource. This will vary based on the "action" provided, so ensure you provide the correct ID:
99-
- Provide a workflow ID or Filename for for 'get_workflow' and 'list_workflow_runs' actions.
100-
- Provide a workflow run ID for 'get_workflow_run', 'list_workflow_jobs', 'download_workflow_artifact', 'list_workflow_artifacts' and 'get_workflow_run_usage' actions.
100+
- Do not provide any resource ID for 'list_workflows' action.
101+
- Provide a workflow ID or Filename for 'get_workflow' and 'list_workflow_runs' actions.
102+
- Provide a workflow run ID for 'get_workflow_run', 'list_workflow_jobs', 'download_workflow_run_artifact', 'list_workflow_run_artifacts' and 'get_workflow_run_usage' actions.
101103
- Provide a job ID for the 'get_workflow_job' action.
102104
`),
103105
),
@@ -188,7 +190,7 @@ func ActionsRead(getClient GetClientFn, t translations.TranslationHelperFunc) (t
188190
return mcp.NewToolResultError(fmt.Sprintf("unknown action: %s", actionTypeStr)), nil
189191
}
190192

191-
resourceID, err := RequiredParam[string](request, "resource_id")
193+
resourceID, err := OptionalParam[string](request, "resource_id")
192194
if err != nil {
193195
return mcp.NewToolResultError(err.Error()), nil
194196
}
@@ -217,6 +219,8 @@ func ActionsRead(getClient GetClientFn, t translations.TranslationHelperFunc) (t
217219
}
218220

219221
switch resourceType {
222+
case actionsActionTypeListWorkflows:
223+
return listWorkflows(ctx, client, request, owner, repo, pagination)
220224
case actionsActionTypeGetWorkflow:
221225
return getWorkflow(ctx, client, request, owner, repo, resourceID)
222226
case actionsActionTypeGetWorkflowRun:
@@ -427,63 +431,25 @@ func listWorkflowArtifacts(ctx context.Context, client *github.Client, _ mcp.Cal
427431
}
428432

429433
// ListWorkflows creates a tool to list workflows in a repository
430-
func ListWorkflows(getClient GetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
431-
return mcp.NewTool("list_workflows",
432-
mcp.WithDescription(t("TOOL_LIST_WORKFLOWS_DESCRIPTION", "List workflows in a repository")),
433-
mcp.WithToolAnnotation(mcp.ToolAnnotation{
434-
Title: t("TOOL_LIST_WORKFLOWS_USER_TITLE", "List workflows"),
435-
ReadOnlyHint: ToBoolPtr(true),
436-
}),
437-
mcp.WithString("owner",
438-
mcp.Required(),
439-
mcp.Description(DescriptionRepositoryOwner),
440-
),
441-
mcp.WithString("repo",
442-
mcp.Required(),
443-
mcp.Description(DescriptionRepositoryName),
444-
),
445-
WithPagination(),
446-
),
447-
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
448-
owner, err := RequiredParam[string](request, "owner")
449-
if err != nil {
450-
return mcp.NewToolResultError(err.Error()), nil
451-
}
452-
repo, err := RequiredParam[string](request, "repo")
453-
if err != nil {
454-
return mcp.NewToolResultError(err.Error()), nil
455-
}
456-
457-
// Get optional pagination parameters
458-
pagination, err := OptionalPaginationParams(request)
459-
if err != nil {
460-
return mcp.NewToolResultError(err.Error()), nil
461-
}
462-
463-
client, err := getClient(ctx)
464-
if err != nil {
465-
return nil, fmt.Errorf("failed to get GitHub client: %w", err)
466-
}
467-
468-
// Set up list options
469-
opts := &github.ListOptions{
470-
PerPage: pagination.PerPage,
471-
Page: pagination.Page,
472-
}
434+
func listWorkflows(ctx context.Context, client *github.Client, _ mcp.CallToolRequest, owner, repo string, pagination PaginationParams) (*mcp.CallToolResult, error) {
435+
// Set up list options
436+
opts := &github.ListOptions{
437+
PerPage: pagination.PerPage,
438+
Page: pagination.Page,
439+
}
473440

474-
workflows, resp, err := client.Actions.ListWorkflows(ctx, owner, repo, opts)
475-
if err != nil {
476-
return nil, fmt.Errorf("failed to list workflows: %w", err)
477-
}
478-
defer func() { _ = resp.Body.Close() }()
441+
workflows, resp, err := client.Actions.ListWorkflows(ctx, owner, repo, opts)
442+
if err != nil {
443+
return nil, fmt.Errorf("failed to list workflows: %w", err)
444+
}
445+
defer func() { _ = resp.Body.Close() }()
479446

480-
r, err := json.Marshal(workflows)
481-
if err != nil {
482-
return nil, fmt.Errorf("failed to marshal response: %w", err)
483-
}
447+
r, err := json.Marshal(workflows)
448+
if err != nil {
449+
return nil, fmt.Errorf("failed to marshal response: %w", err)
450+
}
484451

485-
return mcp.NewToolResultText(string(r)), nil
486-
}
452+
return mcp.NewToolResultText(string(r)), nil
487453
}
488454

489455
// RunWorkflow creates a tool to run an Actions workflow

0 commit comments

Comments
 (0)