Skip to main content
Glama
garc33

Bitbucket Server MCP

by garc33

merge_pull_request

Merge approved pull requests into target branches using specified strategies like merge-commit, squash, or fast-forward to integrate reviewed code changes.

Instructions

Merge an approved pull request into the target branch. Use this when a PR has been reviewed, approved, and is ready to be integrated. Choose the appropriate merge strategy based on your team's workflow and repository history preferences.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectNoBitbucket project key. If omitted, uses BITBUCKET_DEFAULT_PROJECT environment variable.
repositoryYesRepository slug containing the pull request.
prIdYesPull request ID to merge.
messageNoCustom merge commit message. If not provided, uses default merge message format.
strategyNoMerge strategy: "merge-commit" creates a merge commit preserving branch history, "squash" combines all commits into one, "fast-forward" moves the branch pointer without creating a merge commit.

Implementation Reference

  • The primary handler function that executes the merge_pull_request tool logic by making a POST request to Bitbucket's merge endpoint with optional message and strategy.
    private async mergePullRequest(params: PullRequestParams, options: MergeOptions = {}) {
      const { project, repository, prId } = params;
      
      if (!project || !repository || !prId) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Project, repository, and prId are required'
        );
      }
      
      const { message, strategy = 'merge-commit' } = options;
      
      const response = await this.api.post(
        `/projects/${project}/repos/${repository}/pull-requests/${prId}/merge`,
        {
          version: -1,
          message,
          strategy
        }
      );
    
      return {
        content: [{ type: 'text', text: JSON.stringify(response.data, null, 2) }]
      };
    }
  • src/index.ts:223-241 (registration)
    Tool registration in the MCP server's tool list, defining the name, description, and input schema for merge_pull_request.
    {
      name: 'merge_pull_request',
      description: 'Merge an approved pull request into the target branch. Use this when a PR has been reviewed, approved, and is ready to be integrated. Choose the appropriate merge strategy based on your team\'s workflow and repository history preferences.',
      inputSchema: {
        type: 'object',
        properties: {
          project: { type: 'string', description: 'Bitbucket project key. If omitted, uses BITBUCKET_DEFAULT_PROJECT environment variable.' },
          repository: { type: 'string', description: 'Repository slug containing the pull request.' },
          prId: { type: 'number', description: 'Pull request ID to merge.' },
          message: { type: 'string', description: 'Custom merge commit message. If not provided, uses default merge message format.' },
          strategy: {
            type: 'string',
            enum: ['merge-commit', 'squash', 'fast-forward'],
            description: 'Merge strategy: "merge-commit" creates a merge commit preserving branch history, "squash" combines all commits into one, "fast-forward" moves the branch pointer without creating a merge commit.'
          }
        },
        required: ['repository', 'prId']
      }
    },
  • Input schema definition for the merge_pull_request tool, specifying parameters like project, repository, prId, message, and strategy.
    inputSchema: {
      type: 'object',
      properties: {
        project: { type: 'string', description: 'Bitbucket project key. If omitted, uses BITBUCKET_DEFAULT_PROJECT environment variable.' },
        repository: { type: 'string', description: 'Repository slug containing the pull request.' },
        prId: { type: 'number', description: 'Pull request ID to merge.' },
        message: { type: 'string', description: 'Custom merge commit message. If not provided, uses default merge message format.' },
        strategy: {
          type: 'string',
          enum: ['merge-commit', 'squash', 'fast-forward'],
          description: 'Merge strategy: "merge-commit" creates a merge commit preserving branch history, "squash" combines all commits into one, "fast-forward" moves the branch pointer without creating a merge commit.'
        }
      },
      required: ['repository', 'prId']
    }
  • Dispatch handler in the main CallToolRequestSchema switch statement that prepares parameters and calls the mergePullRequest method.
    case 'merge_pull_request': {
      const mergePrParams: PullRequestParams = {
        project: getProject(args.project as string),
        repository: args.repository as string,
        prId: args.prId as number
      };
      return await this.mergePullRequest(mergePrParams, {
        message: args.message as string,
        strategy: args.strategy as 'merge-commit' | 'squash' | 'fast-forward'
      });
    }
Behavior3/5

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

With no annotations provided, the description carries the full burden. It clearly indicates this is a write/mutation operation ('merge'), but doesn't disclose permissions needed, whether the merge is reversible, rate limits, or what happens on failure. It mentions strategy selection but doesn't explain default behavior if strategy is omitted.

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?

Two well-structured sentences with zero waste. First sentence states purpose and prerequisites, second provides strategic guidance. Every word earns its place, and the most critical information (what it does and when to use it) is front-loaded.

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

Completeness3/5

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

For a mutation tool with no annotations and no output schema, the description does well on purpose and guidelines but lacks behavioral details about permissions, reversibility, error conditions, or return values. Given the complexity of merging code changes, more transparency about what happens during execution would be beneficial.

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 the schema already documents all 5 parameters thoroughly. The description doesn't add any parameter-specific information beyond what's in the schema, but doesn't need to since schema coverage is complete. Baseline 3 is appropriate when schema does the heavy lifting.

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

Purpose5/5

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

The description clearly states the specific action ('merge'), the resource ('an approved pull request'), and the outcome ('into the target branch'). It distinguishes this tool from siblings like 'decline_pull_request' or 'create_pull_request' by focusing on the final integration step after approval.

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

Usage Guidelines5/5

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

Explicitly states when to use this tool: 'when a PR has been reviewed, approved, and is ready to be integrated.' It also provides guidance on choosing the merge strategy based on team workflow and repository history, offering contextual decision-making criteria.

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

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

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