GetRepositoryTree creates a tool to get the tree structure of a GitHub repository.
(t translations.TranslationHelperFunc)
| 41 | |
| 42 | // GetRepositoryTree creates a tool to get the tree structure of a GitHub repository. |
| 43 | func GetRepositoryTree(t translations.TranslationHelperFunc) inventory.ServerTool { |
| 44 | return NewTool( |
| 45 | ToolsetMetadataGit, |
| 46 | mcp.Tool{ |
| 47 | Name: "get_repository_tree", |
| 48 | Description: t("TOOL_GET_REPOSITORY_TREE_DESCRIPTION", "Get the tree structure (files and directories) of a GitHub repository at a specific ref or SHA"), |
| 49 | Annotations: &mcp.ToolAnnotations{ |
| 50 | Title: t("TOOL_GET_REPOSITORY_TREE_USER_TITLE", "Get repository tree"), |
| 51 | ReadOnlyHint: true, |
| 52 | }, |
| 53 | InputSchema: &jsonschema.Schema{ |
| 54 | Type: "object", |
| 55 | Properties: map[string]*jsonschema.Schema{ |
| 56 | "owner": { |
| 57 | Type: "string", |
| 58 | Description: "Repository owner (username or organization)", |
| 59 | }, |
| 60 | "repo": { |
| 61 | Type: "string", |
| 62 | Description: "Repository name", |
| 63 | }, |
| 64 | "tree_sha": { |
| 65 | Type: "string", |
| 66 | Description: "The SHA1 value or ref (branch or tag) name of the tree. Defaults to the repository's default branch", |
| 67 | }, |
| 68 | "recursive": { |
| 69 | Type: "boolean", |
| 70 | Description: "Setting this parameter to true returns the objects or subtrees referenced by the tree. Default is false", |
| 71 | Default: json.RawMessage(`false`), |
| 72 | }, |
| 73 | "path_filter": { |
| 74 | Type: "string", |
| 75 | Description: "Optional path prefix to filter the tree results (e.g., 'src/' to only show files in the src directory)", |
| 76 | }, |
| 77 | }, |
| 78 | Required: []string{"owner", "repo"}, |
| 79 | }, |
| 80 | }, |
| 81 | []scopes.Scope{scopes.Repo}, |
| 82 | func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) { |
| 83 | owner, err := RequiredParam[string](args, "owner") |
| 84 | if err != nil { |
| 85 | return utils.NewToolResultError(err.Error()), nil, nil |
| 86 | } |
| 87 | repo, err := RequiredParam[string](args, "repo") |
| 88 | if err != nil { |
| 89 | return utils.NewToolResultError(err.Error()), nil, nil |
| 90 | } |
| 91 | treeSHA, err := OptionalParam[string](args, "tree_sha") |
| 92 | if err != nil { |
| 93 | return utils.NewToolResultError(err.Error()), nil, nil |
| 94 | } |
| 95 | recursive, err := OptionalBoolParamWithDefault(args, "recursive", false) |
| 96 | if err != nil { |
| 97 | return utils.NewToolResultError(err.Error()), nil, nil |
| 98 | } |
| 99 | pathFilter, err := OptionalParam[string](args, "path_filter") |
| 100 | if err != nil { |