SearchRepositories creates a tool to search for GitHub repositories.
(t translations.TranslationHelperFunc)
| 20 | |
| 21 | // SearchRepositories creates a tool to search for GitHub repositories. |
| 22 | func SearchRepositories(t translations.TranslationHelperFunc) inventory.ServerTool { |
| 23 | schema := &jsonschema.Schema{ |
| 24 | Type: "object", |
| 25 | Properties: map[string]*jsonschema.Schema{ |
| 26 | "query": { |
| 27 | Type: "string", |
| 28 | Description: "Repository search query. Examples: 'machine learning in:name stars:>1000 language:python', 'topic:react', 'user:facebook'. Supports advanced search syntax for precise filtering.", |
| 29 | }, |
| 30 | "sort": { |
| 31 | Type: "string", |
| 32 | Description: "Sort repositories by field, defaults to best match", |
| 33 | Enum: []any{"stars", "forks", "help-wanted-issues", "updated"}, |
| 34 | }, |
| 35 | "order": { |
| 36 | Type: "string", |
| 37 | Description: "Sort order", |
| 38 | Enum: []any{"asc", "desc"}, |
| 39 | }, |
| 40 | "minimal_output": { |
| 41 | Type: "boolean", |
| 42 | Description: "Return minimal repository information (default: true). When false, returns full GitHub API repository objects.", |
| 43 | Default: json.RawMessage(`true`), |
| 44 | }, |
| 45 | }, |
| 46 | Required: []string{"query"}, |
| 47 | } |
| 48 | WithPagination(schema) |
| 49 | |
| 50 | return NewTool( |
| 51 | ToolsetMetadataRepos, |
| 52 | mcp.Tool{ |
| 53 | Name: "search_repositories", |
| 54 | Description: t("TOOL_SEARCH_REPOSITORIES_DESCRIPTION", "Find GitHub repositories by name, description, readme, topics, or other metadata. Perfect for discovering projects, finding examples, or locating specific repositories across GitHub."), |
| 55 | Annotations: &mcp.ToolAnnotations{ |
| 56 | Title: t("TOOL_SEARCH_REPOSITORIES_USER_TITLE", "Search repositories"), |
| 57 | ReadOnlyHint: true, |
| 58 | }, |
| 59 | InputSchema: schema, |
| 60 | }, |
| 61 | []scopes.Scope{scopes.Repo}, |
| 62 | func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) { |
| 63 | query, err := RequiredParam[string](args, "query") |
| 64 | if err != nil { |
| 65 | return utils.NewToolResultError(err.Error()), nil, nil |
| 66 | } |
| 67 | sort, err := OptionalParam[string](args, "sort") |
| 68 | if err != nil { |
| 69 | return utils.NewToolResultError(err.Error()), nil, nil |
| 70 | } |
| 71 | order, err := OptionalParam[string](args, "order") |
| 72 | if err != nil { |
| 73 | return utils.NewToolResultError(err.Error()), nil, nil |
| 74 | } |
| 75 | pagination, err := OptionalPaginationParams(args) |
| 76 | if err != nil { |
| 77 | return utils.NewToolResultError(err.Error()), nil, nil |
| 78 | } |
| 79 | minimalOutput, err := OptionalBoolParamWithDefault(args, "minimal_output", true) |