ListReleases creates a tool to list releases in a GitHub repository.
(t translations.TranslationHelperFunc)
| 1733 | |
| 1734 | // ListReleases creates a tool to list releases in a GitHub repository. |
| 1735 | func ListReleases(t translations.TranslationHelperFunc) inventory.ServerTool { |
| 1736 | return NewTool( |
| 1737 | ToolsetMetadataRepos, |
| 1738 | mcp.Tool{ |
| 1739 | Name: "list_releases", |
| 1740 | Description: t("TOOL_LIST_RELEASES_DESCRIPTION", "List releases in a GitHub repository"), |
| 1741 | Annotations: &mcp.ToolAnnotations{ |
| 1742 | Title: t("TOOL_LIST_RELEASES_USER_TITLE", "List releases"), |
| 1743 | ReadOnlyHint: true, |
| 1744 | }, |
| 1745 | InputSchema: WithPagination(&jsonschema.Schema{ |
| 1746 | Type: "object", |
| 1747 | Properties: map[string]*jsonschema.Schema{ |
| 1748 | "owner": { |
| 1749 | Type: "string", |
| 1750 | Description: "Repository owner", |
| 1751 | }, |
| 1752 | "repo": { |
| 1753 | Type: "string", |
| 1754 | Description: "Repository name", |
| 1755 | }, |
| 1756 | }, |
| 1757 | Required: []string{"owner", "repo"}, |
| 1758 | }), |
| 1759 | }, |
| 1760 | []scopes.Scope{scopes.Repo}, |
| 1761 | func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) { |
| 1762 | owner, err := RequiredParam[string](args, "owner") |
| 1763 | if err != nil { |
| 1764 | return utils.NewToolResultError(err.Error()), nil, nil |
| 1765 | } |
| 1766 | repo, err := RequiredParam[string](args, "repo") |
| 1767 | if err != nil { |
| 1768 | return utils.NewToolResultError(err.Error()), nil, nil |
| 1769 | } |
| 1770 | pagination, err := OptionalPaginationParams(args) |
| 1771 | if err != nil { |
| 1772 | return utils.NewToolResultError(err.Error()), nil, nil |
| 1773 | } |
| 1774 | |
| 1775 | opts := &github.ListOptions{ |
| 1776 | Page: pagination.Page, |
| 1777 | PerPage: pagination.PerPage, |
| 1778 | } |
| 1779 | |
| 1780 | client, err := deps.GetClient(ctx) |
| 1781 | if err != nil { |
| 1782 | return nil, nil, fmt.Errorf("failed to get GitHub client: %w", err) |
| 1783 | } |
| 1784 | |
| 1785 | releases, resp, err := client.Repositories.ListReleases(ctx, owner, repo, opts) |
| 1786 | if err != nil { |
| 1787 | return nil, nil, fmt.Errorf("failed to list releases: %w", err) |
| 1788 | } |
| 1789 | defer func() { _ = resp.Body.Close() }() |
| 1790 | |
| 1791 | if resp.StatusCode != http.StatusOK { |
| 1792 | body, err := io.ReadAll(resp.Body) |