create_pull_request
Create a pull request in a GitHub repository, specifying owner, repository name, title, source and target branches, description, and draft status for collaborative code review and merging.
Instructions
Create a new pull request in a GitHub repository
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| base | Yes | The name of the branch you want the changes pulled into | |
| body | No | Pull request body/description | |
| draft | No | Whether to create the pull request as a draft | |
| head | Yes | The name of the branch where your changes are implemented | |
| maintainer_can_modify | No | Whether maintainers can modify the pull request | |
| owner | Yes | Repository owner (username or organization) | |
| repo | Yes | Repository name | |
| title | Yes | Pull request title |
Implementation Reference
- src/operations/pulls.ts:206-222 (handler)The core handler function that executes the create_pull_request tool logic: parses input parameters, makes POST request to GitHub API to create PR, validates and returns the PR object.export async function createPullRequest( github_pat: string, params: z.infer<typeof CreatePullRequestSchema> ): Promise<z.infer<typeof GitHubPullRequestSchema>> { const { owner, repo, ...options } = CreatePullRequestSchema.parse(params); const response = await githubRequest( github_pat, `https://api.github.com/repos/${owner}/${repo}/pulls`, { method: "POST", body: options, } ); return GitHubPullRequestSchema.parse(response); }
- src/operations/pulls.ts:79-88 (schema)Zod input schema defining the parameters for the create_pull_request tool (owner, repo, title, body, head, base, draft, maintainer_can_modify). Used in registration and parsing.export const CreatePullRequestSchema = z.object({ owner: z.string().describe("Repository owner (username or organization)"), repo: z.string().describe("Repository name"), title: z.string().describe("Pull request title"), body: z.string().optional().describe("Pull request body/description"), head: z.string().describe("The name of the branch where your changes are implemented"), base: z.string().describe("The name of the branch you want the changes pulled into"), draft: z.boolean().optional().describe("Whether to create the pull request as a draft"), maintainer_can_modify: z.boolean().optional().describe("Whether maintainers can modify the pull request") });
- src/index.ts:108-112 (registration)MCP tool registration in the listTools response: defines name, description, and converts Zod schema to JSON schema for the tool.{ name: "create_pull_request", description: "Create a new pull request in a GitHub repository", inputSchema: zodToJsonSchema(pulls.CreatePullRequestSchema), },
- src/operations/pulls.ts:90-92 (helper)Internal extended schema used in the tool dispatcher to parse arguments including the GitHub PAT.export const _CreatePullRequestSchema = CreatePullRequestSchema.extend({ github_pat: z.string().describe("GitHub Personal Access Token"), });
- src/index.ts:446-453 (handler)Tool dispatcher case in the main CallToolRequest handler that parses arguments with internal schema, extracts PAT, calls the core createPullRequest handler, and formats response.case "create_pull_request": { const argsWithPat = pulls._CreatePullRequestSchema.parse(params.arguments); const { github_pat, ...args } = argsWithPat; const pullRequest = await pulls.createPullRequest(github_pat, args); return { content: [{ type: "text", text: JSON.stringify(pullRequest, null, 2) }], }; }