fork_repository
Fork a GitLab project to your account or a specific namespace using this tool. Simplify repository duplication and manage projects efficiently with precise namespace control.
Instructions
Fork a GitLab project to your account or specified namespace
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| namespace | No | ||
| project_id | No |
Implementation Reference
- src/index.ts:325-329 (handler)Handler for the fork_repository tool that parses input arguments using the schema, delegates to GitLabApi.forkProject helper, and formats the response as JSON text.case "fork_repository": { const args = ForkRepositorySchema.parse(request.params.arguments); const fork = await gitlabApi.forkProject(args.project_id, args.namespace); return { content: [{ type: "text", text: JSON.stringify(fork, null, 2) }] }; }
- src/schemas.ts:430-433 (schema)Zod schema defining the input structure for the fork_repository tool: project_id (required string) and optional namespace.export const ForkRepositorySchema = z.object({ project_id: z.string(), namespace: z.string().optional() });
- src/index.ts:150-154 (registration)Tool registration in the ALL_TOOLS array, specifying name, description, input schema conversion, and readOnly flag.{ name: "fork_repository", description: "Fork a GitLab project to your account or specified namespace", inputSchema: createJsonSchema(ForkRepositorySchema), readOnly: false
- src/gitlab-api.ts:86-109 (helper)Implementation of forkProject method in GitLabApi class that makes the POST request to GitLab's /projects/{id}/fork endpoint, handles response, and validates with GitLabForkSchema.async forkProject( projectId: string, namespace?: string ): Promise<GitLabFork> { const url = `${this.apiUrl}/projects/${encodeURIComponent(projectId)}/fork`; const queryParams = namespace ? `?namespace=${encodeURIComponent(namespace)}` : ''; const response = await fetch(url + queryParams, { method: "POST", headers: { "Authorization": `Bearer ${this.token}`, "Content-Type": "application/json" } }); if (!response.ok) { throw new McpError( ErrorCode.InternalError, `GitLab API error: ${response.statusText}` ); } return GitLabForkSchema.parse(await response.json()); }