fork_repository
Create a copy of a GitHub repository to your account or organization for independent development, testing, or contribution.
Instructions
Fork a GitHub repository to your account or specified organization
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| owner | Yes | Repository owner (username or organization) | |
| repo | Yes | Repository name | |
| organization | No | Optional: organization to fork to (defaults to your personal account) |
Implementation Reference
- src/operations/repository.ts:64-79 (handler)The main handler function that performs the GitHub repository fork operation using the GitHub API.export async function forkRepository( github_pat: string, owner: string, repo: string, organization?: string ) { const url = organization ? `https://api.github.com/repos/${owner}/${repo}/forks?organization=${organization}` : `https://api.github.com/repos/${owner}/${repo}/forks`; const response = await githubRequest(github_pat, url, { method: "POST" }); return GitHubRepositorySchema.extend({ parent: GitHubRepositorySchema, source: GitHubRepositorySchema, }).parse(response); }
- src/operations/repository.ts:27-35 (schema)Zod schemas defining the input parameters for the fork_repository tool, including the public schema and internal schema with GitHub PAT.export const ForkRepositorySchema = z.object({ owner: z.string().describe("Repository owner (username or organization)"), repo: z.string().describe("Repository name"), organization: z.string().optional().describe("Optional: organization to fork to (defaults to your personal account)"), }); export const _ForkRepositorySchema = ForkRepositorySchema.extend({ github_pat: z.string().describe("GitHub Personal Access Token"), });
- src/index.ts:113-117 (registration)Tool registration in the MCP server's listTools response, defining the name, description, and input schema.{ name: "fork_repository", description: "Fork a GitHub repository to your account or specified organization", inputSchema: zodToJsonSchema(repository.ForkRepositorySchema), },
- src/index.ts:331-337 (registration)Dispatch logic in the MCP server's callTool handler that parses arguments and invokes the forkRepository function.case "fork_repository": { const args = repository._ForkRepositorySchema.parse(params.arguments); const fork = await repository.forkRepository(args.github_pat, args.owner, args.repo, args.organization); return { content: [{ type: "text", text: JSON.stringify(fork, null, 2) }], }; }