Repository navigation
add list automation tags tool #3561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
+404
−0
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6e7546a
add list automation tags tool
notapopsicle e27559d
Improve validation for owner and repo inputs
notapopsicle 0e08c7a
Add validation for required parameters and pagination
notapopsicle fd9422d
Remove duplicate input checks and test dot-dot paths
notapopsicle e75fb4e
Test escaped owner and repo path segments
notapopsicle e7ec39d
Reject invalid inputs in direct list handler calls
notapopsicle bd547cd
Sanitize automation tag names and descriptions
notapopsicle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| { | ||
| "annotations": { | ||
| "idempotentHint": false, | ||
| "readOnlyHint": true, | ||
| "title": "List automation tags" | ||
| }, | ||
| "description": "List caller-visible automation tags in a repository. Tags organize automations; they do not execute them. Use nextPage with the same perPage to continue. Pages are not a snapshot across concurrent changes.", | ||
| "inputSchema": { | ||
| "properties": { | ||
| "owner": { | ||
| "description": "Repository owner", | ||
| "minLength": 1, | ||
| "type": "string" | ||
| }, | ||
| "page": { | ||
| "description": "Page number for pagination (min 1)", | ||
| "minimum": 1, | ||
| "type": "number" | ||
| }, | ||
| "perPage": { | ||
| "description": "Results per page for pagination (min 1, max 100)", | ||
| "maximum": 100, | ||
| "minimum": 1, | ||
| "type": "number" | ||
| }, | ||
| "repo": { | ||
| "description": "Repository name", | ||
| "minLength": 1, | ||
| "type": "string" | ||
| } | ||
| }, | ||
| "required": [ | ||
| "owner", | ||
| "repo" | ||
| ], | ||
| "type": "object" | ||
| }, | ||
| "name": "list_automation_tags" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| package github | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "net/http" | ||
| "net/url" | ||
|
|
||
| ghErrors "github.com/github/github-mcp-server/v2/pkg/errors" | ||
| "github.com/github/github-mcp-server/v2/pkg/inventory" | ||
| "github.com/github/github-mcp-server/v2/pkg/sanitize" | ||
| "github.com/github/github-mcp-server/v2/pkg/scopes" | ||
| "github.com/github/github-mcp-server/v2/pkg/translations" | ||
| "github.com/github/github-mcp-server/v2/pkg/utils" | ||
| "github.com/google/jsonschema-go/jsonschema" | ||
| "github.com/modelcontextprotocol/go-sdk/mcp" | ||
| ) | ||
|
|
||
| type AutomationTag struct { | ||
| ID string `json:"id"` | ||
| Name string `json:"name"` | ||
| Description string `json:"description"` | ||
| Version string `json:"version"` | ||
| CreatedAt string `json:"created_at"` | ||
| UpdatedAt string `json:"updated_at"` | ||
| } | ||
|
|
||
| type ListAutomationTagsResponse struct { | ||
| Tags []AutomationTag `json:"tags"` | ||
| TotalCount int `json:"total_count"` | ||
| NextPage int `json:"nextPage" jsonschema:"Next page from the REST Link header, or 0 when there is no next page"` | ||
| } | ||
|
|
||
| func ListAutomationTags(t translations.TranslationHelperFunc) inventory.ServerTool { | ||
| return NewTool[RepositoryListInput, *ListAutomationTagsResponse]( | ||
| ToolsetMetadataCopilotAutomations, | ||
| mcp.Tool{ | ||
| Name: "list_automation_tags", | ||
| Description: t("TOOL_LIST_AUTOMATION_TAGS_DESCRIPTION", "List caller-visible automation tags in a repository. Tags organize automations; they do not execute them. Use nextPage with the same perPage to continue. Pages are not a snapshot across concurrent changes."), | ||
| Annotations: &mcp.ToolAnnotations{ | ||
| Title: t("TOOL_LIST_AUTOMATION_TAGS_USER_TITLE", "List automation tags"), | ||
| ReadOnlyHint: true, | ||
| }, | ||
| InputSchema: WithPagination(&jsonschema.Schema{ | ||
| Type: "object", | ||
| Properties: map[string]*jsonschema.Schema{ | ||
| "owner": {Type: "string", Description: "Repository owner", MinLength: new(1)}, | ||
| "repo": {Type: "string", Description: "Repository name", MinLength: new(1)}, | ||
| }, | ||
| Required: []string{"owner", "repo"}, | ||
| }), | ||
| }, | ||
| scopes.RequireAll(scopes.Repo), | ||
| func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, input RepositoryListInput) (*mcp.CallToolResult, *ListAutomationTagsResponse, error) { | ||
| if input.Owner == "" { | ||
| return utils.NewToolResultError("missing required parameter: owner"), nil, nil | ||
| } | ||
| if input.Repo == "" { | ||
| return utils.NewToolResultError("missing required parameter: repo"), nil, nil | ||
| } | ||
| if input.Page != nil && *input.Page < 1 { | ||
| return utils.NewToolResultError("page must be at least 1"), nil, nil | ||
| } | ||
| if input.PerPage != nil && (*input.PerPage < 1 || *input.PerPage > 100) { | ||
| return utils.NewToolResultError("perPage must be between 1 and 100"), nil, nil | ||
| } | ||
| if input.Owner == "." || input.Owner == ".." { | ||
| return utils.NewToolResultError(fmt.Sprintf("owner must not be %q", input.Owner)), nil, nil | ||
| } | ||
| if input.Repo == "." || input.Repo == ".." { | ||
| return utils.NewToolResultError(fmt.Sprintf("repo must not be %q", input.Repo)), nil, nil | ||
| } | ||
| pagination := PaginationParams{Page: 1, PerPage: 30} | ||
| if input.Page != nil { | ||
| pagination.Page = *input.Page | ||
| } | ||
| if input.PerPage != nil { | ||
| pagination.PerPage = *input.PerPage | ||
| } | ||
| client, err := deps.GetClient(ctx) | ||
| if err != nil { | ||
| return nil, nil, fmt.Errorf("failed to get GitHub client: %w", err) | ||
| } | ||
| apiURL := fmt.Sprintf("agents/repos/%s/%s/automation-tags?page=%d&per_page=%d", | ||
| url.PathEscape(input.Owner), url.PathEscape(input.Repo), pagination.Page, pagination.PerPage) | ||
| req, err := client.NewRequest(ctx, http.MethodGet, apiURL, nil) | ||
| if err != nil { | ||
| return utils.NewToolResultErrorFromErr("failed to create automation tags request", err), nil, nil | ||
| } | ||
| var output ListAutomationTagsResponse | ||
| resp, err := client.Do(req, &output) | ||
| if resp != nil { | ||
| defer func() { _ = resp.Body.Close() }() | ||
| } | ||
| if err != nil { | ||
| return ghErrors.NewGitHubAPIErrorResponse(ctx, "failed to list automation tags", resp, err), nil, nil | ||
| } | ||
| if resp.StatusCode != http.StatusOK { | ||
| return ghErrors.NewGitHubAPIStatusErrorResponse(ctx, "failed to list automation tags", resp, nil), nil, nil | ||
| } | ||
| for i := range output.Tags { | ||
| sanitizeAutomationTagNameAndDescription(&output.Tags[i]) | ||
| } | ||
| output.NextPage = resp.NextPage | ||
| return MarshalledTextResult(&output), &output, nil | ||
| }, | ||
| ) | ||
| } | ||
|
|
||
| func sanitizeAutomationTagNameAndDescription(tag *AutomationTag) { | ||
| tag.Name = sanitize.PlainText(tag.Name) | ||
| tag.Description = sanitize.Content(tag.Description) | ||
|
notapopsicle marked this conversation as resolved.
|
||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.