Skip to main content
Glama

create_pull_request

Create a pull request to merge code changes from one branch to another in a GitHub repository.

Instructions

Create a new pull request in a GitHub repository

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ownerYesRepository owner (username or organization)
repoYesRepository name
titleYesPull request title
bodyNoPull request body/description
headYesThe name of the branch where your changes are implemented
baseYesThe name of the branch you want the changes pulled into
draftNoWhether to create the pull request as a draft
maintainer_can_modifyNoWhether maintainers can modify the pull request

Implementation Reference

  • The core handler function that executes the create_pull_request tool logic by parsing inputs, making a POST request to GitHub's /pulls endpoint, and parsing the response.
    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);
    }
  • The top-level dispatcher handler in the MCP server that handles the create_pull_request tool call, parses arguments with PAT, delegates to pulls.createPullRequest, and formats the 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) }],
      };
    }
  • Zod schemas defining the input parameters for create_pull_request: CreatePullRequestSchema (public inputs) and _CreatePullRequestSchema (with github_pat for internal use).
    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")
    });
    
    export const _CreatePullRequestSchema = CreatePullRequestSchema.extend({
      github_pat: z.string().describe("GitHub Personal Access Token"),
    });
  • src/index.ts:108-112 (registration)
    Tool registration in the MCP server's listTools response, specifying name, description, and input schema.
    {
      name: "create_pull_request",
      description: "Create a new pull request in a GitHub repository",
      inputSchema: zodToJsonSchema(pulls.CreatePullRequestSchema),
    },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/MissionSquad/mcp-github'

If you have feedback or need assistance with the MCP directory API, please join our Discord server