CreateBranch creates a tool to create a new branch.
(t translations.TranslationHelperFunc)
| 1181 | |
| 1182 | // CreateBranch creates a tool to create a new branch. |
| 1183 | func CreateBranch(t translations.TranslationHelperFunc) inventory.ServerTool { |
| 1184 | return NewTool( |
| 1185 | ToolsetMetadataRepos, |
| 1186 | mcp.Tool{ |
| 1187 | Name: "create_branch", |
| 1188 | Description: t("TOOL_CREATE_BRANCH_DESCRIPTION", "Create a new branch in a GitHub repository"), |
| 1189 | Annotations: &mcp.ToolAnnotations{ |
| 1190 | Title: t("TOOL_CREATE_BRANCH_USER_TITLE", "Create branch"), |
| 1191 | ReadOnlyHint: false, |
| 1192 | }, |
| 1193 | InputSchema: &jsonschema.Schema{ |
| 1194 | Type: "object", |
| 1195 | Properties: map[string]*jsonschema.Schema{ |
| 1196 | "owner": { |
| 1197 | Type: "string", |
| 1198 | Description: "Repository owner", |
| 1199 | }, |
| 1200 | "repo": { |
| 1201 | Type: "string", |
| 1202 | Description: "Repository name", |
| 1203 | }, |
| 1204 | "branch": { |
| 1205 | Type: "string", |
| 1206 | Description: "Name for new branch", |
| 1207 | }, |
| 1208 | "from_branch": { |
| 1209 | Type: "string", |
| 1210 | Description: "Source branch (defaults to repo default)", |
| 1211 | }, |
| 1212 | }, |
| 1213 | Required: []string{"owner", "repo", "branch"}, |
| 1214 | }, |
| 1215 | }, |
| 1216 | []scopes.Scope{scopes.Repo}, |
| 1217 | func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) { |
| 1218 | owner, err := RequiredParam[string](args, "owner") |
| 1219 | if err != nil { |
| 1220 | return utils.NewToolResultError(err.Error()), nil, nil |
| 1221 | } |
| 1222 | repo, err := RequiredParam[string](args, "repo") |
| 1223 | if err != nil { |
| 1224 | return utils.NewToolResultError(err.Error()), nil, nil |
| 1225 | } |
| 1226 | branch, err := RequiredParam[string](args, "branch") |
| 1227 | if err != nil { |
| 1228 | return utils.NewToolResultError(err.Error()), nil, nil |
| 1229 | } |
| 1230 | fromBranch, err := OptionalParam[string](args, "from_branch") |
| 1231 | if err != nil { |
| 1232 | return utils.NewToolResultError(err.Error()), nil, nil |
| 1233 | } |
| 1234 | |
| 1235 | client, err := deps.GetClient(ctx) |
| 1236 | if err != nil { |
| 1237 | return nil, nil, fmt.Errorf("failed to get GitHub client: %w", err) |
| 1238 | } |
| 1239 | |
| 1240 | // Get the source branch SHA |