MCPcopy Index your code
hub / github.com/github/github-mcp-server / StarRepository

Function StarRepository

pkg/github/repositories.go:2139–2202  ·  view source on GitHub ↗

StarRepository creates a tool to star a repository.

(t translations.TranslationHelperFunc)

Source from the content-addressed store, hash-verified

2137
2138// StarRepository creates a tool to star a repository.
2139func StarRepository(t translations.TranslationHelperFunc) inventory.ServerTool {
2140 return NewTool(
2141 ToolsetMetadataStargazers,
2142 mcp.Tool{
2143 Name: "star_repository",
2144 Description: t("TOOL_STAR_REPOSITORY_DESCRIPTION", "Star a GitHub repository"),
2145 Icons: octicons.Icons("star-fill"),
2146 Annotations: &mcp.ToolAnnotations{
2147 Title: t("TOOL_STAR_REPOSITORY_USER_TITLE", "Star repository"),
2148 ReadOnlyHint: false,
2149 },
2150 InputSchema: &jsonschema.Schema{
2151 Type: "object",
2152 Properties: map[string]*jsonschema.Schema{
2153 "owner": {
2154 Type: "string",
2155 Description: "Repository owner",
2156 },
2157 "repo": {
2158 Type: "string",
2159 Description: "Repository name",
2160 },
2161 },
2162 Required: []string{"owner", "repo"},
2163 },
2164 },
2165 []scopes.Scope{scopes.Repo},
2166 func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) {
2167 owner, err := RequiredParam[string](args, "owner")
2168 if err != nil {
2169 return utils.NewToolResultError(err.Error()), nil, nil
2170 }
2171 repo, err := RequiredParam[string](args, "repo")
2172 if err != nil {
2173 return utils.NewToolResultError(err.Error()), nil, nil
2174 }
2175
2176 client, err := deps.GetClient(ctx)
2177 if err != nil {
2178 return nil, nil, fmt.Errorf("failed to get GitHub client: %w", err)
2179 }
2180
2181 resp, err := client.Activity.Star(ctx, owner, repo)
2182 if err != nil {
2183 return ghErrors.NewGitHubAPIErrorResponse(ctx,
2184 fmt.Sprintf("failed to star repository %s/%s", owner, repo),
2185 resp,
2186 err,
2187 ), nil, nil
2188 }
2189 defer func() { _ = resp.Body.Close() }()
2190
2191 if resp.StatusCode != 204 {
2192 body, err := io.ReadAll(resp.Body)
2193 if err != nil {
2194 return nil, nil, fmt.Errorf("failed to read response body: %w", err)
2195 }
2196 return ghErrors.NewGitHubAPIStatusErrorResponse(ctx, "failed to star repository", resp, body), nil, nil

Callers 2

AllToolsFunction · 0.85
Test_StarRepositoryFunction · 0.85

Calls 7

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

Tested by 1

Test_StarRepositoryFunction · 0.68