list_branches
Retrieve and sort branches in a Gitee repository by name or update date, filtering by owner, repo, and page settings. Simplify repository branch management.
Instructions
列出 Gitee 仓库中的分支
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| direction | No | Sort direction | asc |
| owner | Yes | Repository owner path (enterprise, organization, or personal path) | |
| page | No | Page number | |
| per_page | No | Number of items per page, maximum 100 | |
| repo | Yes | Repository path | |
| sort | No | Sort field | name |
Implementation Reference
- operations/branches.ts:67-95 (handler)The core handler function that implements the logic to list branches from a Gitee repository by constructing the API URL with query parameters and fetching/parsing the response.export async function listBranches( owner: string, repo: string, sort?: string, direction?: string, page?: number, per_page?: number ) { owner = validateOwnerName(owner); repo = validateRepositoryName(repo); const url = new URL(`${getGiteeApiBaseUrl()}/repos/${owner}/${repo}/branches`); if (sort) { url.searchParams.append("sort", sort); } if (direction) { url.searchParams.append("direction", direction); } if (page !== undefined) { url.searchParams.append("page", page.toString()); } if (per_page !== undefined) { url.searchParams.append("per_page", per_page.toString()); } const response = await giteeRequest(url.toString()); return z.array(GiteeBranchSchema).parse(response); }
- operations/branches.ts:17-30 (schema)Zod schema defining the input parameters for the list_branches tool, including owner, repo, sorting, pagination options.export const ListBranchesSchema = z.object({ // 仓库所属空间地址 (企业、组织或个人的地址 path) owner: z.string().describe("Repository owner path (enterprise, organization, or personal path)"), // 仓库路径 (path) repo: z.string().describe("Repository path"), // 排序字段 sort: z.enum(["name", "updated"]).default("name").optional().describe("Sort field"), // 排序方向 direction: z.enum(["asc", "desc"]).default("asc").optional().describe("Sort direction"), // 当前的页码 page: z.number().int().default(1).optional().describe("Page number"), // 每页的数量,最大为 100 per_page: z.number().int().min(1).max(100).optional().describe("Number of items per page, maximum 100"), });
- index.ts:72-87 (registration)Tool registration in the MCP server, specifying name, description, schema, and a wrapper handler that delegates to the implementation in branchOperations.server.registerTool({ name: "list_branches", description: "列出 Gitee 仓库中的分支", schema: branchOperations.ListBranchesSchema, handler: async (params: any) => { const { owner, repo, sort, direction, page, per_page } = params; return await branchOperations.listBranches( owner, repo, sort, direction, page, per_page ); }, });