create-pull-request
Create a new pull request in a GitHub repository by specifying the source and target branches, title, and description to propose code changes for review.
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/tools/pull-requests.ts:157-205 (handler)The core handler function that parses the input arguments using CreatePullRequestSchema, calls the GitHub Octokit API to create the pull request, processes the response, and handles errors with tryCatchAsync.export async function createPullRequest(args: unknown): Promise<any> { const { owner, repo, title, head, base, body, draft, maintainer_can_modify } = CreatePullRequestSchema.parse(args); const github = getGitHubApi(); return tryCatchAsync(async () => { const { data } = await github.getOctokit().pulls.create({ owner, repo, title, head, base, body, draft, maintainer_can_modify, }); return { id: data.id, number: data.number, title: data.title, state: data.state, user: data.user ? { login: data.user.login, id: data.user.id, } : null, created_at: data.created_at, updated_at: data.updated_at, head: { ref: data.head.ref, sha: data.head.sha, repo: data.head.repo ? { name: data.head.repo.name, full_name: data.head.repo.full_name, } : null, }, base: { ref: data.base.ref, sha: data.base.sha, repo: data.base.repo ? { name: data.base.repo.name, full_name: data.base.repo.full_name, } : null, }, body: data.body, draft: data.draft, url: data.html_url, }; }, 'Failed to create pull request'); }
- src/utils/validation.ts:129-136 (schema)Zod schema used for input validation in the createPullRequest handler. Extends OwnerRepoSchema with PR-specific fields.export const CreatePullRequestSchema = OwnerRepoSchema.extend({ title: z.string().min(1, 'Pull request title is required'), head: z.string().min(1, 'Head branch is required'), base: z.string().min(1, 'Base branch is required'), body: z.string().optional(), draft: z.boolean().optional(), maintainer_can_modify: z.boolean().optional(), });
- src/server.ts:766-808 (registration)Tool registration entry in the listTools handler, defining the tool's name, description, and input schema for MCP protocol compliance.{ name: 'create-pull-request', description: 'Create a new pull request in a GitHub repository', inputSchema: { type: 'object', properties: { owner: { type: 'string', description: 'Repository owner (username or organization)', }, repo: { type: 'string', description: 'Repository name', }, title: { type: 'string', description: 'Pull request title', }, body: { type: 'string', description: 'Pull request body/description', }, head: { type: 'string', description: 'The name of the branch where your changes are implemented', }, base: { type: 'string', description: 'The name of the branch you want the changes pulled into', }, draft: { type: 'boolean', description: 'Whether to create the pull request as a draft', }, maintainer_can_modify: { type: 'boolean', description: 'Whether maintainers can modify the pull request', }, }, required: ['owner', 'repo', 'title', 'head', 'base'], additionalProperties: false, }, },
- src/server.ts:1232-1234 (registration)Dispatch case in the CallToolRequest handler switch statement that invokes the createPullRequest function.case 'create-pull-request': result = await createPullRequest(parsedArgs); break;