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' }); }

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