ForkRepository creates a tool to fork a repository.
(t translations.TranslationHelperFunc)
| 897 | |
| 898 | // ForkRepository creates a tool to fork a repository. |
| 899 | func ForkRepository(t translations.TranslationHelperFunc) inventory.ServerTool { |
| 900 | return NewTool( |
| 901 | ToolsetMetadataRepos, |
| 902 | mcp.Tool{ |
| 903 | Name: "fork_repository", |
| 904 | Description: t("TOOL_FORK_REPOSITORY_DESCRIPTION", "Fork a GitHub repository to your account or specified organization"), |
| 905 | Icons: octicons.Icons("repo-forked"), |
| 906 | Annotations: &mcp.ToolAnnotations{ |
| 907 | Title: t("TOOL_FORK_REPOSITORY_USER_TITLE", "Fork repository"), |
| 908 | ReadOnlyHint: false, |
| 909 | }, |
| 910 | InputSchema: &jsonschema.Schema{ |
| 911 | Type: "object", |
| 912 | Properties: map[string]*jsonschema.Schema{ |
| 913 | "owner": { |
| 914 | Type: "string", |
| 915 | Description: "Repository owner", |
| 916 | }, |
| 917 | "repo": { |
| 918 | Type: "string", |
| 919 | Description: "Repository name", |
| 920 | }, |
| 921 | "organization": { |
| 922 | Type: "string", |
| 923 | Description: "Organization to fork to", |
| 924 | }, |
| 925 | }, |
| 926 | Required: []string{"owner", "repo"}, |
| 927 | }, |
| 928 | }, |
| 929 | []scopes.Scope{scopes.Repo}, |
| 930 | func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) { |
| 931 | owner, err := RequiredParam[string](args, "owner") |
| 932 | if err != nil { |
| 933 | return utils.NewToolResultError(err.Error()), nil, nil |
| 934 | } |
| 935 | repo, err := RequiredParam[string](args, "repo") |
| 936 | if err != nil { |
| 937 | return utils.NewToolResultError(err.Error()), nil, nil |
| 938 | } |
| 939 | org, err := OptionalParam[string](args, "organization") |
| 940 | if err != nil { |
| 941 | return utils.NewToolResultError(err.Error()), nil, nil |
| 942 | } |
| 943 | |
| 944 | opts := &github.RepositoryCreateForkOptions{} |
| 945 | if org != "" { |
| 946 | opts.Organization = org |
| 947 | } |
| 948 | |
| 949 | client, err := deps.GetClient(ctx) |
| 950 | if err != nil { |
| 951 | return nil, nil, fmt.Errorf("failed to get GitHub client: %w", err) |
| 952 | } |
| 953 | forkedRepo, resp, err := client.Repositories.CreateFork(ctx, owner, repo, opts) |
| 954 | if err != nil { |
| 955 | // Check if it's an acceptedError. An acceptedError indicates that the update is in progress, |
| 956 | // and it's not a real error. |