ListCommits creates a tool to get commits of a branch in a repository.
(t translations.TranslationHelperFunc)
| 134 | |
| 135 | // ListCommits creates a tool to get commits of a branch in a repository. |
| 136 | func ListCommits(t translations.TranslationHelperFunc) inventory.ServerTool { |
| 137 | return NewTool( |
| 138 | ToolsetMetadataRepos, |
| 139 | mcp.Tool{ |
| 140 | Name: "list_commits", |
| 141 | Description: t("TOOL_LIST_COMMITS_DESCRIPTION", "Get list of commits of a branch in a GitHub repository. Returns at least 30 results per page by default, but can return more if specified using the perPage parameter (up to 100)."), |
| 142 | Annotations: &mcp.ToolAnnotations{ |
| 143 | Title: t("TOOL_LIST_COMMITS_USER_TITLE", "List commits"), |
| 144 | ReadOnlyHint: true, |
| 145 | }, |
| 146 | InputSchema: WithPagination(&jsonschema.Schema{ |
| 147 | Type: "object", |
| 148 | Properties: map[string]*jsonschema.Schema{ |
| 149 | "owner": { |
| 150 | Type: "string", |
| 151 | Description: "Repository owner", |
| 152 | }, |
| 153 | "repo": { |
| 154 | Type: "string", |
| 155 | Description: "Repository name", |
| 156 | }, |
| 157 | "sha": { |
| 158 | Type: "string", |
| 159 | Description: "Commit SHA, branch or tag name to list commits of. If not provided, uses the default branch of the repository. If a commit SHA is provided, will list commits up to that SHA.", |
| 160 | }, |
| 161 | "author": { |
| 162 | Type: "string", |
| 163 | Description: "Author username or email address to filter commits by", |
| 164 | }, |
| 165 | "path": { |
| 166 | Type: "string", |
| 167 | Description: "Only commits containing this file path will be returned", |
| 168 | }, |
| 169 | "since": { |
| 170 | Type: "string", |
| 171 | Description: "Only commits after this date will be returned (ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ or YYYY-MM-DD)", |
| 172 | }, |
| 173 | "until": { |
| 174 | Type: "string", |
| 175 | Description: "Only commits before this date will be returned (ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ or YYYY-MM-DD)", |
| 176 | }, |
| 177 | }, |
| 178 | Required: []string{"owner", "repo"}, |
| 179 | }), |
| 180 | }, |
| 181 | []scopes.Scope{scopes.Repo}, |
| 182 | func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) { |
| 183 | owner, err := RequiredParam[string](args, "owner") |
| 184 | if err != nil { |
| 185 | return utils.NewToolResultError(err.Error()), nil, nil |
| 186 | } |
| 187 | repo, err := RequiredParam[string](args, "repo") |
| 188 | if err != nil { |
| 189 | return utils.NewToolResultError(err.Error()), nil, nil |
| 190 | } |
| 191 | sha, err := OptionalParam[string](args, "sha") |
| 192 | if err != nil { |
| 193 | return utils.NewToolResultError(err.Error()), nil, nil |