MCPcopy
hub / github.com/github/github-mcp-server / GetLatestRelease

Function GetLatestRelease

pkg/github/repositories.go:1834–1906  ·  view source on GitHub ↗

GetLatestRelease creates a tool to get the latest release in a GitHub repository.

(t translations.TranslationHelperFunc)

Source from the content-addressed store, hash-verified

1832
1833// GetLatestRelease creates a tool to get the latest release in a GitHub repository.
1834func GetLatestRelease(t translations.TranslationHelperFunc) inventory.ServerTool {
1835 return NewTool(
1836 ToolsetMetadataRepos,
1837 mcp.Tool{
1838 Name: "get_latest_release",
1839 Description: t("TOOL_GET_LATEST_RELEASE_DESCRIPTION", "Get the latest release in a GitHub repository"),
1840 Annotations: &mcp.ToolAnnotations{
1841 Title: t("TOOL_GET_LATEST_RELEASE_USER_TITLE", "Get latest release"),
1842 ReadOnlyHint: true,
1843 },
1844 InputSchema: &jsonschema.Schema{
1845 Type: "object",
1846 Properties: map[string]*jsonschema.Schema{
1847 "owner": {
1848 Type: "string",
1849 Description: "Repository owner",
1850 },
1851 "repo": {
1852 Type: "string",
1853 Description: "Repository name",
1854 },
1855 },
1856 Required: []string{"owner", "repo"},
1857 },
1858 },
1859 []scopes.Scope{scopes.Repo},
1860 func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) {
1861 owner, err := RequiredParam[string](args, "owner")
1862 if err != nil {
1863 return utils.NewToolResultError(err.Error()), nil, nil
1864 }
1865 repo, err := RequiredParam[string](args, "repo")
1866 if err != nil {
1867 return utils.NewToolResultError(err.Error()), nil, nil
1868 }
1869
1870 client, err := deps.GetClient(ctx)
1871 if err != nil {
1872 return nil, nil, fmt.Errorf("failed to get GitHub client: %w", err)
1873 }
1874
1875 release, resp, err := client.Repositories.GetLatestRelease(ctx, owner, repo)
1876 if err != nil {
1877 return nil, nil, fmt.Errorf("failed to get latest release: %w", err)
1878 }
1879 defer func() { _ = resp.Body.Close() }()
1880
1881 if resp.StatusCode != http.StatusOK {
1882 body, err := io.ReadAll(resp.Body)
1883 if err != nil {
1884 return nil, nil, fmt.Errorf("failed to read response body: %w", err)
1885 }
1886 return ghErrors.NewGitHubAPIStatusErrorResponse(ctx, "failed to get latest release", resp, body), nil, nil
1887 }
1888
1889 r, err := json.Marshal(release)
1890 if err != nil {
1891 return nil, nil, fmt.Errorf("failed to marshal response: %w", err)

Callers 2

AllToolsFunction · 0.85
Test_GetLatestReleaseFunction · 0.85

Calls 8

NewToolResultErrorFunction · 0.92
NewToolResultTextFunction · 0.92
LabelReleaseFunction · 0.92
NewToolFunction · 0.85
CloseMethod · 0.80
GetClientMethod · 0.65
ErrorMethod · 0.45

Tested by 1

Test_GetLatestReleaseFunction · 0.68