create_pull_request
Generate a pull request in a GitHub repository by specifying owner, repo, title, head, and base branches. Manage draft status and maintainer permissions for streamlined code collaboration.
Instructions
Create a new pull request in a GitHub repository
Input 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 |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"base": {
"description": "The name of the branch you want the changes pulled into",
"type": "string"
},
"body": {
"description": "Pull request body/description",
"type": "string"
},
"draft": {
"description": "Whether to create the pull request as a draft",
"type": "boolean"
},
"head": {
"description": "The name of the branch where your changes are implemented",
"type": "string"
},
"maintainer_can_modify": {
"description": "Whether maintainers can modify the pull request",
"type": "boolean"
},
"owner": {
"description": "Repository owner (username or organization)",
"type": "string"
},
"repo": {
"description": "Repository name",
"type": "string"
},
"title": {
"description": "Pull request title",
"type": "string"
}
},
"required": [
"owner",
"repo",
"title",
"head",
"base"
],
"type": "object"
}
Implementation Reference
- index.ts:276-282 (handler)MCP server tool handler for create_pull_request: parses arguments using the schema and delegates to the createPullRequest helper function, returning the result as text content.case "create_pull_request": { const args = pulls.CreatePullRequestSchema.parse(request.params.arguments); const pullRequest = await pulls.createPullRequest(args); return { content: [{ type: "text", text: JSON.stringify(pullRequest, null, 2) }], }; }
- operations/pulls.ts:79-88 (schema)Zod input schema defining the parameters required to create a pull request, used for validation in both registration and handler.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") });
- index.ts:103-107 (registration)Registers the create_pull_request tool in the MCP server's list of tools, specifying name, description, and input schema.{ name: "create_pull_request", description: "Create a new pull request in a GitHub repository", inputSchema: zodToJsonSchema(pulls.CreatePullRequestSchema), },
- operations/pulls.ts:163-177 (helper)Helper function implementing the core logic: extracts owner/repo, makes POST request to GitHub API to create the pull request, and parses the response.export async function createPullRequest( params: z.infer<typeof CreatePullRequestSchema> ): Promise<z.infer<typeof GitHubPullRequestSchema>> { const { owner, repo, ...options } = CreatePullRequestSchema.parse(params); const response = await githubRequest( `https://api.github.com/repos/${owner}/${repo}/pulls`, { method: "POST", body: options, } ); return GitHubPullRequestSchema.parse(response); }