create_branch
Create a new branch in a Gitee repository by specifying the owner, repository, and branch name, with an optional reference source for the branch.
Instructions
在 Gitee 仓库中创建一个新分支
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| branch_name | Yes | Name for the new branch | |
| owner | Yes | Repository owner path (enterprise, organization, or personal path) | |
| refs | No | Source reference for the branch, default: master | master |
| repo | Yes | Repository path |
Implementation Reference
- operations/branches.ts:47-65 (handler)Core handler function that performs the actual branch creation by validating inputs, constructing API URL and body, sending POST request to Gitee API, and parsing response.export async function createBranchFromRef( owner: string, repo: string, branchName: string, refs: string = "master" ) { owner = validateOwnerName(owner); repo = validateRepositoryName(repo); branchName = validateBranchName(branchName); const url = `/repos/${owner}/${repo}/branches`; const body = { branch_name: branchName, refs: refs, }; const response = await giteeRequest(url, "POST", body); return GiteeBranchSchema.parse(response); }
- operations/branches.ts:6-15 (schema)Zod schema for input validation of the create_branch tool parameters: owner, repo, branch_name, refs.export const CreateBranchSchema = z.object({ // 仓库所属空间地址 (企业、组织或个人的地址 path) owner: z.string().describe("Repository owner path (enterprise, organization, or personal path)"), // 仓库路径 (path) repo: z.string().describe("Repository path"), // 新创建的分支名称 branch_name: z.string().describe("Name for the new branch"), // 起点名称,默认:master refs: z.string().default("master").describe("Source reference for the branch, default: master"), });
- index.ts:62-70 (registration)Tool registration in MCP server, specifying name, description, schema, and thin handler wrapper that delegates to createBranchFromRef.server.registerTool({ name: "create_branch", description: "在 Gitee 仓库中创建一个新分支", schema: branchOperations.CreateBranchSchema, handler: async (params: any) => { const { owner, repo, branch_name, refs } = params; return await branchOperations.createBranchFromRef(owner, repo, branch_name, refs); }, });