Skip to main content
Glama
pdogra1299
by pdogra1299

merge_pull_request

Merge pull requests in Bitbucket repositories using specified merge strategies, close source branches, and customize commit messages for streamlined PR lifecycle management.

Instructions

Merge a pull request

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
close_source_branchNoWhether to close source branch after merge (optional)
commit_messageNoCustom merge commit message (optional)
merge_strategyNoMerge strategy: merge-commit, squash, fast-forward (optional)
pull_request_idYesPull request ID
repositoryYesRepository slug (e.g., "my-repo")
workspaceYesBitbucket workspace/project key (e.g., "PROJ")

Implementation Reference

  • Core handler function that executes the merge_pull_request tool by calling the appropriate Bitbucket API endpoint for both Cloud and Server instances, handling parameters like merge strategy, close source branch, and custom commit message.
    async handleMergePullRequest(args: any) {
      if (!isMergePullRequestArgs(args)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Invalid arguments for merge_pull_request'
        );
      }
    
      const { workspace, repository, pull_request_id, merge_strategy, close_source_branch, commit_message } = args;
    
      try {
        let apiPath: string;
        let requestBody: any = {};
    
        if (this.apiClient.getIsServer()) {
          // Bitbucket Server API
          apiPath = `/rest/api/1.0/projects/${workspace}/repos/${repository}/pull-requests/${pull_request_id}/merge`;
          
          // Get current PR version
          const prPath = `/rest/api/1.0/projects/${workspace}/repos/${repository}/pull-requests/${pull_request_id}`;
          const currentPr = await this.apiClient.makeRequest<any>('get', prPath);
          
          requestBody.version = currentPr.version;
          if (commit_message) {
            requestBody.message = commit_message;
          }
        } else {
          // Bitbucket Cloud API
          apiPath = `/repositories/${workspace}/${repository}/pullrequests/${pull_request_id}/merge`;
          
          if (merge_strategy) {
            requestBody.merge_strategy = merge_strategy;
          }
          if (close_source_branch !== undefined) {
            requestBody.close_source_branch = close_source_branch;
          }
          if (commit_message) {
            requestBody.message = commit_message;
          }
        }
    
        const result = await this.apiClient.makeRequest<any>('post', apiPath, requestBody);
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                message: 'Pull request merged successfully',
                merge_commit: this.apiClient.getIsServer() ? result.properties?.mergeCommit : result.merge_commit?.hash,
                pull_request_id
              }, null, 2),
            },
          ],
        };
      } catch (error) {
        return this.apiClient.handleApiError(error, `merging pull request ${pull_request_id} in ${workspace}/${repository}`);
      }
    }
    
    private async fetchPullRequestComments(
  • src/index.ts:106-107 (registration)
    Tool registration in the main MCP server switch statement, routing calls to the PullRequestHandlers.
    case 'merge_pull_request':
      return this.pullRequestHandlers.handleMergePullRequest(request.params.arguments);
  • MCP tool schema definition providing input validation schema, description, and parameters for the merge_pull_request tool.
    {
      name: 'merge_pull_request',
      description: 'Merge a pull request',
      inputSchema: {
        type: 'object',
        properties: {
          workspace: {
            type: 'string',
            description: 'Bitbucket workspace/project key (e.g., "PROJ")',
          },
          repository: {
            type: 'string',
            description: 'Repository slug (e.g., "my-repo")',
          },
          pull_request_id: {
            type: 'number',
            description: 'Pull request ID',
          },
          merge_strategy: {
            type: 'string',
            description: 'Merge strategy: merge-commit, squash, fast-forward (optional)',
            enum: ['merge-commit', 'squash', 'fast-forward'],
          },
          close_source_branch: {
            type: 'boolean',
            description: 'Whether to close source branch after merge (optional)',
          },
          commit_message: {
            type: 'string',
            description: 'Custom merge commit message (optional)',
          },
        },
        required: ['workspace', 'repository', 'pull_request_id'],
      },
    },
  • Type guard function for validating merge_pull_request input arguments, used within the handler for runtime checks.
    export const isMergePullRequestArgs = (
      args: any
    ): args is {
      workspace: string;
      repository: string;
      pull_request_id: number;
      merge_strategy?: string;
      close_source_branch?: boolean;
      commit_message?: string;
    } =>
      typeof args === 'object' &&
      args !== null &&
      typeof args.workspace === 'string' &&
      typeof args.repository === 'string' &&
      typeof args.pull_request_id === 'number' &&
      (args.merge_strategy === undefined || typeof args.merge_strategy === 'string') &&
      (args.close_source_branch === undefined || typeof args.close_source_branch === 'boolean') &&
      (args.commit_message === undefined || typeof args.commit_message === 'string');
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but only states the action without behavioral details. It doesn't disclose that merging is a destructive write operation, potential permission requirements, side effects (e.g., closing the PR), or error conditions. This is inadequate for a mutation tool with zero annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, direct sentence with no wasted words. It's front-loaded and efficiently conveys the core action, making it easy to scan and understand quickly. Every word earns its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given this is a complex mutation tool with no annotations and no output schema, the description is incomplete. It lacks critical context: what merging does (e.g., integrates changes, closes PR), success/failure behaviors, or return values. For a tool with 6 parameters and significant impact, more detail is needed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so parameters are well-documented in the schema. The description adds no additional meaning beyond the schema, such as explaining how parameters interact (e.g., merge_strategy affects commit_message). Baseline 3 is appropriate since the schema handles parameter documentation effectively.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states the action ('merge') and resource ('a pull request'), which is clear but basic. It doesn't differentiate from siblings like 'approve_pull_request' or 'update_pull_request', which are related but distinct operations. The purpose is understandable but lacks specificity about what merging entails.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., pull request must be approved or in a mergeable state), exclusions, or how it relates to siblings like 'update_pull_request' for modifying PRs. The description offers no context for decision-making.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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

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