create_branch
Create a new branch in a Codeup repository to organize development work, using a source branch as the starting point for changes.
Instructions
[Code Management] Create a new branch in a Codeup repository
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| organizationId | Yes | Organization ID, can be found in the basic information page of the organization admin console | |
| repositoryId | Yes | Repository ID or a combination of organization ID and repository name, for example: 2835387 or organizationId%2Frepo-name (Note: slashes need to be URL encoded as %2F) | |
| branch | Yes | Name of the branch to be created | |
| ref | No | Source branch name, the new branch will be created based on this branch, default value is master | master |
Implementation Reference
- tool-handlers/code-management.ts:13-24 (handler)MCP tool handler for 'create_branch': parses arguments using CreateBranchSchema and delegates to branches.createBranchFunc, returning the result as JSON text.case "create_branch": { const args = types.CreateBranchSchema.parse(request.params.arguments); const branch = await branches.createBranchFunc( args.organizationId, args.repositoryId, args.branch, args.ref ); return { content: [{ type: "text", text: JSON.stringify(branch, null, 2) }], }; }
- tool-registry/code-management.ts:7-11 (registration)Tool registration entry for 'create_branch' including name, description, and input schema derived from CreateBranchSchema.{ name: "create_branch", description: "[Code Management] Create a new branch in a Codeup repository", inputSchema: zodToJsonSchema(types.CreateBranchSchema), },
- operations/codeup/types.ts:219-224 (schema)Zod input schema definition for create_branch tool parameters: organizationId, repositoryId, branch, ref.export const CreateBranchSchema = z.object({ organizationId: z.string().describe("Organization ID, can be found in the basic information page of the organization admin console"), repositoryId: z.string().describe("Repository ID or a combination of organization ID and repository name, for example: 2835387 or organizationId%2Frepo-name (Note: slashes need to be URL encoded as %2F)"), branch: z.string().describe("Name of the branch to be created"), ref: z.string().default("master").describe("Source branch name, the new branch will be created based on this branch, default value is master"), });
- operations/codeup/branches.ts:19-52 (helper)Core helper function createBranchFunc that constructs the API URL, handles repositoryId encoding, makes POST request to create branch, and parses response with CodeupBranchSchema.export async function createBranchFunc( organizationId: string, repositoryId: string, branch: string, ref: string = "master" ): Promise<z.infer<typeof CodeupBranchSchema>>{ // Automatically handle unencoded slashes in repositoryId if (repositoryId.includes("/")) { // Found unencoded slash, automatically URL encode it const parts = repositoryId.split("/", 2); if (parts.length === 2) { const encodedRepoName = encodeURIComponent(parts[1]); // Remove + signs from encoding (spaces are encoded as +, but we need %20) const formattedEncodedName = encodedRepoName.replace(/\+/g, "%20"); repositoryId = `${parts[0]}%2F${formattedEncodedName}`; } } const baseUrl = `/oapi/v1/codeup/organizations/${organizationId}/repositories/${repositoryId}/branches`; // Build query parameters const queryParams: Record<string, string | number | undefined> = { branch: branch, ref: ref }; const url = buildUrl(baseUrl, queryParams); console.error("createBranchFunc url:" + url); const response = await yunxiaoRequest(url, { method: "POST", }); return CodeupBranchSchema.parse(response); }