Skip to main content
Glama
Korfu
by Korfu

create_pull_request

Create a new pull request in Bitbucket to merge code changes from a source branch to a destination branch, facilitating code review and collaboration.

Instructions

Create a new pull request.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repository_nameYesName of the repository (repo slug)
titleYesThe title of the pull request.
source_branchYesThe source branch of the pull request.
destination_branchNoThe destination branch of the pull request.
descriptionNoThe description of the pull request.

Implementation Reference

  • The async handler function that performs the actual pull request creation using the Bitbucket API, handles errors, and formats the response.
    export async function createPullRequest(
      axiosInstance: AxiosInstance,
      config: Config,
      args: any
    ): Promise<{ content: Array<{ type: string; text: string }> }> {
      try {
        const {
          repository_name,
          title,
          source_branch,
          destination_branch,
          description,
        } = args;
    
        if (!repository_name || !title || !source_branch) {
          throw new Error(
            'Repository name, title, and source branch are required'
          );
        }
    
        console.error(`Creating pull request in repository: ${repository_name}`);
    
        const response = await axiosInstance.post<PullRequest>(
          `/repositories/${config.BITBUCKET_WORKSPACE}/${repository_name}/pullrequests`,
          {
            title: title,
            source: {
              branch: {
                name: source_branch,
              },
            },
            destination: {
              branch: {
                name: destination_branch,
              },
            },
            description: description,
          }
        );
    
        const pr = response.data;
        const prDetails = `**Successfully created PR #${pr.id}: ${pr.title}**
    - State: ${pr.state}
    - Author: ${pr.author.display_name}
    - Source: ${pr.source.branch.name}
    - Destination: ${pr.destination.branch.name}
    - URL: ${pr.links.html.href}`;
    
        return {
          content: [
            {
              type: 'text',
              text: prDetails,
            },
          ],
        };
      } catch (error) {
        console.error('Error creating pull request:', error);
        return {
          content: [
            {
              type: 'text',
              text: `Error creating pull request: ${
                error instanceof Error ? error.message : 'Unknown error'
              }`,
            },
          ],
        };
      }
    } 
  • Tool definition including name, description, and input schema for validating parameters like repository_name, title, source_branch, etc.
    export const createPullRequestTool = {
      name: 'create_pull_request',
      description: 'Create a new pull request.',
      inputSchema: {
        type: 'object',
        properties: {
          repository_name: {
            type: 'string',
            description: 'Name of the repository (repo slug)',
          },
          title: {
            type: 'string',
            description: 'The title of the pull request.',
          },
          source_branch: {
            type: 'string',
            description: 'The source branch of the pull request.',
          },
          destination_branch: {
            type: 'string',
            description: 'The destination branch of the pull request.',
          },
          description: {
            type: 'string',
            description: 'The description of the pull request.',
          },
        },
        required: ['repository_name', 'title', 'source_branch'],
      },
    };
  • src/index.ts:111-136 (registration)
    Registers createPullRequestTool in the list of tools returned by ListToolsRequestSchema handler.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: [
        // Repositories
        listRepositoriesTool,
        getRepositoryDetailsTool,
        // Commits
        listCommitsTool,
        getCommitTool,
        // Branching Model
        updateRepositoryBranchingModelSettingsTool,
        updateProjectBranchingModelSettingsTool,
        listBranchRestrictionsTool,
        getBranchRestrictionTool,
        // Projects
        getProjectTool,
        listDefaultReviewersTool,
        // Pull Requests
        listPullRequestsTool,
        getPullRequestTool,
        createPullRequestTool,
        updatePullRequestTool,
        // Workspaces
        listWorkspacesTool,
      ],
    }));
  • src/index.ts:142-173 (registration)
    Maps the 'create_pull_request' tool name to the createPullRequest handler function in the CallToolRequestSchema handler.
    const handlers: Record<
      string,
      (
        axiosInstance: AxiosInstance,
        config: Config,
        args: any
      ) => Promise<{ content: Array<{ type: string; text: string }> }>
    > = {
      // Repositories
      list_repositories: listRepositories,
      get_repository_details: getRepositoryDetails,
      // Commits
      list_commits: listCommits,
      get_commit: getCommit,
      // Branching Model
      update_repository_branching_model_settings:
        updateRepositoryBranchingModelSettings,
      update_project_branching_model_settings:
        updateProjectBranchingModelSettings,
      list_branch_restrictions: listBranchRestrictions,
      get_branch_restriction: getBranchRestriction,
      // Projects
      get_project: getProject,
      list_default_reviewers: listDefaultReviewers,
      // Pull Requests
      list_pull_requests: listPullRequests,
      get_pull_request: getPullRequest,
      create_pull_request: createPullRequest,
      update_pull_request: updatePullRequest,
      // Workspaces
      list_workspaces: listWorkspaces,
    };

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/Korfu/mcp-bitbucket'

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