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

Function SearchCommits

pkg/github/search.go:496–610  ·  view source on GitHub ↗

SearchCommits creates a tool to search for commits across GitHub repositories.

(t translations.TranslationHelperFunc)

Source from the content-addressed store, hash-verified

494
495// SearchCommits creates a tool to search for commits across GitHub repositories.
496func SearchCommits(t translations.TranslationHelperFunc) inventory.ServerTool {
497 schema := &jsonschema.Schema{
498 Type: "object",
499 Properties: map[string]*jsonschema.Schema{
500 "query": {
501 Type: "string",
502 Description: "Commit search query (GitHub commit search REST). Searches commit messages on the default branch only. Scope the search with `repo:owner/repo`, `org:`, or `user:` (queries without a scope qualifier match across all of GitHub and are usually not what you want). Other qualifiers: `author:`, `committer:`, `author-name:`, `committer-name:`, `author-email:`, `committer-email:`, `author-date:`, `committer-date:` (supports `>`, `<`, `>=`, `<=`, and `YYYY-MM-DD..YYYY-MM-DD` ranges), `merge:true|false`, `hash:`, `tree:`, `parent:`, `is:public`. Examples: `repo:owner/repo fix panic`; `org:github author:defunkt committer-date:>=2024-01-01`; `\"refactor cache\" repo:o/r`; `hash:abc1234 repo:o/r`.",
503 },
504 "sort": {
505 Type: "string",
506 Description: "Sort by author or committer date (defaults to best match)",
507 Enum: []any{"author-date", "committer-date"},
508 },
509 "order": {
510 Type: "string",
511 Description: "Sort order",
512 Enum: []any{"asc", "desc"},
513 },
514 },
515 Required: []string{"query"},
516 }
517 WithPagination(schema)
518
519 return NewTool(
520 ToolsetMetadataRepos,
521 mcp.Tool{
522 Name: "search_commits",
523 Description: t("TOOL_SEARCH_COMMITS_DESCRIPTION", "Search for commits across GitHub repositories using GitHub's commit search syntax. Useful for finding specific changes, authors, or messages across one or many repositories. Searches the default branch only."),
524 Annotations: &mcp.ToolAnnotations{
525 Title: t("TOOL_SEARCH_COMMITS_USER_TITLE", "Search commits"),
526 ReadOnlyHint: true,
527 },
528 InputSchema: schema,
529 },
530 []scopes.Scope{scopes.Repo},
531 func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) {
532 query, err := RequiredParam[string](args, "query")
533 if err != nil {
534 return utils.NewToolResultError(err.Error()), nil, nil
535 }
536 sort, err := OptionalParam[string](args, "sort")
537 if err != nil {
538 return utils.NewToolResultError(err.Error()), nil, nil
539 }
540 order, err := OptionalParam[string](args, "order")
541 if err != nil {
542 return utils.NewToolResultError(err.Error()), nil, nil
543 }
544 pagination, err := OptionalPaginationParams(args)
545 if err != nil {
546 return utils.NewToolResultError(err.Error()), nil, nil
547 }
548
549 opts := &github.SearchOptions{
550 Sort: sort,
551 Order: order,
552 ListOptions: github.ListOptions{
553 Page: pagination.Page,

Callers 2

AllToolsFunction · 0.85
Test_SearchCommitsFunction · 0.85

Calls 11

NewToolResultErrorFunction · 0.92
NewToolResultTextFunction · 0.92
WithPaginationFunction · 0.85
NewToolFunction · 0.85
OptionalPaginationParamsFunction · 0.85
attachJoinedIFCLabelFunction · 0.85
CloseMethod · 0.80
GetClientMethod · 0.65
ErrorMethod · 0.45

Tested by 1

Test_SearchCommitsFunction · 0.68