create_pull_request
Create a new pull request by specifying repository, branches, title, and description to propose code changes for review.
Instructions
Create a new pull request in a GitHub repository.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| owner | Yes | Repository owner | |
| repo | Yes | Repository name | |
| title | Yes | PR title | |
| body | No | PR description | |
| head | Yes | Branch containing changes | |
| base | Yes | Branch to merge into | |
| draft | No | Create as draft PR | |
| maintainer_can_modify | No | Allow maintainer edits |
Implementation Reference
- src/tools/pullrequests.ts:620-672 (registration)Registration of the 'create_pull_request' tool on the MCP server via server.tool(), including the schema definition and async handler function.
// Tool: Create Pull Request server.tool( "create_pull_request", "Create a new pull request in a GitHub repository.", { owner: z.string().describe("Repository owner"), repo: z.string().describe("Repository name"), title: z.string().describe("PR title"), body: z.string().optional().describe("PR description"), head: z.string().describe("Branch containing changes"), base: z.string().describe("Branch to merge into"), draft: z.boolean().optional().describe("Create as draft PR"), maintainer_can_modify: z .boolean() .optional() .describe("Allow maintainer edits"), }, async ({ owner, repo, title, body, head, base, draft, maintainer_can_modify, }) => { try { const response = await octokit.rest.pulls.create({ owner, repo, title, body, head, base, draft, maintainer_can_modify, }) const pr = response.data let text = `PR created: **#${pr.number}: ${pr.title}**\n` text += `URL: ${pr.html_url}\n` text += `State: ${pr.state}${pr.draft ? " (draft)" : ""}\n` text += `Branch: ${pr.head.label} -> ${pr.base.label}\n` return { content: [{ type: "text", text }], } } catch (e: any) { return { content: [{ type: "text", text: `Error: ${e.message}` }], } } }, ) - src/tools/pullrequests.ts:637-671 (handler)Handler function that executes the PR creation via octokit.rest.pulls.create() and formats the success/error response.
async ({ owner, repo, title, body, head, base, draft, maintainer_can_modify, }) => { try { const response = await octokit.rest.pulls.create({ owner, repo, title, body, head, base, draft, maintainer_can_modify, }) const pr = response.data let text = `PR created: **#${pr.number}: ${pr.title}**\n` text += `URL: ${pr.html_url}\n` text += `State: ${pr.state}${pr.draft ? " (draft)" : ""}\n` text += `Branch: ${pr.head.label} -> ${pr.base.label}\n` return { content: [{ type: "text", text }], } } catch (e: any) { return { content: [{ type: "text", text: `Error: ${e.message}` }], } } }, - src/tools/pullrequests.ts:624-636 (schema)Zod schema defining the input parameters for the create_pull_request tool.
{ owner: z.string().describe("Repository owner"), repo: z.string().describe("Repository name"), title: z.string().describe("PR title"), body: z.string().optional().describe("PR description"), head: z.string().describe("Branch containing changes"), base: z.string().describe("Branch to merge into"), draft: z.boolean().optional().describe("Create as draft PR"), maintainer_can_modify: z .boolean() .optional() .describe("Allow maintainer edits"), }, - src/tools/pullrequests.ts:5-5 (helper)Helper export function that registers all pull request tools (including create_pull_request) on the server.
export function registerPullRequestTools(server: McpServer, octokit: Octokit) { - src/index.ts:18-19 (registration)Top-level registration of pull request tools from the main index entry point.
registerPullRequestTools(server, octokit) registerRepositoryResource(server, octokit)