create_repository
Create a Gitee repository with customizable settings, including name, description, privacy, issue tracking, wiki, initialization, and templates for Git Ignore and License.
Instructions
创建 Gitee 仓库
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"name": "<name>"
},
"name": "create_repository"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| auto_init | No | Whether to automatically initialize the repository | |
| description | No | Repository description | |
| gitignore_template | No | Git Ignore template | |
| has_issues | No | Whether to enable Issue functionality | |
| has_wiki | No | Whether to enable Wiki functionality | |
| homepage | No | Homepage URL | |
| license_template | No | License template | |
| name | Yes | Repository name | |
| path | No | Repository path | |
| private | No | Whether the repository is private |
Implementation Reference
- operations/repos.ts:43-62 (handler)Core handler function that performs the HTTP POST request to Gitee API to create a repository.
export async function createRepository(options: CreateRepositoryOptions) { try { console.log('Creating repository parameters:', JSON.stringify(options)); const url = "/user/repos"; const response = await giteeRequest(url, "POST", options); console.log('Create repository response:', JSON.stringify(response)); // Try to parse the response try { return GiteeRepositorySchema.parse(response); } catch (parseError) { console.error('Failed to parse repository response:', parseError); // Return the original response to avoid parsing errors return response; } } catch (error) { console.error('Failed to create repository request:', error); throw error; } } - operations/repos.ts:6-27 (schema)Zod schema defining the input parameters for the create_repository tool.
export const CreateRepositorySchema = z.object({ // 仓库名称 name: z.string().describe("Repository name"), // 仓库描述 description: z.string().optional().describe("Repository description"), // 主页地址 homepage: z.string().optional().describe("Homepage URL"), // 是否私有 private: z.boolean().default(false).optional().describe("Whether the repository is private"), // 是否开启 Issue 功能 has_issues: z.boolean().default(true).optional().describe("Whether to enable Issue functionality"), // 是否开启 Wiki 功能 has_wiki: z.boolean().default(true).optional().describe("Whether to enable Wiki functionality"), // 是否自动初始化仓库 auto_init: z.boolean().default(false).optional().describe("Whether to automatically initialize the repository"), // Git Ignore 模板 gitignore_template: z.string().optional().describe("Git Ignore template"), // License 模板 license_template: z.string().optional().describe("License template"), // 仓库路径 path: z.string().optional().describe("Repository path"), }); - index.ts:22-49 (registration)Tool registration in the MCP server, including a wrapper handler that preprocesses parameters before calling the core createRepository function.
server.registerTool({ name: "create_repository", description: "创建 Gitee 仓库", schema: repoOperations.CreateRepositorySchema, handler: async (params: any) => { try { // 确保 private 参数是布尔值 if (params.private !== undefined) { if (typeof params.private === 'string') { // 将字符串转换为布尔值 params.private = params.private.toLowerCase() === 'true'; } } // 处理其他可能的布尔值字段 ['has_issues', 'has_wiki', 'auto_init'].forEach(field => { if (params[field] !== undefined && typeof params[field] === 'string') { params[field] = params[field].toLowerCase() === 'true'; } }); return await repoOperations.createRepository(params); } catch (error) { console.error('创建仓库失败:', error); throw error; } }, });